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 9fc28e116c..09b5c11731 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 @@ -1223,6 +1223,23 @@ internal class SwapInteractorImpl @Inject constructor( }, ) + val fee = when (txFeeSealedState) { + is TxFeeSealedState.Component -> txFeeSealedState.txFee.fee.amount.value + is TxFeeSealedState.Legacy -> { + when (val txFee = txFeeSealedState.txFeeState) { + TxFeeState.Empty -> BigDecimal.ZERO + is TxFeeState.MultipleFeeState -> txFee.priorityFee.fee.amount.value + is TxFeeState.SingleFeeState -> txFee.fee.fee.amount.value + } + } + } + + val feeState = getFeeState( + fromSwapCurrencyStatus = fromSwapCurrencyStatus, + fee = fee, + spendAmount = amount, + ) + when (provider.type) { ExchangeProviderType.DEX, ExchangeProviderType.DEX_BRIDGE -> { val state = updatePermissionState( @@ -1236,26 +1253,11 @@ internal class SwapInteractorImpl @Inject constructor( state.copy( preparedSwapConfigState = state.preparedSwapConfigState.copy( isBalanceEnough = isBalanceWithoutFeeEnough, + feeState = feeState, ), ) } ExchangeProviderType.CEX -> { - val fee = when (txFeeSealedState) { - is TxFeeSealedState.Component -> txFeeSealedState.txFee.fee.amount.value - is TxFeeSealedState.Legacy -> { - when (val txFee = txFeeSealedState.txFeeState) { - TxFeeState.Empty -> BigDecimal.ZERO - is TxFeeState.MultipleFeeState -> txFee.priorityFee.fee.amount.value - is TxFeeState.SingleFeeState -> txFee.fee.fee.amount.value - } - } - } - - val feeState = getFeeState( - fromSwapCurrencyStatus = fromSwapCurrencyStatus, - fee = fee, - spendAmount = amount, - ) swapState.copy( permissionState = PermissionDataState.Empty, preparedSwapConfigState = PreparedSwapConfigState( diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapNotificationsFactory.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapNotificationsFactory.kt index 2bff6bb705..6f203e2e72 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapNotificationsFactory.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapNotificationsFactory.kt @@ -306,23 +306,25 @@ internal class SwapNotificationsFactory( ) { if (hideFee) return val fromCurrency = quoteModel.fromTokenInfo.swapCurrencyStatus.currency - val feeEnoughState = quoteModel.preparedSwapConfigState.feeState as? SwapFeeState.NotEnough ?: return - val shouldShowCoverWarning = quoteModel.preparedSwapConfigState.isBalanceEnough && + val feeEnoughState = quoteModel.preparedSwapConfigState.feeState as? SwapFeeState.NotEnough + val shouldShowCoverWarning = !quoteModel.preparedSwapConfigState.isBalanceEnough && quoteModel.permissionState !is PermissionDataState.PermissionLoading && feeCryptoCurrencyStatus?.currency != fromCurrency - val isNotEnoughFee = + val isCEXProvider = quoteModel.swapProvider.type == ExchangeProviderType.CEX + + val isNotEnoughFee = feeEnoughState is SwapFeeState.NotEnough && !isCEXProvider || quoteModel.preparedSwapConfigState.includeFeeInAmount is IncludeFeeInAmount.BalanceNotEnough - val isGaslessAvailable = iGaslessFeeSupportedForNetwork(fromCurrency.network) && - quoteModel.swapProvider.type == ExchangeProviderType.CEX + val isGaslessAvailable = iGaslessFeeSupportedForNetwork(fromCurrency.network) && isCEXProvider + if (shouldShowCoverWarning && !isGaslessAvailable || isNotEnoughFee) { add( SwapNotificationUM.Error.UnableToCoverFeeWarning( fromToken = fromCurrency, feeCurrency = feeCryptoCurrencyStatus?.currency, - currencyName = feeEnoughState.currencyName ?: fromCurrency.network.name, - currencySymbol = feeEnoughState.currencySymbol ?: fromCurrency.network.currencySymbol, + currencyName = feeEnoughState?.currencyName ?: fromCurrency.network.name, + currencySymbol = feeEnoughState?.currencySymbol ?: fromCurrency.network.currencySymbol, onConfirmClick = actions.onBuyClick, ), )