From 5b8839cf52e46096821bbbd85f42481b9d8ec026 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 7 Apr 2026 11:17:39 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../v2/impl/amount/model/SwapAmountModel.kt | 2 + .../SwapAmountValueChangeTransformer.kt | 30 ++++++- .../v2/impl/amount/ui/SwapAmountContent.kt | 83 +++++++++---------- 3 files changed, 70 insertions(+), 45 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 06c5a39626..752787e5bb 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 @@ -243,6 +243,7 @@ internal class SwapAmountModel @Inject constructor( primaryMinimumAmountBoundary = primaryMinimumAmountBoundary, secondaryMinimumAmountBoundary = secondaryMinimumAmountBoundary, value = value, + isBalanceHidden = params.isBalanceHidingFlow.value, ), ) quoteTaskScheduler.cancelTask() @@ -808,6 +809,7 @@ internal class SwapAmountModel @Inject constructor( primaryMinimumAmountBoundary = primaryMinimumAmountBoundary, secondaryMinimumAmountBoundary = secondaryMinimumAmountBoundary, value = secondaryValue, + isBalanceHidden = params.isBalanceHidingFlow.value, ), ) } 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 176c541301..5fed107dd7 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 @@ -7,6 +7,7 @@ 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.amount.model.converter.SwapAmountUpdateSubtitleConverter import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM import com.tangem.utils.transformer.Transformer @@ -16,6 +17,7 @@ internal class SwapAmountValueChangeTransformer( private val secondaryMaximumAmountBoundary: EnterAmountBoundary?, private val secondaryMinimumAmountBoundary: EnterAmountBoundary?, private val value: String, + private val isBalanceHidden: Boolean, ) : Transformer { override fun transform(prevState: SwapAmountUM): SwapAmountUM { if (prevState !is SwapAmountUM.Content) return prevState @@ -50,7 +52,7 @@ internal class SwapAmountValueChangeTransformer( val contentState = updatedState as? SwapAmountUM.Content ?: return updatedState val newState = if (value.isEmpty()) { - contentState.clearOppositeField(prevState) + contentState.clearOppositeField(prevState).updateSubtitlesForEmptyState() } else { contentState } @@ -65,6 +67,32 @@ internal class SwapAmountValueChangeTransformer( ) } + private fun SwapAmountUM.Content.updateSubtitlesForEmptyState(): SwapAmountUM.Content { + val subtitleConverter = SwapAmountUpdateSubtitleConverter( + selectedAmountType = selectedAmountType, + isBalanceHidden = isBalanceHidden, + ) + val updatedPrimary = (primaryAmount as? SwapAmountFieldUM.Content)?.let { field -> + subtitleConverter.updateSubtitles( + field = field, + cryptoCurrencyStatus = primaryCryptoCurrencyStatus, + isAmountEmpty = true, + ) + } ?: primaryAmount + val secondaryField = secondaryAmount as? SwapAmountFieldUM.Content + val secondaryStatus = secondaryCryptoCurrencyStatus + val updatedSecondary = if (secondaryField != null && secondaryStatus != null) { + subtitleConverter.updateSubtitles( + field = secondaryField, + cryptoCurrencyStatus = secondaryStatus, + isAmountEmpty = true, + ) + } else { + secondaryAmount + } + return copy(primaryAmount = updatedPrimary, secondaryAmount = updatedSecondary) + } + private fun SwapAmountUM.Content.clearOppositeField(prevState: SwapAmountUM.Content): SwapAmountUM.Content { val isPrimaryFieldEdited = selectedAmountType == SwapAmountType.From && swapDirection == SwapDirection.Direct 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 ff48cf706a..fed51e8242 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 @@ -348,55 +348,50 @@ private fun SwapAmountInfoMain( } AnimatedContent(selectedQuote) { quote -> - when (quote) { - is SwapQuoteUM.Content -> { - SpacerH2() - if (amountFieldUM is SwapAmountFieldUM.Content) { - SpacerH2() - Row( - horizontalArrangement = Arrangement.spacedBy(4.dp), - ) { - EllipsisText( - text = amountFieldUM.subtitleLeft.resolveReference(), - style = TangemTheme.typography.caption2, - color = TangemTheme.colors.text.tertiary, - ellipsis = amountFieldUM.subtitleEllipsisLeft, - modifier = Modifier.weight(1f, fill = false), - ) - EllipsisText( - text = amountFieldUM.subtitleRight.resolveReference(), - style = TangemTheme.typography.caption2, - color = TangemTheme.colors.text.tertiary, - ellipsis = amountFieldUM.subtitleEllipsisRight, - ) - } - } else { - SpacerH2() - TextShimmer( - style = TangemTheme.typography.caption2, - modifier = Modifier.width(72.dp), - ) - } - } - SwapQuoteUM.Loading -> { - SpacerH2() - TextShimmer( - style = TangemTheme.typography.caption2, - modifier = Modifier.width(72.dp), - ) - } - else -> { - SpacerH2() - Text( - text = "", - style = TangemTheme.typography.caption2, - ) - } + if (quote is SwapQuoteUM.Loading) { + SpacerH2() + TextShimmer( + style = TangemTheme.typography.caption2, + modifier = Modifier.width(72.dp), + ) + } else { + SwapAmountSubtitle(amountFieldUM) } } } } +@Composable +private fun SwapAmountSubtitle(amountFieldUM: SwapAmountFieldUM) { + SpacerH2() + if (amountFieldUM is SwapAmountFieldUM.Content) { + SpacerH2() + Row( + horizontalArrangement = Arrangement.spacedBy(4.dp), + ) { + EllipsisText( + text = amountFieldUM.subtitleLeft.resolveReference(), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.tertiary, + ellipsis = amountFieldUM.subtitleEllipsisLeft, + modifier = Modifier.weight(1f, fill = false), + ) + EllipsisText( + text = amountFieldUM.subtitleRight.resolveReference(), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.tertiary, + ellipsis = amountFieldUM.subtitleEllipsisRight, + ) + } + } else { + SpacerH2() + TextShimmer( + style = TangemTheme.typography.caption2, + modifier = Modifier.width(72.dp), + ) + } +} + @Composable private fun AmountMaxButton(onMaxAmountClick: () -> Unit) { Text(