diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt index 4fb9ef47d2..36fc695b7f 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt @@ -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, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetBalanceNotEnoughForFeeWarningUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetBalanceNotEnoughForFeeWarningUseCase.kt index b1f054e498..3f85d27819 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetBalanceNotEnoughForFeeWarningUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetBalanceNotEnoughForFeeWarningUseCase.kt @@ -34,7 +34,7 @@ class GetBalanceNotEnoughForFeeWarningUseCase( coinStatus: CryptoCurrencyStatus, ): Either = 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 diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt index 5be9720ad4..111f62b3ce 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt @@ -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 && diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetFeePaidCryptoCurrencyStatusSyncUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetFeePaidCryptoCurrencyStatusSyncUseCase.kt index 473b7c10b9..a66a4c3074 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetFeePaidCryptoCurrencyStatusSyncUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetFeePaidCryptoCurrencyStatusSyncUseCase.kt @@ -26,7 +26,8 @@ class GetFeePaidCryptoCurrencyStatusSyncUseCase( cryptoCurrencyStatus: CryptoCurrencyStatus, ): Either { 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, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/IsAmountSubtractAvailableUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/IsAmountSubtractAvailableUseCase.kt index 59510b29f3..080d6c0e79 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/IsAmountSubtractAvailableUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/IsAmountSubtractAvailableUseCase.kt @@ -19,7 +19,7 @@ class IsAmountSubtractAvailableUseCase( suspend operator fun invoke(userWalletId: UserWalletId, currency: CryptoCurrency): Either = 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 diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt index b3a7846497..c99a692b70 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt @@ -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 diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt index 6f9e9811af..ce99852888 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt @@ -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 } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt index 3918f10bb4..4736397eb8 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt @@ -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, diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt index 754fc5a789..84fefe7f12 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt @@ -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, ) }