From a2c2cb52ca9d383f2c547b1749e19d46103dd22a Mon Sep 17 00:00:00 2001 From: Tangem Date: Sun, 20 Sep 2020 23:41:08 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../redux/middlewares/AmountMiddleware.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AmountMiddleware.kt b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AmountMiddleware.kt index 55817d9003..3c001122bd 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AmountMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AmountMiddleware.kt @@ -3,6 +3,7 @@ package com.tangem.tap.features.send.redux.middlewares import com.tangem.blockchain.common.Amount import com.tangem.blockchain.common.TransactionError import com.tangem.common.extensions.isZero +import com.tangem.tap.common.extensions.isNegative import com.tangem.tap.common.redux.AppState import com.tangem.tap.domain.TapError import com.tangem.tap.features.send.redux.AmountAction @@ -86,19 +87,17 @@ class AmountMiddleware { val sendState = appState?.sendState ?: return val amountState = sendState.amountState - val maxAmount = if (sendState.feeState.feeIsIncluded) { - amountState.balanceCrypto + val maxAmount = if (sendState.feeState.feeIsIncluded) amountState.balanceCrypto + else amountState.balanceCrypto.minus(sendState.feeState.getCurrentFee()) + + if (maxAmount.isNegative()) { + dispatch(AmountAction.SetAmountError(TapError.FeeExceedsBalance)) } else { - val balanceExtractFee = amountState.balanceCrypto.minus(sendState.feeState.getCurrentFee()) -// if (balanceExtractFee.isNegative()) BigDecimal.ZERO -// else balanceExtractFee - balanceExtractFee + val currentCurrencyValue = if (amountState.mainCurrency.type == MainCurrencyType.CRYPTO) maxAmount + else sendState.convertToFiat(maxAmount) + + dispatch(AmountAction.SetAmount(currentCurrencyValue, false)) } - - val currentCurrencyValue = if (amountState.mainCurrency.type == MainCurrencyType.CRYPTO) maxAmount - else sendState.convertToFiat(maxAmount) - - dispatch(AmountAction.SetAmount(currentCurrencyValue, false)) } private fun toggleMainCurrency(appState: AppState?, dispatch: (Action) -> Unit) {