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 ea00127113..41e06a2c94 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 @@ -87,6 +87,7 @@ sealed class SwapAmountFieldUM { val subtitleEllipsisRight: TextEllipsis, val isClickEnabled: Boolean, val shouldShowApproximatePrefix: Boolean, + val sendSubtitle: SendSubtitleUM? = null, ) : SwapAmountFieldUM() } @@ -119,4 +120,11 @@ data class PriceImpact( type = Type.NONE, ) } -} \ No newline at end of file +} + +@Immutable +data class SendSubtitleUM( + val label: TextReference, + val value: TextReference, + val valueEllipsis: TextEllipsis, +) \ No newline at end of file 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 9f427e5e85..31896ff489 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 @@ -60,6 +60,7 @@ internal class SwapAmountFieldConverter( subtitleEllipsisLeft = subtitles.subtitleEllipsisLeft, subtitleRight = subtitles.subtitleRight, subtitleEllipsisRight = subtitles.subtitleEllipsisRight, + sendSubtitle = subtitles.sendSubtitle, isClickEnabled = true, shouldShowApproximatePrefix = showApproximatePrefix, amountField = AmountStateConverter( diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapAmountUpdateSubtitleConverter.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapAmountUpdateSubtitleConverter.kt index 1ed8a5c867..75f19f7146 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapAmountUpdateSubtitleConverter.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapAmountUpdateSubtitleConverter.kt @@ -58,6 +58,7 @@ internal class SwapAmountUpdateSubtitleConverter( subtitleEllipsisLeft = subtitles.subtitleEllipsisLeft, subtitleRight = subtitles.subtitleRight, subtitleEllipsisRight = subtitles.subtitleEllipsisRight, + sendSubtitle = subtitles.sendSubtitle, ) } } \ No newline at end of file diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapFromSubtitleConverter.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapFromSubtitleConverter.kt index 696f92438a..ed24211c15 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapFromSubtitleConverter.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapFromSubtitleConverter.kt @@ -6,17 +6,17 @@ import com.tangem.core.ui.format.bigdecimal.crypto import com.tangem.core.ui.format.bigdecimal.format import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.features.swap.v2.impl.R -import com.tangem.utils.StringsSigns.DOT +import com.tangem.features.swap.v2.impl.amount.entity.SendSubtitleUM import java.math.BigDecimal /** * Computes all subtitle fields for the **From** (primary) field. * - * | State | subtitleLeft | subtitleRight | ellipsisLeft | - * |--------------------------------|-----------------------------------|-----------------------------------|------------------------| - * | Entering (float), any | "Balance: " (empty param) | "{balance}" masked | OffsetEnd(symbol) | - * | Viewing (fixed), empty | "Balance: " (empty param) | "{balance}" masked (crypto only) | End | - * | Viewing (fixed), not empty | "{balance}" masked | "• Send {displayStr}" masked | OffsetEnd(symbol) | + * | State | subtitleLeft | subtitleRight | sendSubtitle | + * |--------------------------------|-----------------------------------|---------------|-------------------------| + * | Entering (float), any | "Balance: {balance}" masked | EMPTY | null | + * | Viewing (fixed), empty | "Balance: {balance}" masked | EMPTY | null | + * | Viewing (fixed), not empty | "Balance: {balance}" masked | EMPTY | SendSubtitleUM(...) | */ internal object SwapFromSubtitleConverter { @@ -35,40 +35,27 @@ internal object SwapFromSubtitleConverter { crypto(cryptoCurrency = cryptoCurrencyStatus.currency) } ?: balance - val subtitleLeft: TextReference - val subtitleRight: TextReference - val ellipsisLeft: TextEllipsis + val subtitleLeft = combinedReference( + resourceReference(R.string.common_balance, wrappedList("")), + stringReference(balance).orMaskWithStars(isBalanceHidden), + ) - when { - isEntering -> { - subtitleLeft = resourceReference(R.string.common_balance, wrappedList("")) - subtitleRight = combinedReference(stringReference(balance)) - .orMaskWithStars(isBalanceHidden) - ellipsisLeft = TextEllipsis.OffsetEnd(symbol.length) - } - !isEntering && isAmountEmpty -> { - subtitleLeft = resourceReference(R.string.common_balance, wrappedList("")) - subtitleRight = combinedReference(stringReference(balance)) - .orMaskWithStars(isBalanceHidden) - ellipsisLeft = TextEllipsis.End - } - else -> { - subtitleLeft = stringReference(balance) - .orMaskWithStars(isBalanceHidden) - subtitleRight = combinedReference( - stringReference("$DOT "), - resourceReference(R.string.common_send), - stringReference(" $displayStr"), - ).orMaskWithStars(isBalanceHidden) - ellipsisLeft = TextEllipsis.OffsetEnd(symbol.length) - } + val sendSubtitle = if (!isEntering && !isAmountEmpty) { + SendSubtitleUM( + label = resourceReference(R.string.common_send_colon), + value = stringReference(displayStr).orMaskWithStars(isBalanceHidden), + valueEllipsis = TextEllipsis.OffsetEnd(symbol.length), + ) + } else { + null } return SwapSubtitleResult( subtitleLeft = subtitleLeft, - subtitleRight = subtitleRight, - subtitleEllipsisLeft = ellipsisLeft, + subtitleRight = TextReference.EMPTY, + subtitleEllipsisLeft = TextEllipsis.OffsetEnd(symbol.length), subtitleEllipsisRight = TextEllipsis.OffsetEnd(symbol.length), + sendSubtitle = sendSubtitle, ) } } \ No newline at end of file diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapSubtitleResult.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapSubtitleResult.kt index 3253f56f44..85562144d5 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapSubtitleResult.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapSubtitleResult.kt @@ -2,10 +2,12 @@ package com.tangem.features.swap.v2.impl.amount.model.converter import com.tangem.core.ui.components.atoms.text.TextEllipsis import com.tangem.core.ui.extensions.TextReference +import com.tangem.features.swap.v2.impl.amount.entity.SendSubtitleUM internal data class SwapSubtitleResult( val subtitleLeft: TextReference, val subtitleRight: TextReference, val subtitleEllipsisLeft: TextEllipsis, val subtitleEllipsisRight: TextEllipsis, + val sendSubtitle: SendSubtitleUM? = null, ) \ No newline at end of file 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 fed51e8242..cddaedbe4b 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 @@ -365,23 +365,45 @@ private fun SwapAmountInfoMain( private fun SwapAmountSubtitle(amountFieldUM: SwapAmountFieldUM) { SpacerH2() if (amountFieldUM is SwapAmountFieldUM.Content) { - SpacerH2() - Row( - horizontalArrangement = Arrangement.spacedBy(4.dp), + Column( + verticalArrangement = Arrangement.spacedBy(2.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, - ) + 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, + ) + } + if (amountFieldUM.sendSubtitle != null) { + Row( + horizontalArrangement = Arrangement.spacedBy(4.dp), + ) { + Text( + text = amountFieldUM.sendSubtitle.label.resolveReference(), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.tertiary, + ) + EllipsisText( + text = amountFieldUM.sendSubtitle.value.resolveReference(), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.primary1, + ellipsis = amountFieldUM.sendSubtitle.valueEllipsis, + modifier = Modifier.weight(1f, fill = false), + ) + } + } } } else { SpacerH2() 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 9be4de2099..9ed0406b51 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 @@ -16,10 +16,10 @@ import com.tangem.domain.swap.models.SwapAmountType import com.tangem.domain.swap.models.SwapCurrencies import com.tangem.domain.swap.models.SwapDirection import com.tangem.domain.swap.models.SwapRateMode +import com.tangem.features.swap.v2.impl.amount.entity.SendSubtitleUM 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.common.entity.SwapQuoteUM -import com.tangem.utils.StringsSigns import kotlinx.collections.immutable.persistentListOf import java.math.BigDecimal @@ -103,12 +103,17 @@ internal data object SwapAmountContentPreview { amountType = SwapAmountType.From, amountField = AmountStatePreviewData.amountState, title = stringReference("Tether"), - subtitleLeft = stringReference("11 101,123123456 BTC"), - subtitleRight = stringReference(" ${StringsSigns.DOT} 1 212,12 $"), + subtitleLeft = stringReference("Balance: 11 101,123123456 BTC"), + subtitleRight = TextReference.EMPTY, isClickEnabled = false, subtitleEllipsisLeft = TextEllipsis.OffsetEnd(3), subtitleEllipsisRight = TextEllipsis.OffsetEnd(1), shouldShowApproximatePrefix = false, + sendSubtitle = SendSubtitleUM( + label = stringReference("Send:"), + value = stringReference("1 212,12 BTC"), + valueEllipsis = TextEllipsis.OffsetEnd(3), + ), ), secondaryAmount = SwapAmountFieldUM.Content( amountType = SwapAmountType.To, diff --git a/features/swap-v2/impl/src/test/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapFromSubtitleConverterTest.kt b/features/swap-v2/impl/src/test/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapFromSubtitleConverterTest.kt new file mode 100644 index 0000000000..b83923eb34 --- /dev/null +++ b/features/swap-v2/impl/src/test/java/com/tangem/features/swap/v2/impl/amount/model/converter/SwapFromSubtitleConverterTest.kt @@ -0,0 +1,88 @@ +package com.tangem.features.swap.v2.impl.amount.model.converter + +import com.google.common.truth.Truth.assertThat +import com.tangem.core.ui.extensions.TextReference +import com.tangem.domain.models.currency.CryptoCurrencyStatus +import io.mockk.every +import io.mockk.mockk +import org.junit.Test +import java.math.BigDecimal + +internal class SwapFromSubtitleConverterTest { + + @Test + fun `GIVEN isEntering true WHEN convert THEN subtitleRight is EMPTY and sendSubtitle is null`() { + val cryptoCurrencyStatus = mockk(relaxed = true) + every { cryptoCurrencyStatus.currency.symbol } returns "ETH" + every { cryptoCurrencyStatus.currency.decimals } returns 8 + every { cryptoCurrencyStatus.value.amount } returns BigDecimal("1.5") + + val result = SwapFromSubtitleConverter.convert( + cryptoCurrencyStatus = cryptoCurrencyStatus, + isBalanceHidden = false, + isEntering = true, + isAmountEmpty = false, + displayAmount = BigDecimal("0.5"), + ) + + assertThat(result.subtitleRight).isEqualTo(TextReference.EMPTY) + assertThat(result.sendSubtitle).isNull() + } + + @Test + fun `GIVEN isEntering false and isAmountEmpty true WHEN convert THEN subtitleRight is EMPTY and sendSubtitle is null`() { + val cryptoCurrencyStatus = mockk(relaxed = true) + every { cryptoCurrencyStatus.currency.symbol } returns "ETH" + every { cryptoCurrencyStatus.currency.decimals } returns 8 + every { cryptoCurrencyStatus.value.amount } returns BigDecimal("1.5") + + val result = SwapFromSubtitleConverter.convert( + cryptoCurrencyStatus = cryptoCurrencyStatus, + isBalanceHidden = false, + isEntering = false, + isAmountEmpty = true, + displayAmount = null, + ) + + assertThat(result.subtitleRight).isEqualTo(TextReference.EMPTY) + assertThat(result.sendSubtitle).isNull() + } + + @Test + fun `GIVEN isEntering false and isAmountEmpty false WHEN convert THEN subtitleRight is EMPTY and sendSubtitle is not null`() { + val cryptoCurrencyStatus = mockk(relaxed = true) + every { cryptoCurrencyStatus.currency.symbol } returns "ETH" + every { cryptoCurrencyStatus.currency.decimals } returns 8 + every { cryptoCurrencyStatus.value.amount } returns BigDecimal("1.5") + + val result = SwapFromSubtitleConverter.convert( + cryptoCurrencyStatus = cryptoCurrencyStatus, + isBalanceHidden = false, + isEntering = false, + isAmountEmpty = false, + displayAmount = BigDecimal("0.5"), + ) + + assertThat(result.subtitleRight).isEqualTo(TextReference.EMPTY) + assertThat(result.sendSubtitle).isNotNull() + } + + @Test + fun `GIVEN isBalanceHidden true and has amount WHEN convert THEN sendSubtitle is not null`() { + val cryptoCurrencyStatus = mockk(relaxed = true) + every { cryptoCurrencyStatus.currency.symbol } returns "ETH" + every { cryptoCurrencyStatus.currency.decimals } returns 8 + every { cryptoCurrencyStatus.value.amount } returns BigDecimal("1.5") + + val result = SwapFromSubtitleConverter.convert( + cryptoCurrencyStatus = cryptoCurrencyStatus, + isBalanceHidden = true, + isEntering = false, + isAmountEmpty = false, + displayAmount = BigDecimal("0.5"), + ) + + assertThat(result.subtitleRight).isEqualTo(TextReference.EMPTY) + assertThat(result.sendSubtitle).isNotNull() + } +} \ No newline at end of file