From d66758f0c2229a598f50698c55bef7eb1c2f81f5 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 3 Feb 2025 19:29:53 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../ui/notifications/NotificationsFactory.kt | 24 ++++++++++++------- .../data/tokens/converters/UtxoConverter.kt | 5 ++-- .../model/blockchains/UtxoAmountLimit.kt | 10 ++++---- .../state/confirm/SendNotificationFactory.kt | 1 + .../presentation/viewmodel/SendViewModel.kt | 4 ++-- .../AddStakingNotificationsTransformer.kt | 1 + .../presentation/SwapNotificationsFactory.kt | 3 +++ gradle/dependencies.toml | 2 +- 8 files changed, 33 insertions(+), 17 deletions(-) diff --git a/common/ui/src/main/java/com/tangem/common/ui/notifications/NotificationsFactory.kt b/common/ui/src/main/java/com/tangem/common/ui/notifications/NotificationsFactory.kt index d25fea1cbc..06a15df8af 100644 --- a/common/ui/src/main/java/com/tangem/common/ui/notifications/NotificationsFactory.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/notifications/NotificationsFactory.kt @@ -15,6 +15,7 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.blockchains.UtxoAmountLimit import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning import com.tangem.domain.transaction.error.GetFeeError +import com.tangem.utils.extensions.isZero import com.tangem.utils.extensions.orZero import java.math.BigDecimal @@ -126,20 +127,22 @@ object NotificationsFactory { fun MutableList.addTransactionLimitErrorNotification( utxoLimit: UtxoAmountLimit?, cryptoCurrency: CryptoCurrency, + feeValue: BigDecimal, onReduceClick: ( reduceAmountTo: BigDecimal, notification: Class, ) -> Unit, ) { - if (utxoLimit != null) { + val availableToSend = utxoLimit?.availableToSend + if (availableToSend != null && !feeValue.isZero()) { add( NotificationUM.Error.TransactionLimitError( cryptoCurrency = cryptoCurrency.name, - utxoLimit = utxoLimit.maxLimit.toPlainString(), - amountLimit = utxoLimit.maxAmount.format { crypto(cryptoCurrency) }, + utxoLimit = utxoLimit.limit.toPlainString(), + amountLimit = availableToSend.format { crypto(cryptoCurrency) }, onConfirmClick = { onReduceClick( - utxoLimit.maxAmount, + availableToSend, NotificationUM.Error.TransactionLimitError::class.java, ) }, @@ -402,18 +405,23 @@ object NotificationsFactory { ): Boolean { val change = when (cryptoCurrencyStatus.currency) { is CryptoCurrency.Coin -> { - val balance = cryptoCurrencyStatus.value.amount ?: BigDecimal.ZERO + val balance = cryptoCurrencyStatus.value.amount.orZero() balance - (feeAmount + sendingAmount) } is CryptoCurrency.Token -> { - val balance = feeCurrencyStatus?.value?.amount ?: BigDecimal.ZERO + val balance = feeCurrencyStatus?.value?.amount.orZero() balance - feeAmount } } - val isChangeLowerThanDust = change < dustValue && change > BigDecimal.ZERO + val dust = when (cryptoCurrencyStatus.currency) { + is CryptoCurrency.Coin -> dustValue + is CryptoCurrency.Token -> BigDecimal.ZERO + } + + val isChangeLowerThanDust = change < dust && change > BigDecimal.ZERO return when (cryptoCurrencyStatus.currency) { - is CryptoCurrency.Coin -> sendingAmount < dustValue || isChangeLowerThanDust + is CryptoCurrency.Coin -> sendingAmount < dust || isChangeLowerThanDust is CryptoCurrency.Token -> isChangeLowerThanDust } } diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/converters/UtxoConverter.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/converters/UtxoConverter.kt index 2a663558c3..b63fa4173d 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/converters/UtxoConverter.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/converters/UtxoConverter.kt @@ -7,8 +7,9 @@ import com.tangem.blockchain.common.UtxoAmountLimit as BlockchainUtxoAmountLimit internal class UtxoConverter : Converter { override fun convert(value: BlockchainUtxoAmountLimit): UtxoAmountLimit { return UtxoAmountLimit( - maxLimit = value.maxLimit, - maxAmount = value.maxAmount, + limit = value.limit, + availableToSpend = value.availableToSpend, + availableToSend = value.availableToSend, ) } } \ No newline at end of file diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/blockchains/UtxoAmountLimit.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/blockchains/UtxoAmountLimit.kt index ef70be02c4..3e178204d2 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/blockchains/UtxoAmountLimit.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/blockchains/UtxoAmountLimit.kt @@ -5,10 +5,12 @@ import java.math.BigDecimal /** * Model stores utxo limits * - * @property maxLimit utxo limit - * @property maxAmount max amount + * @property limit Maximum allowed number of UTXO in single transaction + * @property availableToSpend Allowed amount to participate in single transaction + * @property availableToSend Amount user can send in single transaction */ data class UtxoAmountLimit( - val maxLimit: BigDecimal, - val maxAmount: BigDecimal, + val limit: BigDecimal, + val availableToSpend: BigDecimal, + val availableToSend: BigDecimal?, ) \ No newline at end of file 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 5369749224..38c478b425 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 @@ -213,6 +213,7 @@ internal class SendNotificationFactory( addTransactionLimitErrorNotification( utxoLimit = currencyCheck.utxoAmountLimit, cryptoCurrency = currency, + feeValue = feeValue, onReduceClick = clickIntents::onAmountReduceToClick, ) addReserveAmountErrorNotification( 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 ec9e878040..945c953dba 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 @@ -872,7 +872,7 @@ internal class SendViewModel @Inject constructor( override fun onAmountReduceToClick(reduceAmountTo: BigDecimal, notification: Class) { uiState.value = amountStateFactory.getOnAmountReduceToState(reduceAmountTo) uiState.value = sendNotificationFactory.dismissNotificationState(notification) - updateNotifications() + feeReload() } override fun onAmountReduceByClick( @@ -886,7 +886,7 @@ internal class SendViewModel @Inject constructor( ) uiState.value = sendNotificationFactory.dismissNotificationState(notification) - updateNotifications() + feeReload() } override fun onNotificationCancel(clazz: Class) { diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/notifications/AddStakingNotificationsTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/notifications/AddStakingNotificationsTransformer.kt index c46880d541..1d7f631da5 100644 --- a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/notifications/AddStakingNotificationsTransformer.kt +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/notifications/AddStakingNotificationsTransformer.kt @@ -170,6 +170,7 @@ internal class AddStakingNotificationsTransformer( addTransactionLimitErrorNotification( utxoLimit = currencyCheck.utxoAmountLimit, cryptoCurrency = cryptoCurrency, + feeValue = feeValue, onReduceClick = prevState.clickIntents::onAmountReduceToClick, ) addReserveAmountErrorNotification( diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapNotificationsFactory.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapNotificationsFactory.kt index 202f7100a6..3bc9bd6767 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapNotificationsFactory.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapNotificationsFactory.kt @@ -29,6 +29,7 @@ import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList import java.math.BigDecimal +@Suppress("LargeClass") internal class SwapNotificationsFactory( private val actions: UiActions, ) { @@ -130,6 +131,7 @@ internal class SwapNotificationsFactory( } } + @Suppress("LongMethod") private fun MutableList.maybeAddDomainWarnings( quoteModel: SwapState.QuotesLoadedState, feeCryptoCurrencyStatus: CryptoCurrencyStatus?, @@ -199,6 +201,7 @@ internal class SwapNotificationsFactory( addTransactionLimitErrorNotification( utxoLimit = quoteModel.currencyCheck?.utxoAmountLimit, cryptoCurrency = fromCurrencyStatus.currency, + feeValue = fee?.feeValue.orZero(), onReduceClick = { reduceTo, _ -> actions.onReduceToAmount(amountToRequest.copy(value = reduceTo)) }, diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index 62b04e4d76..834debb383 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -89,7 +89,7 @@ markdownComposeView = "0.5.4" # endregion Other libraries # region Tangem -tangemBlockchainSdk = "develop-942" +tangemBlockchainSdk = "develop-944" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds tangemCardSdk = "develop-433" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^