From 29bdad0743946234b22e23ac80e5b3fe61452f40 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 28 Nov 2023 14:26:14 +0200 Subject: [PATCH] Updated on 2026-08-14 --- .../repository/DefaultCurrenciesRepository.kt | 1 - .../feature/swap/domain/SwapInteractor.kt | 1 - .../feature/swap/domain/SwapInteractorImpl.kt | 56 +++++++------------ .../swap/domain/di/SwapDomainModule.kt | 11 +--- .../feature/swap/viewmodels/SwapViewModel.kt | 1 - 5 files changed, 21 insertions(+), 49 deletions(-) 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 8e5decb644..85e522335d 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 @@ -381,7 +381,6 @@ internal class DefaultCurrenciesRepository( ) { try { val tokensList = userTokens.tokens - .distinctBy { it.networkId } .map { LeastTokenInfo( contractAddress = it.contractAddress ?: EMPTY_CONTRACT_ADDRESS_VALUE, diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractor.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractor.kt index aa76195519..6f550682f4 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractor.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractor.kt @@ -4,7 +4,6 @@ import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.Network import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.swap.domain.models.SwapAmount import com.tangem.feature.swap.domain.models.domain.* import com.tangem.feature.swap.domain.models.ui.* 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 15bcdad9af..da5dd7b595 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 @@ -1,17 +1,13 @@ package com.tangem.feature.swap.domain import arrow.core.getOrElse -import com.tangem.blockchain.common.TransactionData import com.tangem.blockchain.common.transaction.Fee import com.tangem.blockchain.common.transaction.TransactionFee -import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase import com.tangem.domain.tokens.GetCryptoCurrencyStatusesSyncUseCase import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.Network import com.tangem.domain.tokens.model.Quote -import com.tangem.domain.tokens.repository.CurrenciesRepository -import com.tangem.domain.tokens.repository.NetworksRepository import com.tangem.domain.tokens.repository.QuotesRepository import com.tangem.domain.tokens.utils.convertToAmount import com.tangem.domain.transaction.error.SendTransactionError @@ -28,7 +24,6 @@ import com.tangem.feature.swap.domain.models.data.AggregatedSwapDataModel import com.tangem.feature.swap.domain.models.domain.* import com.tangem.feature.swap.domain.models.toStringWithRightOffset import com.tangem.feature.swap.domain.models.ui.* -import com.tangem.features.wallet.featuretoggles.WalletFeatureToggles import com.tangem.lib.crypto.TransactionManager import com.tangem.lib.crypto.UserWalletManager import com.tangem.lib.crypto.models.* @@ -49,9 +44,6 @@ internal class SwapInteractorImpl @Inject constructor( private val repository: SwapRepository, private val cache: SwapDataCache, private val allowPermissionsHandler: AllowPermissionsHandler, - private val currenciesRepository: CurrenciesRepository, - private val networksRepository: NetworksRepository, - private val walletFeatureToggles: WalletFeatureToggles, private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, private val getMultiCryptoCurrencyStatusUseCase: GetCryptoCurrencyStatusesSyncUseCase, private val walletManagersFacade: WalletManagersFacade, @@ -60,11 +52,6 @@ internal class SwapInteractorImpl @Inject constructor( private val dispatcher: CoroutineDispatcherProvider, ) : SwapInteractor { - // TODO: Move to DI - private val addCryptoCurrenciesUseCase by lazy(LazyThreadSafetyMode.NONE) { - AddCryptoCurrenciesUseCase(currenciesRepository, networksRepository) - } - private val getFeeUseCase by lazy(LazyThreadSafetyMode.NONE) { GetFeeUseCase(walletManagersFacade, dispatcher) } @@ -384,7 +371,7 @@ internal class SwapInteractorImpl @Inject constructor( amount = amount, fee = fee, providerId = swapProvider.providerId, - userWalletId = requireNotNull(getSelectedWallet()).walletId + userWalletId = requireNotNull(getSelectedWallet()).walletId, ) } ExchangeProviderType.DEX -> { @@ -485,7 +472,7 @@ internal class SwapInteractorImpl @Inject constructor( amount: SwapAmount, fee: TxFee, providerId: String, - userWalletId: UserWalletId + userWalletId: UserWalletId, ): TxState { val exchangeData = repository.getExchangeData( fromContractAddress = currencyToSend.currency.getContractAddress(), @@ -511,37 +498,32 @@ internal class SwapInteractorImpl @Inject constructor( val result = sendTransactionUseCase( requireNotNull(txData), userWallet = requireNotNull(getSelectedWallet()), - network = currencyToSend.currency.network + network = currencyToSend.currency.network, ) - return result.fold(ifLeft = { - when(it){ + when (it) { is SendTransactionError.NetworkError -> TxState.NetworkError is SendTransactionError.DataError -> TxState.BlockchainError SendTransactionError.DemoCardError -> TxState.UnknownError else -> TxState.UnknownError } - }, ifRight = { - TxState.TxSent( - fromAmount = amountFormatter.formatSwapAmountToUI( - amount, - currencyToSend.currency.symbol, - ), - toAmount = amountFormatter.formatSwapAmountToUI( - exchangeData.dataModel.toTokenAmount, - currencyToGet.currency.symbol, - ), - txAddress = userWalletManager.getLastTransactionHash(currencyToSend.currency.network.backendId, derivationPath) ?: "", - ) - TxState.TxSent( - txAddress = userWalletManager.getLastTransactionHash( - networkId = currencyToSend.currency.network.backendId, - derivationPath = derivationPath - ) ?: "" - ) - }) + TxState.TxSent( + fromAmount = amountFormatter.formatSwapAmountToUI( + amount, + currencyToSend.currency.symbol, + ), + toAmount = amountFormatter.formatSwapAmountToUI( + exchangeData.dataModel.toTokenAmount, + currencyToGet.currency.symbol, + ), + txAddress = userWalletManager.getLastTransactionHash( + currencyToSend.currency.network.backendId, + derivationPath, + ) ?: "", + ) + },) } @Deprecated("used in old swap mechanism") diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt index 9c06a31f85..734efb5f0d 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt @@ -35,9 +35,6 @@ class SwapDomainModule { swapRepository: SwapRepository, userWalletManager: UserWalletManager, transactionManager: TransactionManager, - currenciesRepository: CurrenciesRepository, - networksRepository: NetworksRepository, - walletFeatureToggles: WalletFeatureToggles, @SwapScope getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, @SwapScope getCryptoCurrencyStatusUseCase: GetCryptoCurrencyStatusesSyncUseCase, @SwapScope sendTransactionUseCase: SendTransactionUseCase, @@ -51,9 +48,6 @@ class SwapDomainModule { repository = swapRepository, cache = SwapDataCacheImpl(), allowPermissionsHandler = AllowPermissionsHandlerImpl(), - currenciesRepository = currenciesRepository, - networksRepository = networksRepository, - walletFeatureToggles = walletFeatureToggles, getSelectedWalletSyncUseCase = getSelectedWalletSyncUseCase, getMultiCryptoCurrencyStatusUseCase = getCryptoCurrencyStatusUseCase, sendTransactionUseCase = sendTransactionUseCase, @@ -114,7 +108,7 @@ class SwapDomainModule { @SwapScope @Provides - fun provideDemoCardUseCase() : IsDemoCardUseCase { + fun provideDemoCardUseCase(): IsDemoCardUseCase { return IsDemoCardUseCase(config = DemoConfig()) } @@ -129,10 +123,9 @@ class SwapDomainModule { return SendTransactionUseCase( isDemoCardUseCase = isDemoCardUseCase, cardSdkConfigRepository = cardSdkConfigRepository, - walletManagersFacade = walletManagersFacade + walletManagersFacade = walletManagersFacade, ) } - } @Qualifier diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt index d3121006ab..b89d4e193d 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt @@ -17,7 +17,6 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.feature.swap.analytics.SwapEvents import com.tangem.feature.swap.domain.BlockchainInteractor import com.tangem.feature.swap.domain.SwapInteractor -import com.tangem.feature.swap.domain.models.SwapAmount import com.tangem.feature.swap.domain.models.domain.PermissionOptions import com.tangem.feature.swap.domain.models.domain.SwapDataModel import com.tangem.feature.swap.domain.models.domain.SwapProvider