Updated on 2026-08-14

This commit is contained in:
Tangem 2026-03-17 22:16:55 +07:00
parent bbf13f1ae8
commit b37737ce8c
25 changed files with 102 additions and 45 deletions

View file

@ -41,7 +41,8 @@ interface TangemExpressApi {
@Query("fromNetwork") fromNetwork: String, @Query("fromNetwork") fromNetwork: String,
@Query("toContractAddress") toContractAddress: String, @Query("toContractAddress") toContractAddress: String,
@Query("toNetwork") toNetwork: String, @Query("toNetwork") toNetwork: String,
@Query("fromAmount") fromAmount: String, @Query("fromAmount") fromAmount: String?,
@Query("toAmount") toAmount: String? = null,
@Query("fromDecimals") fromDecimals: Int, @Query("fromDecimals") fromDecimals: Int,
@Query("toDecimals") toDecimals: Int, @Query("toDecimals") toDecimals: Int,
@Query("providerId") providerId: String, @Query("providerId") providerId: String,
@ -57,7 +58,8 @@ interface TangemExpressApi {
@Query("toContractAddress") toContractAddress: String, @Query("toContractAddress") toContractAddress: String,
@Query("fromAddress") fromAddress: String, @Query("fromAddress") fromAddress: String,
@Query("toNetwork") toNetwork: String, @Query("toNetwork") toNetwork: String,
@Query("fromAmount") fromAmount: String, @Query("fromAmount") fromAmount: String?,
@Query("toAmount") toAmount: String? = null,
@Query("fromDecimals") fromDecimals: Int, @Query("fromDecimals") fromDecimals: Int,
@Query("toDecimals") toDecimals: Int, @Query("toDecimals") toDecimals: Int,
@Query("providerId") providerId: String, @Query("providerId") providerId: String,

View file

@ -32,6 +32,7 @@ import com.tangem.domain.quotes.single.SingleQuoteStatusProducer
import com.tangem.domain.quotes.single.SingleQuoteStatusSupplier import com.tangem.domain.quotes.single.SingleQuoteStatusSupplier
import com.tangem.domain.swap.SwapRepositoryV2 import com.tangem.domain.swap.SwapRepositoryV2
import com.tangem.domain.swap.models.* import com.tangem.domain.swap.models.*
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.tokens.operations.CryptoCurrencyStatusFactory import com.tangem.domain.tokens.operations.CryptoCurrencyStatusFactory
import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -177,12 +178,26 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
userWallet: UserWallet, userWallet: UserWallet,
fromCryptoCurrency: CryptoCurrency, fromCryptoCurrency: CryptoCurrency,
toCryptoCurrency: CryptoCurrency, toCryptoCurrency: CryptoCurrency,
fromAmount: BigDecimal, amount: BigDecimal,
amountType: SwapAmountType,
provider: ExpressProvider, provider: ExpressProvider,
rateType: ExpressRateType, rateType: ExpressRateType,
): SwapQuoteModel = withContext(coroutineDispatcher.io) { ): SwapQuoteModel = withContext(coroutineDispatcher.io) {
val response = tangemExpressApi.getExchangeQuote( val response = tangemExpressApi.getExchangeQuote(
fromAmount = fromAmount.movePointRight(fromCryptoCurrency.decimals).toString(), fromAmount = if (amountType == SwapAmountType.From) {
amount.movePointRight(
fromCryptoCurrency.decimals,
).toString()
} else {
null
},
toAmount = if (amountType == SwapAmountType.To) {
amount.movePointRight(
toCryptoCurrency.decimals,
).toString()
} else {
null
},
fromNetwork = fromCryptoCurrency.network.backendId, fromNetwork = fromCryptoCurrency.network.backendId,
fromContractAddress = fromCryptoCurrency.getContractAddress(), fromContractAddress = fromCryptoCurrency.getContractAddress(),
fromDecimals = fromCryptoCurrency.decimals, fromDecimals = fromCryptoCurrency.decimals,
@ -199,10 +214,12 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
).getOrThrow() ).getOrThrow()
val toTokenAmount = requireNotNull(response.toAmount.toBigDecimalOrNull()?.movePointLeft(response.toDecimals)) val toTokenAmount = requireNotNull(response.toAmount.toBigDecimalOrNull()?.movePointLeft(response.toDecimals))
val fromTokenAmount = response.fromAmount.toBigDecimalOrNull()?.movePointLeft(response.fromDecimals)
return@withContext SwapQuoteModel( return@withContext SwapQuoteModel(
provider = provider, provider = provider,
toTokenAmount = toTokenAmount, toTokenAmount = toTokenAmount,
fromTokenAmount = fromTokenAmount,
allowanceContract = response.allowanceContract, allowanceContract = response.allowanceContract,
) )
} }
@ -211,7 +228,8 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
userWallet: UserWallet, userWallet: UserWallet,
fromCryptoCurrencyStatus: CryptoCurrencyStatus, fromCryptoCurrencyStatus: CryptoCurrencyStatus,
toCryptoCurrency: CryptoCurrency, toCryptoCurrency: CryptoCurrency,
fromAmount: String, amount: String,
amountType: SwapAmountType,
toAddress: String, toAddress: String,
toExtraId: String?, toExtraId: String?,
expressProvider: ExpressProvider, expressProvider: ExpressProvider,
@ -241,7 +259,8 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
toAddress = toAddress, toAddress = toAddress,
fromDecimals = fromCurrency.decimals, fromDecimals = fromCurrency.decimals,
toDecimals = toCryptoCurrency.decimals, toDecimals = toCryptoCurrency.decimals,
fromAmount = fromAmount, fromAmount = if (amountType == SwapAmountType.From) amount else null,
toAmount = if (amountType == SwapAmountType.To) amount else null,
providerId = expressProvider.providerId, providerId = expressProvider.providerId,
rateType = rateType.name.lowercase(), rateType = rateType.name.lowercase(),
requestId = requestId, requestId = requestId,

