Updated on 2026-08-14

This commit is contained in:
Tangem 2024-04-11 16:09:32 +05:00
parent 505400888d
commit 230aff6ed6
5 changed files with 34 additions and 29 deletions

View file

@ -29,8 +29,8 @@ internal class SendTransactionAlertConverter(
onConfirmClick = { clickIntents.onFailedTxEmailClick(value.message.orEmpty()) },
)
is SendTransactionError.NetworkError -> SendAlertState.TransactionError(
code = "",
cause = value.message,
code = value.code.orEmpty(),
cause = value.message.orEmpty(),
onConfirmClick = { clickIntents.onFailedTxEmailClick(value.message.orEmpty()) },
)
is SendTransactionError.UnknownError -> SendAlertState.TransactionError(

View file

@ -20,6 +20,7 @@ import com.tangem.features.send.impl.presentation.state.*
import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState
import com.tangem.features.send.impl.presentation.state.fee.FeeType
import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents
import com.tangem.lib.crypto.BlockchainUtils.isDogecoin
import com.tangem.utils.Provider
import com.tangem.utils.isNullOrZero
import kotlinx.collections.immutable.ImmutableList
@ -52,18 +53,17 @@ internal class SendNotificationFactory(
val feeState = state.feeState ?: return@map persistentListOf()
val feeAmount = feeState.fee?.amount?.value ?: BigDecimal.ZERO
val amountValue = state.amountState?.amountTextField?.cryptoAmount?.value ?: BigDecimal.ZERO
val sendAmount = if (sendState.isSubtract) amountValue.minus(feeAmount) else amountValue
buildList {
// errors
addExceedBalanceNotification(feeAmount, sendAmount)
addExceedBalanceNotification(feeAmount, amountValue)
addExceedsBalanceNotification(feeState.fee)
addInvalidAmountNotification(sendState.isSubtract, sendAmount)
addMinimumAmountErrorNotification(feeAmount, sendAmount)
addDustWarningNotification(feeAmount, sendAmount)
addTransactionLimitErrorNotification(feeAmount, sendAmount)
addInvalidAmountNotification(sendState.isSubtract, amountValue)
addMinimumAmountErrorNotification(feeAmount, amountValue)
addDustWarningNotification(feeAmount, amountValue)
addTransactionLimitErrorNotification(feeAmount, amountValue)
// warnings
addExistentialWarningNotification(feeAmount, sendAmount)
addHighFeeWarningNotification(sendAmount, sendState.ignoreAmountReduce)
addExistentialWarningNotification(feeAmount, amountValue)
addHighFeeWarningNotification(feeAmount, amountValue, sendState.ignoreAmountReduce)
addTooLowNotification(feeState)
}.toImmutableList()
}
@ -121,20 +121,11 @@ internal class SendNotificationFactory(
val totalAmount = feeAmount + receivedAmount
val balance = coinCryptoCurrencyStatus.value.amount ?: BigDecimal.ZERO
// TODO Move Blockchain check elsewhere
when (coinCryptoCurrencyStatus.currency.network.id.value) {
Blockchain.Cardano.id -> {
if (receivedAmount > BigDecimal.ONE || balance - totalAmount < BigDecimal.ONE) {
add(SendNotification.Error.MinimumAmountError(CARDANO_MINIMUM))
}
if (isDogecoin(coinCryptoCurrencyStatus.currency.network.id.value)) {
val minimum = BigDecimal(DOGECOIN_MINIMUM)
if (receivedAmount < minimum || balance - totalAmount < minimum) {
add(SendNotification.Error.MinimumAmountError(DOGECOIN_MINIMUM))
}
Blockchain.Dogecoin.id -> {
val minimum = BigDecimal(DOGECOIN_MINIMUM)
if (receivedAmount > minimum || balance - totalAmount < minimum) {
add(SendNotification.Error.MinimumAmountError(DOGECOIN_MINIMUM))
}
}
else -> Unit
}
}
@ -199,7 +190,9 @@ internal class SendNotificationFactory(
receivedAmount: BigDecimal,
) {
val userWalletId = userWalletProvider().walletId
val cryptoCurrency = cryptoCurrencyStatusProvider().currency
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val cryptoCurrency = cryptoCurrencyStatus.currency
val balance = cryptoCurrencyStatus.value.amount ?: return
val spendingAmount = if (cryptoCurrency is CryptoCurrency.Token) {
feeAmount
} else {
@ -209,7 +202,8 @@ internal class SendNotificationFactory(
userWalletId,
cryptoCurrency.network,
)
if (currencyDeposit != null && currencyDeposit > spendingAmount) {
val diff = balance.minus(spendingAmount)
if (currencyDeposit != null && currencyDeposit > diff) {
add(
SendNotification.Error.ExistentialDeposit(
BigDecimalFormatter.formatCryptoAmount(
@ -222,13 +216,15 @@ internal class SendNotificationFactory(
}
private fun MutableList<SendNotification>.addHighFeeWarningNotification(
feeAmount: BigDecimal,
sendAmount: BigDecimal,
ignoreAmountReduce: Boolean,
) {
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val balance = cryptoCurrencyStatus.value.amount ?: BigDecimal.ZERO
val isTezos = cryptoCurrencyStatus.currency.network.id.value == Blockchain.Tezos.id
if (!ignoreAmountReduce && sendAmount == balance && isTezos) {
val isTotalBalance = feeAmount.plus(sendAmount) >= balance
if (!ignoreAmountReduce && isTotalBalance && isTezos) {
add(
SendNotification.Warning.HighFeeError(
amount = TEZOS_FEE_THRESHOLD.toPlainString(),
@ -361,7 +357,6 @@ internal class SendNotificationFactory(
}
companion object {
private const val CARDANO_MINIMUM = "1"
private const val DOGECOIN_MINIMUM = "0.01"
private val TEZOS_FEE_THRESHOLD = BigDecimal("0.01")
}