Skip to content

Commit

Permalink
Add vault legal text
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Oct 31, 2024
1 parent ca7231c commit 9b36889
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 6 deletions.
2 changes: 1 addition & 1 deletion v4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ext {
compileSdkVersion = 34

// App dependencies
abacusVersion = '1.13.14'
abacusVersion = '1.13.17'
carteraVersion = '0.1.15'
kollectionsVersion = '2.0.16'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ object VaultRoutes {
const val withdraw = "vault/withdraw"
const val confirmation = "vault/confirmation"
const val history = "vault/history"
const val tos = "vault/tos"
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ class DydxOrderDetailsViewModel @Inject constructor(
},
),
)
} else null,
} else {
null
},
).filterNotNull(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import exchange.dydx.trading.feature.vault.DydxVaultView
import exchange.dydx.trading.feature.vault.depositwithdraw.DydxVaultDepositWithdrawView
import exchange.dydx.trading.feature.vault.depositwithdraw.confirmation.DydxVaultConfirmationView
import exchange.dydx.trading.feature.vault.history.DydxVaultHistoryView
import exchange.dydx.trading.feature.vault.tos.DydxVaultTosView
import exchange.dydx.utilities.utils.Logging

fun NavGraphBuilder.vaultGraph(
Expand Down Expand Up @@ -58,4 +59,12 @@ fun NavGraphBuilder.vaultGraph(
) { navBackStackEntry ->
DydxVaultHistoryView.Content(Modifier)
}

dydxComposable(
router = appRouter,
route = VaultRoutes.tos,
deepLinks = appRouter.deeplinks(VaultRoutes.tos),
) { navBackStackEntry ->
DydxVaultTosView.Content(Modifier)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.dydxstatemanager.AbacusStateManagerProtocol
import exchange.dydx.trading.common.DydxViewModel
import exchange.dydx.trading.common.navigation.DydxRouter
import exchange.dydx.trading.common.navigation.VaultRoutes
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import javax.inject.Inject
Expand All @@ -24,10 +25,10 @@ class DydxVaultHeaderViewModel @Inject constructor(
localizer = localizer,
dydxChainLogoUrl = abacusStateManager.environment?.chainLogo,
learnMoreAction = {
val url = abacusStateManager.environment?.links?.vaultLearnMore
if (url != null) {
router.navigateTo(url)
}
router.navigateTo(
route = VaultRoutes.tos,
presentation = DydxRouter.Presentation.Modal,
)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package exchange.dydx.trading.feature.vault.tos

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.ClickableText
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.platformui.components.buttons.PlatformButton
import exchange.dydx.platformui.components.buttons.PlatformButtonState
import exchange.dydx.platformui.components.dividers.PlatformDivider
import exchange.dydx.platformui.components.icons.PlatformImage
import exchange.dydx.platformui.compose.collectAsStateWithLifecycle
import exchange.dydx.platformui.designSystem.theme.ThemeColor
import exchange.dydx.platformui.designSystem.theme.ThemeFont
import exchange.dydx.platformui.designSystem.theme.ThemeShapes
import exchange.dydx.platformui.designSystem.theme.dydxDefault
import exchange.dydx.platformui.designSystem.theme.themeColor
import exchange.dydx.platformui.designSystem.theme.themeFont
import exchange.dydx.platformui.theme.DydxThemedPreviewSurface
import exchange.dydx.platformui.theme.MockLocalizer
import exchange.dydx.trading.common.component.DydxComponent
import exchange.dydx.trading.feature.shared.views.HeaderViewCloseBotton

@Preview
@Composable
fun Preview_DydxVaultTosView() {
DydxThemedPreviewSurface {
DydxVaultTosView.Content(Modifier, DydxVaultTosView.ViewState.preview)
}
}

object DydxVaultTosView : DydxComponent {
data class ViewState(
val localizer: LocalizerProtocol,
val operatorDesc: String? = null,
val operatorLearnMore: String? = null,
val vaultDesc: String? = null,
val operatorAction: (() -> Unit)? = null,
val vaultAction: (() -> Unit)? = null,
val ctaButtonAction: (() -> Unit)? = null,
val dydxChainLogoUrl: String? = null,
) {
companion object {
val preview = ViewState(
localizer = MockLocalizer(),
operatorDesc = "Operator description",
vaultDesc = "Vault description",
operatorLearnMore = "Learn more about operator",
)
}
}

@Composable
override fun Content(modifier: Modifier) {
val viewModel: DydxVaultTosViewModel = hiltViewModel()

val state = viewModel.state.collectAsStateWithLifecycle(initialValue = null).value
Content(modifier, state)
}

@Composable
fun Content(modifier: Modifier, state: ViewState?) {
if (state == null) {
return
}

Column(
modifier = modifier
.fillMaxSize()
.themeColor(ThemeColor.SemanticColor.layer_3),
verticalArrangement = Arrangement.spacedBy(ThemeShapes.VerticalPadding),
) {
HeaderContent(Modifier, state)

PlatformDivider()

Column(
modifier = Modifier
.padding(ThemeShapes.HorizontalPadding),
verticalArrangement = Arrangement.spacedBy(ThemeShapes.VerticalPadding),
) {
Text(
text = state.vaultDesc ?: "",
modifier = Modifier,
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.small)
.themeColor(ThemeColor.SemanticColor.text_secondary),
)

ClickableText(
modifier = Modifier,
text = buildAnnotatedString {
append(state.localizer.localize("APP.VAULTS.LEARN_MORE_ABOUT_MEGAVAULT"))
},
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.small)
.themeColor(ThemeColor.SemanticColor.color_purple),
onClick = {
state.vaultAction?.invoke()
},
)
}

Column(
modifier = Modifier
.padding(ThemeShapes.HorizontalPadding),
verticalArrangement = Arrangement.spacedBy(ThemeShapes.VerticalPadding),
) {
Text(
text = state.operatorDesc ?: "",
modifier = Modifier,
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.small)
.themeColor(ThemeColor.SemanticColor.text_secondary),
)

ClickableText(
modifier = Modifier,
text = buildAnnotatedString {
append(state.operatorLearnMore ?: "")
},
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.small)
.themeColor(ThemeColor.SemanticColor.color_purple),
onClick = {
state.operatorAction?.invoke()
},
)
}

Spacer(modifier = Modifier.weight(1f))

PlatformButton(
modifier = modifier.fillMaxWidth().padding(ThemeShapes.HorizontalPadding),
text = state.localizer.localize("APP.GENERAL.OK"),
state = PlatformButtonState.Primary,
) {
state.ctaButtonAction?.invoke()
}
}
}

@Composable
private fun HeaderContent(modifier: Modifier, state: ViewState) {
Row(
modifier
.fillMaxWidth()
.height(72.dp)
.padding(vertical = ThemeShapes.VerticalPadding)
.padding(horizontal = ThemeShapes.HorizontalPadding),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(ThemeShapes.HorizontalPadding),
) {
PlatformImage(
icon = state.dydxChainLogoUrl,
modifier = Modifier
.size(40.dp)
.clip(CircleShape),
)

Text(
text = state.localizer.localize("APP.VAULTS.MEGAVAULT"),
modifier = Modifier,
style = TextStyle.dydxDefault
.themeFont(
fontType = ThemeFont.FontType.plus,
fontSize = ThemeFont.FontSize.extra,
)
.themeColor(ThemeColor.SemanticColor.text_primary),
)

Spacer(modifier = Modifier.weight(1f))

HeaderViewCloseBotton(closeAction = state.ctaButtonAction)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package exchange.dydx.trading.feature.vault.tos

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.dydxstatemanager.AbacusStateManagerProtocol
import exchange.dydx.dydxstatemanager.localizeWithParams
import exchange.dydx.trading.common.DydxViewModel
import exchange.dydx.trading.common.navigation.DydxRouter
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import javax.inject.Inject

@HiltViewModel
class DydxVaultTosViewModel @Inject constructor(
private val localizer: LocalizerProtocol,
private val abacusStateManager: AbacusStateManagerProtocol,
private val router: DydxRouter,
) : ViewModel(), DydxViewModel {

val state: Flow<DydxVaultTosView.ViewState?> = flowOf(createViewState())

private fun createViewState(): DydxVaultTosView.ViewState {
val operator = abacusStateManager.environment?.megavaultOperatorName ?: "-"
val vaultLearnMoreUrl = abacusStateManager.environment?.links?.vaultLearnMore
val operatorLearnMoreUrl = abacusStateManager.environment?.links?.vaultOperatorLearnMore
return DydxVaultTosView.ViewState(
localizer = localizer,
vaultDesc = localizer.localize("APP.VAULTS.VAULT_DESCRIPTION"),
operatorDesc = localizer.localizeWithParams(
"APP.VAULTS.VAULT_OPERATOR_DESCRIPTION",
params = mapOf("OPERATOR_NAME" to operator),
),
operatorLearnMore = localizer.localizeWithParams(
"APP.VAULTS.LEARN_MORE_ABOUT_OPERATOR",
params = mapOf("OPERATOR_NAME" to operator),
),
dydxChainLogoUrl = abacusStateManager.environment?.chainLogo,
vaultAction = {
if (vaultLearnMoreUrl != null) {
router.navigateTo(vaultLearnMoreUrl)
}
},
operatorAction = {
if (operatorLearnMoreUrl != null) {
router.navigateTo(operatorLearnMoreUrl)
}
},
ctaButtonAction = {
router.navigateBack()
},
)
}
}

0 comments on commit 9b36889

Please sign in to comment.