Updated on 2026-08-14
This commit is contained in:
parent
0ab1c7507a
commit
d14a5cb87a
13 changed files with 255 additions and 100 deletions
|
|
@ -30,8 +30,6 @@ fun AmountScreenContent(
|
|||
clickIntents: AmountScreenClickIntents,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
if (amountState !is AmountState.Data) return
|
||||
|
||||
// Do not put fillMaxSize() in here
|
||||
LazyColumn(
|
||||
modifier = modifier
|
||||
|
|
@ -49,7 +47,7 @@ fun AmountScreenContent(
|
|||
onCurrencyChange = clickIntents::onCurrencyChangeClick,
|
||||
onMaxAmountClick = clickIntents::onMaxValueClick,
|
||||
)
|
||||
} else {
|
||||
} else if (amountState is AmountState.Data) {
|
||||
amountField(
|
||||
amountState = amountState,
|
||||
isBalanceHidden = isBalanceHidden,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package com.tangem.common.ui.amountScreen.converters.field
|
||||
|
||||
import com.tangem.common.ui.R
|
||||
import com.tangem.common.ui.amountScreen.models.AmountState
|
||||
import com.tangem.common.ui.amountScreen.models.EnterAmountBoundary
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.wrappedList
|
||||
import com.tangem.core.ui.format.bigdecimal.crypto
|
||||
import com.tangem.core.ui.format.bigdecimal.fiat
|
||||
import com.tangem.core.ui.format.bigdecimal.format
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.utils.transformer.Transformer
|
||||
|
||||
/**
|
||||
* Updates amount boundaries and revalidates current amount state
|
||||
*
|
||||
* @property cryptoCurrencyStatus current cryptocurrency status
|
||||
* @property maxEnterAmount new maximum enter amount boundary
|
||||
* @property appCurrency current app currency
|
||||
* @property isRedesignEnabled whether redesign mode is enabled
|
||||
*/
|
||||
class AmountBoundaryUpdateTransformer(
|
||||
private val cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
private val maxEnterAmount: EnterAmountBoundary,
|
||||
private val appCurrency: AppCurrency,
|
||||
private val isRedesignEnabled: Boolean,
|
||||
) : Transformer<AmountState> {
|
||||
|
||||
override fun transform(prevState: AmountState): AmountState {
|
||||
if (prevState !is AmountState.Data) return prevState
|
||||
|
||||
val fiat = maxEnterAmount.fiatAmount.format { fiat(appCurrency.code, appCurrency.symbol) }
|
||||
val crypto = maxEnterAmount.amount.format { crypto(cryptoCurrencyStatus.currency) }
|
||||
|
||||
val availableBalance = if (isRedesignEnabled) {
|
||||
resourceReference(R.string.common_balance, wrappedList(crypto))
|
||||
} else {
|
||||
resourceReference(R.string.common_crypto_fiat_format, wrappedList(crypto, fiat))
|
||||
}
|
||||
|
||||
return prevState.copy(
|
||||
availableBalance = availableBalance,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -100,8 +100,8 @@ class AmountFieldConverterV2(
|
|||
val cryptoAmount = cryptoDecimal.convertToAmount(cryptoCurrencyStatus.currency)
|
||||
val fiatRate = cryptoCurrencyStatus.value.fiatRate
|
||||
val (fiatValue, fiatDecimal) = when {
|
||||
fiatRate.isNullOrZero() -> "" to null
|
||||
value.isEmpty() -> "" to BigDecimal.ZERO
|
||||
fiatRate.isNullOrZero() -> "" to null
|
||||
else -> {
|
||||
val fiatDecimal = fiatRate?.multiply(cryptoDecimal)
|
||||
val fiatValue = fiatDecimal?.parseBigDecimal(FIAT_DECIMALS).orEmpty()
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import java.math.BigDecimal
|
|||
sealed class AmountState {
|
||||
|
||||
abstract val isPrimaryButtonEnabled: Boolean
|
||||
abstract val isRedesignEnabled: Boolean
|
||||
|
||||
/**
|
||||
* @param isPrimaryButtonEnabled indicates if next state button enabled
|
||||
|
|
@ -29,6 +30,7 @@ sealed class AmountState {
|
|||
*/
|
||||
data class Data(
|
||||
override val isPrimaryButtonEnabled: Boolean,
|
||||
override val isRedesignEnabled: Boolean,
|
||||
val title: TextReference,
|
||||
val availableBalance: TextReference,
|
||||
val tokenName: TextReference,
|
||||
|
|
@ -41,10 +43,10 @@ sealed class AmountState {
|
|||
val isEditingDisabled: Boolean = false,
|
||||
val reduceAmountBy: BigDecimal = BigDecimal.ZERO,
|
||||
val isIgnoreReduce: Boolean = false,
|
||||
val isRedesignEnabled: Boolean,
|
||||
) : AmountState()
|
||||
|
||||
data class Empty(
|
||||
override val isPrimaryButtonEnabled: Boolean = false,
|
||||
override val isRedesignEnabled: Boolean,
|
||||
) : AmountState()
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ import java.math.BigDecimal
|
|||
|
||||
object AmountStatePreviewData {
|
||||
|
||||
val emptyState = AmountState.Empty()
|
||||
val emptyState = AmountState.Empty(isRedesignEnabled = true)
|
||||
|
||||
val amountState = AmountState.Data(
|
||||
isPrimaryButtonEnabled = false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue