diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/error/SendTransactionError.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/error/SendTransactionError.kt index 2d5536cefb..753f45e4b4 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/error/SendTransactionError.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/error/SendTransactionError.kt @@ -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() diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/SendTransactionUseCase.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/SendTransactionUseCase.kt index c8ed1fe905..059a672c70 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/SendTransactionUseCase.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/SendTransactionUseCase.kt @@ -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, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendAlertState.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendAlertState.kt index 54eb2f7868..672ceb39d5 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendAlertState.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendAlertState.kt @@ -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) + } } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotificationFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotificationFactory.kt index 8b3051e761..05d56ca70b 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotificationFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotificationFactory.kt @@ -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.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.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.addTransactionLimitErrorNotification( feeAmount: BigDecimal, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendTransactionAlertConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendTransactionAlertConverter.kt index 14f9cc265d..a35b421a16 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendTransactionAlertConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendTransactionAlertConverter.kt @@ -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 } } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldChangeConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldChangeConverter.kt index 7a6c696c1a..b9bfa076bd 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldChangeConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldChangeConverter.kt @@ -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() } }