Updated on 2026-08-14

This commit is contained in:
Tangem 2024-12-06 16:05:16 +03:00
parent 476bb30175
commit 2c1f4c0784
4 changed files with 33 additions and 9 deletions

View file

@ -126,16 +126,29 @@ internal class DefaultCurrencyChecksRepository(
override suspend fun getRentInfoWarning(
userWalletId: UserWalletId,
currencyStatus: CryptoCurrencyStatus,
balanceAfterTransaction: BigDecimal?,
): CryptoCurrencyWarning.Rent? {
val rentData = walletManagersFacade.getRentInfo(userWalletId, currencyStatus.currency.network) ?: return null
val balanceValue = currencyStatus.value as? CryptoCurrencyStatus.Loaded ?: return null
val stakingTotalBalance =
(balanceValue.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance() ?: BigDecimal.ZERO
val amount = balanceAfterTransaction ?: balanceValue.amount
return when {
amount.isZero() && stakingTotalBalance.isZero() -> null
amount < rentData.exemptionAmount && stakingTotalBalance.isZero() -> {
balanceValue.amount.isZero() && stakingTotalBalance.isZero() -> null
balanceValue.amount < rentData.exemptionAmount && stakingTotalBalance.isZero() -> {
CryptoCurrencyWarning.Rent(rentData.rent, rentData.exemptionAmount)
}
else -> null
}
}
override suspend fun getRentExemptionError(
userWalletId: UserWalletId,
currencyStatus: CryptoCurrencyStatus,
balanceAfterTransaction: BigDecimal,
): CryptoCurrencyWarning.Rent? {
val rentData = walletManagersFacade.getRentInfo(userWalletId, currencyStatus.currency.network) ?: return null
return when {
balanceAfterTransaction.isZero() -> null
balanceAfterTransaction < rentData.exemptionAmount -> {
CryptoCurrencyWarning.Rent(rentData.rent, rentData.exemptionAmount)
}
else -> null

View file

@ -27,8 +27,11 @@ class GetCurrencyCheckUseCase(
val reserveAmount = currencyChecksRepository.getReserveAmount(userWalletId, network)
val minimumSendAmount = currencyChecksRepository.getMinimumSendAmount(userWalletId, network)
val existentialDeposit = currencyChecksRepository.getExistentialDeposit(userWalletId, network)
val rentWarning =
currencyChecksRepository.getRentInfoWarning(userWalletId, currencyStatus, balanceAfterTransaction)
val rentWarning = currencyChecksRepository.getRentExemptionError(
userWalletId = userWalletId,
currencyStatus = currencyStatus,
balanceAfterTransaction = balanceAfterTransaction ?: BigDecimal.ZERO,
)
val isAccountFunded = recipientAddress?.let {
currencyChecksRepository.checkIfAccountFunded(
userWalletId,

View file

@ -58,7 +58,7 @@ class GetCurrencyWarningsUseCase(
derivationPath = derivationPath,
isSingleWalletWithTokens = isSingleWalletWithTokens,
),
flowOf(currencyChecksRepository.getRentInfoWarning(userWalletId, currencyStatus, null)),
flowOf(currencyChecksRepository.getRentInfoWarning(userWalletId, currencyStatus)),
flowOf(currencyChecksRepository.getExistentialDeposit(userWalletId, currency.network)),
flowOf(currencyChecksRepository.getFeeResourceAmount(userWalletId, currency.network)),
getSwapPromoNotificationWarning(

View file

@ -44,11 +44,19 @@ interface CurrencyChecksRepository {
/**
* Checks if need warning for Solana rent
* @param balanceAfterTransaction if non null, checks with balance remains after transaction
*/
suspend fun getRentInfoWarning(
userWalletId: UserWalletId,
currencyStatus: CryptoCurrencyStatus,
balanceAfterTransaction: BigDecimal?,
): CryptoCurrencyWarning.Rent?
/**
* Checks if need error before Solana tx about rent exemption
* @param balanceAfterTransaction if non null, checks with balance remains after transaction
*/
suspend fun getRentExemptionError(
userWalletId: UserWalletId,
currencyStatus: CryptoCurrencyStatus,
balanceAfterTransaction: BigDecimal,
): CryptoCurrencyWarning.Rent?
}