Updated on 2026-08-14
This commit is contained in:
commit
f268827d55
5 changed files with 39 additions and 17 deletions
|
|
@ -66,6 +66,7 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
|
|||
initialCurrency: CryptoCurrency,
|
||||
cryptoCurrencyStatusList: List<CryptoCurrencyStatus>,
|
||||
filterProviderTypes: List<ExpressProviderType>,
|
||||
swapTxType: SwapTxType,
|
||||
): List<SwapPairModel> = withContext(coroutineDispatcher.default) {
|
||||
val cryptoCurrencyList = cryptoCurrencyStatusList.map { it.currency }
|
||||
|
||||
|
|
@ -73,6 +74,7 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
|
|||
userWallet = userWallet,
|
||||
initialCurrency = initialCurrency,
|
||||
cryptoCurrencyList = cryptoCurrencyList,
|
||||
swapTxType = swapTxType,
|
||||
)
|
||||
|
||||
val providers = expressRepository.getProviders(
|
||||
|
|
@ -114,11 +116,13 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
|
|||
initialCurrency: CryptoCurrency,
|
||||
cryptoCurrencyList: List<CryptoCurrency>,
|
||||
filterProviderTypes: List<ExpressProviderType>,
|
||||
swapTxType: SwapTxType,
|
||||
): List<SwapPairModel> = withContext(coroutineDispatcher.default) {
|
||||
val allPairs = getPairsInternal(
|
||||
userWallet = userWallet,
|
||||
initialCurrency = initialCurrency,
|
||||
cryptoCurrencyList = cryptoCurrencyList,
|
||||
swapTxType = swapTxType,
|
||||
)
|
||||
|
||||
val providers = expressRepository.getProviders(
|
||||
|
|
@ -308,24 +312,34 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
|
|||
userWallet: UserWallet,
|
||||
initialCurrency: CryptoCurrency,
|
||||
cryptoCurrencyList: List<CryptoCurrency>,
|
||||
) = awaitAll(
|
||||
// original pairs
|
||||
async {
|
||||
swapTxType: SwapTxType,
|
||||
) = when (swapTxType) {
|
||||
SwapTxType.Swap -> awaitAll(
|
||||
// original pairs
|
||||
async {
|
||||
invokePairRequest(
|
||||
userWallet = userWallet,
|
||||
from = arrayListOf(initialCurrency),
|
||||
to = cryptoCurrencyList,
|
||||
)
|
||||
},
|
||||
// reversed pairs
|
||||
async {
|
||||
invokePairRequest(
|
||||
userWallet = userWallet,
|
||||
from = cryptoCurrencyList,
|
||||
to = arrayListOf(initialCurrency),
|
||||
)
|
||||
},
|
||||
).flatten()
|
||||
SwapTxType.SendWithSwap -> {
|
||||
invokePairRequest(
|
||||
userWallet = userWallet,
|
||||
from = arrayListOf(initialCurrency),
|
||||
to = cryptoCurrencyList,
|
||||
)
|
||||
},
|
||||
// reversed pairs
|
||||
async {
|
||||
invokePairRequest(
|
||||
userWallet = userWallet,
|
||||
from = cryptoCurrencyList,
|
||||
to = arrayListOf(initialCurrency),
|
||||
)
|
||||
},
|
||||
).flatten()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun invokePairRequest(
|
||||
userWallet: UserWallet,
|
||||
|
|
|
|||
|
|
@ -6,10 +6,7 @@ import com.tangem.domain.express.models.ExpressRateType
|
|||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.swap.models.SwapDataModel
|
||||
import com.tangem.domain.swap.models.SwapPairModel
|
||||
import com.tangem.domain.swap.models.SwapQuoteModel
|
||||
import com.tangem.domain.swap.models.SwapStatusModel
|
||||
import com.tangem.domain.swap.models.*
|
||||
import java.math.BigDecimal
|
||||
|
||||
/**
|
||||
|
|
@ -25,12 +22,14 @@ interface SwapRepositoryV2 {
|
|||
* @param initialCurrency currency being swapped (either to or from)
|
||||
* @param cryptoCurrencyStatusList list of currencies might be swapped
|
||||
* @param filterProviderTypes filters only specified provider types, if empty returns providers as is
|
||||
* @param swapTxType swap tx type
|
||||
*/
|
||||
suspend fun getPairs(
|
||||
userWallet: UserWallet,
|
||||
initialCurrency: CryptoCurrency,
|
||||
cryptoCurrencyStatusList: List<CryptoCurrencyStatus>,
|
||||
filterProviderTypes: List<ExpressProviderType>,
|
||||
swapTxType: SwapTxType,
|
||||
): List<SwapPairModel>
|
||||
|
||||
/**
|
||||
|
|
@ -43,6 +42,7 @@ interface SwapRepositoryV2 {
|
|||
initialCurrency: CryptoCurrency,
|
||||
cryptoCurrencyList: List<CryptoCurrency>,
|
||||
filterProviderTypes: List<ExpressProviderType>,
|
||||
swapTxType: SwapTxType,
|
||||
): List<SwapPairModel>
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.tangem.domain.swap.models.SwapCryptoCurrency
|
|||
import com.tangem.domain.swap.models.SwapCurrencies
|
||||
import com.tangem.domain.swap.models.SwapCurrenciesGroup
|
||||
import com.tangem.domain.swap.models.SwapPairModel
|
||||
import com.tangem.domain.swap.models.SwapTxType
|
||||
|
||||
/**
|
||||
* Get list of swap pairs
|
||||
|
|
@ -31,12 +32,14 @@ class GetSwapPairsUseCase(
|
|||
initialCurrency: CryptoCurrency,
|
||||
cryptoCurrencyStatusList: List<CryptoCurrencyStatus>,
|
||||
filterProviderTypes: List<ExpressProviderType>,
|
||||
swapTxType: SwapTxType,
|
||||
) = Either.catch {
|
||||
val pairs = swapRepositoryV2.getPairs(
|
||||
userWallet = userWallet,
|
||||
initialCurrency = initialCurrency,
|
||||
cryptoCurrencyStatusList = cryptoCurrencyStatusList,
|
||||
filterProviderTypes = filterProviderTypes,
|
||||
swapTxType = swapTxType,
|
||||
)
|
||||
|
||||
val fromGroup = pairs.groupPairs(
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.tangem.domain.swap.models.SwapCryptoCurrency
|
|||
import com.tangem.domain.swap.models.SwapCurrencies
|
||||
import com.tangem.domain.swap.models.SwapCurrenciesGroup
|
||||
import com.tangem.domain.swap.models.SwapPairModel
|
||||
import com.tangem.domain.swap.models.SwapTxType
|
||||
|
||||
/**
|
||||
* Returns pais
|
||||
|
|
@ -25,12 +26,14 @@ class GetSwapSupportedPairsUseCase(
|
|||
initialCurrency: CryptoCurrency,
|
||||
cryptoCurrencyList: List<CryptoCurrency>,
|
||||
filterProviderTypes: List<ExpressProviderType>,
|
||||
swapTxType: SwapTxType,
|
||||
) = Either.catch {
|
||||
val pairs = swapRepositoryV2.getSupportedPairs(
|
||||
userWallet = userWallet,
|
||||
initialCurrency = initialCurrency,
|
||||
cryptoCurrencyList = cryptoCurrencyList,
|
||||
filterProviderTypes = filterProviderTypes,
|
||||
swapTxType = swapTxType,
|
||||
)
|
||||
|
||||
val filteredOutInitial = cryptoCurrencyList.filterNot { it.id == initialCurrency.id }
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
|
|||
import com.tangem.domain.managetokens.CreateCryptoCurrencyUseCase
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.swap.models.SwapCurrencies
|
||||
import com.tangem.domain.swap.models.SwapTxType
|
||||
import com.tangem.domain.swap.usecase.GetSwapSupportedPairsUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
|
||||
import com.tangem.features.managetokens.component.analytics.CommonManageTokensAnalyticEvents
|
||||
|
|
@ -84,6 +85,7 @@ internal class SwapChooseTokenNetworkModel @Inject constructor(
|
|||
initialCurrency = params.initialCurrency,
|
||||
cryptoCurrencyList = cryptoCurrencyList + params.initialCurrency,
|
||||
filterProviderTypes = SEND_WITH_SWAP_PROVIDER_TYPES,
|
||||
swapTxType = SwapTxType.SendWithSwap,
|
||||
).getOrElse {
|
||||
Timber.e(it.toString())
|
||||
uiState.update(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue