From ff985dec4eafa898f5b6825b362a529e4466b839 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 3 Aug 2023 22:59:39 +0800 Subject: [PATCH] Updated on 2026-08-14 --- .../buttons/HorizontalActionChips.kt | 15 ++-- .../buttons/actions/ActionButtonConfig.kt | 3 +- .../ui/components/buttons/actions/Actions.kt | 18 +++- .../empty/EmptyTransactionBlock.kt | 34 +++----- .../empty/EmptyTransactionsBlockState.kt | 62 ++++++++------ .../tokendetails/TokenDetailsPreviewData.kt | 9 +- .../organizetokens/OrganizeTokensScreen.kt | 5 +- .../router/DefaultWalletRouter.kt | 4 + .../presentation/router/InnerWalletRouter.kt | 3 + .../wallet/state/WalletManageButton.kt | 11 +-- .../state/content/WalletTxHistoryState.kt | 40 ++++----- .../presentation/wallet/ui/WalletScreen.kt | 55 +----------- .../multicurrency/MultiCurrencyContent.kt | 31 +++++++ .../multicurrency/OrganizeTokensButton.kt | 4 +- .../singlecurrency/SingleCurrencyContent.kt | 85 +++++++++++++++++++ .../wallet/viewmodels/WalletViewModel.kt | 26 +++--- 16 files changed, 246 insertions(+), 159 deletions(-) create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContent.kt diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/HorizontalActionChips.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/HorizontalActionChips.kt index de7706a43d..c778c6c0a4 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/HorizontalActionChips.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/HorizontalActionChips.kt @@ -14,6 +14,7 @@ import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameter import com.tangem.core.ui.R import com.tangem.core.ui.components.buttons.actions.ActionButton import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig +import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.res.TangemTheme import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @@ -30,11 +31,7 @@ fun HorizontalActionChips( verticalAlignment = Alignment.CenterVertically, contentPadding = contentPadding, ) { - items( - items = buttons, - key = { it.text }, - itemContent = { ActionButton(config = it) }, - ) + items(items = buttons, itemContent = { ActionButton(config = it) }) } } @@ -61,22 +58,22 @@ private fun Preview_HorizontalActionChips_Dark( private class ActionButtonConfigProvider : CollectionPreviewParameterProvider( collection = persistentListOf( ActionButtonConfig( - text = "Buy", + text = TextReference.Str(value = "Buy"), iconResId = R.drawable.ic_plus_24, onClick = {}, ), ActionButtonConfig( - text = "Send", + text = TextReference.Str(value = "Send"), iconResId = R.drawable.ic_arrow_up_24, onClick = {}, ), ActionButtonConfig( - text = "Receive", + text = TextReference.Str(value = "Receive"), iconResId = R.drawable.ic_arrow_down_24, onClick = {}, ), ActionButtonConfig( - text = "Exchange", + text = TextReference.Str(value = "Exchange"), iconResId = R.drawable.ic_exchange_vertical_24, onClick = {}, ), diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/ActionButtonConfig.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/ActionButtonConfig.kt index 3e69942c7f..ae19be321b 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/ActionButtonConfig.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/ActionButtonConfig.kt @@ -1,6 +1,7 @@ package com.tangem.core.ui.components.buttons.actions import androidx.annotation.DrawableRes +import com.tangem.core.ui.extensions.TextReference /** * Action button config @@ -13,7 +14,7 @@ import androidx.annotation.DrawableRes [REDACTED_AUTHOR] */ data class ActionButtonConfig( - val text: String, + val text: TextReference, @DrawableRes val iconResId: Int, val onClick: () -> Unit, val enabled: Boolean = true, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt index 068172b71e..af38dad59f 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt @@ -19,6 +19,8 @@ import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameter import com.tangem.core.ui.R import com.tangem.core.ui.components.SpacerW8 import com.tangem.core.ui.components.buttons.common.* +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme /** @@ -103,7 +105,7 @@ private fun Button( SpacerW8() Text( - text = config.text, + text = config.text.resolveReference(), color = if (config.enabled) TangemTheme.colors.text.primary1 else TangemTheme.colors.text.disabled, overflow = TextOverflow.Ellipsis, maxLines = 1, @@ -146,7 +148,17 @@ private fun Preview_ActionButton_Dark(@PreviewParameter(ActionStateProvider::cla private class ActionStateProvider : CollectionPreviewParameterProvider( collection = listOf( - ActionButtonConfig(text = "Enabled", iconResId = R.drawable.ic_arrow_up_24, enabled = true, onClick = {}), - ActionButtonConfig(text = "Disabled", iconResId = R.drawable.ic_arrow_down_24, enabled = false, onClick = {}), + ActionButtonConfig( + text = TextReference.Str(value = "Enabled"), + iconResId = R.drawable.ic_arrow_up_24, + enabled = true, + onClick = {}, + ), + ActionButtonConfig( + text = TextReference.Str(value = "Disabled"), + iconResId = R.drawable.ic_arrow_down_24, + enabled = false, + onClick = {}, + ), ), ) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/transactions/empty/EmptyTransactionBlock.kt b/core/ui/src/main/java/com/tangem/core/ui/components/transactions/empty/EmptyTransactionBlock.kt index 4bb5a8f0b1..4045bf505e 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/transactions/empty/EmptyTransactionBlock.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/transactions/empty/EmptyTransactionBlock.kt @@ -14,11 +14,15 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import com.tangem.core.ui.components.buttons.actions.ActionButton -import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.R +/** + * Placeholder for transaction's block without content + * + * @param state component state + * @param modifier modifier + */ @Composable fun EmptyTransactionBlock(state: EmptyTransactionsBlockState, modifier: Modifier = Modifier) { Column( @@ -34,6 +38,7 @@ fun EmptyTransactionBlock(state: EmptyTransactionsBlockState, modifier: Modifier painter = painterResource(id = state.iconRes), contentDescription = null, ) + Text( modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing32), textAlign = TextAlign.Center, @@ -41,6 +46,7 @@ fun EmptyTransactionBlock(state: EmptyTransactionsBlockState, modifier: Modifier style = TangemTheme.typography.body2, color = TangemTheme.colors.text.secondary, ) + ActionButton(config = state.actionButtonConfig) } } @@ -67,26 +73,8 @@ private fun EmptyTransactionBlock_Dark( private class EmptyTransactionBlockStateProvider : CollectionPreviewParameterProvider( collection = listOf( - EmptyTransactionsBlockState.Empty( - actionButtonConfig = ActionButtonConfig( - text = "Buy", - iconResId = R.drawable.ic_plus_24, - onClick = {}, - ), - ), - EmptyTransactionsBlockState.FailedToLoad( - actionButtonConfig = ActionButtonConfig( - text = "Reload", - iconResId = R.drawable.ic_refresh_24, - onClick = {}, - ), - ), - EmptyTransactionsBlockState.NotImplemented( - actionButtonConfig = ActionButtonConfig( - text = "Explore transaction history", - iconResId = R.drawable.ic_arrow_top_right_24, - onClick = {}, - ), - ), + EmptyTransactionsBlockState.Empty(onClick = {}), + EmptyTransactionsBlockState.FailedToLoad(onClick = {}), + EmptyTransactionsBlockState.NotImplemented(onClick = {}), ), ) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/transactions/empty/EmptyTransactionsBlockState.kt b/core/ui/src/main/java/com/tangem/core/ui/components/transactions/empty/EmptyTransactionsBlockState.kt index bb26676865..d4c4dad238 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/transactions/empty/EmptyTransactionsBlockState.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/transactions/empty/EmptyTransactionsBlockState.kt @@ -1,37 +1,45 @@ package com.tangem.core.ui.components.transactions.empty -import androidx.annotation.DrawableRes import com.tangem.core.ui.R import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.extensions.TextReference -sealed class EmptyTransactionsBlockState { +sealed class EmptyTransactionsBlockState( + val iconRes: Int, + val text: TextReference, + val actionButtonConfig: ActionButtonConfig, +) { - @get:DrawableRes - abstract val iconRes: Int + class FailedToLoad(onClick: () -> Unit) : EmptyTransactionsBlockState( + actionButtonConfig = ActionButtonConfig( + text = TextReference.Res(R.string.common_reload), + iconResId = R.drawable.ic_refresh_24, + onClick = onClick, + enabled = true, + ), + iconRes = R.drawable.ic_alert_history_64, + text = TextReference.Res(R.string.transaction_history_error_failed_to_load), + ) - abstract val text: TextReference + class Empty(onClick: (() -> Unit)?) : EmptyTransactionsBlockState( + actionButtonConfig = ActionButtonConfig( + text = TextReference.Res(R.string.common_buy), + iconResId = R.drawable.ic_plus_24, + onClick = onClick ?: {}, + enabled = onClick != null, + ), + iconRes = R.drawable.img_coin_64, + text = TextReference.Res(R.string.transaction_history_empty_transactions), + ) - abstract val actionButtonConfig: ActionButtonConfig - - data class FailedToLoad( - override val actionButtonConfig: ActionButtonConfig, - ) : EmptyTransactionsBlockState() { - override val iconRes: Int = R.drawable.ic_alert_history_64 - override val text: TextReference = TextReference.Res(R.string.transaction_history_error_failed_to_load) - } - - data class Empty( - override val actionButtonConfig: ActionButtonConfig, - ) : EmptyTransactionsBlockState() { - override val iconRes: Int = R.drawable.img_coin_64 - override val text: TextReference = TextReference.Res(R.string.transaction_history_empty_transactions) - } - - data class NotImplemented( - override val actionButtonConfig: ActionButtonConfig, - ) : EmptyTransactionsBlockState() { - override val iconRes: Int = R.drawable.ic_compass_64 - override val text: TextReference = TextReference.Res(R.string.transaction_history_not_supported_description) - } + class NotImplemented(onClick: () -> Unit) : EmptyTransactionsBlockState( + actionButtonConfig = ActionButtonConfig( + text = TextReference.Res(R.string.common_explore_transaction_history), + iconResId = R.drawable.ic_arrow_top_right_24, + onClick = onClick, + enabled = true, + ), + iconRes = R.drawable.ic_compass_64, + text = TextReference.Res(R.string.transaction_history_not_supported_description), + ) } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt index 5c20a6664d..47cef6133f 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt @@ -3,6 +3,7 @@ package com.tangem.feature.tokendetails.presentation.tokendetails import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.core.ui.components.marketprice.PriceChangeConfig +import com.tangem.core.ui.extensions.TextReference import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsBalanceBlockState import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsTopAppBarConfig @@ -42,22 +43,22 @@ internal object TokenDetailsPreviewData { private val actionButtons = persistentListOf( ActionButtonConfig( - text = "Buy", + text = TextReference.Str(value = "Buy"), iconResId = R.drawable.ic_plus_24, onClick = {}, ), ActionButtonConfig( - text = "Send", + text = TextReference.Str(value = "Send"), iconResId = R.drawable.ic_arrow_up_24, onClick = {}, ), ActionButtonConfig( - text = "Receive", + text = TextReference.Str(value = "Receive"), iconResId = R.drawable.ic_arrow_down_24, onClick = {}, ), ActionButtonConfig( - text = "Exchange", + text = TextReference.Str(value = "Exchange"), iconResId = R.drawable.ic_exchange_vertical_24, onClick = {}, ), diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt index d0967c3046..87f1b076b2 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt @@ -25,6 +25,7 @@ import com.tangem.core.ui.components.PrimaryButton import com.tangem.core.ui.components.SecondaryButton import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.components.buttons.actions.RoundedActionButton +import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.WalletPreviewData @@ -208,7 +209,7 @@ private fun TopBar( ) { RoundedActionButton( config = ActionButtonConfig( - text = stringResource(id = R.string.organize_tokens_sort_by_balance), + text = TextReference.Res(id = R.string.organize_tokens_sort_by_balance), iconResId = R.drawable.ic_sort_24, onClick = config.onSortByBalanceClick, ), @@ -217,7 +218,7 @@ private fun TopBar( ) RoundedActionButton( config = ActionButtonConfig( - text = stringResource(id = R.string.organize_tokens_group), + text = TextReference.Res(id = R.string.organize_tokens_group), iconResId = R.drawable.ic_group_24, onClick = config.onGroupByNetworkClick, ), diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt index 642d59b17b..de6989f860 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt @@ -90,6 +90,10 @@ internal class DefaultWalletRouter(private val navigationStateHolder: Navigation navigationStateHolder.navigate(action = NavigationAction.NavigateTo(AppScreen.OnboardingWallet)) } + override fun openTxHistoryWebsite(url: String) { + navigationStateHolder.navigate(action = NavigationAction.OpenUrl(url)) + } + private companion object { const val BACKSTACK_ENTRY_COUNT_TO_CLOSE_WALLET_SCREEN = 2 } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt index ef0a6a93b3..5fab6367de 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt @@ -37,4 +37,7 @@ internal interface InnerWalletRouter : WalletRouter { /** Open onboarding screen */ fun openOnboardingScreen() + + /** Open transaction history website by [url] */ + fun openTxHistoryWebsite(url: String) } \ No newline at end of file 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/WalletManageButton.kt index e5f6115aaa..cb07819add 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/WalletManageButton.kt @@ -1,6 +1,7 @@ package com.tangem.feature.wallet.presentation.wallet.state import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig +import com.tangem.core.ui.extensions.TextReference import com.tangem.feature.wallet.impl.R /** @@ -19,7 +20,7 @@ sealed class WalletManageButton(val config: ActionButtonConfig) { */ data class Buy(val onClick: () -> Unit) : WalletManageButton( config = ActionButtonConfig( - text = "Buy", + text = TextReference.Res(id = R.string.common_buy), iconResId = R.drawable.ic_plus_24, onClick = onClick, ), @@ -32,7 +33,7 @@ sealed class WalletManageButton(val config: ActionButtonConfig) { */ data class Send(val onClick: () -> Unit) : WalletManageButton( config = ActionButtonConfig( - text = "Send", + text = TextReference.Res(id = R.string.common_send), iconResId = R.drawable.ic_arrow_up_24, onClick = onClick, ), @@ -45,7 +46,7 @@ sealed class WalletManageButton(val config: ActionButtonConfig) { */ data class Receive(val onClick: () -> Unit) : WalletManageButton( config = ActionButtonConfig( - text = "Receive", + text = TextReference.Res(id = R.string.common_receive), iconResId = R.drawable.ic_arrow_down_24, onClick = onClick, ), @@ -58,7 +59,7 @@ sealed class WalletManageButton(val config: ActionButtonConfig) { */ data class Exchange(val onClick: () -> Unit) : WalletManageButton( config = ActionButtonConfig( - text = "Exchange", + text = TextReference.Res(id = R.string.common_exchange), iconResId = R.drawable.ic_exchange_vertical_24, onClick = onClick, ), @@ -71,7 +72,7 @@ sealed class WalletManageButton(val config: ActionButtonConfig) { */ data class CopyAddress(val onClick: () -> Unit) : WalletManageButton( config = ActionButtonConfig( - text = "Copy address", + text = TextReference.Res(id = R.string.common_copy_address), iconResId = R.drawable.ic_copy_24, onClick = onClick, ), 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/content/WalletTxHistoryState.kt index f9b3c822ee..5252fa8981 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/content/WalletTxHistoryState.kt @@ -17,14 +17,32 @@ internal sealed interface WalletTxHistoryState { * * @property items content items */ - sealed class ContentItemsState(open val items: Flow>) : WalletTxHistoryState + sealed class ContentState(open val items: Flow>) : WalletTxHistoryState /** * Content state * * @property items content items */ - data class Content(override val items: Flow>) : ContentItemsState(items) + data class Content(override val items: Flow>) : ContentState(items) + + /** + * Locked state + * + * @property onExploreClick lambda be invoke when explore button was clicked + */ + data class Locked(val onExploreClick: () -> Unit) : + ContentState( + items = flowOf( + PagingData.from( + listOf( + TxHistoryItemState.Title(onExploreClick = onExploreClick), + TxHistoryItemState.Transaction(state = TransactionState.Loading), + ), + ), + ), + ), + WalletLockedContentState /** * Empty state @@ -47,24 +65,6 @@ internal sealed interface WalletTxHistoryState { */ data class Error(val onReloadClick: () -> Unit) : WalletTxHistoryState - /** - * Locked state - * - * @property onExploreClick lambda be invoke when explore button was clicked - */ - data class Locked(val onExploreClick: () -> Unit) : - ContentItemsState( - items = flowOf( - PagingData.from( - listOf( - TxHistoryItemState.Title(onExploreClick = onExploreClick), - TxHistoryItemState.Transaction(state = TransactionState.Loading), - ), - ), - ), - ), - WalletLockedContentState - /** Transactions history item state */ sealed interface TxHistoryItemState { 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 1ba7a134d6..05f45bd9e4 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 @@ -19,22 +19,19 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems -import androidx.paging.compose.itemsIndexed import com.tangem.core.ui.components.buttons.HorizontalActionChips import com.tangem.core.ui.components.marketprice.MarketPriceBlock import com.tangem.core.ui.components.notifications.Notification import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.presentation.common.WalletPreviewData 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.content.WalletTxHistoryState import com.tangem.feature.wallet.presentation.wallet.ui.components.WalletBottomSheet import com.tangem.feature.wallet.presentation.wallet.ui.components.WalletTopBar import com.tangem.feature.wallet.presentation.wallet.ui.components.WalletsList -import com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency.MultiCurrencyContentItem import com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency.OrganizeTokensButton -import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.SingleCurrencyContentItem -import com.tangem.feature.wallet.presentation.wallet.ui.decorations.walletContentItemDecoration +import com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency.tokensListItems +import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.txHistoryItems import com.tangem.feature.wallet.presentation.wallet.ui.utils.ScrollOffsetCollector import com.tangem.feature.wallet.presentation.wallet.ui.utils.changeWalletAnimator @@ -69,7 +66,7 @@ internal fun WalletScreen(state: WalletStateHolder) { .pullRefresh(pullRefreshState), ) { val txHistoryItems = if (state is WalletStateHolder.SingleCurrencyContent) { - if (state.txHistoryState is WalletTxHistoryState.ContentItemsState) { + if (state.txHistoryState is WalletTxHistoryState.ContentState) { state.txHistoryState.items.collectAsLazyPagingItems() } else { null @@ -177,52 +174,6 @@ private fun LazyListScope.contentItems( } } -private fun LazyListScope.tokensListItems(state: WalletTokensListState, modifier: Modifier = Modifier) { - itemsIndexed( - items = state.items, - key = { index, _ -> index }, - itemContent = { index, item -> - MultiCurrencyContentItem( - state = item, - modifier = modifier.walletContentItemDecoration( - currentIndex = index, - lastIndex = state.items.lastIndex, - ), - ) - }, - ) -} - -private fun LazyListScope.txHistoryItems( - state: WalletTxHistoryState, - txHistoryItems: LazyPagingItems?, - modifier: Modifier = Modifier, -) { - when (state) { - is WalletTxHistoryState.ContentItemsState -> { - checkNotNull(txHistoryItems) - itemsIndexed( - items = txHistoryItems, - key = { index, _ -> index }, - itemContent = { index, item -> - if (item == null) return@itemsIndexed - - SingleCurrencyContentItem( - state = item, - modifier = modifier.walletContentItemDecoration( - currentIndex = index, - lastIndex = txHistoryItems.itemCount, - ), - ) - }, - ) - } - is WalletTxHistoryState.Empty -> TODO("[REDACTED_JIRA]") - is WalletTxHistoryState.Error -> TODO("[REDACTED_JIRA]") - is WalletTxHistoryState.NotSupported -> TODO("[REDACTED_JIRA]") - } -} - @OptIn(ExperimentalMaterialApi::class) @Composable private fun PullToRefreshIndicator(isRefreshing: Boolean, state: PullRefreshState, modifier: Modifier = Modifier) { 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 new file mode 100644 index 0000000000..c8fc7782f3 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt @@ -0,0 +1,31 @@ +package com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency + +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.ui.decorations.walletContentItemDecoration + +/** + * LazyList extension for [WalletTokensListState] + * + * @param state state + * @param modifier modifier + * +[REDACTED_AUTHOR] + */ +internal fun LazyListScope.tokensListItems(state: WalletTokensListState, modifier: Modifier = Modifier) { + itemsIndexed( + items = state.items, + key = { index, _ -> index }, + itemContent = { index, item -> + MultiCurrencyContentItem( + state = item, + modifier = modifier.walletContentItemDecoration( + currentIndex = index, + lastIndex = state.items.lastIndex, + ), + ) + }, + ) +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/OrganizeTokensButton.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/OrganizeTokensButton.kt index f7e77273fa..53aeef026b 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/OrganizeTokensButton.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/OrganizeTokensButton.kt @@ -2,9 +2,9 @@ package com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrenc import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.components.buttons.actions.RoundedActionButton +import com.tangem.core.ui.extensions.TextReference import com.tangem.feature.wallet.impl.R /** @@ -19,7 +19,7 @@ import com.tangem.feature.wallet.impl.R internal fun OrganizeTokensButton(onClick: (() -> Unit)?, modifier: Modifier = Modifier) { RoundedActionButton( config = ActionButtonConfig( - text = stringResource(id = R.string.organize_tokens_title), + text = TextReference.Res(id = R.string.organize_tokens_title), iconResId = R.drawable.ic_filter_24, onClick = onClick ?: {}, enabled = onClick != null, 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 new file mode 100644 index 0000000000..3684c90d62 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyContent.kt @@ -0,0 +1,85 @@ +package com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyListScope +import androidx.compose.ui.Modifier +import androidx.paging.compose.LazyPagingItems +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.ui.decorations.walletContentItemDecoration + +/** + * LazyList extension for transactions history [WalletTxHistoryState] + * + * @param state state + * @param txHistoryItems transactions + * @param modifier modifier + */ +internal fun LazyListScope.txHistoryItems( + state: WalletTxHistoryState, + txHistoryItems: LazyPagingItems?, + modifier: Modifier = Modifier, +) { + when (state) { + is WalletTxHistoryState.ContentState -> { + contentItems( + txHistoryItems = requireNotNull(txHistoryItems), + modifier = modifier, + ) + } + is WalletTxHistoryState.Empty -> { + nonContentItem( + state = EmptyTransactionsBlockState.Empty(onClick = state.onBuyClick), + modifier = modifier, + ) + } + is WalletTxHistoryState.Error -> { + nonContentItem( + state = EmptyTransactionsBlockState.FailedToLoad(onClick = state.onReloadClick), + modifier = modifier, + ) + } + is WalletTxHistoryState.NotSupported -> { + nonContentItem( + state = EmptyTransactionsBlockState.NotImplemented(onClick = state.onExploreClick), + modifier = modifier, + ) + } + } +} + +private fun LazyListScope.contentItems( + txHistoryItems: LazyPagingItems, + modifier: Modifier = Modifier, +) { + itemsIndexed( + items = txHistoryItems, + key = { index, _ -> index }, + itemContent = { index, item -> + if (item == null) return@itemsIndexed + + SingleCurrencyContentItem( + state = item, + modifier = modifier.walletContentItemDecoration( + currentIndex = index, + lastIndex = txHistoryItems.itemSnapshotList.lastIndex, + ), + ) + }, + ) +} + +private fun LazyListScope.nonContentItem(state: EmptyTransactionsBlockState, modifier: Modifier = Modifier) { + item { + EmptyTransactionBlock( + state = state, + modifier = modifier + .padding(horizontal = TangemTheme.dimens.spacing16, vertical = TangemTheme.dimens.spacing12) + .fillMaxWidth(), + ) + } +} \ No newline at end of file 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 af2d2daddd..b0ee734fe4 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 @@ -4,6 +4,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.* +import androidx.paging.cachedIn import com.tangem.blockchain.common.DerivationStyle import com.tangem.common.Provider import com.tangem.common.doOnFailure @@ -125,22 +126,24 @@ internal class WalletViewModel @Inject constructor( private fun updateByTxHistory(index: Int) { viewModelScope.launch(dispatchers.io) { - val wallet = getWallet(index) - val blockchain = wallet.scanResponse.cardTypesResolver.getBlockchain() - uiState = stateFactory.getLoadingTxHistoryState( - itemsCountEither = txHistoryItemsCountUseCase( - networkId = blockchain.id, - derivationPath = requireNotNull(blockchain.derivationPath(style = DerivationStyle.LEGACY)).rawPath, - ), + val blockchain = getWallet(index).scanResponse.cardTypesResolver.getBlockchain() + + val txHistoryItemsCountEither = txHistoryItemsCountUseCase( + networkId = blockchain.id, + derivationPath = requireNotNull(blockchain.derivationPath(style = DerivationStyle.LEGACY)).rawPath, ) - updateTxHistory(networkId = blockchain.id) + uiState = stateFactory.getLoadingTxHistoryState(itemsCountEither = txHistoryItemsCountEither) + + txHistoryItemsCountEither.onRight { updateTxHistory(networkId = blockchain.id) } updateNotifications(index) } } private fun updateTxHistory(networkId: String) { - uiState = stateFactory.getLoadedTxHistoryState(txHistoryEither = txHistoryItemsUseCase(networkId)) + uiState = stateFactory.getLoadedTxHistoryState( + txHistoryEither = txHistoryItemsUseCase(networkId = networkId).map { it.cachedIn(viewModelScope) }, + ) } private fun updateNotifications(index: Int, tokenList: TokenList? = null) { @@ -255,10 +258,11 @@ internal class WalletViewModel @Inject constructor( } override fun onReloadClick() { - // TODO: [REDACTED_JIRA] + uiState = stateFactory.getStateAfterContentRefreshing() + updateByTxHistory(index = uiState.walletsListConfig.selectedWalletIndex) } override fun onExploreClick() { - // TODO: [REDACTED_JIRA] + router.openTxHistoryWebsite(url = "") // TODO } } \ No newline at end of file