Updated on 2026-08-14
This commit is contained in:
commit
5fee537c82
8 changed files with 33 additions and 17 deletions
|
|
@ -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<NotificationUM>.addTransactionLimitErrorNotification(
|
||||
utxoLimit: UtxoAmountLimit?,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
feeValue: BigDecimal,
|
||||
onReduceClick: (
|
||||
reduceAmountTo: BigDecimal,
|
||||
notification: Class<out NotificationUM>,
|
||||
) -> 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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ import com.tangem.blockchain.common.UtxoAmountLimit as BlockchainUtxoAmountLimit
|
|||
internal class UtxoConverter : Converter<BlockchainUtxoAmountLimit, UtxoAmountLimit> {
|
||||
override fun convert(value: BlockchainUtxoAmountLimit): UtxoAmountLimit {
|
||||
return UtxoAmountLimit(
|
||||
maxLimit = value.maxLimit,
|
||||
maxAmount = value.maxAmount,
|
||||
limit = value.limit,
|
||||
availableToSpend = value.availableToSpend,
|
||||
availableToSend = value.availableToSend,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -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?,
|
||||
)
|
||||
|
|
@ -213,6 +213,7 @@ internal class SendNotificationFactory(
|
|||
addTransactionLimitErrorNotification(
|
||||
utxoLimit = currencyCheck.utxoAmountLimit,
|
||||
cryptoCurrency = currency,
|
||||
feeValue = feeValue,
|
||||
onReduceClick = clickIntents::onAmountReduceToClick,
|
||||
)
|
||||
addReserveAmountErrorNotification(
|
||||
|
|
|
|||
|
|
@ -872,7 +872,7 @@ internal class SendViewModel @Inject constructor(
|
|||
override fun onAmountReduceToClick(reduceAmountTo: BigDecimal, notification: Class<out NotificationUM>) {
|
||||
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<out NotificationUM>) {
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ internal class AddStakingNotificationsTransformer(
|
|||
addTransactionLimitErrorNotification(
|
||||
utxoLimit = currencyCheck.utxoAmountLimit,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
feeValue = feeValue,
|
||||
onReduceClick = prevState.clickIntents::onAmountReduceToClick,
|
||||
)
|
||||
addReserveAmountErrorNotification(
|
||||
|
|
|
|||
|
|
@ -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<NotificationUM>.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))
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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 ^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue