Updated on 2026-08-14
This commit is contained in:
parent
c72fb58654
commit
0e55f23e8e
8 changed files with 23 additions and 32 deletions
|
|
@ -6,13 +6,13 @@ import java.math.BigDecimal
|
|||
data class ExchangeQuoteResponse(
|
||||
|
||||
@Json(name = "fromAmount")
|
||||
val fromAmount: BigDecimal,
|
||||
val fromAmount: String,
|
||||
|
||||
@Json(name = "fromDecimals")
|
||||
val fromDecimals: Int,
|
||||
|
||||
@Json(name = "toAmount")
|
||||
val toAmount: BigDecimal,
|
||||
val toAmount: String,
|
||||
|
||||
@Json(name = "toDecimals")
|
||||
val toDecimals: Int,
|
||||
|
|
|
|||
|
|
@ -20,16 +20,14 @@ import com.tangem.domain.walletmanager.WalletManagersFacade
|
|||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.feature.swap.converters.*
|
||||
import com.tangem.feature.swap.domain.SwapRepository
|
||||
import com.tangem.feature.swap.domain.models.SwapAmount
|
||||
import com.tangem.feature.swap.domain.models.createFromAmountWithOffset
|
||||
import com.tangem.feature.swap.domain.models.data.AggregatedSwapDataModel
|
||||
import com.tangem.feature.swap.domain.models.domain.*
|
||||
import com.tangem.feature.swap.domain.models.mapErrors
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.withContext
|
||||
import retrofit2.http.Query
|
||||
import java.math.BigDecimal
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
import com.tangem.datasource.api.express.models.request.LeastTokenInfo as NetworkLeastTokenInfo
|
||||
|
||||
|
|
@ -147,15 +145,12 @@ internal class SwapRepositoryImpl @Inject constructor(
|
|||
toNetwork = toNetwork,
|
||||
fromAmount = fromAmount,
|
||||
providerId = providerId,
|
||||
rateType = rateType.name.lowercase()
|
||||
rateType = rateType.name.lowercase(),
|
||||
).getOrThrow()
|
||||
AggregatedSwapDataModel(
|
||||
dataModel = QuoteModel(
|
||||
SwapAmount(
|
||||
value = response.toAmount,
|
||||
decimals = response.toDecimals
|
||||
)
|
||||
)
|
||||
toTokenAmount = createFromAmountWithOffset(response.toAmount, response.toDecimals),
|
||||
),
|
||||
)
|
||||
} catch (ex: OneIncResponseException) {
|
||||
AggregatedSwapDataModel(null, mapErrors(ex.data.description))
|
||||
|
|
@ -280,7 +275,7 @@ internal class SwapRepositoryImpl @Inject constructor(
|
|||
toNetwork: String,
|
||||
fromAmount: String,
|
||||
providerId: Int,
|
||||
rateType: RateType
|
||||
rateType: RateType,
|
||||
): ExchangeQuote {
|
||||
val response = tangemExpressApi.getExchangeQuote(
|
||||
fromContractAddress,
|
||||
|
|
@ -289,7 +284,7 @@ internal class SwapRepositoryImpl @Inject constructor(
|
|||
toNetwork,
|
||||
fromAmount,
|
||||
providerId,
|
||||
rateType.name.lowercase()
|
||||
rateType.name.lowercase(),
|
||||
).getOrThrow()
|
||||
|
||||
return ExchangeQuote(
|
||||
|
|
|
|||
|
|
@ -33,5 +33,4 @@ class SwapPairInfoConverter : Converter<SwapPair, SwapPairDomain> {
|
|||
rateTypes = swapPairProvider.rateTypes.map { rateTypeConverter.convert(it) },
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -300,14 +300,12 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
} else {
|
||||
loadQuoteData(
|
||||
networkId = networkId,
|
||||
fromTokenAddress = fromTokenAddress,
|
||||
toTokenAddress = toTokenAddress,
|
||||
amount = amount,
|
||||
fromToken = fromToken,
|
||||
toToken = toToken,
|
||||
isAllowedToSpend = isAllowedToSpend,
|
||||
isBalanceWithoutFeeEnough = isBalanceWithoutFeeEnough,
|
||||
providers = providers
|
||||
providers = providers,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -510,8 +508,6 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
@Suppress("LongParameterList")
|
||||
private suspend fun loadQuoteData(
|
||||
networkId: String,
|
||||
fromTokenAddress: String,
|
||||
toTokenAddress: String,
|
||||
amount: SwapAmount,
|
||||
fromToken: CryptoCurrency,
|
||||
toToken: CryptoCurrency,
|
||||
|
|
@ -520,13 +516,13 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
isBalanceWithoutFeeEnough: Boolean,
|
||||
): SwapState {
|
||||
repository.findBestQuote(
|
||||
fromContractAddress = fromToken.getContractAddress(),
|
||||
fromContractAddress = fromToken.getContractAddress(),
|
||||
fromNetwork = fromToken.network.backendId,
|
||||
toContractAddress = toToken.getContractAddress(),
|
||||
toNetwork = toToken.network.backendId,
|
||||
fromAmount = amount.toStringWithRightOffset(),
|
||||
providerId = providers[0].providerId,
|
||||
rateType = RateType.FLOAT
|
||||
rateType = RateType.FLOAT,
|
||||
|
||||
// networkId = networkId,
|
||||
// fromTokenAddress = fromTokenAddress,
|
||||
|
|
@ -653,7 +649,10 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
): SwapState.QuotesLoadedState {
|
||||
val appCurrency = userWalletManager.getUserAppCurrency()
|
||||
val nativeToken = userWalletManager.getNativeTokenForNetwork(networkId)
|
||||
val rates = repository.getRates(appCurrency.code, listOf(fromToken.id.value, toToken.id.value, nativeToken.id))
|
||||
val rates = repository.getRates(
|
||||
appCurrency.code,
|
||||
listOf(fromToken.network.backendId, toToken.network.backendId, nativeToken.id),
|
||||
)
|
||||
val fromTokenBalance = cache.getBalanceForToken(networkId, derivationPath, fromToken.symbol)
|
||||
val toTokenBalance = cache.getBalanceForToken(networkId, derivationPath, toToken.symbol)
|
||||
return SwapState.QuotesLoadedState(
|
||||
|
|
@ -663,7 +662,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
tokenWalletBalance = fromTokenBalance?.let { amountFormatter.formatSwapAmountToUI(it, "") }
|
||||
?: ZERO_BALANCE,
|
||||
tokenFiatBalance = fromTokenAmount.value.toFiatString(
|
||||
rateValue = rates[fromToken.id.value]?.toBigDecimal() ?: BigDecimal.ZERO,
|
||||
rateValue = rates[fromToken.network.backendId]?.toBigDecimal() ?: BigDecimal.ZERO,
|
||||
fiatCurrencyName = appCurrency.symbol,
|
||||
formatWithSpaces = true,
|
||||
),
|
||||
|
|
@ -899,7 +898,6 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
companion object {
|
||||
private const val DEFAULT_SLIPPAGE = 2
|
||||
private const val ZERO_BALANCE = "0"
|
||||
private const val DEFAULT_BLOCKCHAIN_INCH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
|
||||
|
||||
@Suppress("UnusedPrivateMember")
|
||||
private const val INCREASE_FEE_TO_CHECK_ENOUGH_PERCENT = 1.0 // if need to increase fee when check isEnough
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ interface SwapRepository {
|
|||
|
||||
suspend fun getExchangeableTokens(networkId: String): List<Currency>
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
suspend fun findBestQuote(
|
||||
fromContractAddress: String,
|
||||
fromNetwork: String,
|
||||
|
|
@ -74,5 +75,5 @@ interface SwapRepository {
|
|||
fromAmount: String,
|
||||
providerId: Int,
|
||||
rateType: RateType,
|
||||
) : ExchangeQuote
|
||||
): ExchangeQuote
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package com.tangem.feature.swap.domain.models.domain
|
||||
|
||||
import java.math.BigDecimal
|
||||
|
||||
data class ExchangeQuote(
|
||||
val toAmount: BigDecimal,
|
||||
val allowanceContract: String?
|
||||
val toAmount: String,
|
||||
val allowanceContract: String?,
|
||||
)
|
||||
|
|
@ -9,7 +9,7 @@ import java.math.BigDecimal
|
|||
sealed interface SwapState {
|
||||
|
||||
data class QuotesLoadedState(
|
||||
//add map < Provider ID, Swap state data>
|
||||
// add map < Provider ID, Swap state data>
|
||||
val fromTokenInfo: TokenSwapInfo,
|
||||
val toTokenInfo: TokenSwapInfo,
|
||||
val priceImpact: Float,
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ internal class SwapViewModel @Inject constructor(
|
|||
tokensDataState = state,
|
||||
)
|
||||
|
||||
//updateTokensState(state)
|
||||
// updateTokensState(state)
|
||||
|
||||
val toToken = state.toGroup.available.first()
|
||||
startLoadingQuotes(
|
||||
|
|
@ -204,7 +204,7 @@ internal class SwapViewModel @Inject constructor(
|
|||
fromToken = fromToken,
|
||||
toToken = toToken,
|
||||
amount = amount,
|
||||
toProvidersList = toProvidersList
|
||||
toProvidersList = toProvidersList,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue