Updated on 2026-08-14

This commit is contained in:
Tangem 2023-11-17 14:26:13 +02:00
parent fb0cf652ca
commit 6b92fc6179
5 changed files with 20 additions and 24 deletions

View file

@ -5,7 +5,7 @@ import com.tangem.datasource.api.express.models.response.SwapPair
import com.tangem.datasource.api.express.models.response.SwapPairProvider
import com.tangem.feature.swap.domain.models.domain.LeastTokenInfo
import com.tangem.feature.swap.domain.models.domain.SwapPairLeast as SwapPairDomain
import com.tangem.feature.swap.domain.models.domain.SwapPairProvider as SwapPairProviderDomain
import com.tangem.feature.swap.domain.models.domain.SwapProvider as SwapPairProviderDomain
import com.tangem.feature.swap.domain.models.domain.RateType as RateTypeDomain
import com.tangem.utils.converter.Converter

View file

@ -111,15 +111,17 @@ internal class SwapInteractorImpl @Inject constructor(
&& tokenInfoForFilter(it).network == currency.network.backendId
}
val availableCryptoCurrencies = filteredPairs.mapNotNull {
findCryptoCurrencyStatusByLeastInfo(tokenInfoForAvailable(it), cryptoCurrenciesList)
val availableCryptoCurrencies = filteredPairs.mapNotNull { pair ->
val status = findCryptoCurrencyStatusByLeastInfo(tokenInfoForAvailable(pair), cryptoCurrenciesList)
status?.let { CryptoCurrencySwapInfo(it, pair.providers) }
}
val unavailableCryptoCurrencies = cryptoCurrenciesList - availableCryptoCurrencies.toSet()
val unavailableCryptoCurrencies =
(cryptoCurrenciesList - availableCryptoCurrencies.map { it.currencyStatus }.toSet())
return CurrenciesGroup(
available = availableCryptoCurrencies,
unavailable = unavailableCryptoCurrencies
unavailable = unavailableCryptoCurrencies.map { CryptoCurrencySwapInfo(it, emptyList()) }
)
}

View file

@ -1,6 +1,6 @@
package com.tangem.feature.swap.domain.models.domain
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
/**
* Domain layer representation of SwapPair data network model.
@ -12,20 +12,12 @@ import com.tangem.domain.tokens.model.CryptoCurrency
data class SwapPairLeast(
val from: LeastTokenInfo,
val to: LeastTokenInfo,
val providers: List<SwapPairProvider>,
val providers: List<SwapProvider>,
)
/**
* Enriched model of swap pair data. Contains full CryptoCurrency models instead of least info.
*
* @property from CryptoCurrency we want to change
* @property to CryptoCurrency we want to exchange for
* @property providers Exchange providers
*/
data class SwapPair(
val from: CryptoCurrency,
val to: CryptoCurrency,
val providers: List<SwapPairProvider>,
data class CryptoCurrencySwapInfo(
val currencyStatus: CryptoCurrencyStatus,
val providers: List<SwapProvider>
)
/**
@ -34,7 +26,7 @@ data class SwapPair(
* @property providerId provider id
* @property rateTypes supported rate types
*/
data class SwapPairProvider(
data class SwapProvider(
val providerId: Int,
val rateTypes: List<RateType>,
)

View file

@ -1,7 +1,7 @@
package com.tangem.feature.swap.domain.models.ui
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.feature.swap.domain.models.domain.CryptoCurrencySwapInfo
data class TokensDataStateExpress(
val initialCryptoCurrency: CryptoCurrency,
@ -10,8 +10,8 @@ data class TokensDataStateExpress(
)
data class CurrenciesGroup(
val available: List<CryptoCurrencyStatus>,
val unavailable: List<CryptoCurrencyStatus>,
val available: List<CryptoCurrencySwapInfo>,
val unavailable: List<CryptoCurrencySwapInfo>,
)
data class FoundTokensStateExpress(

View file

@ -139,8 +139,10 @@ internal class SwapViewModel @Inject constructor(
runCatching(dispatchers.io) {
swapInteractor.getTokensDataState(currency)
}.onSuccess { state ->
// dataState = dataState.copy(
// )
dataState = dataState.copy(
fromCryptoCurrency = state.initialCryptoCurrency,
toCryptoCurrency = state.toGroup.available.first().currencyStatus.currency
)
cryptoCurrency = state.initialCryptoCurrency
// updateTokensState(dataState = state.foundTokensState)
// startLoadingQuotes(