From 0f74d89efc8f7ae63c52b49eed8b0cb70c96a12d Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 18 Nov 2024 12:31:15 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../swap/presentation/SwapNotificationsFactory.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapNotificationsFactory.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapNotificationsFactory.kt index 0b65e1ab16..dfcb39b3d8 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapNotificationsFactory.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapNotificationsFactory.kt @@ -27,6 +27,7 @@ import com.tangem.utils.extensions.orZero import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList +import java.math.BigDecimal internal class SwapNotificationsFactory( private val actions: UiActions, @@ -190,6 +191,7 @@ internal class SwapNotificationsFactory( addReduceAmountNotification( cryptoCurrencyStatus = fromCurrencyStatus, fromAmount = amountToRequest, + feeValue = fee?.feeValue.orZero(), onReduceAmount = actions.onReduceAmount, ) addTransactionLimitErrorNotification( @@ -293,17 +295,21 @@ internal class SwapNotificationsFactory( private fun MutableList.addReduceAmountNotification( cryptoCurrencyStatus: CryptoCurrencyStatus, fromAmount: SwapAmount, + feeValue: BigDecimal, onReduceAmount: (SwapAmount) -> Unit, ) { val isTezos = isTezos(cryptoCurrencyStatus.currency.network.id.value) - if (isTezos && fromAmount.value == cryptoCurrencyStatus.value.amount) { + val balance = cryptoCurrencyStatus.value.amount ?: BigDecimal.ZERO + val threshold = getTezosThreshold() + val isTotalBalance = fromAmount.value + feeValue >= balance && balance > threshold + if (isTezos && isTotalBalance) { add( SwapNotificationUM.Warning.ReduceAmount( currencyName = cryptoCurrencyStatus.currency.name, - amount = getTezosThreshold().toPlainString(), + amount = threshold.toPlainString(), onConfirmClick = { val patchedAmount = fromAmount.copy( - value = fromAmount.value - getTezosThreshold(), + value = fromAmount.value - threshold, ) onReduceAmount(patchedAmount) },