From 821c6b569732a9d6b3a798db7b51fe0ce2522c01 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 1 Apr 2026 12:01:34 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../v2/impl/amount/model/SwapAmountModel.kt | 3 -- .../SwapAmountValueChangeTransformer.kt | 49 +++++++++++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) 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 b17f11cbb6..398cddb6d9 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 @@ -551,9 +551,6 @@ internal class SwapAmountModel @Inject constructor( initPairs(data.swapCurrencies, data.cryptoCurrency) amountUM.copy( isPrimaryButtonEnabled = false, - secondaryAmount = SwapAmountFieldUM.Loading( - amountType = SwapAmountType.To, - ), ) } else { amountUM diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountValueChangeTransformer.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountValueChangeTransformer.kt index 639f994b78..176c541301 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountValueChangeTransformer.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/transformers/SwapAmountValueChangeTransformer.kt @@ -2,6 +2,9 @@ package com.tangem.features.swap.v2.impl.amount.model.transformers import com.tangem.common.ui.amountScreen.converters.field.AmountFieldChangeTransformer import com.tangem.common.ui.amountScreen.models.EnterAmountBoundary +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.SwapAmountUM import com.tangem.features.swap.v2.impl.amount.model.SwapAmountQuoteUtils.updateAmount import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM @@ -44,13 +47,53 @@ internal class SwapAmountValueChangeTransformer( }, ) - return (updatedState as? SwapAmountUM.Content)?.copy( + val contentState = updatedState as? SwapAmountUM.Content ?: return updatedState + + val newState = if (value.isEmpty()) { + contentState.clearOppositeField(prevState) + } else { + contentState + } + + return newState.copy( isPrimaryButtonEnabled = false, - selectedQuote = if (updatedState.isPrimaryButtonEnabled) { + selectedQuote = if (value.isEmpty()) { SwapQuoteUM.Empty } else { SwapQuoteUM.Loading }, - ) ?: updatedState + ) + } + + private fun SwapAmountUM.Content.clearOppositeField(prevState: SwapAmountUM.Content): SwapAmountUM.Content { + val isPrimaryFieldEdited = + selectedAmountType == SwapAmountType.From && swapDirection == SwapDirection.Direct + + return if (isPrimaryFieldEdited) { + val secondaryStatus = secondaryCryptoCurrencyStatus ?: return this + val secondaryContent = secondaryAmount as? SwapAmountFieldUM.Content ?: return this + copy( + secondaryAmount = secondaryContent.copy( + amountField = AmountFieldChangeTransformer( + cryptoCurrencyStatus = secondaryStatus, + maxEnterAmount = secondaryMaximumAmountBoundary ?: return this, + minimumTransactionAmount = secondaryMinimumAmountBoundary, + value = "", + ).transform(prevState.secondaryAmount.amountField), + ), + ) + } else { + val primaryContent = primaryAmount as? SwapAmountFieldUM.Content ?: return this + copy( + primaryAmount = primaryContent.copy( + amountField = AmountFieldChangeTransformer( + cryptoCurrencyStatus = primaryCryptoCurrencyStatus, + maxEnterAmount = primaryMaximumAmountBoundary, + minimumTransactionAmount = primaryMinimumAmountBoundary, + value = "", + ).transform(prevState.primaryAmount.amountField), + ), + ) + } } } \ No newline at end of file