Updated on 2026-08-14
This commit is contained in:
parent
965a6f8e46
commit
a78432b9f6
8 changed files with 35 additions and 45 deletions
|
|
@ -207,7 +207,13 @@ internal object WalletPreviewData {
|
|||
)
|
||||
}
|
||||
|
||||
val loadingTokenItemState by lazy { TokenItemState.Loading(id = "Loading#1") }
|
||||
val loadingTokenItemState by lazy {
|
||||
TokenItemState.Loading(
|
||||
id = "Loading#1",
|
||||
iconState = customTokenIconState.copy(isGrayscale = true),
|
||||
titleState = TokenItemState.TitleState.Content(text = "Polygon"),
|
||||
)
|
||||
}
|
||||
|
||||
private const val networksSize = 10
|
||||
private const val tokensSize = 3
|
||||
|
|
|
|||
|
|
@ -22,9 +22,11 @@ internal sealed class TokenItemState {
|
|||
abstract val priceChangeState: PriceChangeState?
|
||||
|
||||
/** Loading token state */
|
||||
data class Loading(override val id: String) : TokenItemState() {
|
||||
override val iconState: IconState = IconState.Loading
|
||||
override val titleState: TitleState = TitleState.Loading
|
||||
data class Loading(
|
||||
override val id: String,
|
||||
override val iconState: IconState,
|
||||
override val titleState: TitleState.Content,
|
||||
) : TokenItemState() {
|
||||
override val fiatAmountState: FiatAmountState = FiatAmountState.Loading
|
||||
override val cryptoAmountState: CryptoAmountState = CryptoAmountState.Loading
|
||||
override val priceChangeState: PriceChangeState = PriceChangeState.Loading
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ internal sealed interface WalletCardState {
|
|||
/** Title */
|
||||
val title: String
|
||||
|
||||
val additionalInfo: TextReference?
|
||||
|
||||
/** Wallet image resource id */
|
||||
@get:DrawableRes
|
||||
val imageResId: Int?
|
||||
|
|
@ -41,10 +43,10 @@ internal sealed interface WalletCardState {
|
|||
data class Content(
|
||||
override val id: UserWalletId,
|
||||
override val title: String,
|
||||
override val additionalInfo: TextReference,
|
||||
override val imageResId: Int?,
|
||||
override val onRenameClick: (UserWalletId, String) -> Unit,
|
||||
override val onDeleteClick: (UserWalletId) -> Unit,
|
||||
val additionalInfo: TextReference,
|
||||
val cardCount: Int?,
|
||||
val balance: String,
|
||||
) : WalletCardState
|
||||
|
|
@ -64,10 +66,10 @@ internal sealed interface WalletCardState {
|
|||
data class HiddenContent(
|
||||
override val id: UserWalletId,
|
||||
override val title: String,
|
||||
override val additionalInfo: TextReference,
|
||||
override val imageResId: Int?,
|
||||
override val onRenameClick: (UserWalletId, String) -> Unit,
|
||||
override val onDeleteClick: (UserWalletId) -> Unit,
|
||||
val additionalInfo: TextReference,
|
||||
val balance: String,
|
||||
val cardCount: Int?,
|
||||
) : WalletCardState
|
||||
|
|
@ -77,18 +79,18 @@ internal sealed interface WalletCardState {
|
|||
*
|
||||
* @property id wallet id
|
||||
* @property title wallet name
|
||||
* @property additionalInfo wallet additional info
|
||||
* @property imageResId wallet image resource id
|
||||
* @property onRenameClick lambda be invoked when Rename button is clicked
|
||||
* @property onDeleteClick lambda be invoked when Delete button is clicked
|
||||
* @property additionalInfo wallet additional info
|
||||
*/
|
||||
data class LockedContent(
|
||||
override val id: UserWalletId,
|
||||
override val title: String,
|
||||
override val additionalInfo: TextReference,
|
||||
override val imageResId: Int?,
|
||||
override val onRenameClick: (UserWalletId, String) -> Unit,
|
||||
override val onDeleteClick: (UserWalletId) -> Unit,
|
||||
val additionalInfo: TextReference,
|
||||
) : WalletCardState
|
||||
|
||||
/**
|
||||
|
|
@ -106,7 +108,9 @@ internal sealed interface WalletCardState {
|
|||
override val imageResId: Int?,
|
||||
override val onRenameClick: (UserWalletId, String) -> Unit,
|
||||
override val onDeleteClick: (UserWalletId) -> Unit,
|
||||
) : WalletCardState
|
||||
) : WalletCardState {
|
||||
override val additionalInfo: TextReference = EMPTY_BALANCE_TEXT
|
||||
}
|
||||
|
||||
/**
|
||||
* Wallet card loading state
|
||||
|
|
@ -120,6 +124,7 @@ internal sealed interface WalletCardState {
|
|||
data class Loading(
|
||||
override val id: UserWalletId,
|
||||
override val title: String,
|
||||
override val additionalInfo: TextReference? = null,
|
||||
override val imageResId: Int?,
|
||||
override val onRenameClick: (UserWalletId, String) -> Unit,
|
||||
override val onDeleteClick: (UserWalletId) -> Unit,
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ internal class WalletSkeletonStateConverter(
|
|||
return WalletCardState.Loading(
|
||||
id = walletId,
|
||||
title = name,
|
||||
additionalInfo = if (isMultiCurrency) WalletAdditionalInfoFactory.resolve(wallet = this) else null,
|
||||
imageResId = createImageResId(),
|
||||
onRenameClick = clickIntents::onRenameClick,
|
||||
onDeleteClick = clickIntents::onDeleteClick,
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ internal fun WalletCard(state: WalletCardState, modifier: Modifier = Modifier) {
|
|||
)
|
||||
|
||||
AdditionalInfo(
|
||||
text = resolveAdditionalTextByState(state),
|
||||
text = state.additionalInfo,
|
||||
modifier = Modifier.constrainAs(additionalTextRef) {
|
||||
start.linkTo(parent.start)
|
||||
top.linkTo(balanceRef.bottom)
|
||||
|
|
@ -344,16 +344,6 @@ private fun AdditionalInfo(text: TextReference?, modifier: Modifier = Modifier)
|
|||
}
|
||||
}
|
||||
|
||||
private fun resolveAdditionalTextByState(state: WalletCardState): TextReference? {
|
||||
return when (state) {
|
||||
is WalletCardState.Content -> state.additionalInfo
|
||||
is WalletCardState.LockedContent -> state.additionalInfo
|
||||
is WalletCardState.Error -> WalletCardState.EMPTY_BALANCE_TEXT
|
||||
is WalletCardState.HiddenContent -> WalletCardState.HIDDEN_BALANCE_TEXT
|
||||
is WalletCardState.Loading -> null
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AdditionalInfoText(text: TextReference) {
|
||||
Text(
|
||||
|
|
|
|||
|
|
@ -17,24 +17,31 @@ internal class CryptoCurrencyStatusToTokenItemConverter(
|
|||
private val clickIntents: WalletClickIntents,
|
||||
) : Converter<CryptoCurrencyStatus, TokenItemState> {
|
||||
|
||||
private val iconStateConverter = CryptoCurrencyToIconStateConverter()
|
||||
private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter)
|
||||
|
||||
override fun convert(value: CryptoCurrencyStatus): TokenItemState {
|
||||
return when (value.value) {
|
||||
is CryptoCurrencyStatus.Loading -> TokenItemState.Loading(id = value.currency.id.value)
|
||||
is CryptoCurrencyStatus.Loading -> value.mapToLoadingState()
|
||||
is CryptoCurrencyStatus.Loaded,
|
||||
is CryptoCurrencyStatus.Custom,
|
||||
is CryptoCurrencyStatus.NoQuote,
|
||||
is CryptoCurrencyStatus.NoAccount,
|
||||
-> value.mapToTokenItemState()
|
||||
is CryptoCurrencyStatus.MissedDerivation -> value.mapToNoAddressTokenItemState()
|
||||
// TODO: Add other token item states, currently not designed
|
||||
is CryptoCurrencyStatus.Unreachable,
|
||||
is CryptoCurrencyStatus.NoAmount,
|
||||
-> value.mapToUnreachableTokenItemState()
|
||||
}
|
||||
}
|
||||
|
||||
private fun CryptoCurrencyStatus.mapToLoadingState(): TokenItemState.Loading {
|
||||
return TokenItemState.Loading(
|
||||
id = currency.id.value,
|
||||
iconState = iconStateConverter.convert(value = this),
|
||||
titleState = TokenItemState.TitleState.Content(text = currency.name),
|
||||
)
|
||||
}
|
||||
|
||||
private fun CryptoCurrencyStatus.mapToTokenItemState(): TokenItemState.Content {
|
||||
return TokenItemState.Content(
|
||||
id = currency.id.value,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ internal class FiatBalanceToWalletCardConverter(
|
|||
}
|
||||
|
||||
private fun WalletCardState.toLoadingWalletCardState(): WalletCardState {
|
||||
return WalletCardState.Loading(id, title, imageResId, onRenameClick, onDeleteClick)
|
||||
return WalletCardState.Loading(id, title, additionalInfo, imageResId, onRenameClick, onDeleteClick)
|
||||
}
|
||||
|
||||
private fun WalletCardState.toErrorWalletCardState(): WalletCardState {
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.utils
|
||||
|
||||
import com.tangem.feature.wallet.presentation.common.state.TokenItemState
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
internal object LoadingItemsProvider {
|
||||
|
||||
fun getLoadingMultiCurrencyTokens(): ImmutableList<WalletTokensListState.TokensListItemState.Token> {
|
||||
val items = mutableListOf<WalletTokensListState.TokensListItemState.Token>()
|
||||
repeat(times = 5) {
|
||||
items.add(
|
||||
WalletTokensListState.TokensListItemState.Token(
|
||||
state = TokenItemState.Loading(id = "Loading#$it"),
|
||||
),
|
||||
)
|
||||
}
|
||||
return items.toImmutableList()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue