Updated on 2026-08-14

This commit is contained in:
Tangem 2024-02-14 13:18:44 +03:00
parent 8da3529141
commit ac9e0ac47b
6 changed files with 42 additions and 25 deletions

View file

@ -14,6 +14,8 @@ sealed class SendTransactionError {
object UserCancelledError : SendTransactionError()
data class CreateAccountUnderfunded(val amount: String) : SendTransactionError()
data class TangemSdkError(val code: Int, val messageReference: TextReference) : SendTransactionError()
data class UnknownError(val ex: Exception? = null) : SendTransactionError()

View file

@ -20,6 +20,7 @@ import com.tangem.domain.transaction.error.SendTransactionError
import com.tangem.domain.transaction.error.SendTransactionError.Companion.USER_CANCELLED_ERROR_CODE
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.sdk.extensions.localizedDescriptionRes
import com.tangem.utils.toFormattedString
class SendTransactionUseCase(
private val isDemoCardUseCase: IsDemoCardUseCase,
@ -85,6 +86,11 @@ class SendTransactionUseCase(
}
}
}
is BlockchainSdkError.CreateAccountUnderfunded -> {
val minAmount = error.minReserve
val minValue = minAmount.value?.toFormattedString(minAmount.decimals).orEmpty()
SendTransactionError.CreateAccountUnderfunded(minValue)
}
else -> {
SendTransactionError.BlockchainSdkError(
code = error.code,

View file

@ -49,4 +49,11 @@ internal sealed class SendAlertState {
override val title: TextReference? = null
override val message: TextReference = resourceReference(id = R.string.send_notification_high_fee_title)
}
data class ReserveAmount(val amount: String) : SendAlertState() {
override val title: TextReference =
resourceReference(id = R.string.send_notification_invalid_reserve_amount_title, wrappedList(amount))
override val message: TextReference =
resourceReference(id = R.string.send_notification_invalid_reserve_amount_text)
}
}

View file

@ -31,7 +31,6 @@ internal class SendNotificationFactory(
.map {
val state = currentStateProvider()
val feeState = state.feeState ?: return@map persistentListOf()
val recipientState = state.recipientState ?: return@map persistentListOf()
val feeAmount = feeState.fee?.amount?.value ?: BigDecimal.ZERO
val amountValue = state.amountState?.amountTextField?.value?.toBigDecimalOrNull() ?: BigDecimal.ZERO
val sendAmount = if (feeState.isSubtract) feeState.receivedAmountValue else amountValue
@ -41,7 +40,6 @@ internal class SendNotificationFactory(
addInvalidAmountNotification(feeState.isSubtract, sendAmount)
addMinimumAmountErrorNotification(feeAmount, sendAmount)
addDustWarningNotification(feeAmount, sendAmount)
addReserveAmountErrorNotification(recipientState.addressTextField.value)
addTransactionLimitErrorNotification(feeAmount, sendAmount)
// warnings
addExistentialWarningNotification(feeAmount, sendAmount)
@ -116,26 +114,27 @@ internal class SendNotificationFactory(
}
}
private suspend fun MutableList<SendNotification>.addReserveAmountErrorNotification(recipientAddress: String) {
val userWalletId = userWalletProvider().walletId
val cryptoCurrency = cryptoCurrencyStatusProvider().currency
val isAccountFunded = currencyChecksRepository.checkIfAccountFunded(
userWalletId,
cryptoCurrency.network,
recipientAddress,
)
val minimumAmount = currencyChecksRepository.getReserveAmount(userWalletId, cryptoCurrency.network)
if (!isAccountFunded && minimumAmount != null && minimumAmount > BigDecimal.ZERO) {
add(
SendNotification.Error.ReserveAmountError(
BigDecimalFormatter.formatCryptoAmount(
cryptoAmount = minimumAmount,
cryptoCurrency = cryptoCurrency,
),
),
)
}
}
// todo temporarily disabling notification
// private suspend fun MutableList<SendNotification>.addReserveAmountErrorNotification(recipientAddress: String) {
// val userWalletId = userWalletProvider().walletId
// val cryptoCurrency = cryptoCurrencyStatusProvider().currency
// val isAccountFunded = currencyChecksRepository.checkIfAccountFunded(
// userWalletId,
// cryptoCurrency.network,
// recipientAddress,
// )
// val minimumAmount = currencyChecksRepository.getReserveAmount(userWalletId, cryptoCurrency.network)
// if (!isAccountFunded && minimumAmount != null && minimumAmount > BigDecimal.ZERO) {
// add(
// SendNotification.Error.ReserveAmountError(
// BigDecimalFormatter.formatCryptoAmount(
// cryptoAmount = minimumAmount,
// cryptoCurrency = cryptoCurrency,
// ),
// ),
// )
// }
// }
private suspend fun MutableList<SendNotification>.addTransactionLimitErrorNotification(
feeAmount: BigDecimal,

View file

@ -38,6 +38,7 @@ internal class SendTransactionAlertConverter(
cause = value.ex?.localizedMessage,
onConfirmClick = { clickIntents.onFailedTxEmailClick(value.ex?.localizedMessage.orEmpty()) },
)
is SendTransactionError.CreateAccountUnderfunded -> SendAlertState.ReserveAmount(value.amount)
else -> null
}
}

View file

@ -1,5 +1,6 @@
package com.tangem.features.send.impl.presentation.state.fields
import com.tangem.common.extensions.isZero
import com.tangem.core.ui.utils.parseBigDecimal
import com.tangem.core.ui.utils.parseToBigDecimal
import com.tangem.domain.tokens.model.CryptoCurrency
@ -21,7 +22,6 @@ internal class SendAmountFieldChangeConverter(
val feeState = state.feeState ?: return state
if (value.isEmpty()) return state.emptyState()
val cryptoDecimals = amountTextField.cryptoAmount.decimals
val fiatDecimals = amountTextField.fiatAmount.decimals
@ -89,10 +89,12 @@ internal class SendAmountFieldChangeConverter(
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val currencyCryptoAmount = cryptoCurrencyStatus.value.amount ?: BigDecimal.ZERO
val currencyFiatAmount = cryptoCurrencyStatus.value.fiatAmount ?: BigDecimal.ZERO
val fiatDecimal = parseToBigDecimal(amountTextField.fiatAmount.decimals)
val cryptoDecimal = parseToBigDecimal(amountTextField.cryptoAmount.decimals)
return if (amountTextField.isFiatValue) {
parseToBigDecimal(amountTextField.fiatAmount.decimals) > currencyFiatAmount
fiatDecimal > currencyFiatAmount || fiatDecimal.isZero()
} else {
parseToBigDecimal(amountTextField.cryptoAmount.decimals) > currencyCryptoAmount
cryptoDecimal > currencyCryptoAmount || cryptoDecimal.isZero()
}
}