Updated on 2026-08-14
This commit is contained in:
parent
d92c319583
commit
71e8f40909
21 changed files with 734 additions and 422 deletions
|
|
@ -0,0 +1,85 @@
|
|||
package com.tangem.common.ui.account
|
||||
|
||||
import com.tangem.common.ui.R
|
||||
import com.tangem.common.ui.userwallet.state.UserWalletItemUM
|
||||
import com.tangem.core.ui.extensions.pluralReference
|
||||
import com.tangem.core.ui.extensions.wrappedList
|
||||
import com.tangem.core.ui.format.bigdecimal.fiat
|
||||
import com.tangem.core.ui.format.bigdecimal.format
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.models.StatusSource
|
||||
import com.tangem.domain.models.TotalFiatBalance
|
||||
import com.tangem.domain.models.account.Account
|
||||
import com.tangem.domain.models.account.AccountId
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
||||
class AccountPortfolioItemUMConverter(
|
||||
private val onClick: (AccountId) -> Unit,
|
||||
private val appCurrency: AppCurrency? = null,
|
||||
private val accountBalance: TotalFiatBalance? = null,
|
||||
private val isBalanceHidden: Boolean = false,
|
||||
private val endIcon: UserWalletItemUM.EndIcon = UserWalletItemUM.EndIcon.None,
|
||||
) : Converter<Account, UserWalletItemUM> {
|
||||
|
||||
override fun convert(value: Account): UserWalletItemUM {
|
||||
return with(value) {
|
||||
UserWalletItemUM(
|
||||
id = UserWalletId(value.accountId.value),
|
||||
name = value.accountName.toUM().value,
|
||||
information = getInfo(value),
|
||||
balance = getBalanceInfo(),
|
||||
isEnabled = true,
|
||||
endIcon = endIcon,
|
||||
onClick = { onClick(value.accountId) },
|
||||
imageState = getImageState(value),
|
||||
label = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getInfo(account: Account): UserWalletItemUM.Information.Loaded = when (account) {
|
||||
is Account.CryptoPortfolio -> {
|
||||
val text = pluralReference(
|
||||
R.plurals.common_tokens_count,
|
||||
count = account.tokensCount,
|
||||
formatArgs = wrappedList(account.tokensCount),
|
||||
)
|
||||
UserWalletItemUM.Information.Loaded(text)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getImageState(account: Account) = when (account) {
|
||||
is Account.CryptoPortfolio -> UserWalletItemUM.ImageState.Account(
|
||||
name = account.accountName.toUM().value,
|
||||
icon = account.icon.toUM(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun getBalanceInfo(): UserWalletItemUM.Balance {
|
||||
return when {
|
||||
isBalanceHidden -> UserWalletItemUM.Balance.Hidden
|
||||
accountBalance == null -> UserWalletItemUM.Balance.Loading
|
||||
else -> {
|
||||
when (accountBalance) {
|
||||
is TotalFiatBalance.Loading -> UserWalletItemUM.Balance.Loading
|
||||
is TotalFiatBalance.Failed -> UserWalletItemUM.Balance.Failed
|
||||
is TotalFiatBalance.Loaded -> {
|
||||
if (appCurrency != null) {
|
||||
val formattedAmount = accountBalance.amount.format {
|
||||
fiat(appCurrency.code, appCurrency.symbol)
|
||||
}
|
||||
|
||||
UserWalletItemUM.Balance.Loaded(
|
||||
value = formattedAmount,
|
||||
isFlickering = accountBalance.source == StatusSource.CACHE,
|
||||
)
|
||||
} else {
|
||||
UserWalletItemUM.Balance.Failed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,9 +28,12 @@ import androidx.compose.ui.unit.dp
|
|||
import coil.compose.SubcomposeAsyncImage
|
||||
import coil.request.ImageRequest
|
||||
import com.tangem.common.ui.R
|
||||
import com.tangem.common.ui.account.AccountIcon
|
||||
import com.tangem.common.ui.account.AccountIconPreviewData
|
||||
import com.tangem.common.ui.userwallet.state.UserWalletItemUM
|
||||
import com.tangem.core.ui.components.RectangleShimmer
|
||||
import com.tangem.core.ui.components.TextShimmer
|
||||
import com.tangem.core.ui.components.account.AccountIconSize
|
||||
import com.tangem.core.ui.components.block.BlockCard
|
||||
import com.tangem.core.ui.components.block.TangemBlockCardColors
|
||||
import com.tangem.core.ui.components.label.Label
|
||||
|
|
@ -198,7 +201,7 @@ private fun BalanceContent(balance: UserWalletItemUM.Balance, modifier: Modifier
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
@Suppress("MagicNumber", "LongMethod")
|
||||
@Composable
|
||||
fun CardImage(imageState: UserWalletItemUM.ImageState, modifier: Modifier = Modifier) {
|
||||
val imageModifier = modifier
|
||||
|
|
@ -264,6 +267,11 @@ fun CardImage(imageState: UserWalletItemUM.ImageState, modifier: Modifier = Modi
|
|||
)
|
||||
}
|
||||
}
|
||||
is UserWalletItemUM.ImageState.Account -> AccountIcon(
|
||||
name = imageState.name,
|
||||
icon = imageState.icon,
|
||||
size = AccountIconSize.Default,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -426,6 +434,18 @@ private class UserWalletItemUMPreviewProvider : PreviewParameterProvider<UserWal
|
|||
isEnabled = true,
|
||||
onClick = {},
|
||||
),
|
||||
UserWalletItemUM(
|
||||
id = UserWalletId("user_wallet_4".encodeToByteArray()),
|
||||
name = stringReference("Main account"),
|
||||
information = getInformation(cardCount = 3),
|
||||
balance = UserWalletItemUM.Balance.NotShowing,
|
||||
imageState = UserWalletItemUM.ImageState.Account(
|
||||
name = stringReference("Main account"),
|
||||
icon = AccountIconPreviewData.randomAccountIcon(),
|
||||
),
|
||||
isEnabled = true,
|
||||
onClick = {},
|
||||
),
|
||||
)
|
||||
|
||||
private fun getInformation(cardCount: Int): UserWalletItemUM.Information.Loaded {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.common.ui.userwallet.state
|
||||
|
||||
import com.tangem.common.ui.account.CryptoPortfolioIconUM
|
||||
import com.tangem.core.ui.components.artwork.ArtworkUM
|
||||
import com.tangem.core.ui.components.label.entity.LabelUM
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
|
|
@ -60,6 +61,11 @@ data class UserWalletItemUM(
|
|||
|
||||
data object MobileWallet : ImageState()
|
||||
|
||||
data class Account(
|
||||
val name: TextReference,
|
||||
val icon: CryptoPortfolioIconUM,
|
||||
) : ImageState()
|
||||
|
||||
data class Image(
|
||||
val artwork: ArtworkUM,
|
||||
) : ImageState()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue