Updated on 2026-08-14

This commit is contained in:
Tangem 2023-01-27 13:47:40 +03:00
parent 2dcee55f99
commit 990c07d716
6 changed files with 66 additions and 28 deletions

View file

@ -68,7 +68,7 @@ fun BigDecimal.toFormattedFiatValue(
): String {
val fiatValue = this.setScale(2, RoundingMode.HALF_UP)
.let { if (formatWithSpaces) it.formatWithSpaces() else it }
return "${fiatValue} $fiatCurrencyName"
return "$fiatValue$fiatCurrencyName"
}
fun BigDecimal.stripZeroPlainString(): String = this.stripTrailingZeros().toPlainString()

View file

@ -9,6 +9,7 @@ import com.tangem.tap.features.walletSelector.redux.WalletSelectorState
import com.tangem.tap.features.walletSelector.ui.model.MultiCurrencyUserWalletItem
import com.tangem.tap.features.walletSelector.ui.model.SingleCurrencyUserWalletItem
import com.tangem.tap.features.walletSelector.ui.model.UserWalletItem
import java.math.BigDecimal
internal fun WalletSelectorScreenState.updateWithNewState(
newState: WalletSelectorState,
@ -50,10 +51,14 @@ private fun List<UserWalletModel>.toUiModels(
): Sequence<UserWalletItem> {
return this.asSequence().map { userWalletModel ->
with(userWalletModel) {
val balance = UserWalletItem.Balance(
amount = fiatBalance.amount.toFormattedFiatValue(appCurrency.symbol),
isLoading = fiatBalance is TotalFiatBalance.Loading,
)
val formatAmount = { amount: BigDecimal ->
amount.toFormattedFiatValue(appCurrency.symbol)
}
val balance = when (fiatBalance) {
is TotalFiatBalance.Error -> UserWalletItem.Balance.Error(formatAmount(fiatBalance.amount))
is TotalFiatBalance.Loaded -> UserWalletItem.Balance.Loaded(formatAmount(fiatBalance.amount))
is TotalFiatBalance.Loading -> UserWalletItem.Balance.Loading
}
when (type) {
is UserWalletModel.Type.MultiCurrency -> MultiCurrencyUserWalletItem(
id = id,

View file

@ -9,9 +9,8 @@ import com.tangem.tap.features.walletSelector.ui.model.UserWalletItem
internal object MockData {
private val multiCurrencyUserWallet = MultiCurrencyUserWalletItem(
id = UserWalletId("wallet_1"),
balance = UserWalletItem.Balance(
balance = UserWalletItem.Balance.Loaded(
amount = "6781.05 $",
isLoading = false,
),
name = "Wallet",
imageUrl = "https://app.tangem.com/cards/card_default.png",
@ -22,9 +21,8 @@ internal object MockData {
private val singleCurrencyUserWallet = SingleCurrencyUserWalletItem(
id = UserWalletId("wallet_4"),
balance = UserWalletItem.Balance(
balance = UserWalletItem.Balance.Loaded(
amount = "6781.05 $",
isLoading = false,
),
name = "Wallet",
imageUrl = "https://app.tangem.com/cards/card_default.png",

View file

@ -180,15 +180,24 @@ private fun TokensInfo(
if (isLocked) {
LockedPlaceholder()
} else {
if (balance.isLoading) {
LoadingTokensInfo(
isMultiCurrencyWallet = tokensCount != null,
)
} else {
LoadedTokensInfo(
balanceAmount = balance.amount,
tokensCount = tokensCount,
)
when (balance) {
is UserWalletItem.Balance.Error -> {
LoadedTokensInfo(
balanceAmount = balance.amount,
tokensCount = tokensCount,
showWarning = true,
)
}
is UserWalletItem.Balance.Loaded -> {
LoadedTokensInfo(
balanceAmount = balance.amount,
tokensCount = tokensCount,
showWarning = false,
)
}
is UserWalletItem.Balance.Loading -> {
LoadingTokensInfo(isMultiCurrencyWallet = tokensCount != null)
}
}
}
}
@ -234,17 +243,31 @@ private fun LoadedTokensInfo(
modifier: Modifier = Modifier,
balanceAmount: String,
tokensCount: Int?,
showWarning: Boolean,
) {
Column(
modifier = modifier,
horizontalAlignment = Alignment.End,
) {
Text(
text = balanceAmount,
style = TangemTheme.typography.subtitle1,
color = TangemTheme.colors.text.primary1,
textAlign = TextAlign.End,
)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4),
) {
Text(
text = balanceAmount,
style = TangemTheme.typography.subtitle1,
color = TangemTheme.colors.text.primary1,
textAlign = TextAlign.End,
)
if (showWarning) {
Icon(
modifier = Modifier.size(TangemTheme.dimens.size16),
painter = painterResource(id = R.drawable.ic_alert_24),
tint = TangemTheme.colors.icon.attention,
contentDescription = null,
)
}
}
if (tokensCount != null) {
SpacerH2()
Text(

View file

@ -9,10 +9,13 @@ internal sealed interface UserWalletItem {
val balance: Balance
val isLocked: Boolean
data class Balance(
val amount: String,
val isLoading: Boolean,
)
sealed interface Balance {
object Loading : Balance
data class Error(val amount: String) : Balance
data class Loaded(val amount: String) : Balance
}
}
internal data class MultiCurrencyUserWalletItem(