Updated on 2026-08-14
This commit is contained in:
parent
8891721b89
commit
916a4a7242
47 changed files with 8 additions and 2802 deletions
|
|
@ -49,11 +49,9 @@ import com.tangem.datasource.api.express.models.request.LeastTokenInfo as Networ
|
|||
internal class DefaultSwapRepository(
|
||||
private val tangemExpressApi: TangemExpressApi,
|
||||
private val coroutineDispatcher: CoroutineDispatcherProvider,
|
||||
private val walletManagersFacade: WalletManagersFacade,
|
||||
private val errorsDataConverter: ErrorsDataConverter,
|
||||
private val dataSignatureVerifier: DataSignatureVerifier,
|
||||
private val appPreferencesStore: AppPreferencesStore,
|
||||
private val rampStateManager: RampStateManager,
|
||||
private val expressHistoryDao: ExpressHistoryDao,
|
||||
moshi: Moshi,
|
||||
) : SwapRepository {
|
||||
|
|
@ -122,98 +120,6 @@ internal class DefaultSwapRepository(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun getPairsOnly(
|
||||
userWallet: UserWallet,
|
||||
initialCurrency: LeastTokenInfo,
|
||||
currencyList: List<CryptoCurrency>,
|
||||
isIgnoreExpress: Boolean,
|
||||
): PairsWithProviders {
|
||||
return withContext(coroutineDispatcher.io) {
|
||||
val currenciesList = filterByAssetRequirements(userWallet, currencyList)
|
||||
|
||||
if (isIgnoreExpress) {
|
||||
buildLocalPairs(initialCurrency, currenciesList)
|
||||
} else {
|
||||
fetchExpressPairs(userWallet, initialCurrency, currenciesList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildLocalPairs(
|
||||
initialCurrency: LeastTokenInfo,
|
||||
currenciesList: List<NetworkLeastTokenInfo>,
|
||||
): PairsWithProviders {
|
||||
val pairs = currenciesList.map { tokenInfo ->
|
||||
SwapPairLeast(
|
||||
from = initialCurrency,
|
||||
to = LeastTokenInfo(
|
||||
contractAddress = tokenInfo.contractAddress,
|
||||
network = tokenInfo.network,
|
||||
),
|
||||
providers = emptyList(),
|
||||
)
|
||||
}
|
||||
return PairsWithProviders(pairs = pairs, allProviders = emptyList())
|
||||
}
|
||||
|
||||
private suspend fun fetchExpressPairs(
|
||||
userWallet: UserWallet,
|
||||
initialCurrency: LeastTokenInfo,
|
||||
currenciesList: List<NetworkLeastTokenInfo>,
|
||||
): PairsWithProviders {
|
||||
try {
|
||||
val initial = NetworkLeastTokenInfo(
|
||||
contractAddress = initialCurrency.contractAddress,
|
||||
network = initialCurrency.network,
|
||||
)
|
||||
|
||||
val allPairs = supervisorScope {
|
||||
val pairsDeferred = async {
|
||||
getPairsInternal(
|
||||
userWallet = userWallet,
|
||||
from = arrayListOf(initial),
|
||||
to = currenciesList,
|
||||
)
|
||||
}
|
||||
|
||||
val reversedPairsDeferred = async {
|
||||
getPairsInternal(
|
||||
userWallet = userWallet,
|
||||
from = currenciesList,
|
||||
to = arrayListOf(initial),
|
||||
)
|
||||
}
|
||||
|
||||
pairsDeferred.await().getOrThrow() + reversedPairsDeferred.await().getOrThrow()
|
||||
}
|
||||
|
||||
return swapPairInfoConverter.convert(
|
||||
SwapPairsWithProviders(
|
||||
swapPair = allPairs,
|
||||
providers = emptyList(),
|
||||
),
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
if (exception is ApiResponseError.HttpException) {
|
||||
throw ExpressException(errorsDataConverter.convert(exception.errorBody.orEmpty()))
|
||||
} else {
|
||||
throw exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun filterByAssetRequirements(
|
||||
userWallet: UserWallet,
|
||||
currencyList: List<CryptoCurrency>,
|
||||
): List<NetworkLeastTokenInfo> {
|
||||
return currencyList
|
||||
.filter { currency ->
|
||||
val requirements = walletManagersFacade.getAssetRequirements(userWallet.walletId, currency)
|
||||
rampStateManager.checkAssetRequirements(requirements)
|
||||
}
|
||||
.map { currency -> leastTokenInfoConverter.convert(currency) }
|
||||
}
|
||||
|
||||
private suspend fun getPairsInternal(
|
||||
userWallet: UserWallet,
|
||||
from: List<NetworkLeastTokenInfo>,
|
||||
|
|
|
|||
|
|
@ -39,22 +39,18 @@ internal class SwapDataModule {
|
|||
tangemExpressApi: TangemExpressApi,
|
||||
coroutineDispatcher: CoroutineDispatcherProvider,
|
||||
dataSignature: DataSignatureVerifier,
|
||||
walletManagerFacade: WalletManagersFacade,
|
||||
errorsDataConverter: ErrorsDataConverter,
|
||||
@NetworkMoshi moshi: Moshi,
|
||||
appPreferencesStore: AppPreferencesStore,
|
||||
rampStateManager: RampStateManager,
|
||||
expressHistoryDao: ExpressHistoryDao,
|
||||
): SwapRepository {
|
||||
return DefaultSwapRepository(
|
||||
tangemExpressApi = tangemExpressApi,
|
||||
coroutineDispatcher = coroutineDispatcher,
|
||||
walletManagersFacade = walletManagerFacade,
|
||||
errorsDataConverter = errorsDataConverter,
|
||||
dataSignatureVerifier = dataSignature,
|
||||
moshi = moshi,
|
||||
appPreferencesStore = appPreferencesStore,
|
||||
rampStateManager = rampStateManager,
|
||||
expressHistoryDao = expressHistoryDao,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue