diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt index 9456466cb9..c22554ba8d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt @@ -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 diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt index b5d6b52d47..2002ca9fc9 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt @@ -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 diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt index 8edccf6a0f..b1d0bb3853 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt @@ -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, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt index 51a78e138e..df44339b4d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt @@ -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, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletCard.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletCard.kt index f0348827c3..fb0002479c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletCard.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletCard.kt @@ -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( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CryptoCurrencyStatusToTokenItemConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CryptoCurrencyStatusToTokenItemConverter.kt index 89ce3ee6b1..c23c0cefa7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CryptoCurrencyStatusToTokenItemConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CryptoCurrencyStatusToTokenItemConverter.kt @@ -17,24 +17,31 @@ internal class CryptoCurrencyStatusToTokenItemConverter( private val clickIntents: WalletClickIntents, ) : Converter { - 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, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt index bca1082c42..6be00960a7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt @@ -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 { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/LoadingItemsProvider.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/LoadingItemsProvider.kt deleted file mode 100644 index c7e545dec3..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/LoadingItemsProvider.kt +++ /dev/null @@ -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 { - val items = mutableListOf() - repeat(times = 5) { - items.add( - WalletTokensListState.TokensListItemState.Token( - state = TokenItemState.Loading(id = "Loading#$it"), - ), - ) - } - return items.toImmutableList() - } -} \ No newline at end of file