Updated on 2026-08-14

This commit is contained in:
Tangem 2024-12-04 14:13:00 +03:00
parent 6d3dc33fb6
commit 022c4bcfcd
11 changed files with 82 additions and 21 deletions

View file

@ -7,6 +7,7 @@ import com.tangem.common.ui.notifications.NotificationsFactory.addExceedsBalance
import com.tangem.common.ui.notifications.NotificationsFactory.addExistentialWarningNotification
import com.tangem.common.ui.notifications.NotificationsFactory.addFeeCoverageNotification
import com.tangem.common.ui.notifications.NotificationsFactory.addFeeUnreachableNotification
import com.tangem.common.ui.notifications.NotificationsFactory.addRentExemptionNotification
import com.tangem.common.ui.notifications.NotificationsFactory.addReserveAmountErrorNotification
import com.tangem.common.ui.notifications.NotificationsFactory.addTransactionLimitErrorNotification
import com.tangem.common.ui.notifications.NotificationsFactory.addValidateTransactionNotifications
@ -189,6 +190,10 @@ internal class AddStakingNotificationsTransformer(
val appCurrency = appCurrencyProvider()
val cryptoCurrency = cryptoCurrencyStatus.currency
addRentExemptionNotification(
rentWarning = currencyCheck.rentWarning,
)
addExistentialWarningNotification(
existentialDeposit = currencyCheck.existentialDeposit,
feeAmount = feeState?.fee?.amount?.value.orZero(),

View file

@ -69,6 +69,7 @@ import com.tangem.features.staking.impl.presentation.state.transformers.confirma
import com.tangem.features.staking.impl.presentation.state.transformers.notifications.AddStakingNotificationsTransformer
import com.tangem.features.staking.impl.presentation.state.transformers.notifications.DismissStakingNotificationsStateTransformer
import com.tangem.features.staking.impl.presentation.state.transformers.validator.ValidatorSelectChangeTransformer
import com.tangem.features.staking.impl.presentation.state.utils.checkAndCalculateSubtractedAmount
import com.tangem.features.staking.impl.presentation.state.utils.isSingleAction
import com.tangem.features.staking.impl.presentation.state.utils.withStubUnstakeAction
import com.tangem.utils.Provider
@ -633,12 +634,17 @@ internal class StakingViewModel @Inject constructor(
).leftOrNull()
}
val balanceAfterTransaction = calculateBalanceAfterTransaction(
amount = amount.orZero(),
fee = fee.orZero(),
reduceAmountBy = confirmationState?.reduceAmountBy.orZero(),
)
val currencyStatus = getCurrencyCheckUseCase(
userWalletId = userWalletId,
currencyStatus = cryptoCurrencyStatus,
amount = amount,
fee = fee,
balanceAfterTransaction = null, // ignore this in staking
balanceAfterTransaction = balanceAfterTransaction,
)
stateController.update(
AddStakingNotificationsTransformer(
@ -687,6 +693,22 @@ internal class StakingViewModel @Inject constructor(
stateController.update(DismissStakingNotificationsStateTransformer(notification))
}
private fun calculateBalanceAfterTransaction(
amount: BigDecimal,
fee: BigDecimal,
reduceAmountBy: BigDecimal,
): BigDecimal? {
val subtractedBalanceAmount = checkAndCalculateSubtractedAmount(
isAmountSubtractAvailable = isAmountSubtractAvailable,
cryptoCurrencyStatus = cryptoCurrencyStatus,
amountValue = amount.orZero(),
feeValue = fee.orZero(),
reduceAmountBy = reduceAmountBy,
)
val statusValue = cryptoCurrencyStatus.value as? CryptoCurrencyStatus.Loaded
return statusValue?.let { it.amount - subtractedBalanceAmount - fee.orZero() }
}
private fun awaitForAllowance() {
val approval = stakingApproval as? StakingApproval.Needed ?: return
allowanceTaskScheduler.scheduleTask(