From 3e341569253d78a6b5381ae520cdd9db28243899 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 15 Aug 2024 12:13:02 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../impl/presentation/state/SendAlertState.kt | 7 --- .../state/SendEventStateFactory.kt | 3 - .../presentation/state/SendNotification.kt | 8 +++ .../state/SendTransactionAlertConverter.kt | 10 ---- .../state/confirm/SendNotificationFactory.kt | 55 ++++++++++--------- .../presentation/viewmodel/SendViewModel.kt | 1 - 6 files changed, 38 insertions(+), 46 deletions(-) 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 fc7ae7daf1..4abbd3c665 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 @@ -68,13 +68,6 @@ internal sealed class SendAlertState { override val confirmButtonText: TextReference = resourceReference(R.string.common_continue) } - 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) - } - data class FeeUnreachableError( override val onConfirmClick: (() -> Unit), ) : SendAlertState() { diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendEventStateFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendEventStateFactory.kt index 852339a7ed..3424853d60 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendEventStateFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendEventStateFactory.kt @@ -3,7 +3,6 @@ package com.tangem.features.send.impl.presentation.state import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.event.triggeredEvent -import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.transaction.error.SendTransactionError import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState import com.tangem.features.send.impl.presentation.state.fee.FeeStateFactory @@ -22,13 +21,11 @@ import java.math.BigDecimal internal class SendEventStateFactory( private val stateRouterProvider: Provider, private val currentStateProvider: Provider, - private val cryptoCurrencyStatusProvider: Provider, private val clickIntents: SendClickIntents, private val feeStateFactory: FeeStateFactory, ) { private val sendTransactionErrorConverter by lazy(LazyThreadSafetyMode.NONE) { SendTransactionAlertConverter( - cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider, clickIntents = clickIntents, ) } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt index 017c91f8d4..8a455b1b25 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt @@ -105,6 +105,14 @@ internal sealed class SendNotification(val config: NotificationConfig) { onClick = onConfirmClick, ), ) + + data class ReserveAmount(val amount: String) : Error( + title = resourceReference( + id = R.string.send_notification_invalid_reserve_amount_title, + wrappedList(amount), + ), + subtitle = resourceReference(id = R.string.send_notification_invalid_reserve_amount_text), + ) } sealed class Warning( 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 7f6a8588b1..d37954025b 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 @@ -1,14 +1,10 @@ package com.tangem.features.send.impl.presentation.state -import com.tangem.core.ui.utils.BigDecimalFormatter -import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.transaction.error.SendTransactionError import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents -import com.tangem.utils.Provider import com.tangem.utils.converter.Converter internal class SendTransactionAlertConverter( - private val cryptoCurrencyStatusProvider: Provider, private val clickIntents: SendClickIntents, ) : Converter { override fun convert(value: SendTransactionError): SendAlertState? { @@ -42,12 +38,6 @@ internal class SendTransactionAlertConverter( cause = value.ex?.localizedMessage, onConfirmClick = { clickIntents.onFailedTxEmailClick(value.ex?.localizedMessage.orEmpty()) }, ) - is SendTransactionError.CreateAccountUnderfunded -> SendAlertState.ReserveAmount( - BigDecimalFormatter.formatWithSymbol( - amount = value.amount, - symbol = cryptoCurrencyStatusProvider().currency.symbol, - ), - ) else -> null } } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt index a4e3bcbf9c..54dd992fa4 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt @@ -31,6 +31,7 @@ import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.lib.crypto.BlockchainUtils import com.tangem.lib.crypto.BlockchainUtils.isTezos import com.tangem.utils.Provider +import com.tangem.utils.extensions.orZero import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -60,14 +61,15 @@ internal class SendNotificationFactory( .map { val state = currentStateProvider() val isEditState = stateRouterProvider().isEditState - val balance = cryptoCurrencyStatusProvider().value.amount ?: BigDecimal.ZERO + val balance = cryptoCurrencyStatusProvider().value.amount.orZero() val sendState = state.sendState ?: return@map persistentListOf() val feeState = state.getFeeState(isEditState) ?: return@map persistentListOf() val amountState = state.getAmountState(isEditState) as? AmountState.Data ?: return@map persistentListOf() - val amountValue = amountState.amountTextField.cryptoAmount.value ?: BigDecimal.ZERO - val feeValue = feeState.fee?.amount?.value ?: BigDecimal.ZERO - val reduceAmountBy = sendState.reduceAmountBy ?: BigDecimal.ZERO + val recipientAddress = state.recipientState?.addressTextField?.value.orEmpty() + val amountValue = amountState.amountTextField.cryptoAmount.value.orZero() + val feeValue = feeState.fee?.amount?.value.orZero() + val reduceAmountBy = sendState.reduceAmountBy.orZero() val isFeeCoverage = checkFeeCoverage( isSubtractAvailable = isSubtractAvailableProvider(), balance = balance, @@ -89,6 +91,7 @@ internal class SendNotificationFactory( addExceedsBalanceNotification(feeState.fee) addDustWarningNotificationForSpecificBlockchains(feeValue, sendingAmount) addTransactionLimitErrorNotification(feeValue, sendingAmount) + addReserveAmountErrorNotification(recipientAddress, sendingAmount) // warnings addExistentialWarningNotification(feeValue, amountValue) @@ -156,27 +159,29 @@ internal class SendNotificationFactory( } } - // 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.addReserveAmountErrorNotification( + recipientAddress: String, + sendingAmount: BigDecimal, + ) { + 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 > sendingAmount) { + add( + SendNotification.Error.ReserveAmount( + 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/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt index a57a241ebf..764197090e 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt @@ -161,7 +161,6 @@ internal class SendViewModel @Inject constructor( clickIntents = this, stateRouterProvider = Provider { stateRouter }, currentStateProvider = Provider { uiState.value }, - cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus }, feeStateFactory = feeStateFactory, )