From b37737ce8c805553b112978ef729669630066806 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 17 Mar 2026 22:16:55 +0700 Subject: [PATCH] Updated on 2026-08-14 --- .../api/express/TangemExpressApi.kt | 6 +++-- .../data/swap/DefaultSwapRepositoryV2.kt | 27 ++++++++++++++++--- .../domain/swap/models/SwapAmountType.kt | 6 +++++ .../domain/swap/models/SwapQuoteModel.kt | 2 ++ .../tangem/domain/swap/models/SwapRateMode.kt | 7 +++++ .../tangem/domain/swap/SwapRepositoryV2.kt | 12 ++++++--- .../domain/swap/usecase/GetSwapDataUseCase.kt | 7 +++-- .../swap/usecase/GetSwapQuoteUseCase.kt | 15 ++++++++--- .../swap/usecase/SelectInitialPairUseCase.kt | 18 ++++++------- .../v2/impl/amount/entity/SwapAmountUM.kt | 6 +---- .../amount/model/SwapAmountClickIntents.kt | 2 +- .../v2/impl/amount/model/SwapAmountModel.kt | 11 +++++--- .../impl/amount/model/SwapAmountQuoteUtils.kt | 2 +- .../converter/SwapAmountFieldConverter.kt | 2 +- .../SwapAmountBalanceHiddenTransformer.kt | 2 +- .../SwapAmountPrimaryReadyStateTransformer.kt | 2 +- ...wapAmountSecondaryReadyStateTransformer.kt | 2 +- .../SwapAmountSelectQuoteTransformer.kt | 2 +- .../impl/amount/ui/SwapAmountBlockContent.kt | 2 +- .../v2/impl/amount/ui/SwapAmountContent.kt | 2 +- .../ui/preview/SwapAmountClickIntentsStub.kt | 2 +- .../ui/preview/SwapAmountContentPreview.kt | 2 +- .../swap/v2/impl/common/ConfirmData.kt | 2 ++ .../confirm/model/SendWithSwapConfirmModel.kt | 2 ++ .../confirm/model/SwapTransactionSender.kt | 4 ++- 25 files changed, 102 insertions(+), 45 deletions(-) create mode 100644 domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapAmountType.kt create mode 100644 domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapRateMode.kt diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/express/TangemExpressApi.kt b/core/datasource/src/main/java/com/tangem/datasource/api/express/TangemExpressApi.kt index d4e2600da3..b64ceb1ec2 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/express/TangemExpressApi.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/express/TangemExpressApi.kt @@ -41,7 +41,8 @@ interface TangemExpressApi { @Query("fromNetwork") fromNetwork: String, @Query("toContractAddress") toContractAddress: String, @Query("toNetwork") toNetwork: String, - @Query("fromAmount") fromAmount: String, + @Query("fromAmount") fromAmount: String?, + @Query("toAmount") toAmount: String? = null, @Query("fromDecimals") fromDecimals: Int, @Query("toDecimals") toDecimals: Int, @Query("providerId") providerId: String, @@ -57,7 +58,8 @@ interface TangemExpressApi { @Query("toContractAddress") toContractAddress: String, @Query("fromAddress") fromAddress: String, @Query("toNetwork") toNetwork: String, - @Query("fromAmount") fromAmount: String, + @Query("fromAmount") fromAmount: String?, + @Query("toAmount") toAmount: String? = null, @Query("fromDecimals") fromDecimals: Int, @Query("toDecimals") toDecimals: Int, @Query("providerId") providerId: String, diff --git a/data/swap/src/main/java/com/tangem/data/swap/DefaultSwapRepositoryV2.kt b/data/swap/src/main/java/com/tangem/data/swap/DefaultSwapRepositoryV2.kt index 0386fa396c..e4bbdeebee 100644 --- a/data/swap/src/main/java/com/tangem/data/swap/DefaultSwapRepositoryV2.kt +++ b/data/swap/src/main/java/com/tangem/data/swap/DefaultSwapRepositoryV2.kt @@ -32,6 +32,7 @@ import com.tangem.domain.quotes.single.SingleQuoteStatusProducer import com.tangem.domain.quotes.single.SingleQuoteStatusSupplier import com.tangem.domain.swap.SwapRepositoryV2 import com.tangem.domain.swap.models.* +import com.tangem.domain.swap.models.SwapAmountType import com.tangem.domain.tokens.operations.CryptoCurrencyStatusFactory import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.CoroutineScope @@ -177,12 +178,26 @@ internal class DefaultSwapRepositoryV2 @Inject constructor( userWallet: UserWallet, fromCryptoCurrency: CryptoCurrency, toCryptoCurrency: CryptoCurrency, - fromAmount: BigDecimal, + amount: BigDecimal, + amountType: SwapAmountType, provider: ExpressProvider, rateType: ExpressRateType, ): SwapQuoteModel = withContext(coroutineDispatcher.io) { 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, fromContractAddress = fromCryptoCurrency.getContractAddress(), fromDecimals = fromCryptoCurrency.decimals, @@ -199,10 +214,12 @@ internal class DefaultSwapRepositoryV2 @Inject constructor( ).getOrThrow() val toTokenAmount = requireNotNull(response.toAmount.toBigDecimalOrNull()?.movePointLeft(response.toDecimals)) + val fromTokenAmount = response.fromAmount.toBigDecimalOrNull()?.movePointLeft(response.fromDecimals) return@withContext SwapQuoteModel( provider = provider, toTokenAmount = toTokenAmount, + fromTokenAmount = fromTokenAmount, allowanceContract = response.allowanceContract, ) } @@ -211,7 +228,8 @@ internal class DefaultSwapRepositoryV2 @Inject constructor( userWallet: UserWallet, fromCryptoCurrencyStatus: CryptoCurrencyStatus, toCryptoCurrency: CryptoCurrency, - fromAmount: String, + amount: String, + amountType: SwapAmountType, toAddress: String, toExtraId: String?, expressProvider: ExpressProvider, @@ -241,7 +259,8 @@ internal class DefaultSwapRepositoryV2 @Inject constructor( toAddress = toAddress, fromDecimals = fromCurrency.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, rateType = rateType.name.lowercase(), requestId = requestId, diff --git a/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapAmountType.kt b/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapAmountType.kt new file mode 100644 index 0000000000..4a39ff5a50 --- /dev/null +++ b/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapAmountType.kt @@ -0,0 +1,6 @@ +package com.tangem.domain.swap.models + +enum class SwapAmountType { + From, + To, +} \ No newline at end of file diff --git a/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapQuoteModel.kt b/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapQuoteModel.kt index a808f07e67..3a65c92b9c 100644 --- a/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapQuoteModel.kt +++ b/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapQuoteModel.kt @@ -8,10 +8,12 @@ import java.math.BigDecimal * * @property provider swap provider * @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 */ data class SwapQuoteModel( val provider: ExpressProvider, val toTokenAmount: BigDecimal, + val fromTokenAmount: BigDecimal?, val allowanceContract: String?, ) \ No newline at end of file diff --git a/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapRateMode.kt b/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapRateMode.kt new file mode 100644 index 0000000000..b535fed8e6 --- /dev/null +++ b/domain/swap/models/src/main/java/com/tangem/domain/swap/models/SwapRateMode.kt @@ -0,0 +1,7 @@ +package com.tangem.domain.swap.models + +enum class SwapRateMode { + FLOAT_ONLY, + FIXED_ONLY, + FLOAT_AND_FIXED, +} \ No newline at end of file diff --git a/domain/swap/src/main/java/com/tangem/domain/swap/SwapRepositoryV2.kt b/domain/swap/src/main/java/com/tangem/domain/swap/SwapRepositoryV2.kt index 09bbb443fe..b456087ac4 100644 --- a/domain/swap/src/main/java/com/tangem/domain/swap/SwapRepositoryV2.kt +++ b/domain/swap/src/main/java/com/tangem/domain/swap/SwapRepositoryV2.kt @@ -52,7 +52,8 @@ interface SwapRepositoryV2 { * @param userWallet selected user wallet * @param fromCryptoCurrency currency being swapped from * @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 rateType rate type */ @@ -60,7 +61,8 @@ interface SwapRepositoryV2 { userWallet: UserWallet, fromCryptoCurrency: CryptoCurrency, toCryptoCurrency: CryptoCurrency, - fromAmount: BigDecimal, + amount: BigDecimal, + amountType: SwapAmountType, provider: ExpressProvider, rateType: ExpressRateType, ): SwapQuoteModel @@ -71,7 +73,8 @@ interface SwapRepositoryV2 { * @param userWallet selected user wallet * @param fromCryptoCurrencyStatus currency status being swapped from * @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 expressProvider selected swap provider * @param rateType selected provider rate type @@ -81,7 +84,8 @@ interface SwapRepositoryV2 { userWallet: UserWallet, fromCryptoCurrencyStatus: CryptoCurrencyStatus, toCryptoCurrency: CryptoCurrency, - fromAmount: String, + amount: String, + amountType: SwapAmountType, toAddress: String, toExtraId: String?, expressProvider: ExpressProvider, diff --git a/domain/swap/src/main/java/com/tangem/domain/swap/usecase/GetSwapDataUseCase.kt b/domain/swap/src/main/java/com/tangem/domain/swap/usecase/GetSwapDataUseCase.kt index fed0e324ab..448e5ddcd5 100644 --- a/domain/swap/src/main/java/com/tangem/domain/swap/usecase/GetSwapDataUseCase.kt +++ b/domain/swap/src/main/java/com/tangem/domain/swap/usecase/GetSwapDataUseCase.kt @@ -10,6 +10,7 @@ import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.swap.SwapErrorResolver import com.tangem.domain.swap.SwapRepositoryV2 +import com.tangem.domain.swap.models.SwapAmountType import com.tangem.domain.swap.models.SwapDataModel @Suppress("LongParameterList") @@ -21,7 +22,8 @@ class GetSwapDataUseCase( suspend operator fun invoke( userWallet: UserWallet, fromCryptoCurrencyStatus: CryptoCurrencyStatus, - fromAmount: String, + amount: String, + amountType: SwapAmountType, toCryptoCurrency: CryptoCurrency, toAddress: String, toExtraId: String?, @@ -32,7 +34,8 @@ class GetSwapDataUseCase( swapRepositoryV2.getSwapData( userWallet = userWallet, fromCryptoCurrencyStatus = fromCryptoCurrencyStatus, - fromAmount = fromAmount, + amount = amount, + amountType = amountType, toCryptoCurrency = toCryptoCurrency, toAddress = toAddress, toExtraId = toExtraId, diff --git a/domain/swap/src/main/java/com/tangem/domain/swap/usecase/GetSwapQuoteUseCase.kt b/domain/swap/src/main/java/com/tangem/domain/swap/usecase/GetSwapQuoteUseCase.kt index 1c7659ab36..be11d55e46 100644 --- a/domain/swap/src/main/java/com/tangem/domain/swap/usecase/GetSwapQuoteUseCase.kt +++ b/domain/swap/src/main/java/com/tangem/domain/swap/usecase/GetSwapQuoteUseCase.kt @@ -7,6 +7,7 @@ import com.tangem.domain.express.models.ExpressRateType import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.swap.SwapErrorResolver import com.tangem.domain.swap.SwapRepositoryV2 +import com.tangem.domain.swap.models.SwapAmountType import com.tangem.domain.swap.models.SwapQuoteModel import com.tangem.domain.models.wallet.UserWallet import java.math.BigDecimal @@ -14,6 +15,7 @@ import java.math.BigDecimal /** * Get swap quote for selected pair */ +@Suppress("LongParameterList") class GetSwapQuoteUseCase( private val swapRepositoryV2: SwapRepositoryV2, private val swapErrorResolver: SwapErrorResolver, @@ -23,23 +25,28 @@ class GetSwapQuoteUseCase( * @param userWallet selected user wallet * @param fromCryptoCurrency currency swap from * @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 */ suspend operator fun invoke( userWallet: UserWallet, fromCryptoCurrency: CryptoCurrency, toCryptoCurrency: CryptoCurrency, - fromAmount: BigDecimal, + amount: BigDecimal, + amountType: SwapAmountType, + rateType: ExpressRateType, provider: ExpressProvider, ): Either = Either.catch { swapRepositoryV2.getSwapQuote( userWallet = userWallet, fromCryptoCurrency = fromCryptoCurrency, toCryptoCurrency = toCryptoCurrency, - fromAmount = fromAmount, + amount = amount, + amountType = amountType, provider = provider, - rateType = ExpressRateType.Float, // todo rate type + rateType = rateType, ) }.mapLeft(swapErrorResolver::resolve) } \ No newline at end of file diff --git a/domain/swap/src/main/java/com/tangem/domain/swap/usecase/SelectInitialPairUseCase.kt b/domain/swap/src/main/java/com/tangem/domain/swap/usecase/SelectInitialPairUseCase.kt index 4efb56dffe..aedc62d206 100644 --- a/domain/swap/src/main/java/com/tangem/domain/swap/usecase/SelectInitialPairUseCase.kt +++ b/domain/swap/src/main/java/com/tangem/domain/swap/usecase/SelectInitialPairUseCase.kt @@ -1,9 +1,9 @@ package com.tangem.domain.swap.usecase 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.swap.SwapTransactionRepository +import com.tangem.domain.swap.models.SwapCryptoCurrency import com.tangem.domain.swap.models.SwapCurrencies import com.tangem.domain.swap.models.SwapCurrenciesGroup import com.tangem.domain.swap.models.SwapDirection @@ -30,22 +30,22 @@ class SelectInitialPairUseCase( secondaryCryptoCurrency: CryptoCurrency?, swapCurrencies: SwapCurrencies, swapDirection: SwapDirection, - ): CryptoCurrencyStatus? { + ): SwapCryptoCurrency? { val swapCurrenciesGroup = swapCurrencies.getGroupWithDirection(swapDirection) return tryToGetAlreadySelectedCurrency(secondaryCryptoCurrency, swapCurrenciesGroup) ?: tryGetFromCache(userWallet, primaryCryptoCurrency, swapCurrenciesGroup) ?: tryGetWithMaxAmount(swapCurrenciesGroup) - ?: swapCurrenciesGroup.available.firstOrNull()?.currencyStatus + ?: swapCurrenciesGroup.available.firstOrNull() } private fun tryToGetAlreadySelectedCurrency( secondaryCryptoCurrency: CryptoCurrency?, swapCurrenciesGroup: SwapCurrenciesGroup, - ): CryptoCurrencyStatus? { + ): SwapCryptoCurrency? { return secondaryCryptoCurrency?.let { swapCurrenciesGroup.available.firstOrNull { currency -> secondaryCryptoCurrency.id == currency.currencyStatus.currency.id - }?.currencyStatus + } } } @@ -53,19 +53,19 @@ class SelectInitialPairUseCase( userWallet: UserWallet, primaryCryptoCurrency: CryptoCurrency, swapCurrenciesGroup: SwapCurrenciesGroup, - ): CryptoCurrencyStatus? { + ): SwapCryptoCurrency? { val id = swapTransactionRepository.getLastSwappedCryptoCurrencyId(userWallet.walletId) ?: return null 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 { null } } - private fun tryGetWithMaxAmount(swapCurrenciesGroup: SwapCurrenciesGroup): CryptoCurrencyStatus? { + private fun tryGetWithMaxAmount(swapCurrenciesGroup: SwapCurrenciesGroup): SwapCryptoCurrency? { return swapCurrenciesGroup.available.maxByOrNull { it.currencyStatus.value.fiatAmount.orZero() - }?.currencyStatus + } } } \ No newline at end of file diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/entity/SwapAmountUM.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/entity/SwapAmountUM.kt index 4cbc2867a6..c749636dc6 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/entity/SwapAmountUM.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/entity/SwapAmountUM.kt @@ -7,6 +7,7 @@ import com.tangem.core.ui.extensions.TextReference import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.express.models.ExpressRateType 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.SwapDirection import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM @@ -92,9 +93,4 @@ sealed class PriceImpactUM { data object Empty : PriceImpactUM() data class Value(val value: Float) : PriceImpactUM() -} - -enum class SwapAmountType { - From, - To, } \ No newline at end of file diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountClickIntents.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountClickIntents.kt index cf6b75586e..0e9ba829e8 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountClickIntents.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountClickIntents.kt @@ -1,7 +1,7 @@ package com.tangem.features.swap.v2.impl.amount.model 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 { diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountModel.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountModel.kt index 75b3107ff5..2b3fc14c6d 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountModel.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountModel.kt @@ -20,6 +20,7 @@ import com.tangem.datasource.local.swap.SwapBestRateAnimationStore import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency 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.CryptoCurrencyStatus 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.analytics.SwapAmountAnalyticEvents 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.model.converter.SwapQuoteUMConverter 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?) { modelScope.launch { - val secondaryStatus = selectInitialPairUseCase( + val swapCryptoCurrency = selectInitialPairUseCase( primaryCryptoCurrency = primaryCryptoCurrency, secondaryCryptoCurrency = secondaryCryptoCurrency, userWallet = userWallet, @@ -533,6 +533,8 @@ internal class SwapAmountModel @Inject constructor( swapDirection = params.swapDirection, ) + val secondaryStatus = swapCryptoCurrency?.currencyStatus + val primaryStatus = (uiState.value as? SwapAmountUM.Content)?.primaryCryptoCurrencyStatus if (secondaryStatus != null && primaryStatus != null) { initCurrencies(primaryStatus, secondaryStatus) @@ -594,6 +596,7 @@ internal class SwapAmountModel @Inject constructor( } } + @Suppress("LongMethod") private fun loadQuotes(isSilentReload: Boolean) { val state = uiState.value as? SwapAmountUM.Content ?: return if (state.secondaryCryptoCurrencyStatus == null) return @@ -629,7 +632,9 @@ internal class SwapAmountModel @Inject constructor( userWallet = userWallet, fromCryptoCurrency = fromCryptoCurrency, toCryptoCurrency = toCryptoCurrency, - fromAmount = fromAmountValue, + amount = fromAmountValue, + amountType = SwapAmountType.From, + rateType = ExpressRateType.Float, provider = provider, ).fold( ifLeft = { error -> diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountQuoteUtils.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountQuoteUtils.kt index 9bc9fb3314..f3b1614ce2 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountQuoteUtils.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountQuoteUtils.kt @@ -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.percent import com.tangem.domain.models.currency.CryptoCurrencyStatus +import com.tangem.domain.swap.models.SwapAmountType 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.SwapAmountType import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.utils.extensions.isZero import com.tangem.utils.isNullOrZero diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapAmountFieldConverter.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapAmountFieldConverter.kt index ae17646047..9adad0ddeb 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapAmountFieldConverter.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapAmountFieldConverter.kt @@ -15,10 +15,10 @@ import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.models.account.Account import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.wallet.UserWallet +import com.tangem.domain.swap.models.SwapAmountType import com.tangem.domain.swap.models.SwapDirection 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.SwapAmountType import com.tangem.utils.StringsSigns.DOT @Suppress("LongParameterList") diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountBalanceHiddenTransformer.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountBalanceHiddenTransformer.kt index 56a7fab934..ede7a349fb 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountBalanceHiddenTransformer.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountBalanceHiddenTransformer.kt @@ -5,9 +5,9 @@ import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.models.account.Account import com.tangem.domain.models.wallet.UserWallet +import com.tangem.domain.swap.models.SwapAmountType 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.SwapAmountType import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.model.converter.SwapAmountFieldConverter import com.tangem.utils.transformer.Transformer diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountPrimaryReadyStateTransformer.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountPrimaryReadyStateTransformer.kt index aa09d11164..bb5046a48d 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountPrimaryReadyStateTransformer.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountPrimaryReadyStateTransformer.kt @@ -6,10 +6,10 @@ import com.tangem.domain.express.models.ExpressRateType import com.tangem.domain.models.account.Account import com.tangem.domain.models.currency.CryptoCurrencyStatus 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.SwapDirection 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.model.converter.SwapAmountFieldConverter import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountSecondaryReadyStateTransformer.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountSecondaryReadyStateTransformer.kt index f8f8600421..545c13db6e 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountSecondaryReadyStateTransformer.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountSecondaryReadyStateTransformer.kt @@ -6,9 +6,9 @@ import com.tangem.domain.express.models.ExpressRateType import com.tangem.domain.models.account.Account import com.tangem.domain.models.currency.CryptoCurrencyStatus 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.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.model.converter.SwapAmountFieldConverter import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountSelectQuoteTransformer.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountSelectQuoteTransformer.kt index 03058c869b..3f3f9ac158 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountSelectQuoteTransformer.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountSelectQuoteTransformer.kt @@ -5,8 +5,8 @@ import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.common.ui.amountScreen.models.EnterAmountBoundary import com.tangem.core.ui.extensions.TextReference 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.SwapAmountType 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.converter.SwapAmountErrorConverter diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/SwapAmountBlockContent.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/SwapAmountBlockContent.kt index 008e402a09..b4df59fefc 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/SwapAmountBlockContent.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/SwapAmountBlockContent.kt @@ -37,9 +37,9 @@ import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringResourceSafe import com.tangem.core.ui.res.TangemTheme 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.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.ui.preview.SwapAmountContentPreview import com.tangem.features.swap.v2.impl.chooseprovider.ui.SwapChooseProviderContent diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/SwapAmountContent.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/SwapAmountContent.kt index 61ec2095f4..b314e610b9 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/SwapAmountContent.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/SwapAmountContent.kt @@ -39,9 +39,9 @@ import com.tangem.core.ui.extensions.stringResourceSafe import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview 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.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.model.SwapAmountClickIntents import com.tangem.features.swap.v2.impl.amount.ui.preview.SwapAmountClickIntentsStub diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/preview/SwapAmountClickIntentsStub.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/preview/SwapAmountClickIntentsStub.kt index 4c55f4759a..4a7380480b 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/preview/SwapAmountClickIntentsStub.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/preview/SwapAmountClickIntentsStub.kt @@ -1,6 +1,6 @@ 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 internal object SwapAmountClickIntentsStub : SwapAmountClickIntents { diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/preview/SwapAmountContentPreview.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/preview/SwapAmountContentPreview.kt index 798b7fd4d0..b4ebcff7cb 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/preview/SwapAmountContentPreview.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/ui/preview/SwapAmountContentPreview.kt @@ -12,10 +12,10 @@ import com.tangem.domain.express.models.ExpressRateType import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrencyStatus 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.SwapDirection 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.common.entity.SwapQuoteUM import com.tangem.utils.StringsSigns diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/common/ConfirmData.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/common/ConfirmData.kt index e0fd2912f4..7da47a57aa 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/common/ConfirmData.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/common/ConfirmData.kt @@ -4,6 +4,7 @@ import com.tangem.blockchain.common.transaction.Fee import com.tangem.domain.express.models.ExpressRateType import com.tangem.domain.models.account.Account import com.tangem.domain.models.currency.CryptoCurrencyStatus +import com.tangem.domain.swap.models.SwapAmountType import com.tangem.domain.transaction.error.GetFeeError import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM import java.math.BigDecimal @@ -21,4 +22,5 @@ internal data class ConfirmData( val fromAccount: Account?, val quote: SwapQuoteUM?, val rateType: ExpressRateType?, + val amountType: SwapAmountType, ) \ No newline at end of file diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt index 99fcf5c1e4..bea5544651 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt @@ -29,6 +29,7 @@ import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.wallet.isHotWallet 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.tokens.IsAmountSubtractAvailableUseCase import com.tangem.domain.transaction.error.GetFeeError @@ -158,6 +159,7 @@ internal class SendWithSwapConfirmModel @Inject constructor( fromAccount = params.accountFlow.value, quote = amountUM?.selectedQuote, rateType = amountUM?.swapRateType, + amountType = amountUM?.selectedAmountType ?: SwapAmountType.From, ) } diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SwapTransactionSender.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SwapTransactionSender.kt index 3618110f82..41f709edb1 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SwapTransactionSender.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SwapTransactionSender.kt @@ -11,6 +11,7 @@ import com.tangem.domain.express.models.ExpressProviderType import com.tangem.domain.models.account.Account import com.tangem.domain.models.currency.CryptoCurrencyStatus 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.SwapDataTransactionModel import com.tangem.domain.swap.models.SwapTxType @@ -101,7 +102,8 @@ internal class SwapTransactionSender @AssistedInject constructor( val swapData = getSwapDataUseCase( userWallet = userWallet, fromCryptoCurrencyStatus = fromStatus, - fromAmount = fromAmount.toStringWithRightOffset(fromStatus.currency.decimals), + amount = fromAmount.toStringWithRightOffset(fromStatus.currency.decimals), + amountType = SwapAmountType.From, toCryptoCurrency = toStatus.currency, toAddress = destination, toExtraId = confirmData.enteredMemo,