Skip to content

Commit

Permalink
Integrated new ui_lib changes into screens components
Browse files Browse the repository at this point in the history
  • Loading branch information
AmadeyKuspakov committed Aug 30, 2023
1 parent 0121eda commit 5f8dd7c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import java.math.BigDecimal
data class AssetAmountInputState(
val token: Token,
val balance: String,
val amount: BigDecimal,
val initialAmount: BigDecimal? = null,
val amountFiat: String,
val enabled: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import jp.co.soramitsu.common.R
import jp.co.soramitsu.common.domain.AssetAmountInputState
import jp.co.soramitsu.common.domain.OptionsProvider
import jp.co.soramitsu.common.presentation.compose.TokenIcon
import jp.co.soramitsu.common.util.ext.orZero
import jp.co.soramitsu.common.util.ext.testTagAsId
import jp.co.soramitsu.ui_core.component.button.properties.Size
import jp.co.soramitsu.ui_core.component.input.number.BasicNumberInput
Expand Down Expand Up @@ -215,7 +216,6 @@ val previewAssetAmountInputState = AssetAmountInputState(
token = previewToken,
balance = "10.234 ($2.234.23)",
amountFiat = "$2.342.12",
amount = BigDecimal.ZERO,
initialAmount = null,
enabled = true,
error = false,
Expand All @@ -236,7 +236,6 @@ private fun PreviewAssetAmountInput() {
val state = remember { mutableStateOf(previewAssetAmountInputState) }
Button(onClick = {
state.value = state.value.copy(
amount = bb.value,
initialAmount = bb.value,
)
bb.value = bb.value.plus(BigDecimal.ONE)
Expand All @@ -248,14 +247,14 @@ private fun PreviewAssetAmountInput() {
state = state.value,
onAmountChange = {
state.value = state.value.copy(
amount = it,
initialAmount = it,
)
},
onSelectToken = {},
onFocusChange = {},
)
Spacer(modifier = Modifier.size(10.dp))
Text(text = state.value.amount.toPlainString())
Text(text = state.value.initialAmount.orZero().toPlainString())
AssetAmountInput(
modifier = Modifier,
state = previewAssetAmountInputState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,9 @@ class QRCodeFlowViewModel @AssistedInject constructor(
nf = numbersFormatter,
precision = DEFAULT_TOKEN_PRINT_PRECISION
),
amount = BigDecimal.ZERO,
initialAmount = null,
amountFiat = "",
enabled = false,
enabled = true,
)
)
}.catch {
Expand Down Expand Up @@ -303,7 +302,7 @@ class QRCodeFlowViewModel @AssistedInject constructor(
fun onRequestAmountChange(amount: BigDecimal) {
requestTokenByQrScreenState = requestTokenByQrScreenState.copy(
assetAmountInputState = requestTokenByQrScreenState.assetAmountInputState?.copy(
amount = amount,
initialAmount = amount,
amountFiat = requestTokenByQrScreenState.assetAmountInputState?.token?.printFiat(
amount,
numbersFormatter
Expand Down Expand Up @@ -427,7 +426,7 @@ class QRCodeFlowViewModel @AssistedInject constructor(
tokenId = requestTokenByQrScreenState.assetAmountInputState
?.token?.id,
amount = requestTokenByQrScreenState.assetAmountInputState
?.amount.toString()
?.initialAmount.toString()
)
)
}
Expand All @@ -444,7 +443,7 @@ class QRCodeFlowViewModel @AssistedInject constructor(
assetAmountInputState = requestTokenByQrScreenState
.assetAmountInputState?.copy(
initialAmount = requestTokenByQrScreenState
.assetAmountInputState?.amount,
.assetAmountInputState?.initialAmount,
enabled = false,
readOnly = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class TransferAmountViewModel @AssistedInject constructor(
calcTransactionFee(asset)
}
}
sendState.input?.amount?.let {
sendState.input?.initialAmount?.let {
checkEnteredAmount(it)
}
}
Expand Down Expand Up @@ -171,7 +171,6 @@ class TransferAmountViewModel @AssistedInject constructor(
input = AssetAmountInputState(
token = asset.token,
balance = getAssetBalanceText(asset),
amount = initialSendAmount?.toBigDecimalOrNull() ?: BigDecimal.ZERO,
initialAmount = initialSendAmount?.toBigDecimalOrNull(),
amountFiat = "",
enabled = false,
Expand All @@ -185,7 +184,7 @@ class TransferAmountViewModel @AssistedInject constructor(
token = asset.token,
balance = getAssetBalanceText(asset),
amountFiat = asset.token.printFiat(
sendState.input?.amount.orZero(),
sendState.input?.initialAmount.orZero(),
numbersFormatter
),
)
Expand All @@ -201,7 +200,7 @@ class TransferAmountViewModel @AssistedInject constructor(

val result = interactor.isNotEnoughXorLeftAfterTransaction(
networkFeeInXor = fee.orZero(),
xorChange = if (token.id == SubstrateOptionsProvider.feeAssetId) amount else null,
xorChange = if (token.id == SubstrateOptionsProvider.feeAssetId) initialAmount else null,
)

sendState = sendState.copy(
Expand All @@ -212,7 +211,7 @@ class TransferAmountViewModel @AssistedInject constructor(
fun onTokenChange(tokenId: String) {
curTokenId = tokenId
updateCurAsset()
sendState.input?.amount?.let {
sendState.input?.initialAmount?.let {
checkEnteredAmount(it)
}
hasXorReminderWarningBeenChecked = false
Expand All @@ -230,7 +229,7 @@ class TransferAmountViewModel @AssistedInject constructor(
sendState = sendState.copy(
input = sendState.input?.copy(
readOnly = false,
initialAmount = sendState.input?.amount?.nullZero()
initialAmount = sendState.input?.initialAmount?.nullZero()
),
)
}
Expand Down Expand Up @@ -292,7 +291,7 @@ class TransferAmountViewModel @AssistedInject constructor(

fun onConfirmClick() {
val curAsset = curAsset ?: return
val amount = sendState.input?.amount ?: return
val amount = sendState.input?.initialAmount ?: return
val fee = fee ?: return
viewModelScope.launch {
sendState = sendState.copy(
Expand Down Expand Up @@ -390,15 +389,15 @@ class TransferAmountViewModel @AssistedInject constructor(
fun onReviewClick() {
sendState = sendState.copy(
input = sendState.input?.copy(
initialAmount = sendState.input?.amount.orZero()
initialAmount = sendState.input?.initialAmount.orZero()
)
)
}

fun amountChanged(value: BigDecimal) {
sendState = sendState.copy(
input = sendState.input?.copy(
amount = value,
initialAmount = value,
amountFiat = sendState.input?.token?.printFiat(
value,
numbersFormatter
Expand All @@ -421,7 +420,6 @@ class TransferAmountViewModel @AssistedInject constructor(
}
sendState = sendState.copy(
input = sendState.input?.copy(
amount = amount,
initialAmount = amount,
amountFiat = sendState.input?.token?.printFiat(
amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ internal fun LiquidityAddConfirmScreen(
SwapAmountSquare(
modifier = Modifier.weight(1f),
icon = state.assetState1?.token?.iconUri() ?: DEFAULT_ICON_URI,
amount = state.assetState1?.amount?.toPlainString().orEmpty(),
amount = state.assetState1?.initialAmount?.toPlainString().orEmpty(),
amountFiat = state.assetState1?.amountFiat.orEmpty(),
)
Divider(color = Color.Transparent, modifier = Modifier.width(Dimens.x1))
SwapAmountSquare(
modifier = Modifier.weight(1f),
icon = state.assetState2?.token?.iconUri() ?: DEFAULT_ICON_URI,
amount = state.assetState2?.amount?.toPlainString().orEmpty(),
amount = state.assetState2?.initialAmount?.toPlainString().orEmpty(),
amountFiat = state.assetState2?.amountFiat.orEmpty(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ internal fun LiquidityRemoveConfirmScreen(
SwapAmountSquare(
modifier = Modifier.weight(1f),
icon = state.assetState1?.token?.iconUri() ?: DEFAULT_ICON_URI,
amount = state.assetState1?.amount?.toPlainString().orEmpty(),
amount = state.assetState1?.initialAmount?.toPlainString().orEmpty(),
amountFiat = state.assetState1?.amountFiat.orEmpty(),
)
Divider(color = Color.Transparent, modifier = Modifier.width(Dimens.x1))
SwapAmountSquare(
modifier = Modifier.weight(1f),
icon = state.assetState2?.token?.iconUri() ?: DEFAULT_ICON_URI,
amount = state.assetState2?.amount?.toPlainString().orEmpty(),
amount = state.assetState2?.initialAmount?.toPlainString().orEmpty(),
amountFiat = state.assetState2?.amountFiat.orEmpty(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ internal fun SwapConfirmScreen(
SwapAmountSquare(
modifier = Modifier.weight(1f),
icon = state.tokenFromState?.token?.iconUri() ?: DEFAULT_ICON_URI,
amount = state.tokenFromState?.amount?.toPlainString().orEmpty(),
amount = state.tokenFromState?.initialAmount?.toPlainString().orEmpty(),
amountFiat = state.tokenFromState?.amountFiat.orEmpty(),
)
Divider(color = Color.Transparent, modifier = Modifier.width(Dimens.x1))
SwapAmountSquare(
modifier = Modifier.weight(1f),
icon = state.tokenToState?.token?.iconUri() ?: DEFAULT_ICON_URI,
amount = state.tokenToState?.amount?.toPlainString().orEmpty(),
amount = state.tokenToState?.initialAmount?.toPlainString().orEmpty(),
amountFiat = state.tokenToState?.amountFiat.orEmpty(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import jp.co.soramitsu.common.util.NumbersFormatter
import jp.co.soramitsu.common.util.ext.isZero
import jp.co.soramitsu.common.util.ext.lazyAsync
import jp.co.soramitsu.common.util.ext.nullZero
import jp.co.soramitsu.common.util.ext.orZero
import jp.co.soramitsu.common.view.ViewHelper
import jp.co.soramitsu.common_wallet.domain.model.LiquidityData
import jp.co.soramitsu.common_wallet.domain.model.WithDesired
Expand Down Expand Up @@ -393,7 +394,6 @@ class LiquidityAddViewModel @AssistedInject constructor(
if (desired == WithDesired.INPUT) {
addState = addState.copy(
assetState2 = addState.assetState2?.copy(
amount = it,
initialAmount = it,
amountFiat = addState.assetState2?.token?.printFiat(
it,
Expand All @@ -406,7 +406,6 @@ class LiquidityAddViewModel @AssistedInject constructor(
} else {
addState = addState.copy(
assetState1 = addState.assetState1?.copy(
amount = it,
initialAmount = it,
amountFiat = addState.assetState1?.token?.printFiat(
it,
Expand Down Expand Up @@ -488,7 +487,7 @@ class LiquidityAddViewModel @AssistedInject constructor(

val result = assetsInteractor.isNotEnoughXorLeftAfterTransaction(
networkFeeInXor = networkFee,
xorChange = if (assetState1.token.id == SubstrateOptionsProvider.feeAssetId) assetState1.amount else null,
xorChange = if (assetState1.token.id == SubstrateOptionsProvider.feeAssetId) assetState1.initialAmount else null,
)

addState = addState.copy(
Expand All @@ -507,10 +506,10 @@ class LiquidityAddViewModel @AssistedInject constructor(
fullList = mapAssetsToCardState(list, numbersFormatter),
),
assetState1 = addState.assetState1?.copy(
initialAmount = addState.assetState1?.amount?.nullZero(),
initialAmount = addState.assetState1?.initialAmount?.nullZero(),
),
assetState2 = addState.assetState2?.copy(
initialAmount = addState.assetState2?.amount?.nullZero(),
initialAmount = addState.assetState2?.initialAmount?.nullZero(),
),
)
}
Expand Down Expand Up @@ -549,10 +548,10 @@ class LiquidityAddViewModel @AssistedInject constructor(
fullList = mapAssetsToCardState(list, numbersFormatter),
),
assetState1 = addState.assetState1?.copy(
initialAmount = addState.assetState1?.amount?.nullZero(),
initialAmount = addState.assetState1?.initialAmount?.nullZero(),
),
assetState2 = addState.assetState2?.copy(
initialAmount = addState.assetState2?.amount?.nullZero(),
initialAmount = addState.assetState2?.initialAmount?.nullZero(),
),
)
}
Expand All @@ -567,7 +566,7 @@ class LiquidityAddViewModel @AssistedInject constructor(
assetState1 = state.copy(
token = a.token,
balance = getAssetBalanceText(a),
amountFiat = a.token.printFiat(state.amount, numbersFormatter),
amountFiat = a.token.printFiat(state.initialAmount.orZero(), numbersFormatter),
),
)
hasXorReminderWarningBeenChecked = false
Expand All @@ -583,7 +582,7 @@ class LiquidityAddViewModel @AssistedInject constructor(
assetState2 = state?.copy(
token = a.token,
balance = getAssetBalanceText(a),
amountFiat = a.token.printFiat(state.amount, numbersFormatter),
amountFiat = a.token.printFiat(state.initialAmount.orZero(), numbersFormatter),
)
?: buildInitialAssetState(a),
)
Expand Down Expand Up @@ -712,10 +711,10 @@ class LiquidityAddViewModel @AssistedInject constructor(
fun onSlippageClick() {
addState = addState.copy(
assetState1 = addState.assetState1?.copy(
initialAmount = addState.assetState1?.amount?.nullZero(),
initialAmount = addState.assetState1?.initialAmount?.nullZero(),
),
assetState2 = addState.assetState2?.copy(
initialAmount = addState.assetState2?.amount?.nullZero(),
initialAmount = addState.assetState2?.initialAmount?.nullZero(),
),
)
}
Expand All @@ -730,7 +729,7 @@ class LiquidityAddViewModel @AssistedInject constructor(
fun onAmount1Change(value: BigDecimal) {
addState = addState.copy(
assetState1 = addState.assetState1?.copy(
amount = value,
initialAmount = value,
amountFiat = addState.assetState1?.token?.printFiat(
value,
numbersFormatter
Expand All @@ -743,7 +742,7 @@ class LiquidityAddViewModel @AssistedInject constructor(
fun onAmount2Change(value: BigDecimal) {
addState = addState.copy(
assetState2 = addState.assetState2?.copy(
amount = value,
initialAmount = value,
amountFiat = addState.assetState2?.token?.printFiat(
value,
numbersFormatter
Expand Down Expand Up @@ -781,7 +780,6 @@ class LiquidityAddViewModel @AssistedInject constructor(
addState = addState.copy(
assetState1 = addState.assetState1?.copy(
amountFiat = tokenFrom.printFiat(amount, numbersFormatter),
amount = amount,
initialAmount = amount,
)
)
Expand All @@ -796,7 +794,6 @@ class LiquidityAddViewModel @AssistedInject constructor(
addState = addState.copy(
assetState2 = addState.assetState2?.copy(
amountFiat = tokenTo.printFiat(amount, numbersFormatter),
amount = amount,
initialAmount = amount,
)
)
Expand Down Expand Up @@ -876,7 +873,6 @@ class LiquidityAddViewModel @AssistedInject constructor(
private fun buildInitialAssetState(a: Asset) = AssetAmountInputState(
token = a.token,
balance = getAssetBalanceText(a),
amount = BigDecimal.ZERO,
initialAmount = null,
amountFiat = "",
enabled = true,
Expand Down
Loading

0 comments on commit 5f8dd7c

Please sign in to comment.