From dd186d6fbcc455db635c0d36886c61e64ccd426b Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 8 Aug 2023 12:56:20 +0800 Subject: [PATCH] Updated on 2026-08-14 --- .../presentation/common/WalletPreviewData.kt | 7 +- .../wallet/state/WalletLoading.kt | 37 +++ .../wallet/state/WalletLockedState.kt | 24 ++ .../wallet/state/WalletMultiCurrencyState.kt | 54 ++++ .../wallet/state/WalletSingleCurrencyState.kt | 68 +++++ .../wallet/state/WalletStateHolder.kt | 247 ++++++------------ .../WalletBottomSheetConfig.kt | 2 +- .../state/{ => components}/WalletCardState.kt | 2 +- .../WalletLockedContentState.kt | 2 +- .../{ => components}/WalletManageButton.kt | 2 +- .../{ => components}/WalletNotification.kt | 2 +- .../WalletPullToRefreshConfig.kt | 2 +- .../WalletTokensListState.kt | 2 +- .../{ => components}/WalletTopBarConfig.kt | 2 +- .../WalletTxHistoryState.kt | 2 +- .../{ => components}/WalletsListConfig.kt | 2 +- .../WalletLoadedTokensListConverter.kt | 2 + .../factory/WalletSkeletonStateConverter.kt | 81 ++++-- .../state/factory/WalletStateFactory.kt | 67 ++++- .../WalletLoadedTxHistoryConverter.kt | 9 +- .../WalletLoadingTxHistoryConverter.kt | 9 +- .../WalletTxHistoryItemFlowConverter.kt | 4 +- .../presentation/wallet/ui/WalletScreen.kt | 12 +- .../wallet/ui/components/WalletsList.kt | 2 +- .../ui/components/common/WalletBottomSheet.kt | 2 +- .../wallet/ui/components/common/WalletCard.kt | 2 +- .../ui/components/common/WalletContent.kt | 12 +- .../components/common/WalletNotifications.kt | 2 +- .../ui/components/common/WalletSideEffects.kt | 2 +- .../ui/components/common/WalletTopBar.kt | 2 +- .../multicurrency/MultiCurrencyContent.kt | 2 +- .../multicurrency/MultiCurrencyContentItem.kt | 2 +- .../singlecurrency/SingleCurrencyContent.kt | 2 +- .../SingleCurrencyContentItem.kt | 2 +- .../singlecurrency/TxHistoryGroupTitle.kt | 2 +- .../singlecurrency/TxHistoryTitle.kt | 2 +- .../utils/FiatBalanceToWalletCardConverter.kt | 2 +- .../wallet/utils/LoadingItemsProvider.kt | 2 +- .../TokenListErrorToWalletStateConverter.kt | 5 +- .../utils/TokenListToContentItemsConverter.kt | 4 +- .../utils/TokenListToWalletStateConverter.kt | 16 +- .../wallet/viewmodels/WalletClickIntents.kt | 4 + .../WalletNotificationsListFactory.kt | 7 +- .../wallet/viewmodels/WalletViewModel.kt | 52 +++- 44 files changed, 499 insertions(+), 270 deletions(-) create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLoading.kt create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLockedState.kt create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMultiCurrencyState.kt create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletSingleCurrencyState.kt rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => components}/WalletBottomSheetConfig.kt (98%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => components}/WalletCardState.kt (97%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{content => components}/WalletLockedContentState.kt (73%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => components}/WalletManageButton.kt (96%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => components}/WalletNotification.kt (98%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => components}/WalletPullToRefreshConfig.kt (78%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{content => components}/WalletTokensListState.kt (96%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => components}/WalletTopBarConfig.kt (80%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{content => components}/WalletTxHistoryState.kt (97%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => components}/WalletsListConfig.kt (86%) 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 ba60a1451b..bce4d536e1 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 @@ -12,8 +12,7 @@ import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensListState import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensStateHolder import com.tangem.feature.wallet.presentation.wallet.state.* -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.components.* import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList import kotlinx.coroutines.flow.flowOf @@ -255,7 +254,7 @@ internal object WalletPreviewData { } val multicurrencyWalletScreenState by lazy { - WalletStateHolder.MultiCurrencyContent( + WalletMultiCurrencyState.Content( onBackClick = {}, topBarConfig = walletTopBarConfig, walletsListConfig = walletListConfig, @@ -326,7 +325,7 @@ internal object WalletPreviewData { } val singleWalletScreenState by lazy { - WalletStateHolder.SingleCurrencyContent( + WalletSingleCurrencyState.Content( onBackClick = {}, topBarConfig = walletTopBarConfig, walletsListConfig = walletListConfig, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLoading.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLoading.kt new file mode 100644 index 0000000000..55e211840f --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLoading.kt @@ -0,0 +1,37 @@ +package com.tangem.feature.wallet.presentation.wallet.state + +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.feature.wallet.presentation.wallet.state.components.* +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf + +/** + * Loading wallet state + * + * @property onBackClick Lambda be invoked when back button is clicked + * +[REDACTED_AUTHOR] + */ +internal data class WalletLoading(override val onBackClick: () -> Unit) : WalletStateHolder() { + + override val topBarConfig = WalletTopBarConfig(onScanCardClick = {}, onMoreClick = {}) + + override val walletsListConfig = WalletsListConfig( + selectedWalletIndex = 0, + wallets = persistentListOf( + WalletCardState.Loading( + id = UserWalletId(stringValue = ""), + title = "", + additionalInfo = "", + imageResId = null, + ), + ), + onWalletChange = {}, + ) + + override val pullToRefreshConfig = WalletPullToRefreshConfig(isRefreshing = false, onRefresh = {}) + + override val notifications: ImmutableList = persistentListOf() + + override val bottomSheetConfig = null +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLockedState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLockedState.kt new file mode 100644 index 0000000000..352b0687a2 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLockedState.kt @@ -0,0 +1,24 @@ +package com.tangem.feature.wallet.presentation.wallet.state + +/** + * Locked wallet state + * +[REDACTED_AUTHOR] + */ +internal sealed interface WalletLockedState { + + /** Lambda be invoked when unlock wallet notification is clicked */ + val onUnlockWalletsNotificationClick: () -> Unit + + /** Lambda be invoked when unlock wallet button is clicked */ + val onUnlockClick: () -> Unit + + /** Lambda be invoked when scan button is clicked */ + val onScanClick: () -> Unit + + /** Bottom sheet visibility */ + val isBottomSheetShow: Boolean + + /** Lambda be invoked when bottom sheet is dismissed */ + val onBottomSheetDismiss: () -> Unit +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMultiCurrencyState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMultiCurrencyState.kt new file mode 100644 index 0000000000..0b93c6033d --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMultiCurrencyState.kt @@ -0,0 +1,54 @@ +package com.tangem.feature.wallet.presentation.wallet.state + +import com.tangem.feature.wallet.presentation.wallet.state.components.* +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf + +/** + * Multi currency wallet state + * +[REDACTED_AUTHOR] + */ +internal sealed class WalletMultiCurrencyState : WalletStateHolder() { + + /** Tokens list state */ + abstract val tokensListState: WalletTokensListState + + data class Content( + override val onBackClick: () -> Unit, + override val topBarConfig: WalletTopBarConfig, + override val walletsListConfig: WalletsListConfig, + override val pullToRefreshConfig: WalletPullToRefreshConfig, + override val notifications: ImmutableList, + override val bottomSheetConfig: WalletBottomSheetConfig?, + override val tokensListState: WalletTokensListState, + ) : WalletMultiCurrencyState() + + data class Locked( + override val onBackClick: () -> Unit, + override val topBarConfig: WalletTopBarConfig, + override val walletsListConfig: WalletsListConfig, + override val pullToRefreshConfig: WalletPullToRefreshConfig, + override val onUnlockWalletsNotificationClick: () -> Unit, + override val onUnlockClick: () -> Unit, + override val onScanClick: () -> Unit, + override val isBottomSheetShow: Boolean = false, + override val onBottomSheetDismiss: () -> Unit = {}, + ) : WalletMultiCurrencyState(), WalletLockedState { + + override val notifications = persistentListOf( + WalletNotification.UnlockWallets(onUnlockWalletsNotificationClick), + ) + + override val bottomSheetConfig = WalletBottomSheetConfig( + isShow = isBottomSheetShow, + onDismissRequest = onBottomSheetDismiss, + content = WalletBottomSheetConfig.BottomSheetContentConfig.UnlockWallets( + onUnlockClick = onUnlockClick, + onScanClick = onScanClick, + ), + ) + + override val tokensListState: WalletTokensListState = WalletTokensListState.Locked + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletSingleCurrencyState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletSingleCurrencyState.kt new file mode 100644 index 0000000000..2a01cb5668 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletSingleCurrencyState.kt @@ -0,0 +1,68 @@ +package com.tangem.feature.wallet.presentation.wallet.state + +import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig +import com.tangem.core.ui.components.marketprice.MarketPriceBlockState +import com.tangem.feature.wallet.presentation.wallet.state.components.* +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf + +/** + * Single currency wallet content state + * +[REDACTED_AUTHOR] + */ +internal sealed class WalletSingleCurrencyState : WalletStateHolder() { + + /** Manage buttons */ + abstract val buttons: ImmutableList + + /** Market price block state */ + abstract val marketPriceBlockState: MarketPriceBlockState? + + /** Transactions history state */ + abstract val txHistoryState: WalletTxHistoryState + + data class Content( + override val onBackClick: () -> Unit, + override val topBarConfig: WalletTopBarConfig, + override val walletsListConfig: WalletsListConfig, + override val pullToRefreshConfig: WalletPullToRefreshConfig, + override val notifications: ImmutableList, + override val bottomSheetConfig: WalletBottomSheetConfig?, + override val buttons: ImmutableList, + override val marketPriceBlockState: MarketPriceBlockState, + override val txHistoryState: WalletTxHistoryState, + ) : WalletSingleCurrencyState() + + data class Locked( + override val onBackClick: () -> Unit, + override val topBarConfig: WalletTopBarConfig, + override val walletsListConfig: WalletsListConfig, + override val pullToRefreshConfig: WalletPullToRefreshConfig, + override val buttons: ImmutableList, + override val onUnlockWalletsNotificationClick: () -> Unit, + override val onUnlockClick: () -> Unit, + override val onScanClick: () -> Unit, + override val isBottomSheetShow: Boolean = false, + override val onBottomSheetDismiss: () -> Unit = {}, + val onExploreClick: () -> Unit, + ) : WalletSingleCurrencyState(), WalletLockedState { + + override val notifications = persistentListOf( + WalletNotification.UnlockWallets(onUnlockWalletsNotificationClick), + ) + + override val bottomSheetConfig = WalletBottomSheetConfig( + isShow = isBottomSheetShow, + onDismissRequest = onBottomSheetDismiss, + content = WalletBottomSheetConfig.BottomSheetContentConfig.UnlockWallets( + onUnlockClick = onUnlockClick, + onScanClick = onScanClick, + ), + ) + + override val marketPriceBlockState = null + + override val txHistoryState: WalletTxHistoryState = WalletTxHistoryState.Locked(onExploreClick) + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateHolder.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateHolder.kt index 0967820a37..25338db85c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateHolder.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateHolder.kt @@ -1,33 +1,32 @@ package com.tangem.feature.wallet.presentation.wallet.state -import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig -import com.tangem.core.ui.components.marketprice.MarketPriceBlockState -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletLockedContentState -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.components.* import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.persistentListOf /** * Wallet screen state holder * - * @property onBackClick lambda be invoked when back button is clicked - * @property topBarConfig top bar config - * @property walletsListConfig wallets list config - * @property pullToRefreshConfig pull to refresh config - * @property notifications notifications - * [REDACTED_AUTHOR] */ -internal sealed class WalletStateHolder( - open val onBackClick: () -> Unit, - open val topBarConfig: WalletTopBarConfig, - open val walletsListConfig: WalletsListConfig, - open val pullToRefreshConfig: WalletPullToRefreshConfig, - open val notifications: ImmutableList, - open val bottomSheetConfig: WalletBottomSheetConfig? = null, -) { +internal sealed class WalletStateHolder { + + /** Lambda be invoked when back button is clicked */ + abstract val onBackClick: () -> Unit + + /** Top bar config */ + abstract val topBarConfig: WalletTopBarConfig + + /** Wallets list config */ + abstract val walletsListConfig: WalletsListConfig + + /** Pull to refresh config */ + abstract val pullToRefreshConfig: WalletPullToRefreshConfig + + /** Notifications */ + abstract val notifications: ImmutableList + + /** Bottom sheet config */ + abstract val bottomSheetConfig: WalletBottomSheetConfig? fun copySealed( onBackClick: () -> Unit = this.onBackClick, @@ -38,151 +37,67 @@ internal sealed class WalletStateHolder( bottomSheet: WalletBottomSheetConfig? = this.bottomSheetConfig, ): WalletStateHolder { return when (this) { - is MultiCurrencyContent -> this.copy( - onBackClick = onBackClick, - topBarConfig = topBarConfig, - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - notifications = notifications, - bottomSheetConfig = bottomSheet, - ) - is SingleCurrencyContent -> this.copy( - onBackClick = onBackClick, - topBarConfig = topBarConfig, - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - notifications = notifications, - bottomSheetConfig = bottomSheet, - ) - is UnlockWalletContent -> this.copy( - onBackClick = onBackClick, - topBarConfig = topBarConfig, - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - ) - is Loading -> copy(onBackClick = onBackClick) + is WalletLoading -> { + copy(onBackClick = onBackClick) + } + is WalletMultiCurrencyState.Content -> { + copy( + onBackClick = onBackClick, + topBarConfig = topBarConfig, + walletsListConfig = walletsListConfig, + pullToRefreshConfig = pullToRefreshConfig, + notifications = notifications, + bottomSheetConfig = bottomSheet, + ) + } + is WalletMultiCurrencyState.Locked -> { + if (bottomSheet != null) { + copy( + onBackClick = onBackClick, + topBarConfig = topBarConfig, + walletsListConfig = walletsListConfig, + pullToRefreshConfig = pullToRefreshConfig, + isBottomSheetShow = bottomSheet.isShow, + onBottomSheetDismiss = bottomSheet.onDismissRequest, + ) + } else { + copy( + onBackClick = onBackClick, + topBarConfig = topBarConfig, + walletsListConfig = walletsListConfig, + pullToRefreshConfig = pullToRefreshConfig, + ) + } + } + is WalletSingleCurrencyState.Content -> { + copy( + onBackClick = onBackClick, + topBarConfig = topBarConfig, + walletsListConfig = walletsListConfig, + pullToRefreshConfig = pullToRefreshConfig, + notifications = notifications, + bottomSheetConfig = bottomSheet, + ) + } + is WalletSingleCurrencyState.Locked -> { + if (bottomSheet != null) { + copy( + onBackClick = onBackClick, + topBarConfig = topBarConfig, + walletsListConfig = walletsListConfig, + pullToRefreshConfig = pullToRefreshConfig, + isBottomSheetShow = bottomSheet.isShow, + onBottomSheetDismiss = bottomSheet.onDismissRequest, + ) + } else { + copy( + onBackClick = onBackClick, + topBarConfig = topBarConfig, + walletsListConfig = walletsListConfig, + pullToRefreshConfig = pullToRefreshConfig, + ) + } + } } } - - /** - * Multi currency wallet content state - * - * @property onBackClick lambda be invoked when back button is clicked - * @property topBarConfig top bar config - * @property walletsListConfig wallets list config - * @property pullToRefreshConfig pull to refresh config - * @property tokensListState token list state - * @property notifications notifications - */ - data class MultiCurrencyContent( - override val onBackClick: () -> Unit, - override val topBarConfig: WalletTopBarConfig, - override val walletsListConfig: WalletsListConfig, - override val pullToRefreshConfig: WalletPullToRefreshConfig, - override val notifications: ImmutableList, - override val bottomSheetConfig: WalletBottomSheetConfig? = null, - val tokensListState: WalletTokensListState, - ) : WalletStateHolder( - onBackClick = onBackClick, - topBarConfig = topBarConfig, - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - notifications = notifications, - bottomSheetConfig = bottomSheetConfig, - ) - - /** - * Single currency wallet content state - * - * @property onBackClick lambda be invoked when back button is clicked - * @property topBarConfig top bar config - * @property walletsListConfig wallets list config - * @property pullToRefreshConfig pull to refresh config - * @property notifications notifications - * @property buttons manage buttons - * @property marketPriceBlockState market price block state - * @property txHistoryState transactions history state - */ - data class SingleCurrencyContent( - override val onBackClick: () -> Unit, - override val topBarConfig: WalletTopBarConfig, - override val walletsListConfig: WalletsListConfig, - override val pullToRefreshConfig: WalletPullToRefreshConfig, - override val notifications: ImmutableList, - override val bottomSheetConfig: WalletBottomSheetConfig? = null, - val buttons: ImmutableList, - val marketPriceBlockState: MarketPriceBlockState, - val txHistoryState: WalletTxHistoryState, - ) : WalletStateHolder( - onBackClick = onBackClick, - topBarConfig = topBarConfig, - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - notifications = notifications, - bottomSheetConfig = bottomSheetConfig, - ) - - /** - * Unlock wallet content state - * - * @property onBackClick lambda be invoked when back button is clicked - * @property topBarConfig top bar config - * @property walletsListConfig wallets list config - * @property pullToRefreshConfig pull to refresh config - * @property lockedContentState locked content state - * @property onUnlockWalletsNotificationClick lambda be invoked when unlock wallets notification is clicked - * @property onBottomSheetDismissRequest lambda be invoked when bottom sheet is dismissed - * @property onUnlockClick lambda be invoked when unlock button is clicked - * @property onScanClick lambda be invoked when scan card button is clicked - */ - data class UnlockWalletContent( - override val onBackClick: () -> Unit, - override val topBarConfig: WalletTopBarConfig, - override val walletsListConfig: WalletsListConfig, - override val pullToRefreshConfig: WalletPullToRefreshConfig, - val lockedContentState: WalletLockedContentState, - val onUnlockWalletsNotificationClick: () -> Unit, - val onBottomSheetDismissRequest: () -> Unit, - val onUnlockClick: () -> Unit, - val onScanClick: () -> Unit, - ) : WalletStateHolder( - onBackClick = onBackClick, - topBarConfig = topBarConfig, - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - notifications = persistentListOf(WalletNotification.UnlockWallets(onUnlockWalletsNotificationClick)), - bottomSheetConfig = WalletBottomSheetConfig( - isShow = false, - onDismissRequest = onBottomSheetDismissRequest, - content = WalletBottomSheetConfig.BottomSheetContentConfig.UnlockWallets( - onUnlockClick = onUnlockClick, - onScanClick = onScanClick, - ), - ), - ) - - /** - * Loading state - * - * @property onBackClick lambda be invoked when back button is clicked - */ - data class Loading(override val onBackClick: () -> Unit) : WalletStateHolder( - onBackClick = onBackClick, - topBarConfig = WalletTopBarConfig(onScanCardClick = {}, onMoreClick = {}), - walletsListConfig = WalletsListConfig( - selectedWalletIndex = 0, - wallets = persistentListOf( - WalletCardState.Loading( - id = UserWalletId(stringValue = ""), - title = "", - additionalInfo = "", - imageResId = null, - ), - ), - onWalletChange = {}, - ), - pullToRefreshConfig = WalletPullToRefreshConfig(isRefreshing = false, onRefresh = {}), - notifications = persistentListOf(), - bottomSheetConfig = null, - ) } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletBottomSheetConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletBottomSheetConfig.kt similarity index 98% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletBottomSheetConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletBottomSheetConfig.kt index 5a8f12209b..eef9a95ef0 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletBottomSheetConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletBottomSheetConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.components import androidx.annotation.DrawableRes import androidx.compose.ui.graphics.Color diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletCardState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt similarity index 97% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletCardState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt index b1f88360b1..2da80de62f 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletCardState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.components import androidx.annotation.DrawableRes import androidx.compose.runtime.Immutable diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/content/WalletLockedContentState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletLockedContentState.kt similarity index 73% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/content/WalletLockedContentState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletLockedContentState.kt index 9867aed606..c0a0206ecc 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/content/WalletLockedContentState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletLockedContentState.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.content +package com.tangem.feature.wallet.presentation.wallet.state.components /** * Wallet locked content state. diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletManageButton.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletManageButton.kt similarity index 96% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletManageButton.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletManageButton.kt index cb07819add..61441600c3 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletManageButton.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletManageButton.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.components import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.extensions.TextReference diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletNotification.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt similarity index 98% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletNotification.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt index 842f92ccfe..99a59df14d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletNotification.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.components import com.tangem.core.ui.components.notifications.NotificationState import com.tangem.core.ui.extensions.TextReference diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletPullToRefreshConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletPullToRefreshConfig.kt similarity index 78% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletPullToRefreshConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletPullToRefreshConfig.kt index 8aafa384f0..6714af85cc 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletPullToRefreshConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletPullToRefreshConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.components /** * Wallet screen top bar config diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/content/WalletTokensListState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTokensListState.kt similarity index 96% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/content/WalletTokensListState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTokensListState.kt index 4f7e51d4d3..9fa10a5446 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/content/WalletTokensListState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTokensListState.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.content +package com.tangem.feature.wallet.presentation.wallet.state.components import com.tangem.feature.wallet.presentation.common.state.TokenItemState import kotlinx.collections.immutable.ImmutableList diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletTopBarConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTopBarConfig.kt similarity index 80% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletTopBarConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTopBarConfig.kt index f1838ea250..52e984f940 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletTopBarConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTopBarConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.components /** * Wallet screen top bar config diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/content/WalletTxHistoryState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTxHistoryState.kt similarity index 97% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/content/WalletTxHistoryState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTxHistoryState.kt index 5252fa8981..b09a0410c8 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/content/WalletTxHistoryState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTxHistoryState.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.content +package com.tangem.feature.wallet.presentation.wallet.state.components import androidx.paging.PagingData import com.tangem.core.ui.components.transactions.TransactionState diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletsListConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletsListConfig.kt similarity index 86% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletsListConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletsListConfig.kt index 0349eb57bd..20eac2dec5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletsListConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletsListConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.components import kotlinx.collections.immutable.ImmutableList diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLoadedTokensListConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLoadedTokensListConverter.kt index 293d66e1bc..9ffc95c838 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLoadedTokensListConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLoadedTokensListConverter.kt @@ -24,12 +24,14 @@ import com.tangem.utils.converter.Converter internal class WalletLoadedTokensListConverter( private val currentStateProvider: Provider, cardTypeResolverProvider: Provider, + isLockedWalletProvider: Provider, clickIntents: WalletClickIntents, ) : Converter { private val tokenListStateConverter = TokenListToWalletStateConverter( currentStateProvider = currentStateProvider, cardTypeResolverProvider = cardTypeResolverProvider, + isLockedWalletProvider = isLockedWalletProvider, isWalletContentHidden = false, // TODO: [REDACTED_JIRA] fiatCurrencyCode = "USD", // TODO: [REDACTED_JIRA] fiatCurrencySymbol = "$", // TODO: [REDACTED_JIRA] 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 f1fa529bb3..cd97249197 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 @@ -1,18 +1,21 @@ package com.tangem.feature.wallet.presentation.wallet.state.factory import androidx.paging.PagingData +import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.common.WalletPreviewData import com.tangem.feature.wallet.presentation.wallet.domain.WalletAdditionalInfoFactory import com.tangem.feature.wallet.presentation.wallet.domain.WalletImageResolver -import com.tangem.feature.wallet.presentation.wallet.state.* -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState +import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder +import com.tangem.feature.wallet.presentation.wallet.state.components.* +import com.tangem.feature.wallet.presentation.wallet.state.factory.WalletSkeletonStateConverter.SkeletonModel import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents import com.tangem.utils.converter.Converter +import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.flow @@ -26,45 +29,59 @@ import kotlinx.coroutines.flow.flow */ internal class WalletSkeletonStateConverter( private val clickIntents: WalletClickIntents, -) : Converter, WalletStateHolder> { +) : Converter { - override fun convert(value: List): WalletStateHolder { - val cardTypeResolver = requireNotNull(value.firstOrNull()).scanResponse.cardTypesResolver + override fun convert(value: SkeletonModel): WalletStateHolder { + val wallet = requireNotNull(value.wallets.getOrNull(value.selectedWalletIndex)) { "Empty wallet list" } + val cardTypeResolver = wallet.scanResponse.cardTypesResolver - return if (cardTypeResolver.isMultiwalletAllowed()) { - createMultiCurrencyState(value) - } else { - createSingleCurrencyState(value, cardTypeResolver) + return when { + cardTypeResolver.isMultiwalletAllowed() -> createMultiCurrencyState(value) + !cardTypeResolver.isMultiwalletAllowed() -> createSingleCurrencyState(value, cardTypeResolver) + else -> error("Illegal wallet state: $wallet") } } - private fun createMultiCurrencyState(wallets: List): WalletStateHolder.MultiCurrencyContent { - return WalletStateHolder.MultiCurrencyContent( + /** + * Create [WalletMultiCurrencyState.Content]. + * Tokens and notifications are updated asynchronously. + * + * @param value converted value + */ + private fun createMultiCurrencyState(value: SkeletonModel): WalletMultiCurrencyState.Content { + return WalletMultiCurrencyState.Content( onBackClick = clickIntents::onBackClick, topBarConfig = createTopBarConfig(), - walletsListConfig = createWalletsListConfig(wallets), + walletsListConfig = createWalletsListConfig(value), pullToRefreshConfig = createPullToRefreshConfig(), tokensListState = WalletTokensListState.Content( items = persistentListOf(), - onOrganizeTokensClick = clickIntents::onOrganizeTokensClick, + onOrganizeTokensClick = null, ), notifications = persistentListOf(), bottomSheetConfig = null, ) } + /** + * Create [WalletSingleCurrencyState.Content]. + * Transactions, notifications and market price are updated asynchronously. + * + * @param value converted value + * @param cardTypeResolver card type resolver + */ private fun createSingleCurrencyState( - wallets: List, + value: SkeletonModel, cardTypeResolver: CardTypesResolver, - ): WalletStateHolder.SingleCurrencyContent { - return WalletStateHolder.SingleCurrencyContent( + ): WalletSingleCurrencyState.Content { + return WalletSingleCurrencyState.Content( onBackClick = clickIntents::onBackClick, topBarConfig = createTopBarConfig(), - walletsListConfig = createWalletsListConfig(wallets), + walletsListConfig = createWalletsListConfig(value), pullToRefreshConfig = createPullToRefreshConfig(), notifications = persistentListOf(), bottomSheetConfig = null, - buttons = WalletPreviewData.singleWalletScreenState.buttons, // TODO: create buttons + buttons = getButtons(), marketPriceBlockState = MarketPriceBlockState.Loading( currencyName = cardTypeResolver.getBlockchain().currency, ), @@ -81,10 +98,10 @@ internal class WalletSkeletonStateConverter( ) } - private fun createWalletsListConfig(wallets: List): WalletsListConfig { + private fun createWalletsListConfig(value: SkeletonModel): WalletsListConfig { return WalletsListConfig( - selectedWalletIndex = 0, - wallets = wallets.map { wallet -> + selectedWalletIndex = value.selectedWalletIndex, + wallets = value.wallets.map { wallet -> val cardTypeResolver = wallet.scanResponse.cardTypesResolver WalletCardState.Loading( id = wallet.walletId, @@ -103,4 +120,22 @@ internal class WalletSkeletonStateConverter( private fun createPullToRefreshConfig(): WalletPullToRefreshConfig { return WalletPullToRefreshConfig(isRefreshing = false, onRefresh = clickIntents::onRefreshSwipe) } + + // TODO: [REDACTED_JIRA] + private fun getButtons(): ImmutableList { + return persistentListOf( + WalletManageButton.Buy(onClick = {}), + WalletManageButton.Send(onClick = {}), + WalletManageButton.Receive(onClick = {}), + WalletManageButton.Exchange(onClick = {}), + WalletManageButton.CopyAddress(onClick = {}), + ) + .map(WalletManageButton::config) + .toImmutableList() + } + + data class SkeletonModel( + val wallets: List, + val selectedWalletIndex: Int, + ) } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt index 9dffe74272..a3bb1b915c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt @@ -3,6 +3,7 @@ package com.tangem.feature.wallet.presentation.wallet.state.factory import androidx.paging.PagingData import arrow.core.Either import com.tangem.common.Provider +import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.model.TokenList @@ -10,26 +11,34 @@ import com.tangem.domain.txhistory.error.TxHistoryListError import com.tangem.domain.txhistory.error.TxHistoryStateError import com.tangem.domain.txhistory.model.TxHistoryItem import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state.WalletBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.WalletLoading +import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState +import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletBottomSheetConfig +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification import com.tangem.feature.wallet.presentation.wallet.state.factory.WalletLoadedTokensListConverter.LoadedTokensListModel import com.tangem.feature.wallet.presentation.wallet.state.factory.txhistory.WalletLoadedTxHistoryConverter import com.tangem.feature.wallet.presentation.wallet.state.factory.txhistory.WalletLoadingTxHistoryConverter import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.Flow /** * Main factory for creating [WalletStateHolder] * * @property currentStateProvider current ui state provider - * @param currentCardTypeResolverProvider current card type resolver + * @property currentCardTypeResolverProvider current card type resolver + * @property isLockedWalletProvider current wallet is locked or not * @property clickIntents screen click intents */ internal class WalletStateFactory( private val currentStateProvider: Provider, - currentCardTypeResolverProvider: Provider, + private val currentCardTypeResolverProvider: Provider, + private val isLockedWalletProvider: Provider, private val clickIntents: WalletClickIntents, ) { @@ -39,6 +48,7 @@ internal class WalletStateFactory( WalletLoadedTokensListConverter( currentStateProvider = currentStateProvider, cardTypeResolverProvider = currentCardTypeResolverProvider, + isLockedWalletProvider = isLockedWalletProvider, clickIntents = clickIntents, ) } @@ -59,9 +69,13 @@ internal class WalletStateFactory( ) } - fun getInitialState(): WalletStateHolder = WalletStateHolder.Loading(onBackClick = clickIntents::onBackClick) + fun getInitialState(): WalletStateHolder = WalletLoading(onBackClick = clickIntents::onBackClick) - fun getSkeletonState(wallets: List): WalletStateHolder = skeletonConverter.convert(wallets) + fun getSkeletonState(wallets: List, index: Int): WalletStateHolder { + return skeletonConverter.convert( + value = WalletSkeletonStateConverter.SkeletonModel(wallets = wallets, selectedWalletIndex = index), + ) + } fun getStateByTokensList( tokenListEither: Either, @@ -111,4 +125,45 @@ internal class WalletStateFactory( ): WalletStateHolder { return loadedTxHistoryConverter.convert(txHistoryEither) } + + fun getLockedState(): WalletStateHolder { + val cardTypeResolver = currentCardTypeResolverProvider() + val state = currentStateProvider() + return if (cardTypeResolver.isMultiwalletAllowed()) { + WalletMultiCurrencyState.Locked( + onBackClick = state.onBackClick, + topBarConfig = state.topBarConfig, + walletsListConfig = state.walletsListConfig, + pullToRefreshConfig = state.pullToRefreshConfig, + onUnlockWalletsNotificationClick = clickIntents::onUnlockWalletNotificationClick, + onUnlockClick = clickIntents::onUnlockWalletClick, + onScanClick = clickIntents::onScanCardClick, + ) + } else { + WalletSingleCurrencyState.Locked( + onBackClick = state.onBackClick, + topBarConfig = state.topBarConfig, + walletsListConfig = state.walletsListConfig, + pullToRefreshConfig = state.pullToRefreshConfig, + buttons = getButtons(), + onUnlockWalletsNotificationClick = clickIntents::onUnlockWalletNotificationClick, + onUnlockClick = clickIntents::onUnlockWalletClick, + onScanClick = clickIntents::onScanCardClick, + onExploreClick = clickIntents::onExploreClick, + ) + } + } + + // TODO: [REDACTED_JIRA] + private fun getButtons(): ImmutableList { + return persistentListOf( + WalletManageButton.Buy(onClick = {}), + WalletManageButton.Send(onClick = {}), + WalletManageButton.Receive(onClick = {}), + WalletManageButton.Exchange(onClick = {}), + WalletManageButton.CopyAddress(onClick = {}), + ) + .map(WalletManageButton::config) + .toImmutableList() + } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt index 7c692c4c53..8f4e728d13 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt @@ -8,9 +8,10 @@ import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.txhistory.error.TxHistoryListError import com.tangem.domain.txhistory.model.TxHistoryItem -import com.tangem.feature.wallet.presentation.wallet.state.WalletManageButton +import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents import com.tangem.utils.converter.Converter import kotlinx.collections.immutable.ImmutableList @@ -62,8 +63,8 @@ internal class WalletLoadedTxHistoryConverter( private fun WalletStateHolder.copySingleCurrencyContent( txHistoryState: WalletTxHistoryState, - ): WalletStateHolder.SingleCurrencyContent { - return WalletStateHolder.SingleCurrencyContent( + ): WalletSingleCurrencyState { + return WalletSingleCurrencyState.Content( onBackClick = onBackClick, topBarConfig = topBarConfig, walletsListConfig = walletsListConfig, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt index ea98634f3c..ffe28ac46d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt @@ -8,9 +8,10 @@ import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.core.ui.components.transactions.TransactionState import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.txhistory.error.TxHistoryStateError -import com.tangem.feature.wallet.presentation.wallet.state.WalletManageButton +import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents import com.tangem.utils.converter.Converter import kotlinx.collections.immutable.ImmutableList @@ -69,8 +70,8 @@ internal class WalletLoadingTxHistoryConverter( private fun WalletStateHolder.copySingleCurrencyContent( txHistoryState: WalletTxHistoryState, - ): WalletStateHolder.SingleCurrencyContent { - return WalletStateHolder.SingleCurrencyContent( + ): WalletSingleCurrencyState { + return WalletSingleCurrencyState.Content( onBackClick = onBackClick, topBarConfig = topBarConfig, walletsListConfig = walletsListConfig, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt index 2fe01c3e0e..7d61b17351 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt @@ -5,8 +5,8 @@ import androidx.paging.* import com.tangem.blockchain.common.Blockchain import com.tangem.core.ui.components.transactions.TransactionState import com.tangem.domain.txhistory.model.TxHistoryItem -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState.TxHistoryItemState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState.TxHistoryItemState import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents import com.tangem.utils.converter.Converter import com.tangem.utils.extensions.isToday diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt index 9ac404298b..cc15ab700c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt @@ -18,8 +18,10 @@ import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameter import androidx.paging.compose.collectAsLazyPagingItems import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.presentation.common.WalletPreviewData +import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState +import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState import com.tangem.feature.wallet.presentation.wallet.ui.components.WalletsList import com.tangem.feature.wallet.presentation.wallet.ui.components.common.* import com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency.organizeButton @@ -57,7 +59,7 @@ internal fun WalletScreen(state: WalletStateHolder) { .padding(paddingValues = scaffoldPaddings) .pullRefresh(pullRefreshState), ) { - val txHistoryItems = if (state is WalletStateHolder.SingleCurrencyContent && + val txHistoryItems = if (state is WalletSingleCurrencyState && state.txHistoryState is WalletTxHistoryState.ContentState ) { (state.txHistoryState as? WalletTxHistoryState.ContentState)?.items?.collectAsLazyPagingItems() @@ -80,7 +82,7 @@ internal fun WalletScreen(state: WalletStateHolder) { WalletsList(config = state.walletsListConfig, lazyListState = walletsListState) } - if (state is WalletStateHolder.SingleCurrencyContent) { + if (state is WalletSingleCurrencyState) { controlButtons( configs = state.buttons, modifier = movableItemModifier.padding(top = betweenItemsPadding), @@ -89,13 +91,13 @@ internal fun WalletScreen(state: WalletStateHolder) { notifications(configs = state.notifications, modifier = itemModifier) - if (state is WalletStateHolder.SingleCurrencyContent) { + if (state is WalletSingleCurrencyState.Content) { marketPriceBlock(state = state.marketPriceBlockState, modifier = itemModifier) } contentItems(state = state, txHistoryItems = txHistoryItems, modifier = movableItemModifier) - if (state is WalletStateHolder.MultiCurrencyContent) { + if (state is WalletMultiCurrencyState) { organizeButton(onClick = state.tokensListState.onOrganizeTokensClick, modifier = itemModifier) } } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/WalletsList.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/WalletsList.kt index 462ca897b1..b2505603a2 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/WalletsList.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/WalletsList.kt @@ -20,7 +20,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.presentation.common.WalletPreviewData -import com.tangem.feature.wallet.presentation.wallet.state.WalletsListConfig +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig import com.tangem.feature.wallet.presentation.wallet.ui.components.common.WalletCard /** diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletBottomSheet.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletBottomSheet.kt index 6081e5c0da..bf78b633da 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletBottomSheet.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletBottomSheet.kt @@ -18,7 +18,7 @@ import com.tangem.core.ui.components.SecondaryButtonIconStart import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.presentation.common.WalletPreviewData -import com.tangem.feature.wallet.presentation.wallet.state.WalletBottomSheetConfig +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletBottomSheetConfig /** * Wallet bottom sheet with detail notification information 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 59be3295fd..fd0498866a 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 @@ -22,7 +22,7 @@ import com.tangem.core.ui.components.ResizableText import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.WalletPreviewData -import com.tangem.feature.wallet.presentation.wallet.state.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState private const val DOTS = "•••" diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletContent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletContent.kt index 798f141c4b..f95107b7e9 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletContent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletContent.kt @@ -3,8 +3,11 @@ package com.tangem.feature.wallet.presentation.wallet.ui.components.common import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.ui.Modifier import androidx.paging.compose.LazyPagingItems +import com.tangem.feature.wallet.presentation.wallet.state.WalletLoading +import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState +import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState import com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency.tokensListItems import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.txHistoryItems @@ -23,10 +26,9 @@ internal fun LazyListScope.contentItems( modifier: Modifier = Modifier, ) { when (state) { - is WalletStateHolder.MultiCurrencyContent -> tokensListItems(state.tokensListState, modifier) - is WalletStateHolder.SingleCurrencyContent -> txHistoryItems(state.txHistoryState, txHistoryItems, modifier) - is WalletStateHolder.Loading, - is WalletStateHolder.UnlockWalletContent, + is WalletMultiCurrencyState -> tokensListItems(state.tokensListState, modifier) + is WalletSingleCurrencyState -> txHistoryItems(state.txHistoryState, txHistoryItems, modifier) + is WalletLoading, -> Unit } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletNotifications.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletNotifications.kt index 67d25518b8..4b2f3cffb7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletNotifications.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletNotifications.kt @@ -4,7 +4,7 @@ import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.items import androidx.compose.ui.Modifier import com.tangem.core.ui.components.notifications.Notification -import com.tangem.feature.wallet.presentation.wallet.state.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification import kotlinx.collections.immutable.ImmutableList /** diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletSideEffects.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletSideEffects.kt index 1467c145b0..0d415eaa74 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletSideEffects.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletSideEffects.kt @@ -5,7 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.snapshotFlow -import com.tangem.feature.wallet.presentation.wallet.state.WalletsListConfig +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig import com.tangem.feature.wallet.presentation.wallet.ui.utils.ScrollOffsetCollector /** diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletTopBar.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletTopBar.kt index 6d23d5706f..5b809bf2e7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletTopBar.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletTopBar.kt @@ -7,7 +7,7 @@ import androidx.compose.ui.tooling.preview.Preview import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.WalletPreviewData -import com.tangem.feature.wallet.presentation.wallet.state.WalletTopBarConfig +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTopBarConfig /** * Wallet screen top bar diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt index c8fc7782f3..331d8de5dd 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt @@ -3,7 +3,7 @@ package com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrenc import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.ui.Modifier -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState import com.tangem.feature.wallet.presentation.wallet.ui.decorations.walletContentItemDecoration /** diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContentItem.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContentItem.kt index a387c5f956..3cdfd7517d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContentItem.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContentItem.kt @@ -4,7 +4,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import com.tangem.feature.wallet.presentation.common.component.NetworkGroupItem import com.tangem.feature.wallet.presentation.common.component.TokenItem -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState /** * Multi-currency content item diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContent.kt index 3684c90d62..d70b42ab44 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContent.kt @@ -9,7 +9,7 @@ import androidx.paging.compose.itemsIndexed import com.tangem.core.ui.components.transactions.empty.EmptyTransactionBlock import com.tangem.core.ui.components.transactions.empty.EmptyTransactionsBlockState import com.tangem.core.ui.res.TangemTheme -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState import com.tangem.feature.wallet.presentation.wallet.ui.decorations.walletContentItemDecoration /** diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContentItem.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContentItem.kt index 58489e3a3d..8a20e22efe 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContentItem.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContentItem.kt @@ -3,7 +3,7 @@ package com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurren import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import com.tangem.core.ui.components.transactions.Transaction -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState /** * Single currency content item diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/TxHistoryGroupTitle.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/TxHistoryGroupTitle.kt index 275f2fce6d..b3b8875b39 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/TxHistoryGroupTitle.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/TxHistoryGroupTitle.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import com.tangem.core.ui.res.TangemTheme -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState.TxHistoryItemState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState.TxHistoryItemState /** * Transactions block group title diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/TxHistoryTitle.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/TxHistoryTitle.kt index a71ec939db..58e06ab395 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/TxHistoryTitle.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/TxHistoryTitle.kt @@ -12,7 +12,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTxHistoryState.TxHistoryItemState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState.TxHistoryItemState /** * Transactions block title 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 b197bf76e8..c8b1d0b3b3 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 @@ -5,7 +5,7 @@ import com.tangem.core.ui.utils.BigDecimalFormatter.formatFiatAmount import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.tokens.model.TokenList import com.tangem.feature.wallet.presentation.wallet.domain.WalletAdditionalInfoFactory -import com.tangem.feature.wallet.presentation.wallet.state.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState import com.tangem.utils.converter.Converter internal class FiatBalanceToWalletCardConverter( 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 index 067db48037..174c0b9f50 100644 --- 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 @@ -1,7 +1,7 @@ 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.content.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListErrorToWalletStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListErrorToWalletStateConverter.kt index 6f039ad4d2..2697e71bd3 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListErrorToWalletStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListErrorToWalletStateConverter.kt @@ -2,8 +2,9 @@ package com.tangem.feature.wallet.presentation.wallet.utils import com.tangem.common.Provider import com.tangem.domain.tokens.error.TokenListError +import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState import com.tangem.utils.converter.Converter import kotlinx.collections.immutable.persistentListOf @@ -14,7 +15,7 @@ internal class TokenListErrorToWalletStateConverter( // TODO: [REDACTED_JIRA] override fun convert(value: TokenListError): WalletStateHolder { val state = currentStateProvider() - return WalletStateHolder.MultiCurrencyContent( + return WalletMultiCurrencyState.Content( onBackClick = state.onBackClick, topBarConfig = state.topBarConfig, walletsListConfig = state.walletsListConfig, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToContentItemsConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToContentItemsConverter.kt index 114cd724f9..e76e7535f6 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToContentItemsConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToContentItemsConverter.kt @@ -3,8 +3,8 @@ package com.tangem.feature.wallet.presentation.wallet.utils import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.NetworkGroup import com.tangem.domain.tokens.model.TokenList -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState.TokensListItemState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState.TokensListItemState import com.tangem.feature.wallet.presentation.wallet.utils.LoadingItemsProvider.getLoadingMultiCurrencyTokens import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents import com.tangem.utils.converter.Converter diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToWalletStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToWalletStateConverter.kt index e1a7a84ea9..f94b216186 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToWalletStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToWalletStateConverter.kt @@ -4,18 +4,20 @@ import com.tangem.common.Provider import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.tokens.model.TokenList import com.tangem.feature.wallet.presentation.common.state.TokenItemState +import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder -import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder.MultiCurrencyContent -import com.tangem.feature.wallet.presentation.wallet.state.WalletsListConfig -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig import com.tangem.feature.wallet.presentation.wallet.utils.TokenListToWalletStateConverter.TokensListModel import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents import com.tangem.utils.converter.Converter import kotlinx.collections.immutable.toPersistentList +@Suppress("LongParameterList") internal class TokenListToWalletStateConverter( private val currentStateProvider: Provider, private val cardTypeResolverProvider: Provider, + private val isLockedWalletProvider: Provider, private val isWalletContentHidden: Boolean, private val fiatCurrencyCode: String, private val fiatCurrencySymbol: String, @@ -43,8 +45,8 @@ internal class TokenListToWalletStateConverter( ) } - private fun WalletStateHolder.updateWithTokenList(tokenList: TokenList): MultiCurrencyContent { - return MultiCurrencyContent( + private fun WalletStateHolder.updateWithTokenList(tokenList: TokenList): WalletMultiCurrencyState.Content { + return WalletMultiCurrencyState.Content( onBackClick = onBackClick, topBarConfig = topBarConfig, walletsListConfig = walletsListConfig, @@ -60,7 +62,7 @@ internal class TokenListToWalletStateConverter( val selectedWalletCard = walletsListConfig.wallets[selectedWalletIndex] val converter = FiatBalanceToWalletCardConverter( currentState = selectedWalletCard, - isLockedState = this is WalletStateHolder.UnlockWalletContent, + isLockedState = isLockedWalletProvider(), cardTypeResolverProvider = cardTypeResolverProvider, isWalletContentHidden = isWalletContentHidden, fiatCurrencyCode = fiatCurrencyCode, @@ -75,7 +77,7 @@ internal class TokenListToWalletStateConverter( } private fun WalletStateHolder.getRefreshingStatus(): Boolean { - return if (this is MultiCurrencyContent) { + return if (this is WalletMultiCurrencyState.Content) { tokensListState.items.any { tokensListItemState -> tokensListItemState is WalletTokensListState.TokensListItemState.Token && tokensListItemState.state is TokenItemState.Loading diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt index 503b697419..89d57acf5b 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt @@ -31,4 +31,8 @@ internal interface WalletClickIntents { fun onReloadClick() fun onExploreClick() + + fun onUnlockWalletClick() + + fun onUnlockWalletNotificationClick() } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt index aace48a09d..a7fa8f46f0 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt @@ -6,9 +6,10 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.NetworkGroup import com.tangem.domain.tokens.model.TokenList import com.tangem.feature.wallet.presentation.common.state.TokenItemState -import com.tangem.feature.wallet.presentation.wallet.state.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder -import com.tangem.feature.wallet.presentation.wallet.state.content.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.Flow @@ -117,7 +118,7 @@ internal class WalletNotificationsListFactory( } return currentStateProvider().let { state -> - state is WalletStateHolder.MultiCurrencyContent && state.tokensListState.items.any(isUnreachableState) + state is WalletMultiCurrencyState.Content && state.tokensListState.items.any(isUnreachableState) } } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index 4c1275a2bd..6d08a629c2 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -24,8 +24,10 @@ import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.usecase.GetExploreUrlUseCase import com.tangem.domain.wallets.usecase.GetWalletsUseCase import com.tangem.domain.wallets.usecase.SaveWalletUseCase +import com.tangem.domain.wallets.usecase.UnlockWalletsUseCase import com.tangem.feature.wallet.presentation.router.InnerWalletRouter import com.tangem.feature.wallet.presentation.wallet.state.* +import com.tangem.feature.wallet.presentation.wallet.state.components.WalletBottomSheetConfig import com.tangem.feature.wallet.presentation.wallet.state.factory.WalletStateFactory import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.lifecycle.HiltViewModel @@ -55,6 +57,7 @@ internal class WalletViewModel @Inject constructor( private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase, private val getExploreUrlUseCase: GetExploreUrlUseCase, + private val unlockWalletsUseCase: UnlockWalletsUseCase, private val dispatchers: CoroutineDispatcherProvider, ) : ViewModel(), DefaultLifecycleObserver, WalletClickIntents { @@ -74,6 +77,7 @@ internal class WalletViewModel @Inject constructor( currentCardTypeResolverProvider = Provider { getCardTypeResolver(index = uiState.walletsListConfig.selectedWalletIndex) }, + isLockedWalletProvider = Provider { wallets[uiState.walletsListConfig.selectedWalletIndex].isLocked }, clickIntents = this, ) @@ -90,24 +94,31 @@ internal class WalletViewModel @Inject constructor( getWalletsUseCase() .flowWithLifecycle(owner.lifecycle) .distinctUntilChanged() - .onEach { wallets -> - if (wallets.isEmpty()) return@onEach - this.wallets = wallets - - uiState = stateFactory.getSkeletonState(wallets = wallets) - - updateContentItems(index = 0) - } + .onEach(::updateWallets) .flowOn(dispatchers.io) .launchIn(viewModelScope) } + private fun updateWallets(sourceList: List) { + if (sourceList.isEmpty() || sourceList.all(UserWallet::isLocked)) return + + wallets = sourceList + + val unlockedWalletIndex = sourceList.indexOfFirst { !it.isLocked } + uiState = stateFactory.getSkeletonState( + wallets = wallets, + index = if (unlockedWalletIndex == -1) 0 else unlockedWalletIndex, + ) + + updateContentItems(index = unlockedWalletIndex) + } + private fun updateContentItems(index: Int, isRefreshing: Boolean = false) { val cardTypeResolver = getCardTypeResolver(index) - if (cardTypeResolver.isMultiwalletAllowed()) { - updateByTokensList(index, isRefreshing) - } else { - updateByTxHistory(index) + when { + getWallet(index).isLocked -> uiState = stateFactory.getLockedState() + cardTypeResolver.isMultiwalletAllowed() -> updateByTokensList(index, isRefreshing) + !cardTypeResolver.isMultiwalletAllowed() -> updateByTxHistory(index) } } @@ -120,7 +131,10 @@ internal class WalletViewModel @Inject constructor( isRefreshing = isRefreshing, ) - tokenListEither.onRight { updateNotifications(index = index, tokenList = it) } + updateNotifications( + index = index, + tokenList = tokenListEither.fold(ifLeft = { null }, ifRight = { it }), + ) } .flowOn(dispatchers.io) .launchIn(viewModelScope) @@ -278,4 +292,16 @@ internal class WalletViewModel @Inject constructor( ) } } + + override fun onUnlockWalletClick() { + viewModelScope.launch(dispatchers.io) { + unlockWalletsUseCase() + } + } + + override fun onUnlockWalletNotificationClick() { + uiState = stateFactory.getStateWithOpenBottomSheet( + content = requireNotNull(uiState.bottomSheetConfig?.content), + ) + } } \ No newline at end of file