View file

@ -0,0 +1,6 @@
package com.tangem.domain.swap.models
enum class SwapAmountType {
From,
To,
}

View file

@ -8,10 +8,12 @@ import java.math.BigDecimal
* *
* @property provider swap provider * @property provider swap provider
* @property toTokenAmount amount of token you want to receive * @property toTokenAmount amount of token you want to receive
* @property fromTokenAmount amount of from-token required (for fixed rate quotes)
* @property allowanceContract whether swap occurs via third token * @property allowanceContract whether swap occurs via third token
*/ */
data class SwapQuoteModel( data class SwapQuoteModel(
val provider: ExpressProvider, val provider: ExpressProvider,
val toTokenAmount: BigDecimal, val toTokenAmount: BigDecimal,
val fromTokenAmount: BigDecimal?,
val allowanceContract: String?, val allowanceContract: String?,
) )

View file

@ -0,0 +1,7 @@
package com.tangem.domain.swap.models
enum class SwapRateMode {
FLOAT_ONLY,
FIXED_ONLY,
FLOAT_AND_FIXED,
}

View file

@ -52,7 +52,8 @@ interface SwapRepositoryV2 {
* @param userWallet selected user wallet * @param userWallet selected user wallet
* @param fromCryptoCurrency currency being swapped from * @param fromCryptoCurrency currency being swapped from
* @param toCryptoCurrency currency being swapped to * @param toCryptoCurrency currency being swapped to
* @param fromAmount swap amount * @param amount swap amount
* @param amountType specifies whether amount is fromAmount or toAmount
* @param provider selected express provider * @param provider selected express provider
* @param rateType rate type * @param rateType rate type
*/ */
@ -60,7 +61,8 @@ interface SwapRepositoryV2 {
userWallet: UserWallet, userWallet: UserWallet,
fromCryptoCurrency: CryptoCurrency, fromCryptoCurrency: CryptoCurrency,
toCryptoCurrency: CryptoCurrency, toCryptoCurrency: CryptoCurrency,
fromAmount: BigDecimal, amount: BigDecimal,
amountType: SwapAmountType,
provider: ExpressProvider, provider: ExpressProvider,
rateType: ExpressRateType, rateType: ExpressRateType,
): SwapQuoteModel ): SwapQuoteModel
@ -71,7 +73,8 @@ interface SwapRepositoryV2 {
* @param userWallet selected user wallet * @param userWallet selected user wallet
* @param fromCryptoCurrencyStatus currency status being swapped from * @param fromCryptoCurrencyStatus currency status being swapped from
* @param toCryptoCurrency currency being swapped to * @param toCryptoCurrency currency being swapped to
* @param fromAmount swap amount * @param amount swap amount
* @param amountType specifies whether amount is fromAmount or toAmount
* @param toAddress destination address * @param toAddress destination address
* @param expressProvider selected swap provider * @param expressProvider selected swap provider
* @param rateType selected provider rate type * @param rateType selected provider rate type
@ -81,7 +84,8 @@ interface SwapRepositoryV2 {
userWallet: UserWallet, userWallet: UserWallet,
fromCryptoCurrencyStatus: CryptoCurrencyStatus, fromCryptoCurrencyStatus: CryptoCurrencyStatus,
toCryptoCurrency: CryptoCurrency, toCryptoCurrency: CryptoCurrency,
fromAmount: String, amount: String,
amountType: SwapAmountType,
toAddress: String, toAddress: String,
toExtraId: String?, toExtraId: String?,
expressProvider: ExpressProvider, expressProvider: ExpressProvider,

View file

@ -10,6 +10,7 @@ import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.swap.SwapErrorResolver import com.tangem.domain.swap.SwapErrorResolver
import com.tangem.domain.swap.SwapRepositoryV2 import com.tangem.domain.swap.SwapRepositoryV2
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapDataModel import com.tangem.domain.swap.models.SwapDataModel
@Suppress("LongParameterList") @Suppress("LongParameterList")
@ -21,7 +22,8 @@ class GetSwapDataUseCase(
suspend operator fun invoke( suspend operator fun invoke(
userWallet: UserWallet, userWallet: UserWallet,
fromCryptoCurrencyStatus: CryptoCurrencyStatus, fromCryptoCurrencyStatus: CryptoCurrencyStatus,
fromAmount: String, amount: String,
amountType: SwapAmountType,
toCryptoCurrency: CryptoCurrency, toCryptoCurrency: CryptoCurrency,
toAddress: String, toAddress: String,
toExtraId: String?, toExtraId: String?,
@ -32,7 +34,8 @@ class GetSwapDataUseCase(
swapRepositoryV2.getSwapData( swapRepositoryV2.getSwapData(
userWallet = userWallet, userWallet = userWallet,
fromCryptoCurrencyStatus = fromCryptoCurrencyStatus, fromCryptoCurrencyStatus = fromCryptoCurrencyStatus,
fromAmount = fromAmount, amount = amount,
amountType = amountType,
toCryptoCurrency = toCryptoCurrency, toCryptoCurrency = toCryptoCurrency,
toAddress = toAddress, toAddress = toAddress,
toExtraId = toExtraId, toExtraId = toExtraId,

View file

@ -7,6 +7,7 @@ import com.tangem.domain.express.models.ExpressRateType
import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.swap.SwapErrorResolver import com.tangem.domain.swap.SwapErrorResolver
import com.tangem.domain.swap.SwapRepositoryV2 import com.tangem.domain.swap.SwapRepositoryV2
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapQuoteModel import com.tangem.domain.swap.models.SwapQuoteModel
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import java.math.BigDecimal import java.math.BigDecimal
@ -14,6 +15,7 @@ import java.math.BigDecimal
/** /**
* Get swap quote for selected pair * Get swap quote for selected pair
*/ */
@Suppress("LongParameterList")
class GetSwapQuoteUseCase( class GetSwapQuoteUseCase(
private val swapRepositoryV2: SwapRepositoryV2, private val swapRepositoryV2: SwapRepositoryV2,
private val swapErrorResolver: SwapErrorResolver, private val swapErrorResolver: SwapErrorResolver,
@ -23,23 +25,28 @@ class GetSwapQuoteUseCase(
* @param userWallet selected user wallet * @param userWallet selected user wallet
* @param fromCryptoCurrency currency swap from * @param fromCryptoCurrency currency swap from
* @param toCryptoCurrency currency swap to * @param toCryptoCurrency currency swap to
* @param fromAmount swap amount * @param amount swap amount
* @param rateType rate type for the quote. Float API does not support [SwapAmountType.To].
* @param provider swap provider * @param provider swap provider
*/ */
suspend operator fun invoke( suspend operator fun invoke(
userWallet: UserWallet, userWallet: UserWallet,
fromCryptoCurrency: CryptoCurrency, fromCryptoCurrency: CryptoCurrency,
toCryptoCurrency: CryptoCurrency, toCryptoCurrency: CryptoCurrency,
fromAmount: BigDecimal, amount: BigDecimal,
amountType: SwapAmountType,
rateType: ExpressRateType,
provider: ExpressProvider, provider: ExpressProvider,
): Either<ExpressError, SwapQuoteModel> = Either.catch { ): Either<ExpressError, SwapQuoteModel> = Either.catch {
swapRepositoryV2.getSwapQuote( swapRepositoryV2.getSwapQuote(
userWallet = userWallet, userWallet = userWallet,
fromCryptoCurrency = fromCryptoCurrency, fromCryptoCurrency = fromCryptoCurrency,
toCryptoCurrency = toCryptoCurrency, toCryptoCurrency = toCryptoCurrency,
fromAmount = fromAmount, amount = amount,
amountType = amountType,
provider = provider, provider = provider,
rateType = ExpressRateType.Float, // todo rate type rateType = rateType,
) )
}.mapLeft(swapErrorResolver::resolve) }.mapLeft(swapErrorResolver::resolve)
} }

View file

@ -1,9 +1,9 @@
package com.tangem.domain.swap.usecase package com.tangem.domain.swap.usecase
import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.swap.SwapTransactionRepository import com.tangem.domain.swap.SwapTransactionRepository
import com.tangem.domain.swap.models.SwapCryptoCurrency
import com.tangem.domain.swap.models.SwapCurrencies import com.tangem.domain.swap.models.SwapCurrencies
import com.tangem.domain.swap.models.SwapCurrenciesGroup import com.tangem.domain.swap.models.SwapCurrenciesGroup
import com.tangem.domain.swap.models.SwapDirection import com.tangem.domain.swap.models.SwapDirection
@ -30,22 +30,22 @@ class SelectInitialPairUseCase(
secondaryCryptoCurrency: CryptoCurrency?, secondaryCryptoCurrency: CryptoCurrency?,
swapCurrencies: SwapCurrencies, swapCurrencies: SwapCurrencies,
swapDirection: SwapDirection, swapDirection: SwapDirection,
): CryptoCurrencyStatus? { ): SwapCryptoCurrency? {
val swapCurrenciesGroup = swapCurrencies.getGroupWithDirection(swapDirection) val swapCurrenciesGroup = swapCurrencies.getGroupWithDirection(swapDirection)
return tryToGetAlreadySelectedCurrency(secondaryCryptoCurrency, swapCurrenciesGroup) return tryToGetAlreadySelectedCurrency(secondaryCryptoCurrency, swapCurrenciesGroup)
?: tryGetFromCache(userWallet, primaryCryptoCurrency, swapCurrenciesGroup) ?: tryGetFromCache(userWallet, primaryCryptoCurrency, swapCurrenciesGroup)
?: tryGetWithMaxAmount(swapCurrenciesGroup) ?: tryGetWithMaxAmount(swapCurrenciesGroup)
?: swapCurrenciesGroup.available.firstOrNull()?.currencyStatus ?: swapCurrenciesGroup.available.firstOrNull()
} }
private fun tryToGetAlreadySelectedCurrency( private fun tryToGetAlreadySelectedCurrency(
secondaryCryptoCurrency: CryptoCurrency?, secondaryCryptoCurrency: CryptoCurrency?,
swapCurrenciesGroup: SwapCurrenciesGroup, swapCurrenciesGroup: SwapCurrenciesGroup,
): CryptoCurrencyStatus? { ): SwapCryptoCurrency? {
return secondaryCryptoCurrency?.let { return secondaryCryptoCurrency?.let {
swapCurrenciesGroup.available.firstOrNull { currency -> swapCurrenciesGroup.available.firstOrNull { currency ->
secondaryCryptoCurrency.id == currency.currencyStatus.currency.id secondaryCryptoCurrency.id == currency.currencyStatus.currency.id
}?.currencyStatus }
} }
} }
@ -53,19 +53,19 @@ class SelectInitialPairUseCase(
userWallet: UserWallet, userWallet: UserWallet,
primaryCryptoCurrency: CryptoCurrency, primaryCryptoCurrency: CryptoCurrency,
swapCurrenciesGroup: SwapCurrenciesGroup, swapCurrenciesGroup: SwapCurrenciesGroup,
): CryptoCurrencyStatus? { ): SwapCryptoCurrency? {
val id = swapTransactionRepository.getLastSwappedCryptoCurrencyId(userWallet.walletId) ?: return null val id = swapTransactionRepository.getLastSwappedCryptoCurrencyId(userWallet.walletId) ?: return null
return if (id != primaryCryptoCurrency.id.value) { return if (id != primaryCryptoCurrency.id.value) {
swapCurrenciesGroup.available.find { it.currencyStatus.currency.id.value == id }?.currencyStatus swapCurrenciesGroup.available.find { it.currencyStatus.currency.id.value == id }
} else { } else {
null null
} }
} }
private fun tryGetWithMaxAmount(swapCurrenciesGroup: SwapCurrenciesGroup): CryptoCurrencyStatus? { private fun tryGetWithMaxAmount(swapCurrenciesGroup: SwapCurrenciesGroup): SwapCryptoCurrency? {
return swapCurrenciesGroup.available.maxByOrNull { return swapCurrenciesGroup.available.maxByOrNull {
it.currencyStatus.value.fiatAmount.orZero() it.currencyStatus.value.fiatAmount.orZero()
}?.currencyStatus }
} }
} }

View file

@ -7,6 +7,7 @@ import com.tangem.core.ui.extensions.TextReference
import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.express.models.ExpressRateType import com.tangem.domain.express.models.ExpressRateType
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapCurrencies import com.tangem.domain.swap.models.SwapCurrencies
import com.tangem.domain.swap.models.SwapDirection import com.tangem.domain.swap.models.SwapDirection
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM
@ -92,9 +93,4 @@ sealed class PriceImpactUM {
data object Empty : PriceImpactUM() data object Empty : PriceImpactUM()
data class Value(val value: Float) : PriceImpactUM() data class Value(val value: Float) : PriceImpactUM()
}
enum class SwapAmountType {
From,
To,
} }

View file

@ -1,7 +1,7 @@
package com.tangem.features.swap.v2.impl.amount.model package com.tangem.features.swap.v2.impl.amount.model
import com.tangem.common.ui.amountScreen.AmountScreenClickIntents import com.tangem.common.ui.amountScreen.AmountScreenClickIntents
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType import com.tangem.domain.swap.models.SwapAmountType
internal interface SwapAmountClickIntents : AmountScreenClickIntents { internal interface SwapAmountClickIntents : AmountScreenClickIntents {

View file

@ -20,6 +20,7 @@ import com.tangem.datasource.local.swap.SwapBestRateAnimationStore
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.express.models.ExpressError import com.tangem.domain.express.models.ExpressError
import com.tangem.domain.express.models.ExpressRateType
import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.notifications.ShouldShowNotificationUseCase import com.tangem.domain.notifications.ShouldShowNotificationUseCase
@ -43,7 +44,6 @@ import com.tangem.features.swap.v2.impl.amount.SwapAmountReduceListener
import com.tangem.features.swap.v2.impl.amount.SwapAmountUpdateListener import com.tangem.features.swap.v2.impl.amount.SwapAmountUpdateListener
import com.tangem.features.swap.v2.impl.amount.analytics.SwapAmountAnalyticEvents import com.tangem.features.swap.v2.impl.amount.analytics.SwapAmountAnalyticEvents
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.amount.model.converter.SwapQuoteUMConverter import com.tangem.features.swap.v2.impl.amount.model.converter.SwapQuoteUMConverter
import com.tangem.features.swap.v2.impl.amount.model.transformers.* import com.tangem.features.swap.v2.impl.amount.model.transformers.*
@ -525,7 +525,7 @@ internal class SwapAmountModel @Inject constructor(
private fun initPairs(swapCurrencies: SwapCurrencies, secondaryCryptoCurrency: CryptoCurrency?) { private fun initPairs(swapCurrencies: SwapCurrencies, secondaryCryptoCurrency: CryptoCurrency?) {
modelScope.launch { modelScope.launch {
val secondaryStatus = selectInitialPairUseCase( val swapCryptoCurrency = selectInitialPairUseCase(
primaryCryptoCurrency = primaryCryptoCurrency, primaryCryptoCurrency = primaryCryptoCurrency,
secondaryCryptoCurrency = secondaryCryptoCurrency, secondaryCryptoCurrency = secondaryCryptoCurrency,
userWallet = userWallet, userWallet = userWallet,
@ -533,6 +533,8 @@ internal class SwapAmountModel @Inject constructor(
swapDirection = params.swapDirection, swapDirection = params.swapDirection,
) )
val secondaryStatus = swapCryptoCurrency?.currencyStatus
val primaryStatus = (uiState.value as? SwapAmountUM.Content)?.primaryCryptoCurrencyStatus val primaryStatus = (uiState.value as? SwapAmountUM.Content)?.primaryCryptoCurrencyStatus
if (secondaryStatus != null && primaryStatus != null) { if (secondaryStatus != null && primaryStatus != null) {
initCurrencies(primaryStatus, secondaryStatus) initCurrencies(primaryStatus, secondaryStatus)
@ -594,6 +596,7 @@ internal class SwapAmountModel @Inject constructor(
} }
} }
@Suppress("LongMethod")
private fun loadQuotes(isSilentReload: Boolean) { private fun loadQuotes(isSilentReload: Boolean) {
val state = uiState.value as? SwapAmountUM.Content ?: return val state = uiState.value as? SwapAmountUM.Content ?: return
if (state.secondaryCryptoCurrencyStatus == null) return if (state.secondaryCryptoCurrencyStatus == null) return
@ -629,7 +632,9 @@ internal class SwapAmountModel @Inject constructor(
userWallet = userWallet, userWallet = userWallet,
fromCryptoCurrency = fromCryptoCurrency, fromCryptoCurrency = fromCryptoCurrency,
toCryptoCurrency = toCryptoCurrency, toCryptoCurrency = toCryptoCurrency,
fromAmount = fromAmountValue, amount = fromAmountValue,
amountType = SwapAmountType.From,
rateType = ExpressRateType.Float,
provider = provider, provider = provider,
).fold( ).fold(
ifLeft = { error -> ifLeft = { error ->

View file

@ -5,9 +5,9 @@ import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.format.bigdecimal.format import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.core.ui.format.bigdecimal.percent import com.tangem.core.ui.format.bigdecimal.percent
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapDirection import com.tangem.domain.swap.models.SwapDirection
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.utils.extensions.isZero import com.tangem.utils.extensions.isZero
import com.tangem.utils.isNullOrZero import com.tangem.utils.isNullOrZero

View file

@ -15,10 +15,10 @@ import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.account.Account import com.tangem.domain.models.account.Account
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapDirection import com.tangem.domain.swap.models.SwapDirection
import com.tangem.features.swap.v2.impl.R import com.tangem.features.swap.v2.impl.R
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.utils.StringsSigns.DOT import com.tangem.utils.StringsSigns.DOT
@Suppress("LongParameterList") @Suppress("LongParameterList")

View file

@ -5,9 +5,9 @@ import com.tangem.common.ui.amountScreen.models.AmountState
import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.account.Account import com.tangem.domain.models.account.Account
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapDirection import com.tangem.domain.swap.models.SwapDirection
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.amount.model.converter.SwapAmountFieldConverter import com.tangem.features.swap.v2.impl.amount.model.converter.SwapAmountFieldConverter
import com.tangem.utils.transformer.Transformer import com.tangem.utils.transformer.Transformer

View file

@ -6,10 +6,10 @@ import com.tangem.domain.express.models.ExpressRateType
import com.tangem.domain.models.account.Account import com.tangem.domain.models.account.Account
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapCurrencies import com.tangem.domain.swap.models.SwapCurrencies
import com.tangem.domain.swap.models.SwapDirection import com.tangem.domain.swap.models.SwapDirection
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.amount.model.converter.SwapAmountFieldConverter import com.tangem.features.swap.v2.impl.amount.model.converter.SwapAmountFieldConverter
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM

View file

@ -6,9 +6,9 @@ import com.tangem.domain.express.models.ExpressRateType
import com.tangem.domain.models.account.Account import com.tangem.domain.models.account.Account
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapCurrencies import com.tangem.domain.swap.models.SwapCurrencies
import com.tangem.domain.swap.models.SwapDirection import com.tangem.domain.swap.models.SwapDirection
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.amount.model.converter.SwapAmountFieldConverter import com.tangem.features.swap.v2.impl.amount.model.converter.SwapAmountFieldConverter
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM

View file

@ -5,8 +5,8 @@ import com.tangem.common.ui.amountScreen.models.AmountState
import com.tangem.common.ui.amountScreen.models.EnterAmountBoundary import com.tangem.common.ui.amountScreen.models.EnterAmountBoundary
import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.utils.parseBigDecimal import com.tangem.core.ui.utils.parseBigDecimal
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.amount.model.SwapAmountQuoteUtils.calculatePriceImpact import com.tangem.features.swap.v2.impl.amount.model.SwapAmountQuoteUtils.calculatePriceImpact
import com.tangem.features.swap.v2.impl.amount.model.converter.SwapAmountErrorConverter import com.tangem.features.swap.v2.impl.amount.model.converter.SwapAmountErrorConverter

View file

@ -37,9 +37,9 @@ import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.stringResourceSafe import com.tangem.core.ui.extensions.stringResourceSafe
import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.features.swap.v2.impl.R import com.tangem.features.swap.v2.impl.R
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.amount.ui.preview.SwapAmountContentPreview import com.tangem.features.swap.v2.impl.amount.ui.preview.SwapAmountContentPreview
import com.tangem.features.swap.v2.impl.chooseprovider.ui.SwapChooseProviderContent import com.tangem.features.swap.v2.impl.chooseprovider.ui.SwapChooseProviderContent

View file

@ -39,9 +39,9 @@ import com.tangem.core.ui.extensions.stringResourceSafe
import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.domain.express.models.ExpressRateType import com.tangem.domain.express.models.ExpressRateType
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.features.swap.v2.impl.R import com.tangem.features.swap.v2.impl.R
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.amount.model.SwapAmountClickIntents import com.tangem.features.swap.v2.impl.amount.model.SwapAmountClickIntents
import com.tangem.features.swap.v2.impl.amount.ui.preview.SwapAmountClickIntentsStub import com.tangem.features.swap.v2.impl.amount.ui.preview.SwapAmountClickIntentsStub

View file

@ -1,6 +1,6 @@
package com.tangem.features.swap.v2.impl.amount.ui.preview package com.tangem.features.swap.v2.impl.amount.ui.preview
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.model.SwapAmountClickIntents import com.tangem.features.swap.v2.impl.amount.model.SwapAmountClickIntents
internal object SwapAmountClickIntentsStub : SwapAmountClickIntents { internal object SwapAmountClickIntentsStub : SwapAmountClickIntents {

View file

@ -12,10 +12,10 @@ import com.tangem.domain.express.models.ExpressRateType
import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.network.Network import com.tangem.domain.models.network.Network
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapCurrencies import com.tangem.domain.swap.models.SwapCurrencies
import com.tangem.domain.swap.models.SwapDirection import com.tangem.domain.swap.models.SwapDirection
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM
import com.tangem.utils.StringsSigns import com.tangem.utils.StringsSigns

View file

@ -4,6 +4,7 @@ import com.tangem.blockchain.common.transaction.Fee
import com.tangem.domain.express.models.ExpressRateType import com.tangem.domain.express.models.ExpressRateType
import com.tangem.domain.models.account.Account import com.tangem.domain.models.account.Account
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.transaction.error.GetFeeError import com.tangem.domain.transaction.error.GetFeeError
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM
import java.math.BigDecimal import java.math.BigDecimal
@ -21,4 +22,5 @@ internal data class ConfirmData(
val fromAccount: Account?, val fromAccount: Account?,
val quote: SwapQuoteUM?, val quote: SwapQuoteUM?,
val rateType: ExpressRateType?, val rateType: ExpressRateType?,
val amountType: SwapAmountType,
) )

View file

@ -29,6 +29,7 @@ import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.isHotWallet import com.tangem.domain.models.wallet.isHotWallet
import com.tangem.domain.settings.IsSendTapHelpEnabledUseCase import com.tangem.domain.settings.IsSendTapHelpEnabledUseCase
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapDirection.Companion.withSwapDirection import com.tangem.domain.swap.models.SwapDirection.Companion.withSwapDirection
import com.tangem.domain.tokens.IsAmountSubtractAvailableUseCase import com.tangem.domain.tokens.IsAmountSubtractAvailableUseCase
import com.tangem.domain.transaction.error.GetFeeError import com.tangem.domain.transaction.error.GetFeeError
@ -158,6 +159,7 @@ internal class SendWithSwapConfirmModel @Inject constructor(
fromAccount = params.accountFlow.value, fromAccount = params.accountFlow.value,
quote = amountUM?.selectedQuote, quote = amountUM?.selectedQuote,
rateType = amountUM?.swapRateType, rateType = amountUM?.swapRateType,
amountType = amountUM?.selectedAmountType ?: SwapAmountType.From,
) )
} }

View file

@ -11,6 +11,7 @@ import com.tangem.domain.express.models.ExpressProviderType
import com.tangem.domain.models.account.Account import com.tangem.domain.models.account.Account
import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.swap.models.SwapAmountType
import com.tangem.domain.swap.models.SwapDataModel import com.tangem.domain.swap.models.SwapDataModel
import com.tangem.domain.swap.models.SwapDataTransactionModel import com.tangem.domain.swap.models.SwapDataTransactionModel
import com.tangem.domain.swap.models.SwapTxType import com.tangem.domain.swap.models.SwapTxType
@ -101,7 +102,8 @@ internal class SwapTransactionSender @AssistedInject constructor(
val swapData = getSwapDataUseCase( val swapData = getSwapDataUseCase(
userWallet = userWallet, userWallet = userWallet,
fromCryptoCurrencyStatus = fromStatus, fromCryptoCurrencyStatus = fromStatus,
fromAmount = fromAmount.toStringWithRightOffset(fromStatus.currency.decimals), amount = fromAmount.toStringWithRightOffset(fromStatus.currency.decimals),
amountType = SwapAmountType.From,
toCryptoCurrency = toStatus.currency, toCryptoCurrency = toStatus.currency,
toAddress = destination, toAddress = destination,
toExtraId = confirmData.enteredMemo, toExtraId = confirmData.enteredMemo,