Updated on 2026-08-14

This commit is contained in:
Tangem 2025-08-11 12:42:35 +05:00
parent beceddf1fb
commit b1e333b83b
5 changed files with 39 additions and 17 deletions

View file

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