diff --git a/features/swap/data/src/main/java/com/tangem/feature/swap/DefaultSwapRepository.kt b/features/swap/data/src/main/java/com/tangem/feature/swap/DefaultSwapRepository.kt index 772502d688..e176e30ad1 100644 --- a/features/swap/data/src/main/java/com/tangem/feature/swap/DefaultSwapRepository.kt +++ b/features/swap/data/src/main/java/com/tangem/feature/swap/DefaultSwapRepository.kt @@ -23,6 +23,7 @@ import com.tangem.datasource.crypto.DataSignatureVerifier import com.tangem.domain.common.extensions.fromNetworkId import com.tangem.domain.common.util.derivationStyleProvider import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.tokens.model.Network import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.legacy.WalletsStateHolder import com.tangem.domain.wallets.models.UserWalletId @@ -310,6 +311,10 @@ internal class DefaultSwapRepository @Inject constructor( } } + override suspend fun getExistentialDeposit(userWalletId: UserWalletId, network: Network): BigDecimal? { + return walletManagersFacade.getExistentialDeposit(userWalletId, network) + } + private fun parseTxDetails(txDetailsJson: String): TxDetails? { return try { txDetailsMoshiAdapter.fromJson(txDetailsJson) diff --git a/features/swap/domain/api/src/main/java/com/tangem/feature/swap/domain/api/SwapRepository.kt b/features/swap/domain/api/src/main/java/com/tangem/feature/swap/domain/api/SwapRepository.kt index e0182e8a5e..f22a1cef7b 100644 --- a/features/swap/domain/api/src/main/java/com/tangem/feature/swap/domain/api/SwapRepository.kt +++ b/features/swap/domain/api/src/main/java/com/tangem/feature/swap/domain/api/SwapRepository.kt @@ -2,6 +2,7 @@ package com.tangem.feature.swap.domain.api import arrow.core.Either import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.tokens.model.Network import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.swap.domain.models.DataError import com.tangem.feature.swap.domain.models.domain.* @@ -70,4 +71,6 @@ interface SwapRepository { ): Either fun getNativeTokenForNetwork(networkId: String): CryptoCurrency + + suspend fun getExistentialDeposit(userWalletId: UserWalletId, network: Network): BigDecimal? } \ No newline at end of file diff --git a/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/domain/Warning.kt b/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/domain/Warning.kt new file mode 100644 index 0000000000..b52f4c5586 --- /dev/null +++ b/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/domain/Warning.kt @@ -0,0 +1,8 @@ +package com.tangem.feature.swap.domain.models.domain + +import java.math.BigDecimal + +sealed class Warning { + + data class ExistentialDepositWarning(val existentialDeposit: BigDecimal) : Warning() +} \ No newline at end of file diff --git a/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/ui/SwapState.kt b/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/ui/SwapState.kt index ae50b2dd38..a7c1ff4892 100644 --- a/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/ui/SwapState.kt +++ b/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/ui/SwapState.kt @@ -6,6 +6,7 @@ import com.tangem.feature.swap.domain.models.SwapAmount import com.tangem.feature.swap.domain.models.domain.IncludeFeeInAmount import com.tangem.feature.swap.domain.models.domain.PreparedSwapConfigState import com.tangem.feature.swap.domain.models.domain.SwapDataModel +import com.tangem.feature.swap.domain.models.domain.Warning import java.math.BigDecimal sealed interface SwapState { @@ -25,6 +26,7 @@ sealed interface SwapState { val permissionState: PermissionDataState = PermissionDataState.Empty, val swapDataModel: SwapDataModel? = null, val txFee: TxFeeState, + val warnings: List = emptyList(), ) : SwapState data class EmptyAmountState( 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 aa1167d436..13b4415145 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 @@ -353,6 +353,16 @@ internal class SwapInteractorImpl @Inject constructor( ) } + private suspend fun manageWarnings(fromToken: CryptoCurrency): List { + val userWalletId = getSelectedWallet()?.walletId ?: return emptyList() + val existentialDeposit = repository.getExistentialDeposit(userWalletId, fromToken.network) + val warnings = mutableListOf() + if (existentialDeposit != null) { + warnings.add(Warning.ExistentialDepositWarning(existentialDeposit)) + } + return warnings + } + override suspend fun onSwap( swapProvider: SwapProvider, swapData: SwapDataModel?, @@ -782,6 +792,8 @@ internal class SwapInteractorImpl @Inject constructor( swapData = null, txFeeState = txFee, exchangeProviderType = exchangeProviderType, + ).copy( + warnings = manageWarnings(fromToken.currency), ) when (exchangeProviderType) { @@ -939,6 +951,7 @@ internal class SwapInteractorImpl @Inject constructor( ) swapState.copy( permissionState = PermissionDataState.Empty, + warnings = manageWarnings(fromToken.currency), preparedSwapConfigState = PreparedSwapConfigState( isAllowedToSpend = true, isBalanceEnough = isBalanceIncludeFeeEnough, diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt index 5246e8ed36..cadb2e5087 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt @@ -304,6 +304,7 @@ internal class StateBuilder( fromToken: CryptoCurrency, ): List { val warnings = mutableListOf() + addDomainWarnings(quoteModel, warnings) if (!quoteModel.preparedSwapConfigState.isAllowedToSpend && quoteModel.preparedSwapConfigState.isFeeEnough && quoteModel.permissionState is PermissionDataState.PermissionReadyForRequest @@ -363,6 +364,30 @@ internal class StateBuilder( return warnings } + private fun addDomainWarnings(quoteModel: SwapState.QuotesLoadedState, warnings: MutableList) { + quoteModel.warnings.forEach { + when (it) { + is Warning.ExistentialDepositWarning -> { + warnings.add( + SwapWarning.GeneralWarning( + NotificationConfig( + title = resourceReference(R.string.warning_existential_deposit_title), + subtitle = resourceReference( + R.string.warning_existential_deposit_message, + wrappedList( + quoteModel.fromTokenInfo.cryptoCurrencyStatus.currency.name, + it.existentialDeposit.toPlainString(), + ), + ), + iconResId = R.drawable.img_attention_20, + ), + ), + ) + } + } + } + } + private fun addUnableCoverFeeWarning( quoteModel: SwapState.QuotesLoadedState, fromToken: CryptoCurrency,