From 77741ebf4572cfc79aa8f2357ec35efc0849146a Mon Sep 17 00:00:00 2001 From: Vlad Kozarez Date: Thu, 26 Dec 2024 14:18:43 +0300 Subject: [PATCH] AND-9588 fix error balance notification in unstake flow --- .../viewmodel/StakingViewModel.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingViewModel.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingViewModel.kt index ba7718bde3..83b2fc77fd 100644 --- a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingViewModel.kt +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingViewModel.kt @@ -638,6 +638,7 @@ internal class StakingViewModel @Inject constructor( amount = amount.orZero(), fee = fee.orZero(), reduceAmountBy = confirmationState?.reduceAmountBy.orZero(), + actionType = value.actionType, ) val currencyStatus = getCurrencyCheckUseCase( userWalletId = userWalletId, @@ -697,14 +698,21 @@ internal class StakingViewModel @Inject constructor( amount: BigDecimal, fee: BigDecimal, reduceAmountBy: BigDecimal, + actionType: StakingActionCommonType, ): BigDecimal? { - val subtractedBalanceAmount = checkAndCalculateSubtractedAmount( - isAmountSubtractAvailable = isAmountSubtractAvailable, - cryptoCurrencyStatus = cryptoCurrencyStatus, - amountValue = amount.orZero(), - feeValue = fee.orZero(), - reduceAmountBy = reduceAmountBy, - ) + // TODO split for different networks + val subtractedBalanceAmount = when (actionType) { + StakingActionCommonType.Enter -> checkAndCalculateSubtractedAmount( + isAmountSubtractAvailable = isAmountSubtractAvailable, + cryptoCurrencyStatus = cryptoCurrencyStatus, + amountValue = amount.orZero(), + feeValue = fee.orZero(), + reduceAmountBy = reduceAmountBy, + ) + StakingActionCommonType.Exit, + is StakingActionCommonType.Pending, + -> BigDecimal.ZERO + } val statusValue = cryptoCurrencyStatus.value as? CryptoCurrencyStatus.Loaded return statusValue?.let { it.amount - subtractedBalanceAmount - fee.orZero() } }