Updated on 2026-08-14
This commit is contained in:
commit
a807a300ae
10 changed files with 51 additions and 53 deletions
|
|
@ -1,31 +0,0 @@
|
|||
package com.tangem.tap.network.auth
|
||||
|
||||
import com.tangem.datasource.config.ConfigManager
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.lib.auth.ExpressAuthProvider
|
||||
import com.tangem.lib.auth.sessionId.ExpressSessionIdGenerator
|
||||
import java.util.UUID
|
||||
|
||||
class ExpressAuthProviderImpl(
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
private val configManager: ConfigManager,
|
||||
) : ExpressAuthProvider, ExpressSessionIdGenerator {
|
||||
|
||||
private var uuid = UUID.randomUUID()
|
||||
|
||||
override fun getApiKey(): String {
|
||||
return configManager.config.tangemExpressApiKey
|
||||
}
|
||||
|
||||
override fun getUserId(): String {
|
||||
return userWalletsStore.selectedUserWalletOrNull?.walletId?.stringValue ?: ""
|
||||
}
|
||||
|
||||
override fun getSessionId(): String {
|
||||
return uuid.toString()
|
||||
}
|
||||
|
||||
override fun generateNewSessionId() {
|
||||
uuid = UUID.randomUUID()
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,10 @@ class DefaultMarketCryptoCurrencyRepository(
|
|||
) : MarketCryptoCurrencyRepository {
|
||||
|
||||
override suspend fun isExchangeable(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency): Boolean {
|
||||
return getExchangeableFlag(userWalletId, cryptoCurrency) && !cryptoCurrency.isCustom
|
||||
}
|
||||
|
||||
private suspend fun getExchangeableFlag(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency): Boolean {
|
||||
val contractAddress = (cryptoCurrency as? CryptoCurrency.Token)?.contractAddress ?: EMPTY_CONTRACT_ADDRESS_VALUE
|
||||
|
||||
return assetsStore.getSyncOrNull(userWalletId)?.find {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ internal class SwapRepositoryImpl @Inject constructor(
|
|||
override suspend fun getPairs(
|
||||
initialCurrency: LeastTokenInfo,
|
||||
currencyList: List<CryptoCurrency>,
|
||||
): List<SwapPairLeast> {
|
||||
): PairsWithProviders {
|
||||
return withContext(coroutineDispatcher.io) {
|
||||
val initial = NetworkLeastTokenInfo(
|
||||
contractAddress = initialCurrency.contractAddress,
|
||||
|
|
|
|||
|
|
@ -2,18 +2,20 @@ package com.tangem.feature.swap.converters
|
|||
|
||||
import com.tangem.datasource.api.express.models.response.*
|
||||
import com.tangem.feature.swap.domain.models.domain.LeastTokenInfo
|
||||
import com.tangem.feature.swap.domain.models.domain.PairsWithProviders
|
||||
import com.tangem.feature.swap.domain.models.domain.SwapProvider
|
||||
import com.tangem.utils.converter.Converter
|
||||
import com.tangem.feature.swap.domain.models.domain.ExchangeProviderType as ExchangeProviderTypeDomain
|
||||
import com.tangem.feature.swap.domain.models.domain.SwapPairLeast as SwapPairDomain
|
||||
import com.tangem.feature.swap.domain.models.domain.SwapProvider as SwapPairProviderDomain
|
||||
|
||||
class SwapPairInfoConverter : Converter<SwapPairsWithProviders, List<SwapPairDomain>> {
|
||||
class SwapPairInfoConverter : Converter<SwapPairsWithProviders, PairsWithProviders> {
|
||||
|
||||
private val rateTypeConverter = RateTypeConverter()
|
||||
|
||||
override fun convert(value: SwapPairsWithProviders): List<SwapPairDomain> {
|
||||
override fun convert(value: SwapPairsWithProviders): PairsWithProviders {
|
||||
val providersAdditionalMap = value.providers.associateBy { it.id }
|
||||
return value.swapPair.map { pair ->
|
||||
val pairs = value.swapPair.map { pair ->
|
||||
SwapPairDomain(
|
||||
from = LeastTokenInfo(
|
||||
contractAddress = pair.from.contractAddress,
|
||||
|
|
@ -28,6 +30,20 @@ class SwapPairInfoConverter : Converter<SwapPairsWithProviders, List<SwapPairDom
|
|||
},
|
||||
)
|
||||
}
|
||||
return PairsWithProviders(
|
||||
pairs = pairs,
|
||||
allProviders = value.providers.map { convertLeastProvider(it) },
|
||||
)
|
||||
}
|
||||
|
||||
private fun convertLeastProvider(exchangeProvider: ExchangeProvider): SwapProvider {
|
||||
return SwapProvider(
|
||||
providerId = exchangeProvider.id,
|
||||
rateTypes = emptyList(),
|
||||
name = exchangeProvider.name,
|
||||
type = convertExchangeType(exchangeProvider.type),
|
||||
imageLarge = exchangeProvider.imageLargeUrl,
|
||||
)
|
||||
}
|
||||
|
||||
private fun convertProvider(
|
||||
|
|
|
|||
|
|
@ -79,14 +79,12 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
val currencyFilter = it.currency.network.backendId != currency.network.backendId ||
|
||||
it.currency.getContractAddress() != currency.getContractAddress()
|
||||
val statusFilter = it.value is CryptoCurrencyStatus.Loaded
|
||||
statusFilter && currencyFilter
|
||||
val notCustomTokenFilter = !it.currency.isCustom
|
||||
statusFilter && currencyFilter && notCustomTokenFilter
|
||||
}
|
||||
|
||||
if (walletCurrencyStatusesExceptInitial.isEmpty()) {
|
||||
return TokensDataStateExpress(
|
||||
fromGroup = CurrenciesGroup(emptyList(), emptyList()),
|
||||
toGroup = CurrenciesGroup(emptyList(), emptyList()),
|
||||
)
|
||||
return TokensDataStateExpress.EMPTY
|
||||
}
|
||||
|
||||
val pairsLeast = getPairs(
|
||||
|
|
@ -100,18 +98,19 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
return TokensDataStateExpress(
|
||||
fromGroup = getToCurrenciesGroup(
|
||||
currency = currency,
|
||||
leastPairs = pairsLeast,
|
||||
leastPairs = pairsLeast.pairs,
|
||||
cryptoCurrenciesList = walletCurrencyStatusesExceptInitial,
|
||||
tokenInfoForFilter = { it.from },
|
||||
tokenInfoForAvailable = { it.to },
|
||||
),
|
||||
toGroup = getToCurrenciesGroup(
|
||||
currency = currency,
|
||||
leastPairs = pairsLeast,
|
||||
leastPairs = pairsLeast.pairs,
|
||||
cryptoCurrenciesList = walletCurrencyStatusesExceptInitial,
|
||||
tokenInfoForFilter = { it.to },
|
||||
tokenInfoForAvailable = { it.from },
|
||||
),
|
||||
allProviders = pairsLeast.allProviders,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -177,7 +176,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
private suspend fun getPairs(
|
||||
initialCurrency: LeastTokenInfo,
|
||||
currenciesList: List<CryptoCurrency>,
|
||||
): List<SwapPairLeast> {
|
||||
): PairsWithProviders {
|
||||
return repository.getPairs(initialCurrency, currenciesList)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.math.BigDecimal
|
|||
|
||||
interface SwapRepository {
|
||||
|
||||
suspend fun getPairs(initialCurrency: LeastTokenInfo, currencyList: List<CryptoCurrency>): List<SwapPairLeast>
|
||||
suspend fun getPairs(initialCurrency: LeastTokenInfo, currencyList: List<CryptoCurrency>): PairsWithProviders
|
||||
|
||||
suspend fun getRates(currencyId: String, tokenIds: List<String>): Map<String, Double>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package com.tangem.feature.swap.domain.models.domain
|
||||
|
||||
data class PairsWithProviders(
|
||||
val pairs: List<SwapPairLeast>,
|
||||
val allProviders: List<SwapProvider>,
|
||||
)
|
||||
|
|
@ -1,16 +1,19 @@
|
|||
package com.tangem.feature.swap.domain.models.ui
|
||||
|
||||
import com.tangem.feature.swap.domain.models.domain.CryptoCurrencySwapInfo
|
||||
import com.tangem.feature.swap.domain.models.domain.SwapProvider
|
||||
|
||||
data class TokensDataStateExpress(
|
||||
val fromGroup: CurrenciesGroup,
|
||||
val toGroup: CurrenciesGroup,
|
||||
val allProviders: List<SwapProvider>,
|
||||
) {
|
||||
companion object {
|
||||
val EMPTY =
|
||||
TokensDataStateExpress(
|
||||
fromGroup = CurrenciesGroup(emptyList(), emptyList()),
|
||||
toGroup = CurrenciesGroup(emptyList(), emptyList()),
|
||||
allProviders = emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -648,7 +648,7 @@ internal class StateBuilder(
|
|||
val fee = requireNotNull(dataState.selectedFee)
|
||||
val fromCryptoCurrency = requireNotNull(dataState.fromCryptoCurrency)
|
||||
val toCryptoCurrency = requireNotNull(dataState.toCryptoCurrency)
|
||||
val fromAmount = requireNotNull(dataState.amount?.toBigDecimal())
|
||||
val fromAmount = toBigDecimalOrNull(requireNotNull(dataState.amount))
|
||||
val toAmount = requireNotNull(dataState.swapDataModel?.toTokenAmount?.value)
|
||||
val providerState = uiState.providerState as ProviderState.Content
|
||||
|
||||
|
|
@ -1136,6 +1136,10 @@ internal class StateBuilder(
|
|||
return this.divide(to, min(decimals, MAX_DECIMALS_TO_SHOW), RoundingMode.HALF_UP)
|
||||
}
|
||||
|
||||
private fun toBigDecimalOrNull(text: String): BigDecimal? {
|
||||
return text.replace(",", ".").toBigDecimalOrNull()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val ADDRESS_MIN_LENGTH = 11
|
||||
const val ADDRESS_FIRST_PART_LENGTH = 7
|
||||
|
|
|
|||
|
|
@ -791,7 +791,7 @@ internal class SwapViewModel @Inject constructor(
|
|||
val fromToken = dataState.fromCryptoCurrency ?: return@UiActions
|
||||
val amountToSwap = dataState.amount ?: return@UiActions
|
||||
val selectedProvider = dataState.selectedProvider ?: return@UiActions
|
||||
uiState = stateBuilder.updateSelectedFeeBottomSheet(uiState, it.feeType)
|
||||
uiState = stateBuilder.dismissBottomSheet(uiState)
|
||||
dataState = dataState.copy(selectedFee = it)
|
||||
viewModelScope.launch(dispatchers.io) {
|
||||
val updatedState = swapInteractor.updateQuotesStateWithSelectedFee(
|
||||
|
|
@ -823,7 +823,7 @@ internal class SwapViewModel @Inject constructor(
|
|||
val fromToken = dataState.fromCryptoCurrency
|
||||
if (provider != null && swapState != null && fromToken != null) {
|
||||
analyticsEventHandler.send(SwapEvents.ProviderChosen(provider))
|
||||
uiState = stateBuilder.updateSelectedProvider(uiState, provider.providerId)
|
||||
uiState = stateBuilder.dismissBottomSheet(uiState)
|
||||
setupLoadedState(
|
||||
provider = provider,
|
||||
state = swapState,
|
||||
|
|
@ -915,15 +915,12 @@ internal class SwapViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun getAllProviders(): List<SwapProvider> {
|
||||
dataState.tokensDataState?.let { data ->
|
||||
val allProviders =
|
||||
data.fromGroup.available.flatMap { it.providers } + data.toGroup.available.flatMap { it.providers }
|
||||
return allProviders.distinct()
|
||||
} ?: return emptyList()
|
||||
return dataState.tokensDataState?.allProviders ?: emptyList()
|
||||
}
|
||||
|
||||
private fun getUnavailableProvidersFor(state: Map<SwapProvider, SwapState>): List<SwapProvider> {
|
||||
return getAllProviders().filterNot { it in state }
|
||||
val availableProviders = state.keys.map { it.providerId }
|
||||
return getAllProviders().filterNot { availableProviders.contains(it.providerId) }
|
||||
}
|
||||
|
||||
private fun Map<SwapProvider, SwapState>.getLastLoadedSuccessStates(): SuccessLoadedSwapData {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue