diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/models/SwapStateHolder.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/models/SwapStateHolder.kt index 24b806a74b..0feeebd886 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/models/SwapStateHolder.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/models/SwapStateHolder.kt @@ -59,7 +59,7 @@ sealed class SwapCardState { val tokenSymbol: TextReference, val amountEquivalent: TextReference?, val amountTextFieldValue: TextFieldValue?, - val balance: String, + val balance: TextReference, val isBalanceHidden: Boolean, ) : SwapCardState() diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt index c2cce01561..955473a8f8 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt @@ -303,7 +303,7 @@ internal class StateBuilder( amountEquivalent = emptyAmountState.zeroAmountEquivalent, currencyIconState = iconStateConverter.convert(swapCurrencyStatus.status), tokenSymbol = stringReference(swapCurrencyStatus.currency.symbol), - balance = swapCurrencyStatus.status.getFormattedAmount(isNeedSymbol = false), + balance = swapCurrencyStatus.status.getFormattedAmount(), isBalanceHidden = isBalanceHiddenProvider(), type = cardType, ) @@ -311,7 +311,7 @@ internal class StateBuilder( copy( currencyIconState = iconStateConverter.convert(swapCurrencyStatus.status), tokenSymbol = stringReference(swapCurrencyStatus.currency.symbol), - balance = swapCurrencyStatus.status.getFormattedAmount(isNeedSymbol = false), + balance = swapCurrencyStatus.status.getFormattedAmount(), isBalanceHidden = isBalanceHiddenProvider(), type = cardType, ) @@ -350,7 +350,7 @@ internal class StateBuilder( amountEquivalent = emptyAmountState.zeroAmountEquivalent, currencyIconState = iconStateConverter.convert(swapCurrencyStatus.status), tokenSymbol = stringReference(swapCurrencyStatus.currency.symbol), - balance = swapCurrencyStatus.status.getFormattedAmount(isNeedSymbol = false), + balance = swapCurrencyStatus.status.getFormattedAmount(), isBalanceHidden = isBalanceHiddenProvider(), ) } @@ -387,7 +387,7 @@ internal class StateBuilder( amountEquivalent = getFormattedFiatAmount(BigDecimal.ZERO), currencyIconState = iconStateConverter.convert(fromSwapCurrencyStatus.status), tokenSymbol = stringReference(fromSwapCurrencyStatus.currency.symbol), - balance = fromSwapCurrencyStatus.status.getFormattedAmount(isNeedSymbol = false), + balance = fromSwapCurrencyStatus.status.getFormattedAmount(), isBalanceHidden = isBalanceHiddenProvider(), ), receiveCardData = SwapCardState.SwapCardData( @@ -400,7 +400,7 @@ internal class StateBuilder( amountEquivalent = getFormattedFiatAmount(BigDecimal.ZERO), currencyIconState = iconStateConverter.convert(toSwapCurrencyStatus.status), tokenSymbol = stringReference(toSwapCurrencyStatus.currency.symbol), - balance = toSwapCurrencyStatus.status.getFormattedAmount(isNeedSymbol = false), + balance = toSwapCurrencyStatus.status.getFormattedAmount(), isBalanceHidden = isBalanceHiddenProvider(), ), notifications = notificationsFactory.getSwapNotSupportedNotifications(), @@ -516,7 +516,7 @@ internal class StateBuilder( amountEquivalent = uiStateHolder.sendCardData.amountEquivalent, currencyIconState = iconStateConverter.convert(fromSwapCurrencyStatus.status), tokenSymbol = stringReference(fromSwapCurrencyStatus.currency.symbol), - balance = fromSwapCurrencyStatus.status.getFormattedAmount(isNeedSymbol = false), + balance = fromSwapCurrencyStatus.status.getFormattedAmount(), isBalanceHidden = isBalanceHiddenProvider(), ), receiveCardData = SwapCardState.SwapCardData( @@ -552,7 +552,7 @@ internal class StateBuilder( }, currencyIconState = iconStateConverter.convert(toSwapCurrencyStatus.status), tokenSymbol = stringReference(toSwapCurrencyStatus.currency.symbol), - balance = toSwapCurrencyStatus.status.getFormattedAmount(isNeedSymbol = false), + balance = toSwapCurrencyStatus.status.getFormattedAmount(), isBalanceHidden = isBalanceHiddenProvider(), ), isInsufficientFunds = isInsufficientFundsCondition(quoteModel), @@ -739,7 +739,7 @@ internal class StateBuilder( amountEquivalent = getFormattedFiatAmount(BigDecimal.ZERO), currencyIconState = iconStateConverter.convert(toSwapCurrencyStatus.status), tokenSymbol = stringReference(toSwapCurrencyStatus.currency.symbol), - balance = toToken.getFormattedAmount(isNeedSymbol = false), + balance = toToken.getFormattedAmount(), isBalanceHidden = isBalanceHiddenProvider(), ) } ?: SwapCardState.Empty( @@ -1214,10 +1214,12 @@ internal class StateBuilder( } } - private fun CryptoCurrencyStatus?.getFormattedAmount(isNeedSymbol: Boolean): String { - val amount = this?.value?.amount ?: return DASH_SIGN - val symbol = if (isNeedSymbol) currency.symbol else "" - return amount.format { crypto(symbol, currency.decimals) } + private fun CryptoCurrencyStatus?.getFormattedAmount(): TextReference { + if (this == null) return stringReference(DASH_SIGN) + return resourceReference( + R.string.common_balance, + wrappedList(this.value.amount.format { crypto(currency.symbol, currency.decimals) }), + ) } private fun getFormattedFiatAmount(amount: BigDecimal?): TextReference { diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/TransactionCard.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/TransactionCard.kt index c4c9307346..8db4818844 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/TransactionCard.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/TransactionCard.kt @@ -102,10 +102,8 @@ private fun TransactionCardData( horizontalAlignment = Alignment.Start, ) { Header( - balance = stringResourceSafe( - R.string.common_balance, - cardState.balance, - ).orMaskWithStars(cardState.isBalanceHidden), + balance = cardState.balance, + isBalanceHidden = cardState.isBalanceHidden, type = cardState.type, ) @@ -276,7 +274,12 @@ private fun TransactionCardLoading(modifier: Modifier = Modifier) { } @Composable -private fun Header(type: TransactionCardType, balance: String, modifier: Modifier = Modifier) { +private fun Header( + type: TransactionCardType, + balance: TextReference, + isBalanceHidden: Boolean, + modifier: Modifier = Modifier, +) { Column( modifier = modifier .fillMaxWidth() @@ -298,13 +301,13 @@ private fun Header(type: TransactionCardType, balance: String, modifier: Modifie textColor = titleColor, ) SpacerW16() - if (balance.isNotBlank()) { + if (balance != TextReference.EMPTY) { AnimatedContent( targetState = balance, label = "", ) { balanceText -> Text( - text = balanceText, + text = balanceText.resolveReference().orMaskWithStars(isBalanceHidden), color = TangemTheme.colors.text.tertiary, style = TangemTheme.typography.body2, modifier = Modifier.testTag(SwapTokenScreenTestTags.BALANCE), diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/TransactionCardSimple.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/TransactionCardSimple.kt index a807f078a3..7e57acc625 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/TransactionCardSimple.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/TransactionCardSimple.kt @@ -35,10 +35,7 @@ import com.tangem.core.ui.components.TextShimmer import com.tangem.core.ui.components.buttons.SecondarySmallButton import com.tangem.core.ui.components.buttons.SmallButtonConfig import com.tangem.core.ui.components.buttons.common.TangemButtonIconPosition -import com.tangem.core.ui.extensions.orMaskWithStars -import com.tangem.core.ui.extensions.resolveAnnotatedReference -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.core.ui.extensions.stringResourceSafe +import com.tangem.core.ui.extensions.* import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.test.SwapTokenScreenTestTags @@ -96,10 +93,8 @@ private fun SimpleTransactionCardData( horizontalAlignment = Alignment.Start, ) { SimpleHeader( - balance = stringResourceSafe( - R.string.common_balance, - cardState.balance, - ).orMaskWithStars(cardState.isBalanceHidden), + balance = cardState.balance, + isBalanceHidden = cardState.isBalanceHidden, type = cardState.type, ) @@ -264,7 +259,12 @@ private fun SimpleTransactionCardLoading(modifier: Modifier = Modifier) { } @Composable -private fun SimpleHeader(type: TransactionCardType, balance: String, modifier: Modifier = Modifier) { +private fun SimpleHeader( + type: TransactionCardType, + balance: TextReference, + isBalanceHidden: Boolean, + modifier: Modifier = Modifier, +) { Column( modifier = modifier .fillMaxWidth() @@ -286,10 +286,10 @@ private fun SimpleHeader(type: TransactionCardType, balance: String, modifier: M textColor = titleColor, ) SpacerW16() - if (balance.isNotBlank()) { + if (balance != TextReference.EMPTY) { AnimatedContent(targetState = balance, label = "") { balanceText -> Text( - text = balanceText, + text = balanceText.resolveReference().orMaskWithStars(isBalanceHidden), color = TangemTheme.colors.text.tertiary, style = TangemTheme.typography.body2, modifier = Modifier.testTag(SwapTokenScreenTestTags.BALANCE), diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/preview/SwapTransactionCardPreview.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/preview/SwapTransactionCardPreview.kt index c64731f361..8e35541acd 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/preview/SwapTransactionCardPreview.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/preview/SwapTransactionCardPreview.kt @@ -30,7 +30,7 @@ internal object SwapTransactionCardPreview { amountEquivalent = stringReference("1 000 000"), currencyIconState = CurrencyIconState.Loading, tokenSymbol = stringReference("DAI"), - balance = "123123123.123123", + balance = stringReference("Balance: 123123123.123123 DAI"), isBalanceHidden = false, ) @@ -46,7 +46,7 @@ internal object SwapTransactionCardPreview { amountEquivalent = stringReference("1 000 000"), currencyIconState = CurrencyIconState.Loading, tokenSymbol = stringReference("DAI"), - balance = "33333", + balance = stringReference("Balance: 33333 DAI"), isBalanceHidden = false, ) diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/transfer/SwapTransferStateBuilder.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/transfer/SwapTransferStateBuilder.kt index e9cd7a543b..97897c45c4 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/transfer/SwapTransferStateBuilder.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/transfer/SwapTransferStateBuilder.kt @@ -31,7 +31,6 @@ import com.tangem.feature.swap.models.states.SwapNotificationUM import com.tangem.feature.swap.presentation.R import com.tangem.features.send.v2.api.utils.formatFooterFiatFee import com.tangem.features.send.v2.api.utils.getTronTokenFeeSendingText -import com.tangem.utils.StringsSigns.DASH_SIGN import kotlinx.collections.immutable.ImmutableList import java.math.BigDecimal import javax.inject.Inject @@ -198,9 +197,11 @@ internal class SwapTransferStateBuilder @Inject constructor( ) } - private fun CryptoCurrencyStatus.getFormattedAmount(): String { - val amount = this.value.amount ?: return DASH_SIGN - return amount.format { crypto(symbol = "", decimals = currency.decimals) } + private fun CryptoCurrencyStatus.getFormattedAmount(): TextReference { + return resourceReference( + R.string.common_balance, + wrappedList(value.amount.format { crypto(currency.symbol, currency.decimals) }), + ) } private fun Account.toIconUM(): AccountIconUM { diff --git a/features/swap/impl/src/test/java/com/tangem/feature/swap/ui/transfer/SwapTransferStateBuilderTest.kt b/features/swap/impl/src/test/java/com/tangem/feature/swap/ui/transfer/SwapTransferStateBuilderTest.kt index f9187e54f5..63e58ce5cf 100644 --- a/features/swap/impl/src/test/java/com/tangem/feature/swap/ui/transfer/SwapTransferStateBuilderTest.kt +++ b/features/swap/impl/src/test/java/com/tangem/feature/swap/ui/transfer/SwapTransferStateBuilderTest.kt @@ -592,7 +592,7 @@ internal class SwapTransferStateBuilderTest { tokenSymbol = stringReference(""), amountEquivalent = TextReference.EMPTY, amountTextFieldValue = initialAmountTextFieldValue, - balance = "", + balance = TextReference.EMPTY, isBalanceHidden = false, ), receiveCardData = SwapCardState.Loading(