Updated on 2026-08-14

This commit is contained in:
Tangem 2026-01-18 11:10:11 +03:00
parent 767a995de8
commit 14cbec446e
4 changed files with 14 additions and 12 deletions

View file

@ -34,27 +34,28 @@ class GetBalanceNotEnoughForFeeWarningUseCase(
fee: BigDecimal,
userWalletId: UserWalletId,
tokenStatus: CryptoCurrencyStatus,
coinStatus: CryptoCurrencyStatus,
feeStatus: CryptoCurrencyStatus,
): Either<Throwable, CryptoCurrencyWarning?> = Either.catch {
withContext(dispatchers.io) {
val feePaidCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, tokenStatus.currency.network)
val coinBalance = coinStatus.value.amount ?: BigDecimal.ZERO
val feeTokenBalance = feeStatus.value.amount ?: BigDecimal.ZERO
val isFeePaidByCoin = tokenStatus.currency is CryptoCurrency.Token
val isFeePaidByToken =
feePaidCurrency is FeePaidCurrency.Token && tokenStatus.currency.id != feePaidCurrency.tokenId
val isNetworkSupportGasless = currencyChecksRepository.isNetworkSupportedForGaslessTx(
coinStatus.currency.network,
)
val isFeePaidByGaslessToken =
currencyChecksRepository.isNetworkSupportedForGaslessTx(feeStatus.currency.network) &&
feeStatus.currency is CryptoCurrency.Token
val warning = when {
feePaidCurrency is FeePaidCurrency.Coin &&
isFeePaidByCoin &&
fee > coinBalance &&
!isNetworkSupportGasless -> {
fee > feeTokenBalance &&
!isFeePaidByGaslessToken -> {
CryptoCurrencyWarning.BalanceNotEnoughForFee(
tokenCurrency = tokenStatus.currency,
coinCurrency = coinStatus.currency,
coinCurrency = feeStatus.currency,
)
}
feePaidCurrency is FeePaidCurrency.Token && isFeePaidByToken && fee > feePaidCurrency.balance -> {

View file

@ -235,7 +235,7 @@ internal class NotificationsModel @Inject constructor(
fee = feeValue,
userWalletId = userWalletId,
tokenStatus = cryptoCurrencyStatus,
coinStatus = feeCryptoCurrencyStatus,
feeStatus = notificationData.feeCryptoCurrencyStatus,
).getOrNull()
addExceedBalanceNotification(

View file

@ -852,12 +852,13 @@ internal class StakingModel @Inject constructor(
val amount = amountState?.amountTextField?.cryptoAmount?.value
val fee = feeState?.fee?.amount?.value
val currencyWarning = if (feeCryptoCurrencyStatus != null && fee != null) {
val feeStatus = feeCryptoCurrencyStatus
val currencyWarning = if (feeStatus != null && fee != null) {
getBalanceNotEnoughForFeeWarningUseCase(
fee = fee,
userWalletId = userWalletId,
tokenStatus = cryptoCurrencyStatus,
coinStatus = feeCryptoCurrencyStatus ?: cryptoCurrencyStatus,
feeStatus = feeStatus,
).getOrNull()
} else {
null

View file

@ -54,7 +54,7 @@ internal class YieldSupplyNotificationsModel @Inject constructor(
fee = data.feeValue.orZero(),
userWalletId = params.userWalletId,
tokenStatus = cryptoCurrencyStatus,
coinStatus = feeCryptoCurrencyStatus,
feeStatus = feeCryptoCurrencyStatus,
).getOrNull()
addExceedsBalanceNotification(