Updated on 2026-08-14

This commit is contained in:
Tangem 2024-11-18 17:01:35 +03:00
parent a80542d5da
commit 3d832ddd3e
13 changed files with 88 additions and 24 deletions

View file

@ -25,11 +25,11 @@ import com.tangem.domain.common.util.hasDerivation
import com.tangem.domain.demo.DemoConfig
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning
import com.tangem.domain.transaction.models.AssetRequirementsCondition
import com.tangem.domain.txhistory.models.PaginationWrapper
import com.tangem.domain.txhistory.models.TxHistoryItem
import com.tangem.domain.txhistory.models.TxHistoryState
import com.tangem.domain.walletmanager.model.RentData
import com.tangem.domain.walletmanager.model.SmartContractMethod
import com.tangem.domain.walletmanager.model.TokenInfo
import com.tangem.domain.walletmanager.model.UpdateWalletManagerResult
@ -413,7 +413,7 @@ class DefaultWalletManagersFacade(
return manager?.wallet?.addresses.orEmpty()
}
override suspend fun getRentInfo(userWalletId: UserWalletId, network: Network): CryptoCurrencyWarning.Rent? {
override suspend fun getRentInfo(userWalletId: UserWalletId, network: Network): RentData? {
val manager = getOrCreateWalletManager(
userWalletId = userWalletId,
network = network,
@ -422,24 +422,7 @@ class DefaultWalletManagersFacade(
return when (val result = manager.minimalBalanceForRentExemption()) {
is Result.Success -> {
val balance = manager.wallet.fundsAvailable(AmountType.Coin)
val outgoingTxs = manager.wallet.recentTransactions
.filter {
it.sourceAddress == manager.wallet.address &&
it.amount.type == AmountType.Coin &&
it.status != TransactionStatus.Confirmed
}
val rentExempt = result.data
val setRent = if (outgoingTxs.isEmpty()) {
balance < rentExempt
} else {
val outgoingAmount = outgoingTxs.sumOf { it.amount.value ?: BigDecimal.ZERO }
val rest = balance.minus(outgoingAmount)
balance < rest
}
if (setRent) CryptoCurrencyWarning.Rent(manager.rentAmount(), rentExempt) else null
RentData(manager.rentAmount(), result.data)
}
is Result.Failure -> null
}

View file

@ -12,11 +12,11 @@ import com.tangem.blockchain.extensions.Result
import com.tangem.blockchain.extensions.SimpleResult
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning
import com.tangem.domain.transaction.models.AssetRequirementsCondition
import com.tangem.domain.txhistory.models.PaginationWrapper
import com.tangem.domain.txhistory.models.TxHistoryItem
import com.tangem.domain.txhistory.models.TxHistoryState
import com.tangem.domain.walletmanager.model.RentData
import com.tangem.domain.walletmanager.model.TokenInfo
import com.tangem.domain.walletmanager.model.UpdateWalletManagerResult
import com.tangem.domain.wallets.models.UserWalletId
@ -140,7 +140,7 @@ interface WalletManagersFacade {
* @param userWalletId selected wallet id
* @param network network of currency
*/
suspend fun getRentInfo(userWalletId: UserWalletId, network: Network): CryptoCurrencyWarning.Rent?
suspend fun getRentInfo(userWalletId: UserWalletId, network: Network): RentData?
@Deprecated("Will be removed in future")
fun getAll(userWalletId: UserWalletId): Flow<List<WalletManager>>

View file

@ -0,0 +1,11 @@
package com.tangem.domain.walletmanager.model
import java.math.BigDecimal
/**
* Represents wallet blockchain rent
* @param rent Amount that will be charged in overtime if the blockchain does not have an amount greater than
* the [exemptionAmount]
* @param exemptionAmount Amount that should be on the blockchain balance not to pay rent
*/
data class RentData(val rent: BigDecimal, val exemptionAmount: BigDecimal)