Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-10 20:50:15 +05:00
parent c933d44932
commit f8a9cac801
7 changed files with 44 additions and 38 deletions

View file

@ -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()

View file

@ -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 {

View file

@ -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),

View file

@ -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),

View file

@ -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,
)

View file

@ -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 {

View file

@ -592,7 +592,7 @@ internal class SwapTransferStateBuilderTest {
tokenSymbol = stringReference(""),
amountEquivalent = TextReference.EMPTY,
amountTextFieldValue = initialAmountTextFieldValue,
balance = "",
balance = TextReference.EMPTY,
isBalanceHidden = false,
),
receiveCardData = SwapCardState.Loading(