Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOB-537: Add CEX transfer warning. #144

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,24 @@ object DydxMarketResourcesView : DydxComponent {
) {
HeaderView(state = state)

Spacer(modifier = Modifier.padding(ThemeShapes.VerticalPadding))

Text(
text = state.sharedMarketViewState?.primaryDescription ?: "",
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.base),
)

Spacer(modifier = Modifier.padding(ThemeShapes.VerticalPadding))
state.sharedMarketViewState?.primaryDescription?.let {
Spacer(modifier = Modifier.padding(ThemeShapes.VerticalPadding))
Text(
text = it,
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.base),
)
}

Text(
text = state.sharedMarketViewState?.secondaryDescription ?: "",
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.base)
.themeColor(ThemeColor.SemanticColor.text_tertiary),
)
state.sharedMarketViewState?.secondaryDescription?.let {
Spacer(modifier = Modifier.padding(ThemeShapes.VerticalPadding))
Text(
text = it,
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.base)
.themeColor(ThemeColor.SemanticColor.text_tertiary),
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
Expand Down Expand Up @@ -102,7 +104,7 @@ object DydxReceiptView : DydxComponent {

Box(
modifier = modifier
.height(state.height ?: 210.dp)
.heightIn(max = state.height ?: 210.dp)
.fillMaxWidth()
.padding(horizontal = state.padding ?: ThemeShapes.HorizontalPadding)
.background(
Expand All @@ -113,8 +115,10 @@ object DydxReceiptView : DydxComponent {
LazyColumn(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = ThemeShapes.HorizontalPadding)
.padding(vertical = ThemeShapes.VerticalPadding * 2),
.padding(
horizontal = ThemeShapes.HorizontalPadding,
vertical = ThemeShapes.VerticalPadding * 2,
),
verticalArrangement = Arrangement.spacedBy(ThemeShapes.VerticalPadding),
) {
items(state.lineTypes, key = { it }) { lineType ->
Expand Down Expand Up @@ -180,6 +184,10 @@ object DydxReceiptView : DydxComponent {
}
}
}

item {
Spacer(modifier = Modifier.height(ThemeShapes.VerticalPadding))
prashanDYDX marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ data class SharedMarketViewState(
coloringOption = SignedAmountView.ColoringOption.AllText,
),
primaryDescription = asset?.resources?.primaryDescriptionKey?.let { key ->
localizer.localize("APP.$key")
localizer.localize("APP.$key").takeUnless { it.startsWith("APP.__ASSETS.") }
},
secondaryDescription = asset?.resources?.secondaryDescriptionKey?.let { key ->
localizer.localize("APP.$key")
localizer.localize("APP.$key").takeUnless { it.startsWith("APP.__ASSETS.") }
},
websiteUrl = asset?.resources?.websiteLink,
whitepaperUrl = asset?.resources?.whitepaperLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ object TransferAmountBox {
return
}

Column {
InputFieldScaffold(modifier.zIndex(1f)) {
Column(modifier) {
InputFieldScaffold(Modifier.zIndex(1f)) {
TopContent(modifier, state)
}
val shape = RoundedCornerShape(0.dp, 0.dp, 8.dp, 8.dp)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package exchange.dydx.trading.feature.transfer.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.platformui.components.alerts.PlatformInlineAlert
import exchange.dydx.platformui.components.inputs.PlatformTextInput
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.feature.shared.scaffolds.InputFieldScaffold

@Preview
@Composable
fun Preview_TransferMemoBox() {
DydxThemedPreviewSurface {
TransferMemoBox.Content(Modifier, TransferMemoBox.ViewState.preview)
}
}

object TransferMemoBox {
data class ViewState(
val localizer: LocalizerProtocol,
val value: String? = null,
val showCexWarning: Boolean,
val onEditAction: (String) -> Unit = {},
) {
companion object {
val preview = ViewState(
localizer = MockLocalizer(),
showCexWarning = true,
)
}
}

@Composable
fun Content(modifier: Modifier, state: ViewState?) {
if (state == null) {
return
}
Column(modifier) {
InputFieldScaffold {
Column(
modifier = modifier
.padding(horizontal = ThemeShapes.HorizontalPadding)
.padding(vertical = ThemeShapes.VerticalPadding),
verticalArrangement = Arrangement.spacedBy(6.dp),
) {
Text(
text = state.localizer.localize("APP.GENERAL.MEMO"),
style = TextStyle.dydxDefault
.themeColor(ThemeColor.SemanticColor.text_tertiary)
.themeFont(fontSize = ThemeFont.FontSize.mini),
)

PlatformTextInput(
modifier = Modifier.fillMaxWidth(),
value = state.value ?: "",
textStyle = TextStyle.dydxDefault
.themeColor(ThemeColor.SemanticColor.text_primary)
.themeFont(fontSize = ThemeFont.FontSize.medium),
placeHolder = state.localizer.localize("APP.DIRECT_TRANSFER_MODAL.REQUIRED_FOR_CEX"),
onValueChange = { state.onEditAction(it) },
)
}
}
if (state.showCexWarning) {
Spacer(modifier = Modifier.height(24.dp))

PlatformInlineAlert(
text = state.localizer.localize("ERRORS.TRANSFER_MODAL.TRANSFER_WITHOUT_MEMO"),
level = PlatformInlineAlert.Level.WARNING,
modifier = Modifier.fillMaxWidth(),
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package exchange.dydx.trading.feature.transfer.transferout
import androidx.compose.foundation.ExperimentalFoundationApi
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.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -25,6 +28,7 @@ import exchange.dydx.trading.feature.transfer.components.AddressInputBox
import exchange.dydx.trading.feature.transfer.components.ChainsComboBox
import exchange.dydx.trading.feature.transfer.components.TokensComboBox
import exchange.dydx.trading.feature.transfer.components.TransferAmountBox
import exchange.dydx.trading.feature.transfer.components.TransferMemoBox

@Preview
@Composable
Expand All @@ -41,7 +45,9 @@ object DydxTransferOutView : DydxComponent {
val chainsComboBox: ChainsComboBox.ViewState? = null,
val tokensComboBox: TokensComboBox.ViewState? = null,
val transferAmount: TransferAmountBox.ViewState? = null,
val transferMemo: TransferMemoBox.ViewState? = null,
) {

companion object {
val preview = ViewState(
localizer = MockLocalizer(),
Expand Down Expand Up @@ -81,30 +87,37 @@ object DydxTransferOutView : DydxComponent {
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
item {
ChainsComboBox.Content(
modifier = Modifier.animateItemPlacement(),
state = state.chainsComboBox,
)
Row(Modifier.animateItemPlacement()) {
AddressInputBox.Content(
modifier = Modifier.weight(1f),
state = state.addressInput,
)
Spacer(Modifier.width(ThemeShapes.HorizontalPadding))
ChainsComboBox.Content(
modifier = Modifier.weight(1f),
state = state.chainsComboBox,
)
}
}

item {
AddressInputBox.Content(
TokensComboBox.Content(
modifier = Modifier.animateItemPlacement(),
state = state.addressInput,
state = state.tokensComboBox,
)
}

item {
TokensComboBox.Content(
TransferAmountBox.Content(
modifier = Modifier.animateItemPlacement(),
state = state.tokensComboBox,
state = state.transferAmount,
)
}

item {
TransferAmountBox.Content(
TransferMemoBox.Content(
modifier = Modifier.animateItemPlacement(),
state = state.transferAmount,
state = state.transferMemo,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import exchange.dydx.trading.feature.transfer.components.AddressInputBox
import exchange.dydx.trading.feature.transfer.components.ChainsComboBox
import exchange.dydx.trading.feature.transfer.components.TokensComboBox
import exchange.dydx.trading.feature.transfer.components.TransferAmountBox
import exchange.dydx.trading.feature.transfer.components.TransferMemoBox
import exchange.dydx.trading.feature.transfer.search.DydxTransferSearchParam
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -42,7 +43,6 @@ class DydxTransferOutViewModel @Inject constructor(
private val router: DydxRouter,
private val paramFlow: MutableStateFlow<DydxTransferSearchParam?>,
) : ViewModel(), DydxViewModel {
private val selectedChainFlow: MutableStateFlow<SelectionOption?> = MutableStateFlow(null)
private val selectedTokenFlow: MutableStateFlow<SelectionOption?> = MutableStateFlow(null)

val state: Flow<DydxTransferOutView.ViewState?> =
Expand All @@ -51,27 +51,22 @@ class DydxTransferOutViewModel @Inject constructor(
abacusStateManager.state.selectedSubaccount
.map { it?.freeCollateral?.current },
abacusStateManager.state.accountBalance(abacusStateManager.nativeTokenDenom),
selectedChainFlow,
selectedTokenFlow,
) { transferInput, freeCollateral, nativeTokenAmount, selectedChain, selectedToken ->
createViewState(transferInput, freeCollateral, nativeTokenAmount, selectedChain, selectedToken)
) { transferInput, freeCollateral, nativeTokenAmount, selectedToken ->
createViewState(transferInput, freeCollateral, nativeTokenAmount, selectedToken)
}
.distinctUntilChanged()

init {
abacusStateManager.state.transferInput
.map { it?.transferOutOptions?.chains?.toList() }
.distinctUntilChanged()
.onEach { chains ->
selectedChainFlow.value = chains?.firstOrNull()
.map { input ->
input?.transferOutOptions?.assets?.run {
firstOrNull { it.type == input.token } ?: firstOrNull()
}
}
.launchIn(viewModelScope)

abacusStateManager.state.transferInput
.map { it?.transferOutOptions?.assets?.toList() }
.distinctUntilChanged()
.onEach { tokens ->
selectedTokenFlow.value = tokens?.firstOrNull()
.onEach {
selectedTokenFlow.value = it
}
.launchIn(viewModelScope)
}
Expand All @@ -80,7 +75,6 @@ class DydxTransferOutViewModel @Inject constructor(
transferInput: TransferInput?,
freeCollateral: Double?,
nativeTokenAmount: Double?,
chain: SelectionOption?,
token: SelectionOption?,
): DydxTransferOutView.ViewState {
val tokenSymbol = token?.localizedString(localizer)
Expand Down Expand Up @@ -173,6 +167,17 @@ class DydxTransferOutViewModel @Inject constructor(
}
},
),
transferMemo = TransferMemoBox.ViewState(
localizer = localizer,
value = transferInput?.memo,
showCexWarning = transferInput?.token != abacusStateManager.usdcTokenKey && transferInput?.memo.isNullOrEmpty(),
onEditAction = { memo ->
abacusStateManager.transfer(
input = memo,
type = TransferInputField.MEMO,
)
},
),
addressInput = AddressInputBox.ViewState(
localizer = localizer,
formatter = formatter,
Expand Down
2 changes: 2 additions & 0 deletions v4/platformUI/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ dependencies {
api "androidx.compose.material:material:$composeVersion"
implementation "androidx.compose.material3:material3:$material3Version"
implementation "androidx.hilt:hilt-navigation-compose:$hiltAndroidXVersion"
implementation "androidx.compose.ui:ui-tooling-preview:$composeVersion"
debugImplementation "androidx.compose.ui:ui-tooling:$composeVersion"

implementation "com.google.code.gson:gson:$gsonVersion"

Expand Down
Loading
Loading