Updated on 2026-08-14

This commit is contained in:
Tangem 2025-10-14 19:52:46 +05:00
parent 06e726d9ad
commit a6ec3453dd
5 changed files with 69 additions and 44 deletions

View file

@ -44,10 +44,12 @@ object NotificationsFactory {
}
}
@Suppress("LongParameterList")
fun MutableList<NotificationUM>.addFeeUnreachableNotification(
tokenStatus: CryptoCurrencyStatus,
coinStatus: CryptoCurrencyStatus,
feeError: GetFeeError?,
dustValue: BigDecimal?,
onReload: () -> Unit,
onClick: (currency: CryptoCurrency) -> Unit,
) {
@ -70,7 +72,16 @@ object NotificationsFactory {
)
is GetFeeError.BlockchainErrors.SuiOneCoinRequired ->
add(NotificationUM.Sui.NotEnoughCoinForTokenTransaction)
is GetFeeError.DataError,
is GetFeeError.DataError -> when (feeError.cause) {
BlockchainSdkError.TransactionDustChangeError -> add(
NotificationUM.Error.MinimumAmountError(
amount = dustValue.format { crypto(tokenStatus.currency) },
),
)
else -> add(
NotificationUM.Warning.NetworkFeeUnreachable(onReload),
)
}
is GetFeeError.UnknownError,
-> add(
NotificationUM.Warning.NetworkFeeUnreachable(onReload),
@ -358,6 +369,11 @@ object NotificationsFactory {
is BlockchainSdkError.Solana.DestinationRentExemption -> addRentExemptionDestinationNotification(
rentExemptionAmount = validationError.rentAmount,
)
is BlockchainSdkError.TransactionDustChangeError -> add(
NotificationUM.Error.MinimumAmountError(
amount = dustValue.format { crypto(cryptoCurrency) },
),
)
null,
-> minAdaValue?.let {
add(

View file

@ -21,9 +21,10 @@ object FeeCalculationUtils {
isAmountSubtractAvailable: Boolean,
cryptoCurrencyStatus: CryptoCurrencyStatus,
amountValue: BigDecimal,
feeValue: BigDecimal,
feeValue: BigDecimal?,
reduceAmountBy: BigDecimal,
): BigDecimal {
if (feeValue == null || feeValue.isZero()) return amountValue
val balance = cryptoCurrencyStatus.value.amount ?: return amountValue
val isFeeCoverage = checkFeeCoverage(
isSubtractAvailable = isAmountSubtractAvailable,

View file

@ -161,6 +161,7 @@ internal class SendConfirmModel @Inject constructor(
fun updateState(state: SendUM) {
_uiState.value = state
onFeeReload()
updateConfirmNotifications()
}

View file

@ -120,46 +120,8 @@ internal class NotificationsModel @Inject constructor(
buildNotifications()
}
private suspend fun buildNotifications() {
val notifications = buildList {
addFeeUnreachableNotification(
tokenStatus = cryptoCurrencyStatus,
coinStatus = feeCryptoCurrencyStatus,
feeError = notificationData.feeError,
onReload = params.callback::onFeeReload,
onClick = ::showTokenDetails,
)
addDomainNotifications()
}
notificationsUpdateTrigger.callbackHasError(notifications.any { it is NotificationUM.Error })
_uiState.value = notifications.toImmutableList()
}
private fun showTokenDetails(currency: CryptoCurrency) {
appRouter.pop { isSuccess ->
if (isSuccess) {
appRouter.push(
AppRoute.CurrencyDetails(
userWalletId = userWalletId,
currency = currency,
),
)
}
}
}
private suspend fun MutableList<NotificationUM>.addDomainNotifications() = with(notificationData) {
val balance = cryptoCurrencyStatus.value.amount ?: return
val feeValue = fee?.amount?.value ?: return
val isFeeCoverage = checkFeeCoverage(
isSubtractAvailable = isAmountSubtractAvailable,
balance = balance,
amountValue = amountValue,
feeValue = feeValue,
reduceAmountBy = reduceAmountBy,
)
private suspend fun buildNotifications() = with(notificationData) {
val feeValue = fee?.amount?.value
val sendingAmount = checkAndCalculateSubtractedAmount(
isAmountSubtractAvailable = isAmountSubtractAvailable,
cryptoCurrencyStatus = cryptoCurrencyStatus,
@ -180,6 +142,50 @@ internal class NotificationsModel @Inject constructor(
feeCurrencyBalanceAfterTransaction = feeCurrencyBalanceAfterTransaction,
)
val notifications = buildList {
addFeeUnreachableNotification(
tokenStatus = cryptoCurrencyStatus,
coinStatus = feeCryptoCurrencyStatus,
feeError = notificationData.feeError,
dustValue = currencyCheck.dustValue,
onReload = params.callback::onFeeReload,
onClick = ::showTokenDetails,
)
addDomainNotifications(currencyCheck = currencyCheck, sendingAmount = sendingAmount)
}
notificationsUpdateTrigger.callbackHasError(notifications.any { it is NotificationUM.Error })
_uiState.value = notifications.toImmutableList()
}
private fun showTokenDetails(currency: CryptoCurrency) {
appRouter.pop { isSuccess ->
if (isSuccess) {
appRouter.push(
AppRoute.CurrencyDetails(
userWalletId = userWalletId,
currency = currency,
),
)
}
}
}
private suspend fun MutableList<NotificationUM>.addDomainNotifications(
currencyCheck: CryptoCurrencyCheck,
sendingAmount: BigDecimal,
) = with(notificationData) {
val balance = cryptoCurrencyStatus.value.amount ?: return
val feeValue = fee?.amount?.value ?: return
val isFeeCoverage = checkFeeCoverage(
isSubtractAvailable = isAmountSubtractAvailable,
balance = balance,
amountValue = amountValue,
feeValue = feeValue,
reduceAmountBy = reduceAmountBy,
)
addErrorNotifications(
sendingAmount = sendingAmount,
feeValue = feeValue,
@ -198,10 +204,10 @@ internal class NotificationsModel @Inject constructor(
addInfoNotifications()
}
private fun getFeeCurrencyBalanceAfterTx(sendingAmount: BigDecimal, feeValue: BigDecimal): BigDecimal? {
private fun getFeeCurrencyBalanceAfterTx(sendingAmount: BigDecimal, feeValue: BigDecimal?): BigDecimal? {
val sendingCurrencyBalance = cryptoCurrencyStatus.value as? CryptoCurrencyStatus.Loaded
val feeCurrencyBalance = feeCryptoCurrencyStatus.value as? CryptoCurrencyStatus.Loaded
if (feeCryptoCurrencyStatus.value !is CryptoCurrencyStatus.Loaded) return null
if (feeCryptoCurrencyStatus.value !is CryptoCurrencyStatus.Loaded || feeValue == null) return null
return when {
feeCryptoCurrencyStatus == cryptoCurrencyStatus -> sendingCurrencyBalance?.let {
it.amount - sendingAmount - feeValue

View file

@ -68,6 +68,7 @@ internal class YieldSupplyNotificationsModel @Inject constructor(
coinStatus = feeCryptoCurrencyStatus,
feeError = data.feeError,
onClick = ::openTokenDetails,
dustValue = null,
onReload = params.callback::onFeeReload,
)
}