diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyCheckUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyCheckUseCase.kt index 41d994c8c0..33c899c9d2 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyCheckUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyCheckUseCase.kt @@ -19,7 +19,7 @@ class GetCurrencyCheckUseCase( currencyStatus: CryptoCurrencyStatus, amount: BigDecimal?, fee: BigDecimal?, - balanceAfterTransaction: BigDecimal?, + feeCurrencyBalanceAfterTransaction: BigDecimal?, recipientAddress: String? = null, ): CryptoCurrencyCheck { return withContext(dispatchers.io) { @@ -32,7 +32,7 @@ class GetCurrencyCheckUseCase( val rentWarning = currencyChecksRepository.getRentExemptionError( userWalletId = userWalletId, currencyStatus = currencyStatus, - balanceAfterTransaction = balanceAfterTransaction ?: BigDecimal.ZERO, + balanceAfterTransaction = feeCurrencyBalanceAfterTransaction ?: BigDecimal.ZERO, ) val isAccountFunded = recipientAddress?.let { currencyChecksRepository.checkIfAccountFunded( diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt index 4736397eb8..5369749224 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt @@ -95,20 +95,19 @@ internal class SendNotificationFactory( val feeError = (feeState.feeSelectorState as? FeeSelectorState.Error)?.error val recipientAddress = state.recipientState?.addressTextField?.value - val statusValue = cryptoCurrencyStatus.value as? CryptoCurrencyStatus.Loaded - val feeToSubtract = if (isSubtractAvailableProvider()) { - feeValue - } else { - BigDecimal.ZERO - } - val balanceAfterTransaction = statusValue?.let { it.amount - sendingAmount - feeToSubtract } + val feeCurrencyBalanceAfterTransaction = getFeeCurrencyBalanceAfterTx( + feeCurrencyStatus = feeCryptoCurrencyStatusProvider(), + sendingCurrencyStatus = cryptoCurrencyStatus, + sendingAmount = sendingAmount, + feeValue = feeValue, + ) val currencyCheck = getCurrencyCheckUseCase( userWalletId = userWalletId, currencyStatus = cryptoCurrencyStatus, amount = sendingAmount, fee = feeValue, recipientAddress = recipientAddress, - balanceAfterTransaction = balanceAfterTransaction, + feeCurrencyBalanceAfterTransaction = feeCurrencyBalanceAfterTransaction, ) buildList { addErrorNotifications( @@ -143,6 +142,23 @@ internal class SendNotificationFactory( ) } + private fun getFeeCurrencyBalanceAfterTx( + feeCurrencyStatus: CryptoCurrencyStatus?, + sendingCurrencyStatus: CryptoCurrencyStatus, + sendingAmount: BigDecimal, + feeValue: BigDecimal, + ): BigDecimal? { + val sendingCurrencyBalance = sendingCurrencyStatus.value as? CryptoCurrencyStatus.Loaded + val feeCurrencyBalance = feeCurrencyStatus?.value as? CryptoCurrencyStatus.Loaded + if (feeCurrencyStatus?.value !is CryptoCurrencyStatus.Loaded) return null + return when { + feeCurrencyStatus == sendingCurrencyStatus -> sendingCurrencyBalance?.let { + it.amount - sendingAmount - feeValue + } + else -> feeCurrencyBalance?.let { it.amount - feeValue } + } + } + private suspend fun MutableList.addErrorNotifications( feeError: GetFeeError?, sendingAmount: BigDecimal, 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 58f5125717..895dd62b2a 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 @@ -647,7 +647,7 @@ internal class StakingViewModel @Inject constructor( currencyStatus = cryptoCurrencyStatus, amount = amount, fee = fee, - balanceAfterTransaction = balanceAfterTransaction, + feeCurrencyBalanceAfterTransaction = balanceAfterTransaction, ) stateController.update( AddStakingNotificationsTransformer( diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt index 84fefe7f12..298af784a2 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt @@ -409,7 +409,7 @@ internal class SwapInteractorImpl @AssistedInject constructor( currencyStatus = fromTokenStatus, amount = amount.value, fee = fee, - balanceAfterTransaction = balanceAfterTransaction, + feeCurrencyBalanceAfterTransaction = balanceAfterTransaction, ) return currencyCheck