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 2bb5569c19..60fcbfece5 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 @@ -244,7 +244,7 @@ internal class SwapInteractorImpl @Inject constructor( return repository.getTangemFee() } - fun getTokenDecimals(token: Currency): Int { + private fun getTokenDecimals(token: Currency): Int { return if (token is Currency.NonNativeToken) { token.decimalCount } else { @@ -355,15 +355,15 @@ internal class SwapInteractorImpl @Inject constructor( swapStateData = null, formattedFee = null, ) - return updatePermissionState( + val quotesState = updatePermissionState( networkId = networkId, fromToken = fromToken, quotesLoadedState = swapState, - ).copy( - preparedSwapConfigState = PreparedSwapConfigState( + ) + return quotesState.copy( + preparedSwapConfigState = quotesState.preparedSwapConfigState.copy( isAllowedToSpend = isAllowedToSpend, isBalanceEnough = isBalanceWithoutFeeEnough, - isFeeEnough = true, ), ) } else { @@ -540,7 +540,14 @@ internal class SwapInteractorImpl @Inject constructor( decimals = transactionManager.getNativeTokenDecimals(networkId), currency = userWalletManager.getNetworkCurrency(networkId), ) + feeFiat + val isFeeEnough = checkFeeIsEnough( + fee = feeData.fee.value, + spendAmount = SwapAmount.zeroSwapAmount(), + networkId = networkId, + fromToken = fromToken, + ) return quotesLoadedState.copy( + fee = formattedFee, permissionState = PermissionDataState.PermissionReadyForRequest( currency = fromToken.symbol, amount = INFINITY_SYMBOL, @@ -553,6 +560,9 @@ internal class SwapInteractorImpl @Inject constructor( approveModel = transactionData, ), ), + preparedSwapConfigState = quotesLoadedState.preparedSwapConfigState.copy( + isFeeEnough = isFeeEnough, + ), ) } diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/models/SwapAmount.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/models/SwapAmount.kt index 342ce251e7..c37e6fbc96 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/models/SwapAmount.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/models/SwapAmount.kt @@ -6,7 +6,14 @@ import java.math.BigDecimal data class SwapAmount( val value: BigDecimal, val decimals: Int, -) +) { + + companion object { + fun zeroSwapAmount(): SwapAmount { + return SwapAmount(BigDecimal.ZERO, 0) + } + } +} fun SwapAmount.formatToUIRepresentation(): String { return value.toFormattedString(decimals = decimals) diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/models/domain/PreparedSwapConfigState.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/models/domain/PreparedSwapConfigState.kt index 29515eef16..8b9f1c963b 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/models/domain/PreparedSwapConfigState.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/models/domain/PreparedSwapConfigState.kt @@ -1,5 +1,12 @@ package com.tangem.feature.swap.domain.models.domain +/** + * Prepared swap config state that contains flags to determine + * + * @property isAllowedToSpend shows is token allowed to spend + * @property isBalanceEnough shows is balance of token enough + * @property isFeeEnough shows is amount of main coin enough for fee + */ data class PreparedSwapConfigState( val isAllowedToSpend: Boolean, val isBalanceEnough: Boolean,