Updated on 2026-08-14

This commit is contained in:
Tangem 2023-11-28 14:26:14 +02:00
parent 03f003091e
commit 29bdad0743
5 changed files with 21 additions and 49 deletions

View file

@ -381,7 +381,6 @@ internal class DefaultCurrenciesRepository(
) {
try {
val tokensList = userTokens.tokens
.distinctBy { it.networkId }
.map {
LeastTokenInfo(
contractAddress = it.contractAddress ?: EMPTY_CONTRACT_ADDRESS_VALUE,

View file

@ -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.*

View file

@ -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")

View file

@ -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

View file

@ -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