Updated on 2026-08-14

This commit is contained in:
Tangem 2024-11-05 14:31:53 +05:00
parent bfff994f56
commit fc70ce1462
5 changed files with 37 additions and 54 deletions

View file

@ -12,8 +12,8 @@ import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.stringReference
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.core.ui.utils.BigDecimalFormatter.formatFiatAmount
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.utils.Provider
@ -26,7 +26,7 @@ import kotlinx.collections.immutable.persistentListOf
*
* @property clickIntents amount screen clicks
* @property appCurrencyProvider selected app currency provider
* @property maxEnterAmountProvider max enter amount data provider
* @property maxEnterAmount max enter amount data
* @property cryptoCurrencyStatusProvider current cryptocurrency status provider
* @property iconStateConverter currency icon converter
*/
@ -34,7 +34,7 @@ class AmountStateConverter(
private val clickIntents: AmountScreenClickIntents,
private val appCurrencyProvider: Provider<AppCurrency>,
private val cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus>,
private val maxEnterAmountProvider: Provider<MaxEnterAmount>,
private val maxEnterAmount: MaxEnterAmount,
private val iconStateConverter: CryptoCurrencyToIconStateConverter,
) : Converter<AmountParameters, AmountState> {
@ -47,10 +47,9 @@ class AmountStateConverter(
}
override fun convert(value: AmountParameters): AmountState {
val maxEnterAmount = maxEnterAmountProvider()
val appCurrency = appCurrencyProvider()
val status = cryptoCurrencyStatusProvider()
val fiat = formatFiatAmount(maxEnterAmount.fiatAmount, appCurrency.code, appCurrency.symbol)
val fiat = maxEnterAmount.fiatAmount.format { fiat(appCurrency.code, appCurrency.symbol) }
val crypto = maxEnterAmount.amount.format { crypto(status.currency) }
val noFeeRate = status.value.fiatRate.isNullOrZero()

View file

@ -44,7 +44,7 @@ internal class SendStateFactory(
appCurrencyProvider = appCurrencyProvider,
iconStateConverter = iconStateConverter,
cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider,
maxEnterAmountProvider = Provider { maxEnterAmountConverter.convert(cryptoCurrencyStatusProvider()) },
maxEnterAmount = maxEnterAmountConverter.convert(cryptoCurrencyStatusProvider()),
)
}
private val recipientStateConverter by lazy(LazyThreadSafetyMode.NONE) {

View file

@ -11,7 +11,7 @@ import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.features.staking.impl.R
import com.tangem.features.staking.impl.presentation.state.*
import com.tangem.features.staking.impl.presentation.state.StakingUiState
import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents
import com.tangem.utils.Provider
import com.tangem.utils.transformer.Transformer
@ -21,30 +21,36 @@ internal class SetAmountDataTransformer(
private val cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus>,
private val userWalletProvider: Provider<UserWallet>,
private val appCurrencyProvider: Provider<AppCurrency>,
private val maxEnterAmountProvider: Provider<MaxEnterAmount>,
) : Transformer<StakingUiState> {
private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter)
private val amountStateConverter by lazy(LazyThreadSafetyMode.NONE) {
AmountStateConverter(
clickIntents = clickIntents,
cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider,
appCurrencyProvider = appCurrencyProvider,
iconStateConverter = iconStateConverter,
maxEnterAmountProvider = maxEnterAmountProvider,
)
}
override fun transform(prevState: StakingUiState): StakingUiState {
val title = if (prevState.actionType == StakingActionCommonType.Exit) {
resourceReference(R.string.staking_staked_amount)
} else {
stringReference(userWalletProvider().name)
}
val cryptoBalanceValue = cryptoCurrencyStatusProvider().value
val (amount, fiatAmount) = if (prevState.actionType != StakingActionCommonType.Enter) {
prevState.balanceState?.cryptoAmount to prevState.balanceState?.fiatAmount
} else {
cryptoBalanceValue.amount to cryptoBalanceValue.fiatAmount
}
val maxEnterAmount = MaxEnterAmount(
amount = amount,
fiatAmount = fiatAmount,
fiatRate = cryptoBalanceValue.fiatRate,
)
return prevState.copy(
amountState = amountStateConverter.convert(
amountState = AmountStateConverter(
clickIntents = clickIntents,
cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider,
appCurrencyProvider = appCurrencyProvider,
iconStateConverter = iconStateConverter,
maxEnterAmount = maxEnterAmount,
).convert(
AmountParameters(
title = title,
value = "",

View file

@ -41,21 +41,10 @@ internal class SetInitialDataStateTransformer(
private val userWalletProvider: Provider<UserWallet>,
private val appCurrencyProvider: Provider<AppCurrency>,
private val balancesToShowProvider: Provider<List<BalanceItem>>,
private val maxEnterAmountProvider: Provider<MaxEnterAmount>,
) : Transformer<StakingUiState> {
private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter)
private val amountStateConverter by lazy(LazyThreadSafetyMode.NONE) {
AmountStateConverter(
clickIntents = clickIntents,
cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider,
appCurrencyProvider = appCurrencyProvider,
iconStateConverter = iconStateConverter,
maxEnterAmountProvider = maxEnterAmountProvider,
)
}
private val rewardsValidatorStateConverter by lazy(LazyThreadSafetyMode.NONE) {
RewardsValidatorStateConverter(cryptoCurrencyStatusProvider, appCurrencyProvider, yield)
}
@ -211,7 +200,19 @@ internal class SetInitialDataStateTransformer(
}
private fun createInitialAmountState(): AmountState {
return amountStateConverter.convert(
val cryptoBalanceValue = cryptoCurrencyStatusProvider().value
val maxEnterAmount = MaxEnterAmount(
amount = cryptoBalanceValue.amount,
fiatAmount = cryptoBalanceValue.fiatAmount,
fiatRate = cryptoBalanceValue.fiatRate,
)
return AmountStateConverter(
clickIntents = clickIntents,
cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider,
appCurrencyProvider = appCurrencyProvider,
iconStateConverter = iconStateConverter,
maxEnterAmount = maxEnterAmount,
).convert(
AmountParameters(
title = stringReference(userWalletProvider().name),
value = "",

View file

@ -11,7 +11,6 @@ import com.tangem.common.routing.AppRoute
import com.tangem.common.routing.bundle.unbundle
import com.tangem.common.ui.amountScreen.converters.AmountReduceByTransformer
import com.tangem.common.ui.amountScreen.models.AmountState
import com.tangem.common.ui.amountScreen.models.MaxEnterAmount
import com.tangem.common.ui.bottomsheet.permission.state.ApproveType
import com.tangem.common.ui.bottomsheet.permission.state.GiveTxPermissionBottomSheetConfig
import com.tangem.common.ui.notifications.NotificationUM
@ -154,14 +153,6 @@ internal class StakingViewModel @Inject constructor(
).getOrElse { emptyList() }
}
private val maxEnterAmount: MaxEnterAmount
get() =
MaxEnterAmount(
amount = uiState.value.balanceState?.cryptoAmount,
fiatAmount = uiState.value.balanceState?.fiatAmount,
fiatRate = cryptoCurrencyStatus.value.fiatRate,
)
private var isInitialInfoAnalyticSent: Boolean = false
private val balanceUpdater by lazy(LazyThreadSafetyMode.NONE) {
@ -233,18 +224,6 @@ internal class StakingViewModel @Inject constructor(
}
override fun onNextClick(balanceState: BalanceState?) {
if (value.currentStep == StakingStep.InitialInfo && balanceState == null) {
stateController.update(
SetConfirmationStateInitTransformer(
isEnter = true,
isExplicitExit = false,
balanceState = null,
cryptoCurrencyStatus = cryptoCurrencyStatus,
stakingApproval = stakingApproval,
stakingAllowance = stakingAllowance,
),
)
}
stakingStateRouter.onNextClick()
}
@ -913,7 +892,6 @@ internal class StakingViewModel @Inject constructor(
userWalletProvider = Provider { userWallet },
appCurrencyProvider = Provider { appCurrency },
balancesToShowProvider = Provider { balancesToShow },
maxEnterAmountProvider = Provider { maxEnterAmount },
),
SetConfirmationStateEmptyTransformer,
)
@ -947,7 +925,6 @@ internal class StakingViewModel @Inject constructor(
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
userWalletProvider = Provider { userWallet },
appCurrencyProvider = Provider { appCurrency },
maxEnterAmountProvider = Provider { maxEnterAmount },
),
AmountChangeStateTransformer(
cryptoCurrencyStatus = cryptoCurrencyStatus,