Updated on 2026-08-14

This commit is contained in:
Tangem 2025-01-24 10:48:32 +03:00
parent 7d870833db
commit b8a3a6899f
9 changed files with 20 additions and 14 deletions

View file

@ -417,16 +417,16 @@ internal class DefaultCurrenciesRepository(
}
}
override suspend fun getFeePaidCurrency(userWalletId: UserWalletId, currency: CryptoCurrency): FeePaidCurrency {
override suspend fun getFeePaidCurrency(userWalletId: UserWalletId, network: Network): FeePaidCurrency {
return withContext(dispatchers.io) {
val blockchain = Blockchain.fromId(currency.network.id.value)
val blockchain = Blockchain.fromId(network.id.value)
when (val feePaidCurrency = blockchain.feePaidCurrency()) {
FeePaidSdkCurrency.Coin -> FeePaidCurrency.Coin
FeePaidSdkCurrency.SameCurrency -> FeePaidCurrency.SameCurrency
is FeePaidSdkCurrency.Token -> {
val balance = walletManagersFacade.tokenBalance(
userWalletId = userWalletId,
network = currency.network,
network = network,
name = feePaidCurrency.token.name,
symbol = feePaidCurrency.token.symbol,
contractAddress = feePaidCurrency.token.contractAddress,
@ -434,7 +434,7 @@ internal class DefaultCurrenciesRepository(
id = feePaidCurrency.token.id,
)
FeePaidCurrency.Token(
tokenId = getTokenId(network = currency.network, sdkToken = feePaidCurrency.token),
tokenId = getTokenId(network = network, sdkToken = feePaidCurrency.token),
name = feePaidCurrency.token.name,
symbol = feePaidCurrency.token.symbol,
contractAddress = feePaidCurrency.token.contractAddress,

View file

@ -34,7 +34,7 @@ class GetBalanceNotEnoughForFeeWarningUseCase(
coinStatus: CryptoCurrencyStatus,
): Either<Throwable, CryptoCurrencyWarning?> = Either.catch {
withContext(dispatchers.io) {
val feePaidCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, tokenStatus.currency)
val feePaidCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, tokenStatus.currency.network)
val coinBalance = coinStatus.value.amount ?: BigDecimal.ZERO
val isFeePaidByCoin = tokenStatus.currency is CryptoCurrency.Token

View file

@ -115,7 +115,7 @@ class GetCurrencyWarningsUseCase(
coinStatus: CryptoCurrencyStatus,
tokenStatus: CryptoCurrencyStatus,
): CryptoCurrencyWarning? {
val feePaidCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, tokenStatus.currency)
val feePaidCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, tokenStatus.currency.network)
val isNetworkFeeZero = currenciesRepository.isNetworkFeeZero(userWalletId, tokenStatus.currency.network)
return when {
feePaidCurrency is FeePaidCurrency.Coin &&

View file

@ -26,7 +26,8 @@ class GetFeePaidCryptoCurrencyStatusSyncUseCase(
cryptoCurrencyStatus: CryptoCurrencyStatus,
): Either<TokenListError, CryptoCurrencyStatus?> {
val cryptoCurrency = cryptoCurrencyStatus.currency
val feePaidCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, cryptoCurrency)
val network = cryptoCurrency.network
val feePaidCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, network)
val operations = CurrenciesStatusesOperations(
userWalletId = userWalletId,
currenciesRepository = currenciesRepository,
@ -39,7 +40,7 @@ class GetFeePaidCryptoCurrencyStatusSyncUseCase(
when (feePaidCurrency) {
FeePaidCurrency.Coin ->
operations
.getNetworkCoinSync(cryptoCurrency.network.id, cryptoCurrency.network.derivationPath)
.getNetworkCoinSync(network.id, network.derivationPath)
.getOrNull()
FeePaidCurrency.SameCurrency,
is FeePaidCurrency.FeeResource,

View file

@ -19,7 +19,7 @@ class IsAmountSubtractAvailableUseCase(
suspend operator fun invoke(userWalletId: UserWalletId, currency: CryptoCurrency): Either<Throwable, Boolean> =
Either.catch {
withContext(dispatchers.io) {
when (val feeCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, currency)) {
when (val feeCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, currency.network)) {
is FeePaidCurrency.Coin -> currency is CryptoCurrency.Coin
is FeePaidCurrency.SameCurrency -> true
is FeePaidCurrency.Token -> currency.id == feeCurrency.tokenId

View file

@ -231,9 +231,9 @@ interface CurrenciesRepository {
): Boolean
/**
* Retrieves fee paid currency for specific [currency].
* Retrieves fee paid currency for specific [network].
*/
suspend fun getFeePaidCurrency(userWalletId: UserWalletId, currency: CryptoCurrency): FeePaidCurrency
suspend fun getFeePaidCurrency(userWalletId: UserWalletId, network: Network): FeePaidCurrency
/**
* Creates token [cryptoCurrency] based on current token and [network] it`s will be added

View file

@ -137,7 +137,7 @@ internal class MockCurrenciesRepository(
return false
}
override suspend fun getFeePaidCurrency(userWalletId: UserWalletId, currency: CryptoCurrency): FeePaidCurrency {
override suspend fun getFeePaidCurrency(userWalletId: UserWalletId, network: Network): FeePaidCurrency {
return FeePaidCurrency.Coin
}

View file

@ -96,7 +96,12 @@ internal class SendNotificationFactory(
val recipientAddress = state.recipientState?.addressTextField?.value
val statusValue = cryptoCurrencyStatus.value as? CryptoCurrencyStatus.Loaded
val balanceAfterTransaction = statusValue?.let { it.amount - sendingAmount - feeValue }
val feeToSubtract = if (isSubtractAvailableProvider()) {
feeValue
} else {
BigDecimal.ZERO
}
val balanceAfterTransaction = statusValue?.let { it.amount - sendingAmount - feeToSubtract }
val currencyCheck = getCurrencyCheckUseCase(
userWalletId = userWalletId,
currencyStatus = cryptoCurrencyStatus,

View file

@ -1992,7 +1992,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
private suspend fun getFeePaidCurrency(currency: CryptoCurrency): FeePaidCurrency {
return currenciesRepository.getFeePaidCurrency(
userWalletId = userWalletId,
currency = currency,
network = currency.network,
)
}