Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-30 16:06:33 +01:00
parent 50fa269746
commit 4cb147b27e
7 changed files with 345 additions and 10 deletions

View file

@ -515,6 +515,13 @@ internal class SendConfirmModel @Inject constructor(
feeCryptoCurrencyStatus = getCurrencyStatusForFeePayment(),
),
)
val balance = cryptoCurrencyStatus.value.amount.orZero()
val feeValue = confirmData.fee?.amount?.value.orZero()
val isTotalSendingMoreThanBalance = confirmData.enteredAmount.orZero() + feeValue > balance
val isFeeSubtractedFromAmount = isAmountSubtractAvailable && isTotalSendingMoreThanBalance
// Fee alone can't be covered by the balance → nothing can be sent, footer must show $0.
val isFeeExceedingBalance = isAmountSubtractAvailable && feeValue > balance
_uiState.update { state ->
state.copy(
confirmUM = SendConfirmationNotificationsTransformerV2(
@ -524,6 +531,8 @@ internal class SendConfirmModel @Inject constructor(
cryptoCurrency = cryptoCurrencyStatus.currency,
appCurrency = appCurrency,
analyticsCategoryName = params.analyticsCategoryName,
isFeeSubtractedFromAmount = isFeeSubtractedFromAmount,
isFeeExceedingBalance = isFeeExceedingBalance,
).transform(uiState.value.confirmUM),
)
}

View file

@ -21,7 +21,9 @@ import com.tangem.features.send.common.ui.state.ConfirmUM
import com.tangem.features.send.impl.R
import com.tangem.utils.transformer.Transformer
import kotlinx.collections.immutable.toPersistentList
import java.math.BigDecimal
@Suppress("LongParameterList")
internal class SendConfirmationNotificationsTransformerV2(
private val feeSelectorUM: FeeSelectorUM,
private val amountUM: AmountState,
@ -29,6 +31,8 @@ internal class SendConfirmationNotificationsTransformerV2(
private val cryptoCurrency: CryptoCurrency,
private val appCurrency: AppCurrency,
private val analyticsCategoryName: String,
private val isFeeSubtractedFromAmount: Boolean,
private val isFeeExceedingBalance: Boolean,
) : Transformer<ConfirmUM> {
override fun transform(prevState: ConfirmUM): ConfirmUM {
val state = prevState as? ConfirmUM.Content ?: return prevState
@ -73,10 +77,14 @@ internal class SendConfirmationNotificationsTransformerV2(
val isFeeConvertibleToFiat = feeSelectorUM.feeExtraInfo.isFeeConvertibleToFiat
val fiatSendingValue = if (isFeeConvertibleToFiat) {
fiatFeeValue?.let { fiatAmountValue?.plus(it) }
} else {
fiatAmountValue
val fiatSendingValue = when {
!isFeeConvertibleToFiat -> fiatAmountValue
// Fee alone exceeds the balance → the transaction can't go through, nothing is sent.
isFeeExceedingBalance -> BigDecimal.ZERO
// When the fee is subtracted from the amount, the entered amount is the gross that already
// includes the fee, so it must not be added again — that double-counts it.
isFeeSubtractedFromAmount -> fiatAmountValue
else -> fiatFeeValue?.let { fiatAmountValue?.plus(it) }
}
val fiatSending = fiatSendingValue.format {