From 0b8c00c15622edefe44dc674daf5a9a6f6c3854a Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 9 Feb 2024 14:09:56 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../configs/feature_toggles_config.json | 4 - .../featuretoggles/WalletFeatureToggles.kt | 11 - .../wallet/di/WalletFeatureTogglesModule.kt | 21 - .../feature/wallet/di/WalletRouterModule.kt | 8 +- .../DefaultWalletFeatureToggles.kt | 19 - .../presentation/common/WalletPreviewData.kt | 166 +- .../router/DefaultWalletRouter.kt | 23 +- .../utils/TokenListAnalyticsSender.kt | 2 +- .../utils/WalletWarningsAnalyticsSender.kt | 4 +- .../domain/GetMultiWalletWarningsFactory.kt | 14 +- .../domain/GetSingleWalletWarningsFactory.kt | 10 +- .../domain/WalletAdditionalInfoFactory.kt | 2 +- .../loaders/WalletContentLoaderFactory.kt | 4 +- .../loaders/WalletScreenContentLoader.kt | 6 +- .../implementors/MultiWalletContentLoader.kt | 6 +- .../MultiWalletContentLoaderFactory.kt | 6 +- .../implementors/SingleWalletContentLoader.kt | 6 +- .../SingleWalletContentLoaderFactory.kt | 6 +- .../SingleWalletWithTokenContentLoader.kt | 6 +- ...ngleWalletWithTokenContentLoaderFactory.kt | 6 +- .../implementors/VisaWalletContentLoader.kt | 6 +- .../VisaWalletContentLoaderFactory.kt | 6 +- .../wallet/state/WalletLockedState.kt | 32 - .../wallet/state/WalletMultiCurrencyState.kt | 63 - .../wallet/state/WalletSingleCurrencyState.kt | 91 - .../presentation/wallet/state/WalletState.kt | 101 -- .../WalletStateController.kt | 16 +- .../state/components/WalletTokensListState.kt | 109 -- .../state/components/WalletsListConfig.kt | 18 - .../state/factory/TokenActionsProvider.kt | 104 -- .../state/factory/TokenListWithWallet.kt | 9 - .../WalletCryptoCurrencyActionsConverter.kt | 76 - .../factory/WalletDeleteStateConverter.kt | 50 - .../WalletLoadedTokensListConverter.kt | 49 - .../state/factory/WalletLockedConverter.kt | 80 - .../factory/WalletRefreshStateConverter.kt | 115 -- .../factory/WalletRenameStateConverter.kt | 33 - ...letSingleCurrencyLoadedBalanceConverter.kt | 181 -- .../factory/WalletSkeletonStateConverter.kt | 157 -- .../state/factory/WalletStateFactory.kt | 288 ---- .../factory/WalletUpdateCardCountConverter.kt | 51 - .../factory/WalletsUnlockStateConverter.kt | 132 -- .../WalletLoadedTxHistoryConverter.kt | 80 - .../WalletLoadingTxHistoryConverter.kt | 105 -- .../WalletTxHistoryItemFlowConverter.kt | 131 -- ...alletTxHistoryTransactionStateConverter.kt | 103 -- .../{ => model}/ActionsBottomSheetConfig.kt | 2 +- .../model/BalancesAndLimitsBlockState.kt | 2 +- .../BalancesAndLimitsBottomSheetConfig.kt | 2 +- .../model/DepositButtonState.kt | 2 +- .../model/ManageTokensButtonConfig.kt | 2 +- .../{ => model}/TokenActionButtonConfig.kt | 2 +- .../WalletAdditionalInfo.kt | 2 +- .../state/{ => model}/WalletAlertState.kt | 2 +- .../WalletBottomSheetConfig.kt | 2 +- .../{components => model}/WalletCardState.kt | 2 +- .../wallet/state/{ => model}/WalletEvent.kt | 2 +- .../WalletManageButton.kt | 2 +- .../WalletNotification.kt | 2 +- .../WalletPullToRefreshConfig.kt | 2 +- .../model/WalletScreenState.kt | 4 +- .../{state2 => state}/model/WalletState.kt | 14 +- .../model/WalletTokensListState.kt | 2 +- .../WalletTopBarConfig.kt | 2 +- .../model/holder/LockedWalletStateHolder.kt | 10 +- .../model/holder/TxHistoryStateHolder.kt | 2 +- .../transformers/AddWalletTransformer.kt | 10 +- .../CloseBottomSheetTransformer.kt | 4 +- .../transformers/DeleteWalletTransformer.kt | 6 +- .../InitializeWalletsTransformer.kt | 16 +- .../OpenBottomSheetTransformer.kt | 4 +- .../ReinitializeWalletTransformer.kt | 10 +- .../transformers/RenameWalletTransformer.kt | 4 +- .../transformers/ScrollToWalletTransformer.kt | 6 +- .../transformers/SendEventTransformer.kt | 6 +- .../SetBalancesAndLimitsTransformer.kt | 14 +- .../SetCryptoCurrencyActionsTransformer.kt | 10 +- .../SetPrimaryCurrencyTransformer.kt | 10 +- .../SetRefreshStateTransformer.kt | 9 +- .../SetTokenListErrorTransformer.kt | 6 +- .../transformers/SetTokenListTransformer.kt | 18 +- .../SetTxHistoryCountErrorTransformer.kt | 10 +- .../SetTxHistoryCountTransformer.kt | 8 +- .../SetTxHistoryItemsErrorTransformer.kt | 8 +- .../SetTxHistoryItemsTransformer.kt | 10 +- .../transformers/SetWarningsTransformer.kt | 6 +- .../transformers/UnlockWalletTransformer.kt | 14 +- .../UpdateBalanceHidingModeTransformer.kt | 4 +- .../UpdateWalletCardsCountTransformer.kt | 6 +- .../WalletScreenStateTransformer.kt | 8 + .../transformers/WalletStateTransformer.kt | 6 +- .../BalancesAndLimitsBottomSheetConverter.kt | 10 +- .../MultiWalletCardStateConverter.kt | 4 +- .../MultiWalletCurrencyActionsConverter.kt | 4 +- .../SingleWalletCardStateConverter.kt | 4 +- .../SingleWalletMarketPriceConverter.kt | 2 +- .../converter/TokenItemStateConverter.kt | 6 +- .../converter/TokenListStateConverter.kt | 12 +- .../converter/TxHistoryItemFlowConverter.kt | 6 +- .../converter/TxHistoryItemStateConverter.kt | 6 +- .../VisaTxHistoryItemStateConverter.kt | 2 +- .../utils/UserWalletConverterExt.kt | 4 +- .../utils/WalletEventSender.kt | 8 +- .../utils/WalletLoadingStateFactory.kt | 11 +- .../WalletScreenStateTransformer.kt | 8 - .../subscribers/BasicTokenListSubscriber.kt | 10 +- .../MultiWalletTokenListSubscriber.kt | 6 +- .../MultiWalletWarningsSubscriber.kt | 10 +- .../subscribers/PrimaryCurrencySubscriber.kt | 4 +- .../SingleWalletButtonsSubscriber.kt | 8 +- .../SingleWalletNotificationsSubscriber.kt | 10 +- .../SingleWalletWithTokenListSubscriber.kt | 6 +- .../wallet/subscribers/TxHistorySubscriber.kt | 16 +- .../subscribers/VisaWalletSubscriber.kt | 16 +- .../presentation/wallet/ui/WalletAlert.kt | 2 +- .../wallet/ui/WalletEventEffect.kt | 66 +- .../wallet/ui/WalletEventEffectV2.kt | 62 - .../presentation/wallet/ui/WalletScreen.kt | 337 ++-- .../presentation/wallet/ui/WalletScreenV2.kt | 257 --- .../wallet/ui/WalletsListEffects.kt | 20 +- .../wallet/ui/WalletsListEffectsV2.kt | 45 - .../ui/components/TokenActionsBottomSheet.kt | 4 +- .../wallet/ui/components/WalletsList.kt | 44 +- .../ui/components/common/WalletBottomSheet.kt | 5 +- .../wallet/ui/components/common/WalletCard.kt | 16 +- .../ui/components/common/WalletContent.kt | 28 +- .../components/common/WalletNotifications.kt | 2 +- .../ui/components/common/WalletTopBar.kt | 2 +- .../multicurrency/MultiCurrencyContent.kt | 50 +- .../multicurrency/MultiCurrencyContentItem.kt | 19 +- .../SingleCurrencyControlButtons.kt | 2 +- .../components/visa/BalancesAndLimitsBlock.kt | 2 +- .../visa/BalancesAndLimitsBottomSheet.kt | 2 +- .../ui/components/visa/VisaDepositButton.kt | 2 +- .../wallet/ui/utils/ScrollOffsetCollector.kt | 26 +- .../ui/utils/ScrollOffsetCollectorV2.kt | 49 - .../ui/utils/WalletsScrollPreviewExt.kt | 2 +- ...ryptoCurrencyStatusToTokenItemConverter.kt | 122 -- .../utils/CurrencyStatusErrorConverter.kt | 17 - .../utils/FiatBalanceToWalletCardConverter.kt | 60 - .../wallet/utils/HiddenStateConverter.kt | 26 - .../wallet/utils/TokenListErrorConverter.kt | 35 - .../utils/TokenListToContentItemsConverter.kt | 114 -- .../utils/TokenListToWalletStateConverter.kt | 63 - .../wallet/viewmodels/WalletClickIntents.kt | 77 - .../WalletNotificationsListFactory.kt | 230 --- .../wallet/viewmodels/WalletStateCache.kt | 29 - .../wallet/viewmodels/WalletStateHolder.kt | 40 - .../viewmodels/WalletStateHolderDelegate.kt | 20 - .../wallet/viewmodels/WalletViewModel.kt | 1525 +++-------------- .../wallet/viewmodels/WalletViewModelV2.kt | 319 ---- .../viewmodels/WalletsUpdateActionResolver.kt | 282 ++- .../WalletsUpdateActionResolverV2.kt | 312 ---- .../viewmodels/intents/VisaWalletIntents.kt | 6 +- .../intents/WalletCardClickIntents.kt | 12 +- ...lickIntentsV2.kt => WalletClickIntents.kt} | 14 +- .../intents/WalletContentClickIntents.kt | 6 +- .../WalletCurrencyActionsClickIntents.kt | 10 +- .../intents/WalletWarningsClickIntents.kt | 10 +- 159 files changed, 1006 insertions(+), 6331 deletions(-) delete mode 100644 features/wallet/api/src/main/kotlin/com/tangem/features/wallet/featuretoggles/WalletFeatureToggles.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletFeatureTogglesModule.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/featuretoggles/DefaultWalletFeatureToggles.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLockedState.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMultiCurrencyState.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletSingleCurrencyState.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletState.kt rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/WalletStateController.kt (78%) delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTokensListState.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletsListConfig.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenListWithWallet.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletCryptoCurrencyActionsConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletDeleteStateConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLoadedTokensListConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLockedConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletRefreshStateConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletRenameStateConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSingleCurrencyLoadedBalanceConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletUpdateCardCountConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletsUnlockStateConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryTransactionStateConverter.kt rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => model}/ActionsBottomSheetConfig.kt (84%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/model/BalancesAndLimitsBlockState.kt (85%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/model/BalancesAndLimitsBottomSheetConfig.kt (91%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/model/DepositButtonState.kt (59%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/model/ManageTokensButtonConfig.kt (51%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => model}/TokenActionButtonConfig.kt (88%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{components => model}/WalletAdditionalInfo.kt (73%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => model}/WalletAlertState.kt (97%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{components => model}/WalletBottomSheetConfig.kt (95%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{components => model}/WalletCardState.kt (98%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{ => model}/WalletEvent.kt (92%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{components => model}/WalletManageButton.kt (97%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{components => model}/WalletNotification.kt (99%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{components => model}/WalletPullToRefreshConfig.kt (78%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/model/WalletScreenState.kt (63%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/model/WalletState.kt (86%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/model/WalletTokensListState.kt (96%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/{components => model}/WalletTopBarConfig.kt (72%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/model/holder/LockedWalletStateHolder.kt (75%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/model/holder/TxHistoryStateHolder.kt (92%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/AddWalletTransformer.kt (65%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/CloseBottomSheetTransformer.kt (87%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/DeleteWalletTransformer.kt (79%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/InitializeWalletsTransformer.kt (85%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/OpenBottomSheetTransformer.kt (93%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/ReinitializeWalletTransformer.kt (66%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/RenameWalletTransformer.kt (88%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/ScrollToWalletTransformer.kt (79%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SendEventTransformer.kt (62%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetBalancesAndLimitsTransformer.kt (88%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetCryptoCurrencyActionsTransformer.kt (91%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetPrimaryCurrencyTransformer.kt (79%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetRefreshStateTransformer.kt (84%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetTokenListErrorTransformer.kt (85%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetTokenListTransformer.kt (75%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetTxHistoryCountErrorTransformer.kt (87%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetTxHistoryCountTransformer.kt (91%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetTxHistoryItemsErrorTransformer.kt (86%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetTxHistoryItemsTransformer.kt (82%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/SetWarningsTransformer.kt (79%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/UnlockWalletTransformer.kt (79%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/UpdateBalanceHidingModeTransformer.kt (63%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/UpdateWalletCardsCountTransformer.kt (88%) create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletScreenStateTransformer.kt rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/WalletStateTransformer.kt (81%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/BalancesAndLimitsBottomSheetConverter.kt (82%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/MultiWalletCardStateConverter.kt (93%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/MultiWalletCurrencyActionsConverter.kt (96%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/SingleWalletCardStateConverter.kt (94%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/SingleWalletMarketPriceConverter.kt (97%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/TokenItemStateConverter.kt (96%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/TokenListStateConverter.kt (87%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/TxHistoryItemFlowConverter.kt (95%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/TxHistoryItemStateConverter.kt (96%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/transformers/converter/VisaTxHistoryItemStateConverter.kt (96%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/utils/UserWalletConverterExt.kt (83%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/utils/WalletEventSender.kt (72%) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/{state2 => state}/utils/WalletLoadingStateFactory.kt (90%) delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/WalletScreenStateTransformer.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffectV2.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreenV2.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletsListEffectsV2.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/ScrollOffsetCollectorV2.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CryptoCurrencyStatusToTokenItemConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CurrencyStatusErrorConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/HiddenStateConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListErrorConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToContentItemsConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToWalletStateConverter.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateCache.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateHolder.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateHolderDelegate.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModelV2.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolverV2.kt rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/{WalletClickIntentsV2.kt => WalletClickIntents.kt} (92%) diff --git a/core/featuretoggles/src/main/assets/configs/feature_toggles_config.json b/core/featuretoggles/src/main/assets/configs/feature_toggles_config.json index 13b20fb797..e76218c369 100644 --- a/core/featuretoggles/src/main/assets/configs/feature_toggles_config.json +++ b/core/featuretoggles/src/main/assets/configs/feature_toggles_config.json @@ -14,9 +14,5 @@ { "name": "REDESIGNED_SEND_SCREEN_ENABLED", "version": "undefined" - }, - { - "name": "WALLETS_SCROLLING_PREVIEW_ENABLED", - "version": "5.5.0" } ] diff --git a/features/wallet/api/src/main/kotlin/com/tangem/features/wallet/featuretoggles/WalletFeatureToggles.kt b/features/wallet/api/src/main/kotlin/com/tangem/features/wallet/featuretoggles/WalletFeatureToggles.kt deleted file mode 100644 index f2bd26a6ba..0000000000 --- a/features/wallet/api/src/main/kotlin/com/tangem/features/wallet/featuretoggles/WalletFeatureToggles.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.tangem.features.wallet.featuretoggles - -/** - * Wallet feature toggles - * -[REDACTED_AUTHOR] - */ -interface WalletFeatureToggles { - - val isWalletsScrollingPreviewEnabled: Boolean -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletFeatureTogglesModule.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletFeatureTogglesModule.kt deleted file mode 100644 index ed23c5d4c3..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletFeatureTogglesModule.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.tangem.feature.wallet.di - -import com.tangem.core.featuretoggle.manager.FeatureTogglesManager -import com.tangem.feature.wallet.featuretoggles.DefaultWalletFeatureToggles -import com.tangem.features.wallet.featuretoggles.WalletFeatureToggles -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton - -@Module -@InstallIn(SingletonComponent::class) -internal object WalletFeatureTogglesModule { - - @Provides - @Singleton - fun provideWalletFeatureToggles(featureTogglesManager: FeatureTogglesManager): WalletFeatureToggles { - return DefaultWalletFeatureToggles(featureTogglesManager = featureTogglesManager) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt index 81c4fd83ef..1e64fc4122 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt @@ -2,7 +2,6 @@ package com.tangem.feature.wallet.di import com.tangem.core.navigation.ReduxNavController import com.tangem.feature.wallet.presentation.router.DefaultWalletRouter -import com.tangem.features.wallet.featuretoggles.WalletFeatureToggles import com.tangem.features.wallet.navigation.WalletRouter import dagger.Module import dagger.Provides @@ -16,10 +15,7 @@ internal object WalletRouterModule { @Provides @ActivityScoped - fun provideWalletRouter( - reduxNavController: ReduxNavController, - walletFeatureToggles: WalletFeatureToggles, - ): WalletRouter { - return DefaultWalletRouter(reduxNavController = reduxNavController, walletFeatureToggles = walletFeatureToggles) + fun provideWalletRouter(reduxNavController: ReduxNavController): WalletRouter { + return DefaultWalletRouter(reduxNavController = reduxNavController) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/featuretoggles/DefaultWalletFeatureToggles.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/featuretoggles/DefaultWalletFeatureToggles.kt deleted file mode 100644 index 628055d566..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/featuretoggles/DefaultWalletFeatureToggles.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.tangem.feature.wallet.featuretoggles - -import com.tangem.core.featuretoggle.manager.FeatureTogglesManager -import com.tangem.features.wallet.featuretoggles.WalletFeatureToggles - -/** - * Default implementation of Wallet feature toggles - * - * @property featureTogglesManager manager for getting information about the availability of feature toggles - * -[REDACTED_AUTHOR] - */ -internal class DefaultWalletFeatureToggles( - private val featureTogglesManager: FeatureTogglesManager, -) : WalletFeatureToggles { - - override val isWalletsScrollingPreviewEnabled: Boolean - get() = featureTogglesManager.isFeatureEnabled(name = "WALLETS_SCROLLING_PREVIEW_ENABLED") -} \ No newline at end of file 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 727545a58c..aed97693c7 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 @@ -1,17 +1,10 @@ package com.tangem.feature.wallet.presentation.common -import androidx.paging.PagingData import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig import com.tangem.core.ui.components.currency.tokenicon.TokenIconState -import com.tangem.core.ui.components.marketprice.MarketPriceBlockState -import com.tangem.core.ui.components.marketprice.PriceChangeState import com.tangem.core.ui.components.marketprice.PriceChangeType -import com.tangem.core.ui.components.transactions.state.TransactionState -import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.extensions.TextReference -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.res.TangemColorPalette import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.wallet.impl.R @@ -19,16 +12,9 @@ import com.tangem.feature.wallet.presentation.common.state.TokenItemState import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState -import com.tangem.feature.wallet.presentation.wallet.state.ActionsBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state.TokenActionButtonConfig -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.components.* -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState.TokensListItemState -import kotlinx.collections.immutable.persistentListOf +import com.tangem.feature.wallet.presentation.wallet.state.model.* import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toPersistentList -import kotlinx.coroutines.flow.MutableStateFlow import java.util.UUID @Suppress("LargeClass") @@ -80,14 +66,6 @@ internal object WalletPreviewData { ) } - val walletListConfig by lazy { - WalletsListConfig( - selectedWalletIndex = 0, - wallets = wallets.values.toPersistentList(), - onWalletChange = {}, - ) - } - val coinIconState get() = TokenIconState.CoinIcon( url = null, @@ -320,146 +298,4 @@ internal object WalletPreviewData { ), ).toImmutableList(), ) - - private val manageButtons by lazy { - persistentListOf( - WalletManageButton.Buy(enabled = true, onClick = {}), - WalletManageButton.Send(enabled = true, onClick = {}), - WalletManageButton.Receive(enabled = true, onClick = {}), - WalletManageButton.Sell(enabled = true, onClick = {}), - WalletManageButton.Swap(enabled = true, onClick = {}), - ) - } - - val multicurrencyWalletScreenState by lazy { - WalletMultiCurrencyState.Content( - onBackClick = {}, - topBarConfig = topBarConfig, - walletsListConfig = walletListConfig, - tokensListState = WalletTokensListState.Content( - persistentListOf( - TokensListItemState.NetworkGroupTitle(id = 0, stringReference("Bitcoin")), - TokensListItemState.Token( - tokenItemVisibleState.copy( - id = "token_1", - titleState = TokenItemState.TitleState.Content(text = "Ethereum"), - cryptoAmountState = TokenItemState.CryptoAmountState.Content("1,89340821 ETH"), - ), - ), - TokensListItemState.Token( - tokenItemVisibleState.copy( - id = "token_2", - titleState = TokenItemState.TitleState.Content(text = "Ethereum"), - cryptoAmountState = TokenItemState.CryptoAmountState.Content("1,89340821 ETH"), - ), - ), - TokensListItemState.Token( - tokenItemVisibleState.copy( - id = "token_3", - titleState = TokenItemState.TitleState.Content(text = "Ethereum"), - cryptoAmountState = TokenItemState.CryptoAmountState.Content("1,89340821 ETH"), - ), - ), - TokensListItemState.Token( - tokenItemVisibleState.copy( - id = "token_4", - titleState = TokenItemState.TitleState.Content(text = "Ethereum"), - cryptoAmountState = TokenItemState.CryptoAmountState.Content("1,89340821 ETH"), - ), - ), - TokensListItemState.NetworkGroupTitle(id = 1, stringReference("Ethereum")), - TokensListItemState.Token( - tokenItemVisibleState.copy( - id = "token_5", - titleState = TokenItemState.TitleState.Content(text = "Ethereum"), - cryptoAmountState = TokenItemState.CryptoAmountState.Content("1,89340821 ETH"), - ), - ), - ), - organizeTokensButton = WalletTokensListState.OrganizeTokensButtonState.Visible(isEnabled = true, {}), - ), - pullToRefreshConfig = WalletPullToRefreshConfig( - isRefreshing = false, - onRefresh = {}, - ), - notifications = persistentListOf( - WalletNotification.Critical.DevCard, - WalletNotification.Informational.MissingAddresses(missingAddressesCount = 0, onGenerateClick = {}), - WalletNotification.Warning.NetworksUnreachable, - ), - bottomSheetConfig = bottomSheet, - onManageTokensClick = {}, - event = consumedEvent(), - isBalanceHidden = false, - ) - } - - val singleWalletScreenState by lazy { - WalletSingleCurrencyState.Content( - onBackClick = {}, - topBarConfig = topBarConfig, - walletsListConfig = walletListConfig, - pullToRefreshConfig = WalletPullToRefreshConfig( - isRefreshing = false, - onRefresh = {}, - ), - notifications = persistentListOf(WalletNotification.Warning.NetworksUnreachable), - buttons = manageButtons, - bottomSheetConfig = bottomSheet, - marketPriceBlockState = MarketPriceBlockState.Content( - currencySymbol = "BTC", - price = "98900.12$", - priceChangeConfig = PriceChangeState.Content( - valueInPercent = "5.16%", - type = PriceChangeType.UP, - ), - ), - txHistoryState = TxHistoryState.Content( - contentItems = MutableStateFlow( - PagingData.from( - listOf( - TxHistoryState.TxHistoryItemState.GroupTitle( - title = "Today", - itemKey = UUID.randomUUID().toString(), - ), - TxHistoryState.TxHistoryItemState.Transaction( - TransactionState.Content( - txHash = UUID.randomUUID().toString(), - amount = "-0.500913 BTC", - time = "8:41", - status = TransactionState.Content.Status.Unconfirmed, - direction = TransactionState.Content.Direction.OUTGOING, - iconRes = com.tangem.core.ui.R.drawable.ic_arrow_up_24, - title = resourceReference(com.tangem.core.ui.R.string.common_transfer), - subtitle = TextReference.Str("33BddS...ga2B"), - timestamp = 0L, - onClick = {}, - ), - ), - TxHistoryState.TxHistoryItemState.GroupTitle( - title = "Yesterday", - itemKey = UUID.randomUUID().toString(), - ), - TxHistoryState.TxHistoryItemState.Transaction( - TransactionState.Content( - txHash = UUID.randomUUID().toString(), - amount = "-0.500913 BTC", - time = "8:41", - status = TransactionState.Content.Status.Confirmed, - direction = TransactionState.Content.Direction.OUTGOING, - iconRes = com.tangem.core.ui.R.drawable.ic_arrow_up_24, - title = resourceReference(com.tangem.core.ui.R.string.common_transfer), - subtitle = TextReference.Str("33BddS...ga2B"), - timestamp = 0L, - onClick = {}, - ), - ), - ), - ), - ), - ), - event = consumedEvent(), - isBalanceHidden = false, - ) - } } \ No newline at end of file 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 fa60d699bf..5a7e3675da 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 @@ -26,17 +26,13 @@ import com.tangem.feature.wallet.presentation.WalletFragment import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensScreen import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensViewModel import com.tangem.feature.wallet.presentation.wallet.ui.WalletScreen -import com.tangem.feature.wallet.presentation.wallet.ui.WalletScreenV2 import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletViewModel -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletViewModelV2 import com.tangem.features.tokendetails.navigation.TokenDetailsRouter -import com.tangem.features.wallet.featuretoggles.WalletFeatureToggles import kotlin.properties.Delegates /** Default implementation of wallet feature router */ internal class DefaultWalletRouter( private val reduxNavController: ReduxNavController, - private val walletFeatureToggles: WalletFeatureToggles, ) : InnerWalletRouter { private var navController: NavHostController by Delegates.notNull() @@ -53,21 +49,12 @@ internal class DefaultWalletRouter( startDestination = WalletRoute.Wallet.route, ) { composable(WalletRoute.Wallet.route) { - if (walletFeatureToggles.isWalletsScrollingPreviewEnabled) { - val viewModel = hiltViewModel().apply { - setWalletRouter(router = this@DefaultWalletRouter) - subscribeToLifecycle(LocalLifecycleOwner.current) - } - - WalletScreenV2(state = viewModel.uiState.collectAsStateWithLifecycle().value) - } else { - val viewModel = hiltViewModel().apply { - router = this@DefaultWalletRouter - } - LocalLifecycleOwner.current.lifecycle.addObserver(viewModel) - - WalletScreen(state = viewModel.uiState) + val viewModel = hiltViewModel().apply { + setWalletRouter(router = this@DefaultWalletRouter) + subscribeToLifecycle(LocalLifecycleOwner.current) } + + WalletScreen(state = viewModel.uiState.collectAsStateWithLifecycle().value) } composable( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/TokenListAnalyticsSender.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/TokenListAnalyticsSender.kt index 8ddb6b3b90..563ab70f1e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/TokenListAnalyticsSender.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/TokenListAnalyticsSender.kt @@ -11,7 +11,7 @@ import com.tangem.domain.tokens.model.TokenList import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent.Basic import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent.MainScreen -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState import com.tangem.feature.wallet.presentation.wallet.utils.ScreenLifecycleProvider import dagger.hilt.android.scopes.ViewModelScoped import java.math.BigDecimal diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/WalletWarningsAnalyticsSender.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/WalletWarningsAnalyticsSender.kt index d8f8fa7457..899dd5a09a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/WalletWarningsAnalyticsSender.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/WalletWarningsAnalyticsSender.kt @@ -3,8 +3,8 @@ package com.tangem.feature.wallet.presentation.wallet.analytics.utils import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.analytics.models.AnalyticsEvent import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent.MainScreen -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState import com.tangem.feature.wallet.presentation.wallet.utils.ScreenLifecycleProvider import dagger.hilt.android.scopes.ViewModelScoped import javax.inject.Inject diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt index 574705c9f4..6b9d320700 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt @@ -13,8 +13,8 @@ import com.tangem.domain.tokens.model.NetworkGroup import com.tangem.domain.tokens.model.TokenList import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase import com.tangem.domain.wallets.usecase.IsNeedToBackupUseCase -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @@ -37,7 +37,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private var readyForRateAppNotification = false - fun create(clickIntents: WalletClickIntentsV2): Flow> { + fun create(clickIntents: WalletClickIntents): Flow> { val userWallet = getSelectedWalletSyncUseCase().fold( ifLeft = { Timber.e("Failed to get selected wallet $it") @@ -88,7 +88,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private fun MutableList.addInformationalNotifications( cardTypesResolver: CardTypesResolver, maybeTokenList: Either, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, ) { addIf( element = WalletNotification.Informational.DemoCard, @@ -100,7 +100,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private fun MutableList.addMissingAddressesNotification( maybeTokenList: Either, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, ) { val currencies = maybeTokenList.getMissingAddressCurrencies() @@ -136,7 +136,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( cardTypesResolver: CardTypesResolver, tokenList: Either, isNeedToBackup: Boolean, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, ) { addIf( element = WalletNotification.Warning.MissingBackup( @@ -173,7 +173,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private fun MutableList.addRateTheAppNotification( isReadyToShowRating: Boolean, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, ) { addIf( element = WalletNotification.RateApp( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetSingleWalletWarningsFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetSingleWalletWarningsFactory.kt index a248e07dbe..edcbb820d8 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetSingleWalletWarningsFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetSingleWalletWarningsFactory.kt @@ -11,8 +11,8 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase import com.tangem.domain.wallets.usecase.IsNeedToBackupUseCase -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @@ -33,7 +33,7 @@ internal class GetSingleWalletWarningsFactory @Inject constructor( private var readyForRateAppNotification = false - fun create(clickIntents: WalletClickIntentsV2): Flow> { + fun create(clickIntents: WalletClickIntents): Flow> { val userWallet = getSelectedWalletSyncUseCase().fold( ifLeft = { Timber.e("Failed to get selected wallet $it") @@ -99,7 +99,7 @@ internal class GetSingleWalletWarningsFactory @Inject constructor( cardTypesResolver: CardTypesResolver, maybePrimaryCurrencyStatus: Either, isNeedToBackup: Boolean, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, ) { val cryptoCurrencyStatus = maybePrimaryCurrencyStatus.fold(ifLeft = { null }, ifRight = { it }) @@ -157,7 +157,7 @@ internal class GetSingleWalletWarningsFactory @Inject constructor( private fun MutableList.addRateTheAppNotification( isReadyToShowRating: Boolean, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, ) { addIf( element = WalletNotification.RateApp( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/WalletAdditionalInfoFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/WalletAdditionalInfoFactory.kt index 40ba99fbde..1f34e460f2 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/WalletAdditionalInfoFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/WalletAdditionalInfoFactory.kt @@ -8,7 +8,7 @@ import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletAdditionalInfo +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletAdditionalInfo import java.math.BigDecimal /** diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletContentLoaderFactory.kt index f897350e0e..cbb2dad87f 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletContentLoaderFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletContentLoaderFactory.kt @@ -3,7 +3,7 @@ package com.tangem.feature.wallet.presentation.wallet.loaders import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.loaders.implementors.* -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import dagger.hilt.android.scopes.ViewModelScoped import javax.inject.Inject @@ -17,7 +17,7 @@ internal class WalletContentLoaderFactory @Inject constructor( fun create( userWallet: UserWallet, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, isRefresh: Boolean = false, ): WalletContentLoader? { return when { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletScreenContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletScreenContentLoader.kt index 4742aea08d..66990ac417 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletScreenContentLoader.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/WalletScreenContentLoader.kt @@ -2,7 +2,7 @@ package com.tangem.feature.wallet.presentation.wallet.loaders import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.coroutines.CoroutineScope @@ -35,7 +35,7 @@ internal class WalletScreenContentLoader @Inject constructor( */ fun load( userWallet: UserWallet, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, isRefresh: Boolean = false, coroutineScope: CoroutineScope, ) { @@ -67,7 +67,7 @@ internal class WalletScreenContentLoader @Inject constructor( private fun loadInternal( userWallet: UserWallet, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, coroutineScope: CoroutineScope, isRefresh: Boolean, ) { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt index 4fba2e23e0..91b6a97137 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt @@ -8,18 +8,18 @@ import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAn import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController import com.tangem.feature.wallet.presentation.wallet.subscribers.MultiWalletTokenListSubscriber import com.tangem.feature.wallet.presentation.wallet.subscribers.MultiWalletWarningsSubscriber import com.tangem.feature.wallet.presentation.wallet.subscribers.WalletConnectNetworksSubscriber import com.tangem.feature.wallet.presentation.wallet.subscribers.WalletSubscriber -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents @Suppress("LongParameterList") internal class MultiWalletContentLoader( private val userWallet: UserWallet, private val stateHolder: WalletStateController, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, private val tokenListAnalyticsSender: TokenListAnalyticsSender, private val walletWarningsAnalyticsSender: WalletWarningsAnalyticsSender, private val walletWithFundsChecker: WalletWithFundsChecker, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt index 59ed8ae50f..a434e73c58 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt @@ -8,8 +8,8 @@ import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAn import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import dagger.hilt.android.scopes.ViewModelScoped import javax.inject.Inject @@ -26,7 +26,7 @@ internal class MultiWalletContentLoaderFactory @Inject constructor( private val walletWarningsAnalyticsSender: WalletWarningsAnalyticsSender, ) { - fun create(userWallet: UserWallet, clickIntents: WalletClickIntentsV2): WalletContentLoader { + fun create(userWallet: UserWallet, clickIntents: WalletClickIntents): WalletContentLoader { return MultiWalletContentLoader( userWallet = userWallet, clickIntents = clickIntents, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoader.kt index e9ed0d42aa..45b3b831a5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoader.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoader.kt @@ -10,14 +10,14 @@ import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetSingleWalletWarningsFactory -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController import com.tangem.feature.wallet.presentation.wallet.subscribers.* -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents @Suppress("LongParameterList") internal class SingleWalletContentLoader( private val userWallet: UserWallet, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, private val isRefresh: Boolean, private val stateHolder: WalletStateController, private val getPrimaryCurrencyStatusUpdatesUseCase: GetPrimaryCurrencyStatusUpdatesUseCase, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoaderFactory.kt index 1dce97e173..c6be994278 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoaderFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletContentLoaderFactory.kt @@ -10,8 +10,8 @@ import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetSingleWalletWarningsFactory -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import dagger.hilt.android.scopes.ViewModelScoped import javax.inject.Inject @@ -30,7 +30,7 @@ internal class SingleWalletContentLoaderFactory @Inject constructor( private val walletWarningsAnalyticsSender: WalletWarningsAnalyticsSender, ) { - fun create(userWallet: UserWallet, clickIntents: WalletClickIntentsV2, isRefresh: Boolean): WalletContentLoader { + fun create(userWallet: UserWallet, clickIntents: WalletClickIntents, isRefresh: Boolean): WalletContentLoader { return SingleWalletContentLoader( userWallet = userWallet, clickIntents = clickIntents, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoader.kt index 8e436284e8..42e26f47f2 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoader.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoader.kt @@ -7,16 +7,16 @@ import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAn import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController import com.tangem.feature.wallet.presentation.wallet.subscribers.MultiWalletWarningsSubscriber import com.tangem.feature.wallet.presentation.wallet.subscribers.SingleWalletWithTokenListSubscriber import com.tangem.feature.wallet.presentation.wallet.subscribers.WalletSubscriber -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents @Suppress("LongParameterList") internal class SingleWalletWithTokenContentLoader( private val userWallet: UserWallet, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, private val stateHolder: WalletStateController, private val tokenListAnalyticsSender: TokenListAnalyticsSender, private val walletWarningsAnalyticsSender: WalletWarningsAnalyticsSender, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoaderFactory.kt index 6afb0a59bf..e92241ad9a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoaderFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/SingleWalletWithTokenContentLoaderFactory.kt @@ -7,8 +7,8 @@ import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAn import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import javax.inject.Inject // TODO: Refactor @@ -23,7 +23,7 @@ internal class SingleWalletWithTokenContentLoaderFactory @Inject constructor( private val walletWarningsAnalyticsSender: WalletWarningsAnalyticsSender, ) { - fun create(userWallet: UserWallet, clickIntents: WalletClickIntentsV2): SingleWalletWithTokenContentLoader { + fun create(userWallet: UserWallet, clickIntents: WalletClickIntents): SingleWalletWithTokenContentLoader { return SingleWalletWithTokenContentLoader( userWallet = userWallet, clickIntents = clickIntents, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoader.kt index 990533203a..63c0590221 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoader.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoader.kt @@ -3,14 +3,14 @@ package com.tangem.feature.wallet.presentation.wallet.loaders.implementors import com.tangem.domain.visa.GetVisaCurrencyUseCase import com.tangem.domain.visa.GetVisaTxHistoryUseCase import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController import com.tangem.feature.wallet.presentation.wallet.subscribers.VisaWalletSubscriber import com.tangem.feature.wallet.presentation.wallet.subscribers.WalletSubscriber -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents internal class VisaWalletContentLoader( private val userWallet: UserWallet, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, private val isRefresh: Boolean, private val stateController: WalletStateController, private val getVisaTxHistoryUseCase: GetVisaTxHistoryUseCase, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoaderFactory.kt index 1d00369116..ff7033b81d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoaderFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/VisaWalletContentLoaderFactory.kt @@ -3,8 +3,8 @@ package com.tangem.feature.wallet.presentation.wallet.loaders.implementors import com.tangem.domain.visa.GetVisaCurrencyUseCase import com.tangem.domain.visa.GetVisaTxHistoryUseCase import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import dagger.hilt.android.scopes.ViewModelScoped import javax.inject.Inject @@ -15,7 +15,7 @@ internal class VisaWalletContentLoaderFactory @Inject constructor( private val getVisaTxHistoryUseCase: GetVisaTxHistoryUseCase, ) { - fun create(userWallet: UserWallet, clickIntents: WalletClickIntentsV2, isRefresh: Boolean): WalletContentLoader { + fun create(userWallet: UserWallet, clickIntents: WalletClickIntents, isRefresh: Boolean): WalletContentLoader { return VisaWalletContentLoader( userWallet = userWallet, clickIntents = clickIntents, 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 deleted file mode 100644 index dd3bbbeee7..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletLockedState.kt +++ /dev/null @@ -1,32 +0,0 @@ -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 - - /** Get selected wallet index */ - fun getSelectedWalletIndex(): Int { - return when (this) { - is WalletMultiCurrencyState.Locked -> walletsListConfig.selectedWalletIndex - is WalletSingleCurrencyState.Locked -> walletsListConfig.selectedWalletIndex - } - } -} \ 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 deleted file mode 100644 index 109b58c2b2..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMultiCurrencyState.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state - -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.event.StateEvent -import com.tangem.core.ui.event.consumedEvent -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 : WalletState.ContentState() { - - /** 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: TangemBottomSheetConfig?, - override val tokensListState: WalletTokensListState, - override val event: StateEvent = consumedEvent(), - override val isBalanceHidden: Boolean, - val isManageTokensAvailable: Boolean = true, - val onManageTokensClick: () -> Unit, - ) : 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 = {}, - override val event: StateEvent = consumedEvent(), - override val isBalanceHidden: Boolean, - ) : WalletMultiCurrencyState(), WalletLockedState { - - override val notifications = persistentListOf( - WalletNotification.UnlockWallets(onUnlockWalletsNotificationClick), - ) - - override val bottomSheetConfig = TangemBottomSheetConfig( - isShow = isBottomSheetShow, - onDismissRequest = onBottomSheetDismiss, - content = WalletBottomSheetConfig.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 deleted file mode 100644 index 4bb761d008..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletSingleCurrencyState.kt +++ /dev/null @@ -1,91 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state - -import androidx.compose.runtime.Immutable -import androidx.paging.PagingData -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.marketprice.MarketPriceBlockState -import com.tangem.core.ui.components.transactions.state.TransactionState -import com.tangem.core.ui.components.transactions.state.TxHistoryState -import com.tangem.core.ui.event.StateEvent -import com.tangem.core.ui.event.consumedEvent -import com.tangem.feature.wallet.presentation.wallet.state.components.* -import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.PersistentList -import kotlinx.collections.immutable.persistentListOf -import kotlinx.coroutines.flow.MutableStateFlow - -/** - * Single currency wallet content state - * -[REDACTED_AUTHOR] - */ -@Immutable -internal sealed class WalletSingleCurrencyState : WalletState.ContentState() { - - /** Manage buttons */ - abstract val buttons: PersistentList - - /** Transactions history state */ - abstract val txHistoryState: TxHistoryState - - 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: TangemBottomSheetConfig?, - override val buttons: PersistentList, - override val txHistoryState: TxHistoryState, - override val event: StateEvent = consumedEvent(), - override val isBalanceHidden: Boolean, - val marketPriceBlockState: MarketPriceBlockState, - ) : WalletSingleCurrencyState() - - data class Locked( - override val onBackClick: () -> Unit, - override val topBarConfig: WalletTopBarConfig, - override val walletsListConfig: WalletsListConfig, - override val pullToRefreshConfig: WalletPullToRefreshConfig, - override val buttons: PersistentList, - override val onUnlockWalletsNotificationClick: () -> Unit, - override val onUnlockClick: () -> Unit, - override val onScanClick: () -> Unit, - override val isBottomSheetShow: Boolean = false, - override val onBottomSheetDismiss: () -> Unit = {}, - override val event: StateEvent = consumedEvent(), - override val isBalanceHidden: Boolean, - val onExploreClick: () -> Unit, - ) : WalletSingleCurrencyState(), WalletLockedState { - - override val notifications = persistentListOf( - WalletNotification.UnlockWallets(onUnlockWalletsNotificationClick), - ) - - override val bottomSheetConfig = TangemBottomSheetConfig( - isShow = isBottomSheetShow, - onDismissRequest = onBottomSheetDismiss, - content = WalletBottomSheetConfig.UnlockWallets( - onUnlockClick = onUnlockClick, - onScanClick = onScanClick, - ), - ) - - override val txHistoryState: TxHistoryState = TxHistoryState.Content( - contentItems = MutableStateFlow( - value = PagingData.from( - data = listOf( - TxHistoryState.TxHistoryItemState.Title(onExploreClick = onExploreClick), - TxHistoryState.TxHistoryItemState.Transaction( - state = TransactionState.Locked(txHash = LOCKED_TX_HASH), - ), - ), - ), - ), - ) - - private companion object { - const val LOCKED_TX_HASH = "LOCKED_TX_HASH" - } - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletState.kt deleted file mode 100644 index a3e9904881..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletState.kt +++ /dev/null @@ -1,101 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state - -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.event.StateEvent -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletPullToRefreshConfig -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTopBarConfig -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig -import kotlinx.collections.immutable.ImmutableList - -/** - * Wallet screen state - * -[REDACTED_AUTHOR] - */ -internal sealed class WalletState { - - /** Lambda be invoked when back button is clicked */ - abstract val onBackClick: () -> Unit - - /** Wallet screen content state */ - sealed class ContentState : WalletState() { - - /** 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: TangemBottomSheetConfig? - - /** State event */ - abstract val event: StateEvent - - /** Whether balance should be hidden */ - abstract val isBalanceHidden: Boolean - - /** - * Util function that allow to make a copy - * - * @param walletsListConfig wallets list config - * @param pullToRefreshConfig pull to refresh config - * @param event state event - */ - fun copySealed( - walletsListConfig: WalletsListConfig = this.walletsListConfig, - pullToRefreshConfig: WalletPullToRefreshConfig = this.pullToRefreshConfig, - event: StateEvent = this.event, - isBalanceHidden: Boolean = this.isBalanceHidden, - ): ContentState { - return when (this) { - is WalletMultiCurrencyState.Content -> { - copy( - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - event = event, - isBalanceHidden = isBalanceHidden, - ) - } - is WalletMultiCurrencyState.Locked -> { - copy( - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - event = event, - isBalanceHidden = isBalanceHidden, - ) - } - is WalletSingleCurrencyState.Content -> { - copy( - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - event = event, - isBalanceHidden = isBalanceHidden, - ) - } - is WalletSingleCurrencyState.Locked -> { - copy( - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig, - event = event, - isBalanceHidden = isBalanceHidden, - ) - } - } - } - } - - /** - * Initial state - * - * @property onBackClick lambda be invoked when back button is clicked - */ - data class Initial(override val onBackClick: () -> Unit) : WalletState() -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/WalletStateController.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt similarity index 78% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/WalletStateController.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt index 0ef36a7f4a..6f86d37b02 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/WalletStateController.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt @@ -1,15 +1,15 @@ -package com.tangem.feature.wallet.presentation.wallet.state2 +package com.tangem.feature.wallet.presentation.wallet.state import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent import com.tangem.core.ui.event.consumedEvent import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTopBarConfig -import com.tangem.feature.wallet.presentation.wallet.state2.model.NOT_INITIALIZED_WALLET_INDEX -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.CloseBottomSheetTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.OpenBottomSheetTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.WalletScreenStateTransformer +import com.tangem.feature.wallet.presentation.wallet.state.model.NOT_INITIALIZED_WALLET_INDEX +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTopBarConfig +import com.tangem.feature.wallet.presentation.wallet.state.transformers.CloseBottomSheetTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.OpenBottomSheetTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.WalletScreenStateTransformer import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTokensListState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTokensListState.kt deleted file mode 100644 index fe750ba585..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTokensListState.kt +++ /dev/null @@ -1,109 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.components - -import com.tangem.core.ui.extensions.TextReference -import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.common.state.TokenItemState -import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.persistentListOf -import javax.annotation.concurrent.Immutable - -/** - * Wallet tokens list state - * -[REDACTED_AUTHOR] - */ -internal sealed class WalletTokensListState { - - /** Empty token list state */ - object Empty : WalletTokensListState() - - /** - * Wallet content token list state - * - * @property items content items - */ - sealed class ContentState( - open val items: ImmutableList, - open val organizeTokensButton: OrganizeTokensButtonState, - ) : WalletTokensListState() - - /** - * Loading content state - * - * @property items content items - */ - data class Loading( - override val items: ImmutableList = persistentListOf(), - ) : ContentState(items = items, organizeTokensButton = OrganizeTokensButtonState.Hidden) - - /** - * Content state - * - * @property items content items - * @property organizeTokensButton represents the state of the 'Organize Tokens' button - */ - data class Content( - override val items: ImmutableList, - override val organizeTokensButton: OrganizeTokensButtonState, - ) : ContentState(items, organizeTokensButton) - - /** Locked content state */ - object Locked : ContentState( - items = persistentListOf( - TokensListItemState.NetworkGroupTitle(id = 42, name = TextReference.Res(id = R.string.main_tokens)), - TokensListItemState.Token(state = TokenItemState.Locked(id = LOCKED_TOKEN_ID)), - ), - organizeTokensButton = OrganizeTokensButtonState.Hidden, - ) - - /** - * Represents the state of the 'Organize Tokens' button. - */ - @Immutable - sealed class OrganizeTokensButtonState { - - /** Represents the state where the 'Organize Tokens' button is hidden. */ - object Hidden : OrganizeTokensButtonState() - - /** - * Represents the state where the 'Organize Tokens' button is visible. - * - * @property isEnabled Indicates if the button is enabled or not. - * @property onClick Callback to be executed when the button is clicked. - */ - data class Visible( - val isEnabled: Boolean, - val onClick: () -> Unit, - ) : OrganizeTokensButtonState() - } - - /** Tokens list item state */ - @Immutable - sealed interface TokensListItemState { - - val id: Any - - /** - * Network group title item - * - * @property name network name - */ - data class NetworkGroupTitle( - override val id: Int, - val name: TextReference, - ) : TokensListItemState - - /** - * Token item - * - * @property state token item state - */ - data class Token(val state: TokenItemState) : TokensListItemState { - override val id: String = state.id - } - } - - private companion object { - const val LOCKED_TOKEN_ID = "Locked#1" - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletsListConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletsListConfig.kt deleted file mode 100644 index 20eac2dec5..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletsListConfig.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.components - -import kotlinx.collections.immutable.ImmutableList - -/** - * Wallets list config - * - * @property selectedWalletIndex selected wallet index - * @property wallets wallets list - * @property onWalletChange lambda be invoked when wallet is swiped - * -[REDACTED_AUTHOR] - */ -internal data class WalletsListConfig( - val selectedWalletIndex: Int, - val wallets: ImmutableList, - val onWalletChange: (Int) -> Unit, -) \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt deleted file mode 100644 index 652a516847..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt +++ /dev/null @@ -1,104 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import com.tangem.core.ui.extensions.TextReference -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.domain.common.util.cardTypesResolver -import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.domain.tokens.model.TokenActionsState -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.common.state.TokenItemState -import com.tangem.feature.wallet.presentation.wallet.state.TokenActionButtonConfig -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.isNullOrZero -import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.toImmutableList - -/** - * Converter from loaded [TokenItemState.Content] to ImmutableList<[TokenActionButtonConfig]> - * - * @property currentWalletProvider current wallet provider - * @property clickIntents screen click intents - */ -internal class TokenActionsProvider( - private val currentWalletProvider: Provider, - private val clickIntents: WalletClickIntents, -) { - - fun provideActions(tokenActions: TokenActionsState): ImmutableList { - return tokenActions.states - .filterIfSingleWithToken() - .mapNotNull { - mapTokenActionState( - actionsState = it, - cryptoCurrencyStatus = tokenActions.cryptoCurrencyStatus, - ) - } - .toImmutableList() - } - - private fun List.filterIfSingleWithToken(): List { - return if (currentWalletProvider().scanResponse.cardTypesResolver.isSingleWalletWithToken()) { - filter { it !is TokenActionsState.ActionState.HideToken } - } else { - this - } - } - - private fun mapTokenActionState( - actionsState: TokenActionsState.ActionState, - cryptoCurrencyStatus: CryptoCurrencyStatus, - ): TokenActionButtonConfig? { - if (actionsState is TokenActionsState.ActionState.Send && cryptoCurrencyStatus.value.amount.isNullOrZero()) { - return null - } - val title: TextReference - val icon: Int - val action: () -> Unit - when (actionsState) { - is TokenActionsState.ActionState.Buy -> { - title = resourceReference(R.string.common_buy) - icon = R.drawable.ic_plus_24 - action = { clickIntents.onBuyClick(cryptoCurrencyStatus) } - } - is TokenActionsState.ActionState.Receive -> { - title = resourceReference(R.string.common_receive) - icon = R.drawable.ic_arrow_down_24 - action = { clickIntents.onReceiveClick(cryptoCurrencyStatus) } - } - is TokenActionsState.ActionState.Sell -> { - title = resourceReference(R.string.common_sell) - icon = R.drawable.ic_currency_24 - action = { clickIntents.onSellClick(cryptoCurrencyStatus) } - } - is TokenActionsState.ActionState.Send -> { - title = resourceReference(R.string.common_send) - icon = R.drawable.ic_arrow_up_24 - action = { clickIntents.onMultiCurrencySendClick(cryptoCurrencyStatus) } - } - is TokenActionsState.ActionState.Swap -> { - title = resourceReference(R.string.swapping_swap_action) - icon = R.drawable.ic_exchange_horizontal_24 - action = { clickIntents.onSwapClick(cryptoCurrencyStatus) } - } - is TokenActionsState.ActionState.CopyAddress -> { - title = resourceReference(R.string.common_copy_address) - icon = R.drawable.ic_copy_24 - action = { clickIntents.onCopyAddressClick(cryptoCurrencyStatus) } - } - is TokenActionsState.ActionState.HideToken -> { - title = resourceReference(R.string.token_details_hide_token) - icon = R.drawable.ic_hide_24 - action = { clickIntents.onHideTokensClick(cryptoCurrencyStatus) } - } - } - return TokenActionButtonConfig( - text = title, - iconResId = icon, - onClick = action, - isWarning = actionsState is TokenActionsState.ActionState.HideToken, - enabled = actionsState.enabled, - ) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenListWithWallet.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenListWithWallet.kt deleted file mode 100644 index bd9060c2ce..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenListWithWallet.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import com.tangem.domain.tokens.model.TokenList -import com.tangem.domain.wallets.models.UserWallet - -data class TokenListWithWallet( - val tokenList: TokenList, - val wallet: UserWallet, -) \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletCryptoCurrencyActionsConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletCryptoCurrencyActionsConverter.kt deleted file mode 100644 index ef2281406c..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletCryptoCurrencyActionsConverter.kt +++ /dev/null @@ -1,76 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import com.tangem.domain.common.util.cardTypesResolver -import com.tangem.domain.tokens.model.TokenActionsState -import com.tangem.domain.wallets.models.UserWallet -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.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.PersistentList -import kotlinx.collections.immutable.toPersistentList - -internal class WalletCryptoCurrencyActionsConverter( - private val currentWalletProvider: Provider, - private val currentStateProvider: Provider, - private val clickIntents: WalletClickIntents, -) : Converter { - - override fun convert(value: TokenActionsState): WalletState { - return when (val state = currentStateProvider()) { - is WalletSingleCurrencyState.Content -> state.copy(buttons = value.mapToManageButtons()) - is WalletSingleCurrencyState.Locked, - is WalletMultiCurrencyState, - is WalletState.Initial, - -> state - } - } - - private fun TokenActionsState.mapToManageButtons(): PersistentList { - return this.states - .filterIfS2C() - .mapNotNull { action -> - when (action) { - is TokenActionsState.ActionState.Buy -> { - WalletManageButton.Buy( - enabled = action.enabled, - onClick = { clickIntents.onBuyClick(cryptoCurrencyStatus) }, - ) - } - is TokenActionsState.ActionState.Receive -> { - WalletManageButton.Receive( - enabled = action.enabled, - onClick = { clickIntents.onReceiveClick(cryptoCurrencyStatus) }, - ) - } - is TokenActionsState.ActionState.Sell -> { - WalletManageButton.Sell( - enabled = action.enabled, - onClick = { clickIntents.onSellClick(cryptoCurrencyStatus) }, - ) - } - is TokenActionsState.ActionState.Send -> { - WalletManageButton.Send( - enabled = action.enabled, - onClick = { clickIntents.onSingleCurrencySendClick(cryptoCurrencyStatus) }, - ) - } - else -> { - null - } - } - } - .toPersistentList() - } - - private fun List.filterIfS2C(): List { - return if (currentWalletProvider().scanResponse.cardTypesResolver.isStart2Coin()) { - filterNot { it is TokenActionsState.ActionState.Buy || it is TokenActionsState.ActionState.Sell } - } else { - this - } - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletDeleteStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletDeleteStateConverter.kt deleted file mode 100644 index 94b4b07979..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletDeleteStateConverter.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state.factory.WalletDeleteStateConverter.DeleteWalletModel -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletsUpdateActionResolver -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.toImmutableList - -/** - * Converter that responds on wallet deleting action. Returns [WalletState] without deleted wallet. - * - * @property currentStateProvider current state provider - */ -internal class WalletDeleteStateConverter( - private val currentStateProvider: Provider, -) : Converter { - - override fun convert(value: DeleteWalletModel): WalletState { - return when (val state = currentStateProvider()) { - is WalletState.ContentState -> { - value.cacheState.copySealed( - walletsListConfig = state.walletsListConfig.copy( - selectedWalletIndex = value.action.selectedWalletIndex, - wallets = state.walletsListConfig.wallets.deleteWallet(id = value.action.deletedWalletId), - ), - pullToRefreshConfig = value.cacheState.pullToRefreshConfig.copy(isRefreshing = false), - ) - } - is WalletState.Initial -> state - } - } - - private fun List.deleteWallet(id: UserWalletId): ImmutableList { - return this - .mapIndexedNotNull { index, currentWallet -> - if (currentWallet.id == id) return@mapIndexedNotNull null - getOrNull(index) ?: return@mapIndexedNotNull null - } - .toImmutableList() - } - - data class DeleteWalletModel( - val cacheState: WalletState.ContentState, - val action: WalletsUpdateActionResolver.Action.DeleteWallet, - ) -} \ No newline at end of file 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 deleted file mode 100644 index 1a1b95cedc..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLoadedTokensListConverter.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import arrow.core.Either -import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.tokens.error.TokenListError -import com.tangem.domain.tokens.model.TokenList -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -import com.tangem.feature.wallet.presentation.wallet.utils.TokenListErrorConverter -import com.tangem.feature.wallet.presentation.wallet.utils.TokenListToWalletStateConverter -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter - -/** - * Converter from loaded [TokenListError] or [TokenList] to [WalletMultiCurrencyState] - * - * @property currentStateProvider current ui state provider - * @property tokenListErrorConverter converter of tokens list - * @param appCurrencyProvider app currency provider - * @param currentWalletProvider current wallet provider - * @param clickIntents screen click intents - * -[REDACTED_AUTHOR] - */ -@Suppress("LongParameterList") -internal class WalletLoadedTokensListConverter( - private val currentStateProvider: Provider, - private val tokenListErrorConverter: TokenListErrorConverter, - appCurrencyProvider: Provider, - currentWalletProvider: Provider, - clickIntents: WalletClickIntents, -) : Converter, WalletState> { - - private val tokenListStateConverter = TokenListToWalletStateConverter( - currentStateProvider = currentStateProvider, - currentWalletProvider = currentWalletProvider, - appCurrencyProvider = appCurrencyProvider, - clickIntents = clickIntents, - ) - - override fun convert(value: Either): WalletState { - return value.fold( - ifLeft = tokenListErrorConverter::convert, - ifRight = tokenListStateConverter::convert, - ) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLockedConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLockedConverter.kt deleted file mode 100644 index ac45532c00..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletLockedConverter.kt +++ /dev/null @@ -1,80 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -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.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletPullToRefreshConfig -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTopBarConfig -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.PersistentList -import kotlinx.collections.immutable.toPersistentList - -internal class WalletLockedConverter( - private val currentStateProvider: Provider, - private val clickIntents: WalletClickIntents, -) : Converter { - - override fun convert(value: Unit): WalletState { - return when (val state = currentStateProvider()) { - is WalletMultiCurrencyState.Content -> state.toMultiCurrencyLockedState() - is WalletSingleCurrencyState.Content -> state.toSingleCurrencyLockedState() - is WalletMultiCurrencyState.Locked, - is WalletSingleCurrencyState.Locked, - is WalletState.Initial, - -> state - } - } - - private fun WalletMultiCurrencyState.Content.toMultiCurrencyLockedState(): WalletState { - return WalletMultiCurrencyState.Locked( - onBackClick = onBackClick, - topBarConfig = topBarConfig.updateCallback(), - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig.stopRefreshing(), - onUnlockWalletsNotificationClick = clickIntents::onUnlockWalletNotificationClick, - onUnlockClick = clickIntents::onUnlockWalletClick, - onScanClick = clickIntents::onScanToUnlockWalletClick, - isBalanceHidden = isBalanceHidden, - ) - } - - private fun WalletSingleCurrencyState.Content.toSingleCurrencyLockedState(): WalletState { - return WalletSingleCurrencyState.Locked( - onBackClick = onBackClick, - topBarConfig = topBarConfig.updateCallback(), - walletsListConfig = walletsListConfig, - pullToRefreshConfig = pullToRefreshConfig.stopRefreshing(), - buttons = buttons.disableButtons(), - onUnlockWalletsNotificationClick = clickIntents::onUnlockWalletNotificationClick, - onUnlockClick = clickIntents::onUnlockWalletClick, - onScanClick = clickIntents::onScanToUnlockWalletClick, - onExploreClick = clickIntents::onExploreClick, - isBalanceHidden = isBalanceHidden, - ) - } - - private fun WalletTopBarConfig.updateCallback(): WalletTopBarConfig { - return copy(onDetailsClick = clickIntents::onUnlockWalletNotificationClick) - } - - private fun WalletPullToRefreshConfig.stopRefreshing(): WalletPullToRefreshConfig { - return copy(isRefreshing = false) - } - - private fun PersistentList.disableButtons(): PersistentList { - return this - .map { button -> - when (button) { - is WalletManageButton.Buy -> button.copy(enabled = false) - is WalletManageButton.Sell -> button.copy(enabled = false) - is WalletManageButton.Send -> button.copy(enabled = false) - is WalletManageButton.Swap -> button.copy(enabled = false) - is WalletManageButton.Receive -> button.copy(enabled = false) - } - } - .toPersistentList() - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletRefreshStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletRefreshStateConverter.kt deleted file mode 100644 index d0e92be7ec..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletRefreshStateConverter.kt +++ /dev/null @@ -1,115 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -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.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletPullToRefreshConfig -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.PersistentList -import kotlinx.collections.immutable.mutate - -internal class WalletRefreshStateConverter( - private val currentStateProvider: Provider, -) : Converter { - - override fun convert(value: Boolean): WalletState { - val state = currentStateProvider() - val contentState = state as? WalletState.ContentState ?: return state - - return if (value) { - contentState.getRefreshingState() - } else { - contentState.getRefreshedState() - } - } - - private fun WalletState.ContentState.getRefreshingState(): WalletState { - return when (this) { - is WalletMultiCurrencyState.Content -> getRefreshingState() - is WalletSingleCurrencyState.Content -> getRefreshingState() - is WalletMultiCurrencyState.Locked, - is WalletSingleCurrencyState.Locked, - -> this - } - } - - private fun WalletState.ContentState.getRefreshedState(): WalletState { - return when (this) { - is WalletMultiCurrencyState.Content -> getRefreshedState() - is WalletSingleCurrencyState.Content -> getRefreshedState() - is WalletMultiCurrencyState.Locked, - is WalletSingleCurrencyState.Locked, - -> this - } - } - - private fun WalletMultiCurrencyState.Content.getRefreshingState(): WalletMultiCurrencyState { - return copy( - pullToRefreshConfig = updatePullToRefreshConfig(isRefreshing = true), - tokensListState = updateTokenListState(isRefreshing = true), - ) - } - - private fun WalletSingleCurrencyState.Content.getRefreshingState(): WalletSingleCurrencyState { - return copy( - pullToRefreshConfig = updatePullToRefreshConfig(isRefreshing = true), - buttons = updateButtons(isRefreshing = true), - ) - } - - private fun WalletMultiCurrencyState.Content.getRefreshedState(): WalletMultiCurrencyState { - return copy( - pullToRefreshConfig = updatePullToRefreshConfig(isRefreshing = false), - tokensListState = updateTokenListState(isRefreshing = false), - ) - } - - private fun WalletSingleCurrencyState.Content.getRefreshedState(): WalletSingleCurrencyState { - return copy( - pullToRefreshConfig = updatePullToRefreshConfig(isRefreshing = false), - buttons = updateButtons(isRefreshing = false), - ) - } - - private fun WalletMultiCurrencyState.updateTokenListState(isRefreshing: Boolean): WalletTokensListState { - return when (val listState = tokensListState) { - is WalletTokensListState.Content -> { - when (listState.organizeTokensButton) { - is WalletTokensListState.OrganizeTokensButtonState.Hidden -> listState - is WalletTokensListState.OrganizeTokensButtonState.Visible -> listState.copy( - organizeTokensButton = listState.organizeTokensButton.copy( - isEnabled = !isRefreshing, - ), - ) - } - } - is WalletTokensListState.Locked, - is WalletTokensListState.Loading, - is WalletTokensListState.Empty, - -> listState - } - } - - private fun WalletSingleCurrencyState.updateButtons(isRefreshing: Boolean): PersistentList { - val isButtonsEnabled = !isRefreshing - - return buttons.mutate { - it.mapNotNull { button -> - when (button) { - is WalletManageButton.Buy -> button.copy(enabled = isButtonsEnabled) - is WalletManageButton.Send -> button.copy(enabled = isButtonsEnabled) - is WalletManageButton.Sell -> button.copy(enabled = isButtonsEnabled) - is WalletManageButton.Receive -> button - is WalletManageButton.Swap -> null - } - } - } - } - - private fun WalletState.ContentState.updatePullToRefreshConfig(isRefreshing: Boolean): WalletPullToRefreshConfig { - return pullToRefreshConfig.copy(isRefreshing = isRefreshing) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletRenameStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletRenameStateConverter.kt deleted file mode 100644 index aec0b673f7..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletRenameStateConverter.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.toImmutableList - -internal class WalletRenameStateConverter( - private val currentStateProvider: Provider, -) : Converter { - - override fun convert(value: String): WalletState { - return when (val state = currentStateProvider()) { - is WalletState.ContentState -> { - state.copySealed( - walletsListConfig = state.walletsListConfig.renameSelectedWallet(name = value), - ) - } - is WalletState.Initial -> state - } - } - - private fun WalletsListConfig.renameSelectedWallet(name: String): WalletsListConfig { - return copy( - wallets = wallets - .mapIndexed { index, walletCard -> - if (index == selectedWalletIndex) walletCard.copySealed(title = name) else walletCard - } - .toImmutableList(), - ) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSingleCurrencyLoadedBalanceConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSingleCurrencyLoadedBalanceConverter.kt deleted file mode 100644 index 75ce18f490..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSingleCurrencyLoadedBalanceConverter.kt +++ /dev/null @@ -1,181 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import arrow.core.Either -import com.tangem.core.ui.components.marketprice.MarketPriceBlockState -import com.tangem.core.ui.components.marketprice.PriceChangeState -import com.tangem.core.ui.components.marketprice.PriceChangeType -import com.tangem.core.ui.utils.BigDecimalFormatter -import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.tokens.error.CurrencyStatusError -import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.domain.WalletAdditionalInfoFactory -import com.tangem.feature.wallet.presentation.wallet.domain.getCardsCount -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.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig -import com.tangem.feature.wallet.presentation.wallet.utils.CurrencyStatusErrorConverter -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.toPersistentList -import java.math.BigDecimal - -internal class WalletSingleCurrencyLoadedBalanceConverter( - private val currentStateProvider: Provider, - private val appCurrencyProvider: Provider, - private val currentWalletProvider: Provider, - private val currencyStatusErrorConverter: CurrencyStatusErrorConverter, -) : Converter, WalletState> { - - override fun convert(value: Either): WalletState { - return value.fold( - ifLeft = currencyStatusErrorConverter::convert, - ifRight = ::convertContent, - ) - } - - private fun convertContent(status: CryptoCurrencyStatus): WalletState { - return when (val state = currentStateProvider()) { - is WalletSingleCurrencyState.Content -> { - val currencyName = state.marketPriceBlockState.currencySymbol - - state.copy( - walletsListConfig = getUpdatedSelectedWallet(status = status.value, state = state), - marketPriceBlockState = getMarketPriceState(status = status.value, currencySymbol = currencyName), - ) - } - is WalletMultiCurrencyState.Content, - is WalletMultiCurrencyState.Locked, - is WalletSingleCurrencyState.Locked, - is WalletState.Initial, - -> state - } - } - - private fun getMarketPriceState( - status: CryptoCurrencyStatus.Status, - currencySymbol: String, - ): MarketPriceBlockState { - return when (status) { - is CryptoCurrencyStatus.Loaded, - is CryptoCurrencyStatus.NoAmount, - -> status.toContentConfig(currencySymbol) - is CryptoCurrencyStatus.NoAccount -> { - if (status.fiatRate == null) { - MarketPriceBlockState.Error(currencySymbol) - } else { - status.toContentConfig(currencySymbol) - } - } - is CryptoCurrencyStatus.Loading -> MarketPriceBlockState.Loading(currencySymbol) - is CryptoCurrencyStatus.Custom, - is CryptoCurrencyStatus.MissedDerivation, - is CryptoCurrencyStatus.Unreachable, - is CryptoCurrencyStatus.NoQuote, - -> MarketPriceBlockState.Error(currencySymbol) - } - } - - private fun getUpdatedSelectedWallet( - status: CryptoCurrencyStatus.Status, - state: WalletSingleCurrencyState, - ): WalletsListConfig { - val selectedWallet = state.walletsListConfig.wallets[state.walletsListConfig.selectedWalletIndex] - - val updatedWallet = when (status) { - is CryptoCurrencyStatus.NoQuote, - is CryptoCurrencyStatus.Loaded, - is CryptoCurrencyStatus.NoAccount, - is CryptoCurrencyStatus.NoAmount, - -> { - WalletCardState.Content( - id = selectedWallet.id, - title = selectedWallet.title, - additionalInfo = WalletAdditionalInfoFactory.resolve( - wallet = currentWalletProvider(), - currencyAmount = status.amount, - ), - imageResId = selectedWallet.imageResId, - onRenameClick = selectedWallet.onRenameClick, - onDeleteClick = selectedWallet.onDeleteClick, - balance = formatFiatAmount(status = status, appCurrency = appCurrencyProvider()), - cardCount = currentWalletProvider().getCardsCount(), - ) - } - is CryptoCurrencyStatus.Loading -> { - WalletCardState.Loading( - id = selectedWallet.id, - title = selectedWallet.title, - imageResId = selectedWallet.imageResId, - onRenameClick = selectedWallet.onRenameClick, - onDeleteClick = selectedWallet.onDeleteClick, - ) - } - is CryptoCurrencyStatus.MissedDerivation, - is CryptoCurrencyStatus.Custom, - is CryptoCurrencyStatus.Unreachable, - -> { - WalletCardState.Error( - id = selectedWallet.id, - title = selectedWallet.title, - imageResId = selectedWallet.imageResId, - onRenameClick = selectedWallet.onRenameClick, - onDeleteClick = selectedWallet.onDeleteClick, - ) - } - } - - return state.walletsListConfig.copy( - wallets = state.walletsListConfig.wallets.toPersistentList() - .set(index = state.walletsListConfig.selectedWalletIndex, element = updatedWallet), - ) - } - - private fun CryptoCurrencyStatus.Status.toContentConfig(currencySymbol: String): MarketPriceBlockState.Content { - return MarketPriceBlockState.Content( - currencySymbol = currencySymbol, - price = formatPrice(status = this, appCurrency = appCurrencyProvider()), - priceChangeConfig = PriceChangeState.Content( - valueInPercent = formatPriceChange(status = this), - type = getPriceChangeType(status = this), - ), - ) - } - - private fun getPriceChangeType(status: CryptoCurrencyStatus.Status): PriceChangeType { - val priceChange = status.priceChange ?: return PriceChangeType.DOWN - - return if (priceChange > BigDecimal.ZERO) PriceChangeType.UP else PriceChangeType.DOWN - } - - private fun formatPriceChange(status: CryptoCurrencyStatus.Status): String { - val priceChange = status.priceChange ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN - - return BigDecimalFormatter.formatPercent( - percent = priceChange, - useAbsoluteValue = true, - ) - } - - private fun formatPrice(status: CryptoCurrencyStatus.Status, appCurrency: AppCurrency): String { - val fiatRate = status.fiatRate ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN - - return BigDecimalFormatter.formatFiatAmount( - fiatAmount = fiatRate, - fiatCurrencyCode = appCurrency.code, - fiatCurrencySymbol = appCurrency.symbol, - ) - } - - private fun formatFiatAmount(status: CryptoCurrencyStatus.Status, appCurrency: AppCurrency): String { - val fiatAmount = status.fiatAmount ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN - - return BigDecimalFormatter.formatFiatAmount( - fiatAmount = fiatAmount, - fiatCurrencyCode = appCurrency.code, - fiatCurrencySymbol = appCurrency.symbol, - ) - } -} \ No newline at end of file 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 deleted file mode 100644 index 1c3c556b1f..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt +++ /dev/null @@ -1,157 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import androidx.annotation.DrawableRes -import com.tangem.core.ui.components.marketprice.MarketPriceBlockState -import com.tangem.core.ui.components.transactions.state.TxHistoryState -import com.tangem.domain.common.util.cardTypesResolver -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.models.UserWalletId -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.WalletMultiCurrencyState -import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -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.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.PersistentList -import kotlinx.collections.immutable.persistentListOf -import kotlinx.collections.immutable.toImmutableList -import kotlinx.coroutines.flow.MutableStateFlow - -/** - * Converter from loaded list of [UserWallet] to skeleton state of screen [WalletState.ContentState] - * - * @property currentStateProvider current ui state provider - * @property clickIntents screen click intents - * -[REDACTED_AUTHOR] - */ -internal class WalletSkeletonStateConverter( - private val currentStateProvider: Provider, - private val isBalanceHiddenProvider: Provider, - private val clickIntents: WalletClickIntents, -) : Converter { - - override fun convert(value: SkeletonModel): WalletState.ContentState { - val selectedWallet = value.wallets[value.selectedWalletIndex] - - val isSingleWalletWithToken = !selectedWallet.isMultiCurrency && - selectedWallet.scanResponse.walletData?.token != null - return if (selectedWallet.isMultiCurrency || isSingleWalletWithToken) { - createMultiCurrencyState(value = value) - } else { - createSingleCurrencyState(value = value, currencyName = selectedWallet.getPrimaryCurrencyName()) - } - } - - private fun createMultiCurrencyState(value: SkeletonModel): WalletMultiCurrencyState { - return WalletMultiCurrencyState.Content( - onBackClick = clickIntents::onBackClick, - topBarConfig = createTopBarConfig(), - walletsListConfig = createWalletsListConfig(value), - pullToRefreshConfig = createPullToRefreshConfig(), - tokensListState = WalletTokensListState.Loading(), - notifications = persistentListOf(), - bottomSheetConfig = null, - onManageTokensClick = clickIntents::onManageTokensClick, - isBalanceHidden = isBalanceHiddenProvider(), - ) - } - - private fun createSingleCurrencyState(value: SkeletonModel, currencyName: String): WalletSingleCurrencyState { - return WalletSingleCurrencyState.Content( - onBackClick = clickIntents::onBackClick, - topBarConfig = createTopBarConfig(), - walletsListConfig = createWalletsListConfig(value), - pullToRefreshConfig = createPullToRefreshConfig(), - notifications = persistentListOf(), - bottomSheetConfig = null, - buttons = createButtons(), - marketPriceBlockState = MarketPriceBlockState.Loading(currencySymbol = currencyName), - txHistoryState = TxHistoryState.Content( - contentItems = MutableStateFlow( - value = TxHistoryState.getDefaultLoadingTransactions(clickIntents::onExploreClick), - ), - ), - isBalanceHidden = isBalanceHiddenProvider(), - ) - } - - private fun UserWallet.getPrimaryCurrencyName(): String { - return scanResponse.cardTypesResolver.getBlockchain().currency - } - - private fun createTopBarConfig(): WalletTopBarConfig { - return WalletTopBarConfig(onDetailsClick = clickIntents::onDetailsClick) - } - - private fun createWalletsListConfig(value: SkeletonModel): WalletsListConfig { - return WalletsListConfig( - selectedWalletIndex = value.selectedWalletIndex, - wallets = value.wallets.map(::createWalletCardState).toImmutableList(), - onWalletChange = clickIntents::onWalletChange, - ) - } - - /** - * Create wallet card state by [wallet]. - * If current wallet card state is initialized, then method returns it. - * Otherwise, returns loading wallet card state. - */ - private fun createWalletCardState(wallet: UserWallet): WalletCardState { - return currentStateProvider().getInitializedWalletCardState(wallet.walletId) ?: wallet.mapToWalletCardState() - } - - private fun WalletState.getInitializedWalletCardState(walledId: UserWalletId): WalletCardState? { - return (this as? WalletState.ContentState)?.walletsListConfig?.wallets?.firstOrNull { it.id == walledId } - } - - private fun UserWallet.mapToWalletCardState(): WalletCardState { - return if (isLocked) mapToLockedWalletCardState() else mapToLoadingWalletCardState() - } - - private fun UserWallet.mapToLockedWalletCardState(): WalletCardState { - return WalletCardState.LockedContent( - id = walletId, - title = name, - additionalInfo = WalletAdditionalInfoFactory.resolve(wallet = this), - imageResId = createImageResId(), - onRenameClick = clickIntents::onRenameClick, - onDeleteClick = clickIntents::onDeleteBeforeConfirmationClick, - ) - } - - private fun UserWallet.mapToLoadingWalletCardState(): WalletCardState { - return WalletCardState.Loading( - id = walletId, - title = name, - additionalInfo = if (isMultiCurrency) WalletAdditionalInfoFactory.resolve(wallet = this) else null, - imageResId = createImageResId(), - onRenameClick = clickIntents::onRenameClick, - onDeleteClick = clickIntents::onDeleteBeforeConfirmationClick, - ) - } - - @DrawableRes - private fun UserWallet.createImageResId(): Int? { - return WalletImageResolver.resolve(userWallet = this) - } - - private fun createPullToRefreshConfig(): WalletPullToRefreshConfig { - return WalletPullToRefreshConfig(isRefreshing = false, onRefresh = clickIntents::onRefreshSwipe) - } - - private fun createButtons(): PersistentList { - return persistentListOf( - WalletManageButton.Buy(enabled = false, onClick = {}), - WalletManageButton.Send(enabled = false, onClick = {}), - WalletManageButton.Receive(enabled = false, onClick = {}), - WalletManageButton.Sell(enabled = false, onClick = {}), - ) - } - - 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 deleted file mode 100644 index e803ae15cd..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt +++ /dev/null @@ -1,288 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import androidx.paging.PagingData -import arrow.core.Either -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent -import com.tangem.core.ui.event.consumedEvent -import com.tangem.core.ui.event.triggeredEvent -import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.common.CardTypesResolver -import com.tangem.domain.tokens.error.CurrencyStatusError -import com.tangem.domain.tokens.error.TokenListError -import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.domain.tokens.model.TokenActionsState -import com.tangem.domain.txhistory.models.TxHistoryItem -import com.tangem.domain.txhistory.models.TxHistoryListError -import com.tangem.domain.txhistory.models.TxHistoryStateError -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state.* -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -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.utils.CurrencyStatusErrorConverter -import com.tangem.feature.wallet.presentation.wallet.utils.HiddenStateConverter -import com.tangem.feature.wallet.presentation.wallet.utils.TokenListErrorConverter -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletsUpdateActionResolver -import com.tangem.utils.Provider -import kotlinx.collections.immutable.ImmutableList -import kotlinx.coroutines.flow.Flow - -/** - * Main factory for creating [WalletState] - * - * @property currentStateProvider current ui state provider - * @property currentCardTypeResolverProvider current card type resolver - * @property currentWalletProvider current wallet - * @property appCurrencyProvider app currency provider - * @property clickIntents screen click intents - */ -@Suppress("TooManyFunctions") -internal class WalletStateFactory( - private val currentStateProvider: Provider, - private val currentCardTypeResolverProvider: Provider, - private val currentWalletProvider: Provider, - private val appCurrencyProvider: Provider, - private val isBalanceHiddenProvider: Provider, - private val clickIntents: WalletClickIntents, -) { - - private val tokenActionsProvider by lazy { TokenActionsProvider(currentWalletProvider, clickIntents) } - - private val skeletonConverter by lazy { - WalletSkeletonStateConverter( - currentStateProvider = currentStateProvider, - isBalanceHiddenProvider = isBalanceHiddenProvider, - clickIntents = clickIntents, - ) - } - - private val walletsUnlockStateConverter by lazy { WalletsUnlockStateConverter(currentStateProvider, clickIntents) } - - private val walletRenameStateConverter by lazy { WalletRenameStateConverter(currentStateProvider) } - - private val walletDeleteStateConverter by lazy { WalletDeleteStateConverter(currentStateProvider) } - - private val hiddenStateConverter by lazy { HiddenStateConverter(currentStateProvider) } - - private val walletUpdateCardCountConverter by lazy { - WalletUpdateCardCountConverter( - currentStateProvider, - currentWalletProvider, - ) - } - - private val tokenListErrorConverter by lazy { - TokenListErrorConverter(currentStateProvider) - } - private val currencyStatusErrorConverter by lazy { - CurrencyStatusErrorConverter(currentStateProvider) - } - private val loadedTokensListConverter by lazy { - WalletLoadedTokensListConverter( - currentStateProvider = currentStateProvider, - tokenListErrorConverter = tokenListErrorConverter, - appCurrencyProvider = appCurrencyProvider, - currentWalletProvider = currentWalletProvider, - clickIntents = clickIntents, - ) - } - - private val loadingTransactionsStateConverter by lazy { - WalletLoadingTxHistoryConverter( - currentStateProvider = currentStateProvider, - currentCardTypeResolverProvider = currentCardTypeResolverProvider, - clickIntents = clickIntents, - ) - } - - private val loadedTxHistoryConverter by lazy { - WalletLoadedTxHistoryConverter( - currentStateProvider = currentStateProvider, - currentCardTypeResolverProvider = currentCardTypeResolverProvider, - clickIntents = clickIntents, - ) - } - - private val singleCurrencyLoadedBalanceConverter by lazy { - WalletSingleCurrencyLoadedBalanceConverter( - currentStateProvider = currentStateProvider, - appCurrencyProvider = appCurrencyProvider, - currentWalletProvider = currentWalletProvider, - currencyStatusErrorConverter = currencyStatusErrorConverter, - ) - } - - private val lockedConverter by lazy { - WalletLockedConverter( - currentStateProvider = currentStateProvider, - clickIntents = clickIntents, - ) - } - - private val refreshStateConverter by lazy { - WalletRefreshStateConverter(currentStateProvider) - } - - private val cryptoCurrencyActionsConverter by lazy { - WalletCryptoCurrencyActionsConverter( - currentWalletProvider = currentWalletProvider, - currentStateProvider = currentStateProvider, - clickIntents = clickIntents, - ) - } - - fun getInitialState(): WalletState = WalletState.Initial(onBackClick = clickIntents::onBackClick) - - fun getSkeletonState(wallets: List, selectedWalletIndex: Int): WalletState { - return skeletonConverter.convert( - value = WalletSkeletonStateConverter.SkeletonModel( - wallets = wallets, - selectedWalletIndex = selectedWalletIndex, - ), - ) - } - - fun getStateWithUpdatedWalletName(name: String): WalletState = walletRenameStateConverter.convert(value = name) - - fun getStateWithUpdatedWalletCardCount(): WalletState = walletUpdateCardCountConverter.convert(Unit) - - fun getUnlockedState(action: WalletsUpdateActionResolver.Action.UnlockWallet): WalletState { - return walletsUnlockStateConverter.convert(value = action) - } - - fun getStateWithoutDeletedWallet( - cacheState: WalletState.ContentState, - action: WalletsUpdateActionResolver.Action.DeleteWallet, - ): WalletState { - return walletDeleteStateConverter.convert( - value = WalletDeleteStateConverter.DeleteWalletModel(cacheState = cacheState, action = action), - ) - } - - fun getStateByTokensList(maybeTokenListWithWallet: Either): WalletState { - return loadedTokensListConverter.convert(maybeTokenListWithWallet) - } - - fun getStateByTokenListError(error: TokenListError): WalletState { - return tokenListErrorConverter.convert(error) - } - - fun getStateByNotifications(notifications: ImmutableList): WalletState { - return when (val state = currentStateProvider()) { - is WalletMultiCurrencyState.Content -> state.copy(notifications = notifications) - is WalletSingleCurrencyState.Content -> state.copy(notifications = notifications) - else -> state - } - } - - fun getRefreshingState(): WalletState = refreshStateConverter.convert(value = true) - - fun getRefreshedState(): WalletState = refreshStateConverter.convert(value = false) - - fun getStateWithOpenWalletBottomSheet(content: TangemBottomSheetConfigContent): WalletState { - return when (val state = currentStateProvider() as WalletState.ContentState) { - is WalletMultiCurrencyState.Content -> state.copy( - bottomSheetConfig = TangemBottomSheetConfig( - isShow = true, - onDismissRequest = clickIntents::onDismissBottomSheet, - content = content, - ), - ) - is WalletMultiCurrencyState.Locked -> state.copy( - isBottomSheetShow = true, - onBottomSheetDismiss = clickIntents::onDismissBottomSheet, - ) - is WalletSingleCurrencyState.Content -> state.copy( - bottomSheetConfig = TangemBottomSheetConfig( - isShow = true, - onDismissRequest = clickIntents::onDismissBottomSheet, - content = content, - ), - ) - is WalletSingleCurrencyState.Locked -> state.copy( - isBottomSheetShow = true, - onBottomSheetDismiss = clickIntents::onDismissBottomSheet, - ) - } - } - - fun getStateWithClosedBottomSheet(): WalletState { - return when (val state = currentStateProvider() as WalletState.ContentState) { - is WalletMultiCurrencyState.Content -> state.copy( - bottomSheetConfig = state.bottomSheetConfig?.copy(isShow = false), - ) - is WalletMultiCurrencyState.Locked -> state.copy(isBottomSheetShow = false) - is WalletSingleCurrencyState.Content -> state.copy( - bottomSheetConfig = state.bottomSheetConfig?.copy(isShow = false), - ) - is WalletSingleCurrencyState.Locked -> state.copy(isBottomSheetShow = false) - } - } - - fun getStateWithTokenActionBottomSheet(tokenActions: TokenActionsState): WalletState { - return getStateWithOpenWalletBottomSheet( - content = ActionsBottomSheetConfig(actions = tokenActionsProvider.provideActions(tokenActions)), - ) - } - - fun getLoadingTxHistoryState( - itemsCountEither: Either, - pendingTransactions: Set, - ): WalletState { - return loadingTransactionsStateConverter.convert( - WalletLoadingTxHistoryConverter.WalletLoadingTxHistoryModel( - historyLoadingState = itemsCountEither, - pendingTransactions = pendingTransactions, - ), - ) - } - - fun getLoadedTxHistoryState( - txHistoryEither: Either>>, - ): WalletState { - return loadedTxHistoryConverter.convert(txHistoryEither) - } - - fun getLockedState(): WalletState = lockedConverter.convert(Unit) - - fun getSingleCurrencyLoadedBalanceState( - maybeCryptoCurrencyStatus: Either, - ): WalletState { - return singleCurrencyLoadedBalanceConverter.convert(maybeCryptoCurrencyStatus) - } - - fun getSingleCurrencyManageButtonsState(actionsState: TokenActionsState): WalletState { - return cryptoCurrencyActionsConverter.convert(value = actionsState) - } - - fun getStateByCurrencyStatusError(error: CurrencyStatusError): WalletState { - return currencyStatusErrorConverter.convert(error) - } - - fun getHiddenBalanceState(isBalanceHidden: Boolean): WalletState { - return hiddenStateConverter.convert(isBalanceHidden) - } - - fun getStateAndTriggerEvent( - state: WalletState, - event: WalletEvent, - setUiState: (WalletState) -> Unit, - ): WalletState { - return when (state) { - is WalletState.ContentState -> state.copySealed( - event = triggeredEvent( - data = event, - onConsume = { - val currentState = currentStateProvider() - if (currentState is WalletState.ContentState) { - setUiState(currentState.copySealed(event = consumedEvent())) - } - }, - ), - ) - is WalletState.Initial -> state - } - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletUpdateCardCountConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletUpdateCardCountConverter.kt deleted file mode 100644 index 3092c454c6..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletUpdateCardCountConverter.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import com.tangem.domain.wallets.models.UserWallet -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.domain.getCardsCount -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.toImmutableList - -internal class WalletUpdateCardCountConverter( - private val currentStateProvider: Provider, - private val currentWalletProvider: Provider, -) : Converter { - - override fun convert(value: Unit): WalletState { - return when (val state = currentStateProvider()) { - is WalletState.ContentState -> { - state.copySealed( - walletsListConfig = state.walletsListConfig.refreshCardCount(), - ) - } - is WalletState.Initial -> state - } - } - - private fun WalletsListConfig.refreshCardCount(): WalletsListConfig { - val selectedWallet = currentWalletProvider() - return copy( - wallets = wallets - .mapIndexed { index, walletCard -> - if (index == selectedWalletIndex) { - when (walletCard) { - is WalletCardState.Content -> walletCard.copy( - additionalInfo = WalletAdditionalInfoFactory.resolve(wallet = selectedWallet), - imageResId = WalletImageResolver.resolve(userWallet = selectedWallet), - cardCount = selectedWallet.getCardsCount(), - ) - else -> walletCard - } - } else { - walletCard - } - } - .toImmutableList(), - ) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletsUnlockStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletsUnlockStateConverter.kt deleted file mode 100644 index 4dc8b76098..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletsUnlockStateConverter.kt +++ /dev/null @@ -1,132 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory - -import com.tangem.core.ui.components.marketprice.MarketPriceBlockState -import com.tangem.core.ui.components.transactions.state.TxHistoryState -import com.tangem.domain.common.util.cardTypesResolver -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.domain.WalletImageResolver -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.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.* -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -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.MutableStateFlow -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletsUpdateActionResolver.Action.UnlockWallet as UnlockWalletAction - -/** - * Converter that responds on wallets unlocking action. Returns [WalletState] with unlocked wallets. - * - * @property currentStateProvider current ui state provider - * @property clickIntents screen click intents - * -[REDACTED_AUTHOR] - */ -internal class WalletsUnlockStateConverter( - private val currentStateProvider: Provider, - private val clickIntents: WalletClickIntents, -) : Converter { - - override fun convert(value: UnlockWalletAction): WalletState { - return when (val state = currentStateProvider()) { - is WalletMultiCurrencyState.Locked -> state.toMultiCurrencyContentState(value) - is WalletSingleCurrencyState.Locked -> state.toSingleCurrencyContentState(value) - is WalletState.Initial, - is WalletMultiCurrencyState.Content, - is WalletSingleCurrencyState.Content, - -> state - } - } - - private fun WalletMultiCurrencyState.Locked.toMultiCurrencyContentState(action: UnlockWalletAction): WalletState { - return WalletMultiCurrencyState.Content( - onBackClick = onBackClick, - topBarConfig = topBarConfig.updateCallback(), - walletsListConfig = walletsListConfig.unlockWallets(action), - pullToRefreshConfig = pullToRefreshConfig.stopRefreshing(), - tokensListState = WalletTokensListState.Loading(), - notifications = persistentListOf(), - bottomSheetConfig = null, - onManageTokensClick = clickIntents::onManageTokensClick, - isBalanceHidden = isBalanceHidden, - ) - } - - private fun WalletSingleCurrencyState.Locked.toSingleCurrencyContentState(action: UnlockWalletAction): WalletState { - return WalletSingleCurrencyState.Content( - onBackClick = onBackClick, - topBarConfig = topBarConfig.updateCallback(), - walletsListConfig = walletsListConfig.unlockWallets(action), - pullToRefreshConfig = pullToRefreshConfig.stopRefreshing(), - notifications = persistentListOf(), - bottomSheetConfig = null, - buttons = buttons, - marketPriceBlockState = MarketPriceBlockState.Loading( - currencySymbol = action.selectedWallet.getPrimaryCurrencyName(), - ), - txHistoryState = TxHistoryState.Content( - contentItems = MutableStateFlow( - value = TxHistoryState.getDefaultLoadingTransactions(clickIntents::onExploreClick), - ), - ), - isBalanceHidden = isBalanceHidden, - ) - } - - private fun WalletTopBarConfig.updateCallback(): WalletTopBarConfig { - return copy(onDetailsClick = clickIntents::onDetailsClick) - } - - private fun WalletsListConfig.unlockWallets(action: UnlockWalletAction): WalletsListConfig { - return this.copy( - selectedWalletIndex = action.selectedWalletIndex, - wallets = wallets.unlockWallets(action), - ) - } - - private fun List.unlockWallets(action: UnlockWalletAction): ImmutableList { - return this - .map { prevWallet -> - if (prevWallet is WalletCardState.LockedContent && action.isUnlockedWallet(prevWallet.id)) { - prevWallet.mapToLoadingWalletCardState( - userWallet = action.getUnlockWallet(prevWallet.id), - ) - } else { - prevWallet - } - } - .toImmutableList() - } - - private fun UnlockWalletAction.isUnlockedWallet(walletId: UserWalletId): Boolean { - return unlockedWallets.any { it.walletId == walletId } - } - - private fun UnlockWalletAction.getUnlockWallet(walletId: UserWalletId): UserWallet { - return unlockedWallets.firstOrNull { it.walletId == walletId } - ?: error("Unlocked wallet with id $walletId not found") - } - - private fun WalletCardState.mapToLoadingWalletCardState(userWallet: UserWallet): WalletCardState { - return WalletCardState.Loading( - id = id, - title = title, - imageResId = WalletImageResolver.resolve(userWallet = userWallet), - onRenameClick = onRenameClick, - onDeleteClick = onDeleteClick, - ) - } - - private fun WalletPullToRefreshConfig.stopRefreshing(): WalletPullToRefreshConfig { - return copy(isRefreshing = false) - } - - private fun UserWallet.getPrimaryCurrencyName(): String { - return scanResponse.cardTypesResolver.getBlockchain().currency - } -} \ 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 deleted file mode 100644 index d2fd2b4f17..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt +++ /dev/null @@ -1,80 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory.txhistory - -import androidx.paging.PagingData -import arrow.core.Either -import com.tangem.core.ui.components.transactions.state.TxHistoryState -import com.tangem.domain.common.CardTypesResolver -import com.tangem.domain.txhistory.models.TxHistoryItem -import com.tangem.domain.txhistory.models.TxHistoryListError -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.WalletState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.coroutines.flow.Flow - -/** - * Converter from loaded tx history to [TxHistoryState] - * - * @property currentStateProvider current state provider - * @property currentCardTypeResolverProvider current card type resolver provider - * @property clickIntents screen click intents - * -[REDACTED_AUTHOR] - */ -internal class WalletLoadedTxHistoryConverter( - private val currentStateProvider: Provider, - private val currentCardTypeResolverProvider: Provider, - private val clickIntents: WalletClickIntents, -) : Converter>>, WalletState> { - - private val walletTxHistoryItemFlowConverter by lazy { - WalletTxHistoryItemFlowConverter( - currentStateProvider = currentStateProvider, - blockchain = currentCardTypeResolverProvider().getBlockchain(), - clickIntents = clickIntents, - ) - } - - override fun convert(value: Either>>): WalletState { - return value.fold(ifLeft = ::convertError, ifRight = ::convert) - } - - private fun convertError(error: TxHistoryListError): WalletState { - return when (val state = currentStateProvider()) { - is WalletSingleCurrencyState.Content -> { - state.copy( - txHistoryState = when (error) { - is TxHistoryListError.DataError -> { - TxHistoryState.Error( - onReloadClick = clickIntents::onReloadClick, - onExploreClick = clickIntents::onExploreClick, - ) - } - }, - ) - } - is WalletMultiCurrencyState.Content, - is WalletMultiCurrencyState.Locked, - is WalletSingleCurrencyState.Locked, - is WalletState.Initial, - -> state - } - } - - private fun convert(items: Flow>): WalletState { - return when (val state = currentStateProvider()) { - is WalletSingleCurrencyState.Content -> { - return state.copy( - txHistoryState = walletTxHistoryItemFlowConverter.convert(value = items) ?: state.txHistoryState, - ) - } - is WalletMultiCurrencyState.Content, - is WalletMultiCurrencyState.Locked, - is WalletSingleCurrencyState.Locked, - is WalletState.Initial, - -> state - } - } -} \ No newline at end of file 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 deleted file mode 100644 index 3f4b843c86..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt +++ /dev/null @@ -1,105 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory.txhistory - -import androidx.paging.PagingData -import arrow.core.Either -import com.tangem.core.ui.components.transactions.state.TransactionState -import com.tangem.core.ui.components.transactions.state.TxHistoryState.* -import com.tangem.domain.common.CardTypesResolver -import com.tangem.domain.txhistory.models.TxHistoryItem -import com.tangem.domain.txhistory.models.TxHistoryStateError -import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.toImmutableList -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.update - -/** - * Converter from loading tx history state to [WalletSingleCurrencyState.Content] - * - * @property currentStateProvider current state provider - * @property clickIntents screen click intents - * -[REDACTED_AUTHOR] - */ -internal class WalletLoadingTxHistoryConverter( - private val currentStateProvider: Provider, - private val currentCardTypeResolverProvider: Provider, - private val clickIntents: WalletClickIntents, -) : Converter { - - private val txHistoryItemConverter by lazy { - val blockchain = currentCardTypeResolverProvider().getBlockchain() - WalletTxHistoryTransactionStateConverter( - symbol = blockchain.currency, - decimals = blockchain.decimals(), - clickIntents = clickIntents, - ) - } - - override fun convert(value: WalletLoadingTxHistoryModel): WalletState { - return value.historyLoadingState.fold( - ifLeft = { convertError(it, value.pendingTransactions) }, - ifRight = ::convertRight, - ) - } - - private fun convertError(error: TxHistoryStateError, pendingTransactions: Set): WalletState { - val state = currentStateProvider() - - return if (state is WalletSingleCurrencyState.Content) { - state.copy( - txHistoryState = when (error) { - is TxHistoryStateError.EmptyTxHistories -> Empty(onExploreClick = clickIntents::onExploreClick) - is TxHistoryStateError.DataError -> Error( - onReloadClick = clickIntents::onReloadClick, - onExploreClick = clickIntents::onExploreClick, - ) - is TxHistoryStateError.TxHistoryNotImplemented -> { - NotSupported( - pendingTransactions = txHistoryItemConverter.convertList(pendingTransactions) - .toImmutableList(), - onExploreClick = clickIntents::onExploreClick, - ) - } - }, - ) - } else { - state - } - } - - private fun convertRight(value: Int): WalletState { - val state = currentStateProvider() - val singleCurrencyContentState = state as? WalletSingleCurrencyState.Content ?: return state - return if (singleCurrencyContentState.txHistoryState is Content) { - singleCurrencyContentState.txHistoryState.contentItems.update { - PagingData.from(data = createLoadingItems(value)) - } - state - } else { - val txHistoryContent = Content( - contentItems = MutableStateFlow( - value = PagingData.from(data = createLoadingItems(value)), - ), - ) - state.copy(txHistoryState = txHistoryContent) - } - } - - private fun createLoadingItems(size: Int): List { - return buildList { - add(TxHistoryItemState.Title(onExploreClick = clickIntents::onExploreClick)) - (1..size).forEach { - add(TxHistoryItemState.Transaction(state = TransactionState.Loading(it.toString()))) - } - } - } - - data class WalletLoadingTxHistoryModel( - val historyLoadingState: Either, - val pendingTransactions: Set, - ) -} \ No newline at end of file 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 deleted file mode 100644 index f0ab700230..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt +++ /dev/null @@ -1,131 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory.txhistory - -import android.text.format.DateUtils -import androidx.paging.* -import com.tangem.blockchain.common.Blockchain -import com.tangem.core.ui.components.transactions.state.TransactionState -import com.tangem.core.ui.components.transactions.state.TxHistoryState -import com.tangem.core.ui.components.transactions.state.TxHistoryState.TxHistoryItemState -import com.tangem.core.ui.utils.DateTimeFormatters -import com.tangem.domain.txhistory.models.TxHistoryItem -import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import com.tangem.utils.extensions.isToday -import com.tangem.utils.extensions.isYesterday -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.* -import org.joda.time.DateTime -import org.joda.time.DateTimeZone -import java.util.UUID - -/** - * Convert from [Flow] of [TxHistoryItem] to [TxHistoryState] - * - * @property currentStateProvider current state provider - * @property blockchain blockchain of transactions history - * @property clickIntents screen click intents - * -[REDACTED_AUTHOR] - */ -internal class WalletTxHistoryItemFlowConverter( - private val currentStateProvider: Provider, - private val blockchain: Blockchain, - private val clickIntents: WalletClickIntents, -) : Converter>, TxHistoryState?> { - - private val txHistoryItemConverter by lazy { - WalletTxHistoryTransactionStateConverter( - symbol = blockchain.currency, - decimals = blockchain.decimals(), - clickIntents = clickIntents, - ) - } - - override fun convert(value: Flow>): TxHistoryState? { - val state = currentStateProvider() as? WalletSingleCurrencyState ?: return null - val txHistoryContent = state.txHistoryState as? TxHistoryState.Content - ?: TxHistoryState.Content(contentItems = MutableStateFlow(PagingData.empty())) - - // FIXME: TxHistoryRepository should send loading transactions - // [REDACTED_JIRA] - value - .onEach { txHistoryStatePagingData -> - txHistoryContent.contentItems.update { - txHistoryStatePagingData - .map { item -> - // [createTransactionState] returns timestamp without formatting - TxHistoryItemState.Transaction(state = createTransactionState(item)) - } - .insertHeaderItem( - terminalSeparatorType = TerminalSeparatorType.SOURCE_COMPLETE, - item = TxHistoryItemState.Title(clickIntents::onExploreClick), - ) - .insertGroupTitle() - } - } - .launchIn(CoroutineScope(Dispatchers.IO)) - - return txHistoryContent - } - - private fun createTransactionState(item: TxHistoryItem): TransactionState { - return txHistoryItemConverter.convert(value = item) - } - - private fun PagingData.insertGroupTitle(): PagingData { - return insertSeparators(terminalSeparatorType = TerminalSeparatorType.SOURCE_COMPLETE) { before, after -> - // Use raw timestamp to get date - - // If [afterDate] is the first transaction in the flow, add the group title - val afterDate = after.getTimestamp()?.toDateFormat() ?: return@insertSeparators null - if (before is TxHistoryItemState.Title) { - return@insertSeparators TxHistoryItemState.GroupTitle( - title = afterDate, - itemKey = UUID.randomUUID().toString(), - ) - } - - /* - * If [beforeDate] is not equals to [afterDate], then [afterDate] is first transaction in - * the new group - */ - val beforeDate = before.getTimestamp()?.toDateFormat() ?: return@insertSeparators null - return@insertSeparators if (beforeDate != afterDate) { - TxHistoryItemState.GroupTitle(title = afterDate, itemKey = UUID.randomUUID().toString()) - } else { - null - } - } - } - - private fun TxHistoryItemState?.getTimestamp(): Long? { - return if (this is TxHistoryItemState.Transaction && this.state is TransactionState.Content) { - val txContent = this.state as TransactionState.Content - txContent.timestamp - } else { - null - } - } - - /** - * If [this] timestamp is today or yesterday, returns relative date, - * otherwise returns formatting date. - */ - private fun Long.toDateFormat(): String { - val localDate = DateTime(this, DateTimeZone.getDefault()) - return if (localDate.isToday() || localDate.isYesterday()) { - DateUtils.getRelativeTimeSpanString( - this, - DateTime.now().millis, - DateUtils.DAY_IN_MILLIS, - DateUtils.FORMAT_ABBREV_RELATIVE, - ).toString() - } else { - DateTimeFormatters.formatDate(date = localDate) - } - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryTransactionStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryTransactionStateConverter.kt deleted file mode 100644 index 720addb22a..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryTransactionStateConverter.kt +++ /dev/null @@ -1,103 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state.factory.txhistory - -import com.tangem.core.ui.components.transactions.state.TransactionState -import com.tangem.core.ui.extensions.TextReference -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.core.ui.extensions.stringReference -import com.tangem.core.ui.extensions.wrappedList -import com.tangem.core.ui.utils.toTimeFormat -import com.tangem.domain.txhistory.models.TxHistoryItem -import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.converter.Converter -import com.tangem.utils.toBriefAddressFormat -import com.tangem.utils.toFormattedCurrencyString - -internal class WalletTxHistoryTransactionStateConverter( - private val symbol: String, - private val decimals: Int, - private val clickIntents: WalletClickIntents, -) : Converter { - - override fun convert(value: TxHistoryItem): TransactionState { - return createTransactionStateItem(item = value) - } - - @Suppress("LongMethod") - private fun createTransactionStateItem(item: TxHistoryItem): TransactionState { - return TransactionState.Content( - txHash = item.txHash, - amount = item.getAmount(), - time = item.timestampInMillis.toTimeFormat(), - status = item.status.tiUiStatus(), - direction = item.extractDirection(), - iconRes = item.extractIcon(), - title = item.extractTitle(), - subtitle = item.extractSubtitle(), - timestamp = item.timestampInMillis, - onClick = { clickIntents.onTransactionClick(item.txHash) }, - ) - } - - private fun TxHistoryItem.extractIcon(): Int = if (status == TxHistoryItem.TransactionStatus.Failed) { - R.drawable.ic_close_24 - } else { - when (type) { - is TxHistoryItem.TransactionType.Approve -> R.drawable.ic_doc_24 - is TxHistoryItem.TransactionType.Operation, - is TxHistoryItem.TransactionType.Swap, - is TxHistoryItem.TransactionType.Transfer, - is TxHistoryItem.TransactionType.UnknownOperation, - -> if (isOutgoing) R.drawable.ic_arrow_up_24 else R.drawable.ic_arrow_down_24 - } - } - - private fun TxHistoryItem.extractTitle(): TextReference = when (val type = type) { - is TxHistoryItem.TransactionType.Approve -> resourceReference(R.string.common_approval) - is TxHistoryItem.TransactionType.Operation -> stringReference(type.name) - is TxHistoryItem.TransactionType.Swap -> resourceReference(R.string.common_swap) - is TxHistoryItem.TransactionType.Transfer -> resourceReference(R.string.common_transfer) - is TxHistoryItem.TransactionType.UnknownOperation -> resourceReference(R.string.transaction_history_operation) - } - - private fun TxHistoryItem.extractSubtitle(): TextReference = - when (val interactionAddress = interactionAddressType) { - is TxHistoryItem.InteractionAddressType.Contract -> resourceReference( - id = R.string.transaction_history_contract_address, - formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()), - ) - is TxHistoryItem.InteractionAddressType.Multiple -> resourceReference( - id = if (isOutgoing) { - R.string.transaction_history_transaction_to_address - } else { - R.string.transaction_history_transaction_from_address - }, - formatArgs = wrappedList(resourceReference(R.string.transaction_history_multiple_addresses)), - ) - is TxHistoryItem.InteractionAddressType.User -> resourceReference( - id = if (isOutgoing) { - R.string.transaction_history_transaction_to_address - } else { - R.string.transaction_history_transaction_from_address - }, - formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()), - ) - } - - private fun TxHistoryItem.extractDirection() = - if (isOutgoing) TransactionState.Content.Direction.OUTGOING else TransactionState.Content.Direction.INCOMING - - private fun TxHistoryItem.TransactionStatus.tiUiStatus() = when (this) { - TxHistoryItem.TransactionStatus.Confirmed -> TransactionState.Content.Status.Confirmed - TxHistoryItem.TransactionStatus.Failed -> TransactionState.Content.Status.Failed - TxHistoryItem.TransactionStatus.Unconfirmed -> TransactionState.Content.Status.Unconfirmed - } - - private fun TxHistoryItem.getAmount(): String { - val prefix = when (status) { - TxHistoryItem.TransactionStatus.Failed -> "" - else -> if (isOutgoing) "-" else "+" - } - return prefix + amount.toFormattedCurrencyString(currency = symbol, decimals = decimals) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/ActionsBottomSheetConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/ActionsBottomSheetConfig.kt similarity index 84% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/ActionsBottomSheetConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/ActionsBottomSheetConfig.kt index 42cf37464b..84ec1221bd 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/ActionsBottomSheetConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/ActionsBottomSheetConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.model import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent import kotlinx.collections.immutable.ImmutableList diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/BalancesAndLimitsBlockState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/BalancesAndLimitsBlockState.kt similarity index 85% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/BalancesAndLimitsBlockState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/BalancesAndLimitsBlockState.kt index a64e659900..85ebece2af 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/BalancesAndLimitsBlockState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/BalancesAndLimitsBlockState.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.model +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.compose.runtime.Immutable diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/BalancesAndLimitsBottomSheetConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/BalancesAndLimitsBottomSheetConfig.kt similarity index 91% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/BalancesAndLimitsBottomSheetConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/BalancesAndLimitsBottomSheetConfig.kt index dc15fc27b1..5945197384 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/BalancesAndLimitsBottomSheetConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/BalancesAndLimitsBottomSheetConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.model +package com.tangem.feature.wallet.presentation.wallet.state.model import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/DepositButtonState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/DepositButtonState.kt similarity index 59% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/DepositButtonState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/DepositButtonState.kt index 9577abc99e..9a490bf52e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/DepositButtonState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/DepositButtonState.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.model +package com.tangem.feature.wallet.presentation.wallet.state.model internal data class DepositButtonState( val isEnabled: Boolean, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/ManageTokensButtonConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/ManageTokensButtonConfig.kt similarity index 51% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/ManageTokensButtonConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/ManageTokensButtonConfig.kt index 0548298dc0..52c4b9f6dc 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/ManageTokensButtonConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/ManageTokensButtonConfig.kt @@ -1,3 +1,3 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.model +package com.tangem.feature.wallet.presentation.wallet.state.model internal data class ManageTokensButtonConfig(val onClick: () -> Unit) \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/TokenActionButtonConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/TokenActionButtonConfig.kt similarity index 88% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/TokenActionButtonConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/TokenActionButtonConfig.kt index db94522760..12c3c648f1 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/TokenActionButtonConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/TokenActionButtonConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.annotation.DrawableRes import com.tangem.core.ui.extensions.TextReference diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletAdditionalInfo.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletAdditionalInfo.kt similarity index 73% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletAdditionalInfo.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletAdditionalInfo.kt index 612f2111e5..2e210c2221 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletAdditionalInfo.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletAdditionalInfo.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.components +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.compose.runtime.Immutable import com.tangem.core.ui.extensions.TextReference diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletAlertState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletAlertState.kt similarity index 97% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletAlertState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletAlertState.kt index 300369728f..74b0c80769 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletAlertState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletAlertState.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.compose.runtime.Immutable import com.tangem.core.ui.extensions.TextReference diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletBottomSheetConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletBottomSheetConfig.kt similarity index 95% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletBottomSheetConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletBottomSheetConfig.kt index 31291aabe5..d6ec5fcc93 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletBottomSheetConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletBottomSheetConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.components +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.annotation.DrawableRes import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletCardState.kt similarity index 98% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletCardState.kt index 094d5338c1..a533eeabfb 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletCardState.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.components +package com.tangem.feature.wallet.presentation.wallet.state.model 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/WalletEvent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletEvent.kt similarity index 92% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletEvent.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletEvent.kt index a269d87651..5ee98fda79 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletEvent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletEvent.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.compose.runtime.Immutable import com.tangem.core.ui.extensions.TextReference diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletManageButton.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletManageButton.kt similarity index 97% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletManageButton.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletManageButton.kt index 797aaa2711..124d3bf6a9 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletManageButton.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletManageButton.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.components +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.compose.runtime.Immutable import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletNotification.kt similarity index 99% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletNotification.kt index 7f6bfd6b46..1b9721b2cf 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletNotification.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.components +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.compose.runtime.Immutable import com.tangem.core.ui.components.notifications.NotificationConfig diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletPullToRefreshConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletPullToRefreshConfig.kt similarity index 78% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletPullToRefreshConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletPullToRefreshConfig.kt index 6714af85cc..ca91846374 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletPullToRefreshConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletPullToRefreshConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.components +package com.tangem.feature.wallet.presentation.wallet.state.model /** * Wallet screen top bar config diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/WalletScreenState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletScreenState.kt similarity index 63% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/WalletScreenState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletScreenState.kt index 8b092c830c..9285575d9e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/WalletScreenState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletScreenState.kt @@ -1,8 +1,6 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.model +package com.tangem.feature.wallet.presentation.wallet.state.model import com.tangem.core.ui.event.StateEvent -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTopBarConfig import kotlinx.collections.immutable.ImmutableList internal data class WalletScreenState( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/WalletState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletState.kt similarity index 86% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/WalletState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletState.kt index f3b70aa395..0792d8f25a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/WalletState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletState.kt @@ -1,17 +1,13 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.model +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.compose.runtime.Immutable import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.core.ui.components.transactions.state.TxHistoryState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -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.components.WalletPullToRefreshConfig -import com.tangem.feature.wallet.presentation.wallet.state2.model.holder.LockedTxHistoryStateHolder -import com.tangem.feature.wallet.presentation.wallet.state2.model.holder.LockedWalletStateHolder -import com.tangem.feature.wallet.presentation.wallet.state2.model.holder.TxHistoryStateHolder -import com.tangem.feature.wallet.presentation.wallet.state2.model.holder.WalletStateHolder +import com.tangem.feature.wallet.presentation.wallet.state.model.holder.LockedTxHistoryStateHolder +import com.tangem.feature.wallet.presentation.wallet.state.model.holder.LockedWalletStateHolder +import com.tangem.feature.wallet.presentation.wallet.state.model.holder.TxHistoryStateHolder +import com.tangem.feature.wallet.presentation.wallet.state.model.holder.WalletStateHolder import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.PersistentList diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/WalletTokensListState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTokensListState.kt similarity index 96% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/WalletTokensListState.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTokensListState.kt index 0cddc53540..e861c77579 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/WalletTokensListState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTokensListState.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.model +package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.compose.runtime.Immutable import com.tangem.core.ui.extensions.TextReference diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTopBarConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTopBarConfig.kt similarity index 72% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTopBarConfig.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTopBarConfig.kt index 9b3cf42edf..0bf162e9c7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletTopBarConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTopBarConfig.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state.components +package com.tangem.feature.wallet.presentation.wallet.state.model /** * Wallet screen top bar config diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/holder/LockedWalletStateHolder.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/holder/LockedWalletStateHolder.kt similarity index 75% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/holder/LockedWalletStateHolder.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/holder/LockedWalletStateHolder.kt index c54e99c560..6c361d5da7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/holder/LockedWalletStateHolder.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/holder/LockedWalletStateHolder.kt @@ -1,10 +1,10 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.model.holder +package com.tangem.feature.wallet.presentation.wallet.state.model.holder import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletPullToRefreshConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletBottomSheetConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletPullToRefreshConfig import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/holder/TxHistoryStateHolder.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/holder/TxHistoryStateHolder.kt similarity index 92% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/holder/TxHistoryStateHolder.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/holder/TxHistoryStateHolder.kt index 3094cfe505..0350800f16 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/model/holder/TxHistoryStateHolder.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/holder/TxHistoryStateHolder.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.model.holder +package com.tangem.feature.wallet.presentation.wallet.state.model.holder import androidx.paging.PagingData import com.tangem.core.ui.components.transactions.state.TransactionState diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/AddWalletTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/AddWalletTransformer.kt similarity index 65% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/AddWalletTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/AddWalletTransformer.kt index 5100664912..dd9b3ee7d1 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/AddWalletTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/AddWalletTransformer.kt @@ -1,14 +1,14 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletLoadingStateFactory -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.collections.immutable.toImmutableList internal class AddWalletTransformer( private val userWallet: UserWallet, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletScreenStateTransformer { private val walletLoadingStateFactory by lazy { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/CloseBottomSheetTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/CloseBottomSheetTransformer.kt similarity index 87% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/CloseBottomSheetTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/CloseBottomSheetTransformer.kt index 28e7b364c6..81106b0db4 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/CloseBottomSheetTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/CloseBottomSheetTransformer.kt @@ -1,7 +1,7 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState internal class CloseBottomSheetTransformer(userWalletId: UserWalletId) : WalletStateTransformer(userWalletId) { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/DeleteWalletTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/DeleteWalletTransformer.kt similarity index 79% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/DeleteWalletTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/DeleteWalletTransformer.kt index f36010a664..3c2590c4da 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/DeleteWalletTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/DeleteWalletTransformer.kt @@ -1,8 +1,8 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState import kotlinx.collections.immutable.toImmutableList import timber.log.Timber diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/InitializeWalletsTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/InitializeWalletsTransformer.kt similarity index 85% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/InitializeWalletsTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/InitializeWalletsTransformer.kt index 46b15ef604..630c7dfb2c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/InitializeWalletsTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/InitializeWalletsTransformer.kt @@ -1,16 +1,12 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWallet 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.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTopBarConfig -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletLoadingStateFactory -import com.tangem.feature.wallet.presentation.wallet.state2.utils.createStateByWalletType -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.* +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory +import com.tangem.feature.wallet.presentation.wallet.state.utils.createStateByWalletType +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -19,7 +15,7 @@ internal class InitializeWalletsTransformer( private val selectedWalletIndex: Int, private val selectedWallet: UserWallet, private val wallets: List, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletScreenStateTransformer { private val walletLoadingStateFactory by lazy { WalletLoadingStateFactory(clickIntents = clickIntents) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/OpenBottomSheetTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/OpenBottomSheetTransformer.kt similarity index 93% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/OpenBottomSheetTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/OpenBottomSheetTransformer.kt index 9d6737e940..141f4a57d0 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/OpenBottomSheetTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/OpenBottomSheetTransformer.kt @@ -1,9 +1,9 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState internal class OpenBottomSheetTransformer( userWalletId: UserWalletId, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/ReinitializeWalletTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeWalletTransformer.kt similarity index 66% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/ReinitializeWalletTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeWalletTransformer.kt index dac563b4cc..7caf5d79e0 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/ReinitializeWalletTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeWalletTransformer.kt @@ -1,9 +1,9 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletLoadingStateFactory -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.collections.immutable.persistentListOf /** @@ -11,7 +11,7 @@ import kotlinx.collections.immutable.persistentListOf */ internal class ReinitializeWalletTransformer( private val userWallet: UserWallet, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletScreenStateTransformer { private val walletLoadingStateFactory by lazy { WalletLoadingStateFactory(clickIntents = clickIntents) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/RenameWalletTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/RenameWalletTransformer.kt similarity index 88% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/RenameWalletTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/RenameWalletTransformer.kt index b218f47ee2..f0b5cf9e20 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/RenameWalletTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/RenameWalletTransformer.kt @@ -1,7 +1,7 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState import timber.log.Timber internal class RenameWalletTransformer( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/ScrollToWalletTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ScrollToWalletTransformer.kt similarity index 79% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/ScrollToWalletTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ScrollToWalletTransformer.kt index 2651e80ebe..6381c98d9d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/ScrollToWalletTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ScrollToWalletTransformer.kt @@ -1,9 +1,9 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.event.triggeredEvent -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState import com.tangem.utils.Provider internal class ScrollToWalletTransformer( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SendEventTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SendEventTransformer.kt similarity index 62% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SendEventTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SendEventTransformer.kt index c56f4d9918..4b9025e588 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SendEventTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SendEventTransformer.kt @@ -1,8 +1,8 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.core.ui.event.triggeredEvent -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState internal class SendEventTransformer( private val event: WalletEvent, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetBalancesAndLimitsTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetBalancesAndLimitsTransformer.kt similarity index 88% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetBalancesAndLimitsTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetBalancesAndLimitsTransformer.kt index 959a6527ac..ea53efb4c6 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetBalancesAndLimitsTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetBalancesAndLimitsTransformer.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import arrow.core.Either import arrow.core.getOrElse @@ -7,18 +7,18 @@ import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.visa.model.VisaCurrency import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.domain.getCardsCount -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletAdditionalInfo -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state2.model.BalancesAndLimitsBlockState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.BalancesAndLimitsBlockState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletAdditionalInfo +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import org.joda.time.DateTime import org.joda.time.Days internal class SetBalancesAndLimitsTransformer( private val userWallet: UserWallet, private val maybeVisaCurrency: Either, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletStateTransformer(userWallet.walletId) { override fun transform(prevState: WalletState): WalletState { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetCryptoCurrencyActionsTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetCryptoCurrencyActionsTransformer.kt similarity index 91% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetCryptoCurrencyActionsTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetCryptoCurrencyActionsTransformer.kt index 88ebcb4e14..e7fedeba18 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetCryptoCurrencyActionsTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetCryptoCurrencyActionsTransformer.kt @@ -1,11 +1,11 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.tokens.model.TokenActionsState import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletManageButton +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.toPersistentList import timber.log.Timber @@ -13,7 +13,7 @@ import timber.log.Timber internal class SetCryptoCurrencyActionsTransformer( private val tokenActionsState: TokenActionsState, private val userWallet: UserWallet, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletStateTransformer(userWallet.walletId) { override fun transform(prevState: WalletState): WalletState { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetPrimaryCurrencyTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetPrimaryCurrencyTransformer.kt similarity index 79% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetPrimaryCurrencyTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetPrimaryCurrencyTransformer.kt index da21391c07..056d47e276 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetPrimaryCurrencyTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetPrimaryCurrencyTransformer.kt @@ -1,13 +1,13 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.SingleWalletCardStateConverter -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.SingleWalletMarketPriceConverter +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.SingleWalletCardStateConverter +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.SingleWalletMarketPriceConverter import timber.log.Timber internal class SetPrimaryCurrencyTransformer( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetRefreshStateTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetRefreshStateTransformer.kt similarity index 84% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetRefreshStateTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetRefreshStateTransformer.kt index 315d64ab8f..0f6d520acf 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetRefreshStateTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetRefreshStateTransformer.kt @@ -1,12 +1,7 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletPullToRefreshConfig -import com.tangem.feature.wallet.presentation.wallet.state2.model.BalancesAndLimitsBlockState -import com.tangem.feature.wallet.presentation.wallet.state2.model.DepositButtonState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.model.* import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.mutate diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTokenListErrorTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTokenListErrorTransformer.kt similarity index 85% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTokenListErrorTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTokenListErrorTransformer.kt index 587ef5d25d..046b5fd498 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTokenListErrorTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTokenListErrorTransformer.kt @@ -1,9 +1,9 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState import timber.log.Timber internal class SetTokenListErrorTransformer( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTokenListTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTokenListTransformer.kt similarity index 75% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTokenListTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTokenListTransformer.kt index 65c3cff6d7..b852f07fa7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTokenListTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTokenListTransformer.kt @@ -1,23 +1,23 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.tokens.model.TokenList import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state2.model.ManageTokensButtonConfig -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensListState -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.MultiWalletCardStateConverter -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.TokenListStateConverter -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.ManageTokensButtonConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.MultiWalletCardStateConverter +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.TokenListStateConverter +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import timber.log.Timber internal class SetTokenListTransformer( private val tokenList: TokenList, private val userWallet: UserWallet, private val appCurrency: AppCurrency, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletStateTransformer(userWallet.walletId) { override fun transform(prevState: WalletState): WalletState { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryCountErrorTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryCountErrorTransformer.kt similarity index 87% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryCountErrorTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryCountErrorTransformer.kt index 745028a37a..9d97991b83 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryCountErrorTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryCountErrorTransformer.kt @@ -1,13 +1,13 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.domain.txhistory.models.TxHistoryStateError import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.TxHistoryItemStateConverter -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.TxHistoryItemStateConverter +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.collections.immutable.toImmutableList import timber.log.Timber @@ -15,7 +15,7 @@ internal class SetTxHistoryCountErrorTransformer( private val userWallet: UserWallet, private val error: TxHistoryStateError, private val pendingTransactions: Set, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletStateTransformer(userWallet.walletId) { private val txHistoryItemConverter by lazy { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryCountTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryCountTransformer.kt similarity index 91% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryCountTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryCountTransformer.kt index 74fa8ea8a3..f61b4961fe 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryCountTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryCountTransformer.kt @@ -1,11 +1,11 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import androidx.paging.PagingData import com.tangem.core.ui.components.transactions.state.TransactionState import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update import timber.log.Timber @@ -13,7 +13,7 @@ import timber.log.Timber internal class SetTxHistoryCountTransformer( userWalletId: UserWalletId, private val transactionsCount: Int, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletStateTransformer(userWalletId) { override fun transform(prevState: WalletState): WalletState { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryItemsErrorTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryItemsErrorTransformer.kt similarity index 86% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryItemsErrorTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryItemsErrorTransformer.kt index 204b038dd8..5eda4b196e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryItemsErrorTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryItemsErrorTransformer.kt @@ -1,16 +1,16 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.domain.txhistory.models.TxHistoryListError import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import timber.log.Timber internal class SetTxHistoryItemsErrorTransformer( userWalletId: UserWalletId, private val error: TxHistoryListError, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletStateTransformer(userWalletId) { override fun transform(prevState: WalletState): WalletState { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryItemsTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryItemsTransformer.kt similarity index 82% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryItemsTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryItemsTransformer.kt index f1001f3495..09c90b2841 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetTxHistoryItemsTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetTxHistoryItemsTransformer.kt @@ -1,19 +1,19 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import androidx.paging.PagingData import com.tangem.core.ui.components.transactions.state.TransactionState import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.TxHistoryItemFlowConverter -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.TxHistoryItemFlowConverter +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.coroutines.flow.Flow import timber.log.Timber internal class SetTxHistoryItemsTransformer( userWallet: UserWallet, private val flow: Flow>, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletStateTransformer(userWallet.walletId) { override fun transform(prevState: WalletState): WalletState { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetWarningsTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetWarningsTransformer.kt similarity index 79% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetWarningsTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetWarningsTransformer.kt index 1fcac2e3d4..7d7246a01e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/SetWarningsTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetWarningsTransformer.kt @@ -1,8 +1,8 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState import kotlinx.collections.immutable.ImmutableList import timber.log.Timber diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/UnlockWalletTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/UnlockWalletTransformer.kt similarity index 79% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/UnlockWalletTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/UnlockWalletTransformer.kt index c905844bb0..f22dedbc22 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/UnlockWalletTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/UnlockWalletTransformer.kt @@ -1,18 +1,18 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTopBarConfig -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletLoadingStateFactory -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTopBarConfig +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.collections.immutable.toImmutableList import timber.log.Timber internal class UnlockWalletTransformer( private val unlockedWallets: List, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletScreenStateTransformer { private val walletLoadingStateFactory by lazy { WalletLoadingStateFactory(clickIntents = clickIntents) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/UpdateBalanceHidingModeTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/UpdateBalanceHidingModeTransformer.kt similarity index 63% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/UpdateBalanceHidingModeTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/UpdateBalanceHidingModeTransformer.kt index 73be934720..e866e02864 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/UpdateBalanceHidingModeTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/UpdateBalanceHidingModeTransformer.kt @@ -1,6 +1,6 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState internal class UpdateBalanceHidingModeTransformer( private val isHidingMode: Boolean, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/UpdateWalletCardsCountTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/UpdateWalletCardsCountTransformer.kt similarity index 88% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/UpdateWalletCardsCountTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/UpdateWalletCardsCountTransformer.kt index f88cebf21d..1994185f73 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/UpdateWalletCardsCountTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/UpdateWalletCardsCountTransformer.kt @@ -1,11 +1,11 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWallet 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.domain.getCardsCount -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState import timber.log.Timber internal class UpdateWalletCardsCountTransformer( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletScreenStateTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletScreenStateTransformer.kt new file mode 100644 index 0000000000..7bfc34bd81 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletScreenStateTransformer.kt @@ -0,0 +1,8 @@ +package com.tangem.feature.wallet.presentation.wallet.state.transformers + +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState + +internal interface WalletScreenStateTransformer { + + fun transform(prevState: WalletScreenState): WalletScreenState +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/WalletStateTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletStateTransformer.kt similarity index 81% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/WalletStateTransformer.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletStateTransformer.kt index a96c554e7e..f02bd16531 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/WalletStateTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletStateTransformer.kt @@ -1,8 +1,8 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers +package com.tangem.feature.wallet.presentation.wallet.state.transformers import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState import kotlinx.collections.immutable.toImmutableList import timber.log.Timber diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/BalancesAndLimitsBottomSheetConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/BalancesAndLimitsBottomSheetConverter.kt similarity index 82% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/BalancesAndLimitsBottomSheetConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/BalancesAndLimitsBottomSheetConverter.kt index 2a6139aa60..14f9493984 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/BalancesAndLimitsBottomSheetConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/BalancesAndLimitsBottomSheetConverter.kt @@ -1,12 +1,12 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.core.ui.utils.DateTimeFormatters import com.tangem.domain.visa.model.VisaCurrency -import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.state2.model.BalancesAndLimitsBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletEventSender +import com.tangem.feature.wallet.presentation.wallet.state.model.BalancesAndLimitsBottomSheetConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletAlertState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletEventSender import com.tangem.utils.converter.Converter import java.math.BigDecimal diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/MultiWalletCardStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCardStateConverter.kt similarity index 93% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/MultiWalletCardStateConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCardStateConverter.kt index 8c3b84bf05..1e1d944584 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/MultiWalletCardStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCardStateConverter.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.model.AppCurrency @@ -6,7 +6,7 @@ import com.tangem.domain.tokens.model.TokenList import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.domain.WalletAdditionalInfoFactory import com.tangem.feature.wallet.presentation.wallet.domain.getCardsCount -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState import com.tangem.utils.converter.Converter internal class MultiWalletCardStateConverter( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/MultiWalletCurrencyActionsConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCurrencyActionsConverter.kt similarity index 96% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/MultiWalletCurrencyActionsConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCurrencyActionsConverter.kt index e43e0fb2a6..16876a9396 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/MultiWalletCurrencyActionsConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCurrencyActionsConverter.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resourceReference @@ -7,7 +7,7 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.TokenActionsState import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.state.TokenActionButtonConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.TokenActionButtonConfig import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletCurrencyActionsClickIntentsImplementor import com.tangem.utils.converter.Converter import com.tangem.utils.isNullOrZero diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/SingleWalletCardStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/SingleWalletCardStateConverter.kt similarity index 94% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/SingleWalletCardStateConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/SingleWalletCardStateConverter.kt index e54cf09dfa..028d2ea966 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/SingleWalletCardStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/SingleWalletCardStateConverter.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.model.AppCurrency @@ -6,7 +6,7 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.domain.WalletAdditionalInfoFactory import com.tangem.feature.wallet.presentation.wallet.domain.getCardsCount -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState import com.tangem.utils.converter.Converter internal class SingleWalletCardStateConverter( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/SingleWalletMarketPriceConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/SingleWalletMarketPriceConverter.kt similarity index 97% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/SingleWalletMarketPriceConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/SingleWalletMarketPriceConverter.kt index 1f1237f976..60fcaa1c3c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/SingleWalletMarketPriceConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/SingleWalletMarketPriceConverter.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.core.ui.components.marketprice.PriceChangeState diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TokenItemStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenItemStateConverter.kt similarity index 96% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TokenItemStateConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenItemStateConverter.kt index e3b9517efb..66311796de 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TokenItemStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenItemStateConverter.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.components.marketprice.PriceChangeType @@ -6,14 +6,14 @@ import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.feature.wallet.presentation.common.state.TokenItemState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import com.tangem.utils.Provider import com.tangem.utils.converter.Converter import java.math.BigDecimal internal class TokenItemStateConverter( private val appCurrencyProvider: Provider, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : Converter { private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TokenListStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenListStateConverter.kt similarity index 87% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TokenListStateConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenListStateConverter.kt index 77b6288d67..02c8d42705 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TokenListStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenListStateConverter.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import com.tangem.core.ui.extensions.stringReference import com.tangem.domain.appcurrency.model.AppCurrency @@ -7,21 +7,21 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.NetworkGroup import com.tangem.domain.tokens.model.TokenList import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensListState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensListState.TokensListItemState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState.TokensListItemState +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import com.tangem.utils.Provider import com.tangem.utils.converter.Converter import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.mutate import kotlinx.collections.immutable.persistentListOf -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensListState.OrganizeTokensButtonConfig as WalletOrganizeTokensButtonConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState.OrganizeTokensButtonConfig as WalletOrganizeTokensButtonConfig internal class TokenListStateConverter( private val tokenList: TokenList, private val selectedWallet: UserWallet, private val appCurrency: AppCurrency, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : Converter { private val tokenStatusConverter = TokenItemStateConverter( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TxHistoryItemFlowConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemFlowConverter.kt similarity index 95% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TxHistoryItemFlowConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemFlowConverter.kt index 6372e43581..62c49d5586 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TxHistoryItemFlowConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemFlowConverter.kt @@ -1,11 +1,11 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import androidx.paging.* import com.tangem.core.ui.components.transactions.state.TransactionState import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.core.ui.components.transactions.state.TxHistoryState.TxHistoryItemState import com.tangem.core.ui.utils.toDateFormat -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import com.tangem.utils.converter.Converter import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -16,7 +16,7 @@ private val scope = CoroutineScope(Dispatchers.IO) internal class TxHistoryItemFlowConverter( private val currentState: TxHistoryState, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : Converter>, TxHistoryState?> { override fun convert(value: Flow>): TxHistoryState { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TxHistoryItemStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemStateConverter.kt similarity index 96% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TxHistoryItemStateConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemStateConverter.kt index 888144c3eb..d3fd7a6127 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/TxHistoryItemStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemStateConverter.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import com.tangem.core.ui.components.transactions.state.TransactionState import com.tangem.core.ui.extensions.TextReference @@ -8,7 +8,7 @@ import com.tangem.core.ui.extensions.wrappedList import com.tangem.core.ui.utils.toTimeFormat import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import com.tangem.utils.converter.Converter import com.tangem.utils.toBriefAddressFormat import com.tangem.utils.toFormattedCurrencyString @@ -16,7 +16,7 @@ import com.tangem.utils.toFormattedCurrencyString internal class TxHistoryItemStateConverter( private val symbol: String, private val decimals: Int, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : Converter { override fun convert(value: TxHistoryItem): TransactionState { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/VisaTxHistoryItemStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/VisaTxHistoryItemStateConverter.kt similarity index 96% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/VisaTxHistoryItemStateConverter.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/VisaTxHistoryItemStateConverter.kt index c1f801a339..bddc7ec7aa 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/converter/VisaTxHistoryItemStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/VisaTxHistoryItemStateConverter.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter +package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter import com.tangem.core.ui.components.transactions.state.TransactionState import com.tangem.core.ui.extensions.stringReference diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/utils/UserWalletConverterExt.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/utils/UserWalletConverterExt.kt similarity index 83% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/utils/UserWalletConverterExt.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/utils/UserWalletConverterExt.kt index 9d03b341a7..c7a8830b71 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/utils/UserWalletConverterExt.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/utils/UserWalletConverterExt.kt @@ -1,8 +1,8 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.utils +package com.tangem.feature.wallet.presentation.wallet.state.utils import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState internal inline fun UserWallet.createStateByWalletType( multiCurrencyCreator: () -> WalletState.MultiCurrency, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/utils/WalletEventSender.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/utils/WalletEventSender.kt similarity index 72% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/utils/WalletEventSender.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/utils/WalletEventSender.kt index 7b225aa521..34859d54d9 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/utils/WalletEventSender.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/utils/WalletEventSender.kt @@ -1,9 +1,9 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.utils +package com.tangem.feature.wallet.presentation.wallet.state.utils import com.tangem.core.ui.event.consumedEvent -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SendEventTransformer +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SendEventTransformer import javax.inject.Inject /** diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/utils/WalletLoadingStateFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/utils/WalletLoadingStateFactory.kt similarity index 90% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/utils/WalletLoadingStateFactory.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/utils/WalletLoadingStateFactory.kt index fdf4fb6287..9315797f9a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/utils/WalletLoadingStateFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/utils/WalletLoadingStateFactory.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.utils +package com.tangem.feature.wallet.presentation.wallet.state.utils import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.core.ui.components.transactions.state.TxHistoryState @@ -6,11 +6,8 @@ import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.wallets.models.UserWallet 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.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletPullToRefreshConfig -import com.tangem.feature.wallet.presentation.wallet.state2.model.* -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.model.* +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.flow.MutableStateFlow @@ -20,7 +17,7 @@ import kotlinx.coroutines.flow.MutableStateFlow * * @property clickIntents click intents */ -internal class WalletLoadingStateFactory(private val clickIntents: WalletClickIntentsV2) { +internal class WalletLoadingStateFactory(private val clickIntents: WalletClickIntents) { fun create(userWallet: UserWallet): WalletState { return userWallet.createStateByWalletType( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/WalletScreenStateTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/WalletScreenStateTransformer.kt deleted file mode 100644 index 9cae2fd8e8..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state2/transformers/WalletScreenStateTransformer.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state2.transformers - -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState - -internal interface WalletScreenStateTransformer { - - fun transform(prevState: WalletScreenState): WalletScreenState -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/BasicTokenListSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/BasicTokenListSubscriber.kt index ddc8f7fb6a..a1f88b718d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/BasicTokenListSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/BasicTokenListSubscriber.kt @@ -9,10 +9,10 @@ import com.tangem.domain.tokens.model.TokenList import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTokenListErrorTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTokenListTransformer -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTokenListErrorTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTokenListTransformer +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine @@ -25,7 +25,7 @@ internal typealias MaybeTokenListFlow = Flow> internal abstract class BasicTokenListSubscriber( private val userWallet: UserWallet, private val stateHolder: WalletStateController, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, private val tokenListAnalyticsSender: TokenListAnalyticsSender, private val walletWithFundsChecker: WalletWithFundsChecker, private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt index 46de409a7d..cb5fdbc166 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt @@ -5,15 +5,15 @@ import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents @Suppress("LongParameterList") internal class MultiWalletTokenListSubscriber( private val userWallet: UserWallet, private val getTokenListUseCase: GetTokenListUseCase, stateHolder: WalletStateController, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, tokenListAnalyticsSender: TokenListAnalyticsSender, walletWithFundsChecker: WalletWithFundsChecker, getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletWarningsSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletWarningsSubscriber.kt index 152aa30cae..d9029393c1 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletWarningsSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletWarningsSubscriber.kt @@ -3,10 +3,10 @@ package com.tangem.feature.wallet.presentation.wallet.subscribers import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetWarningsTransformer -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetWarningsTransformer +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.collections.immutable.ImmutableList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow @@ -17,7 +17,7 @@ import kotlinx.coroutines.flow.onEach internal class MultiWalletWarningsSubscriber( private val userWalletId: UserWalletId, private val stateHolder: WalletStateController, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, private val walletWarningsAnalyticsSender: WalletWarningsAnalyticsSender, ) : WalletSubscriber() { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/PrimaryCurrencySubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/PrimaryCurrencySubscriber.kt index de0c3f2634..41fef9b424 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/PrimaryCurrencySubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/PrimaryCurrencySubscriber.kt @@ -13,8 +13,8 @@ import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetPrimaryCurrencyTransformer +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetPrimaryCurrencyTransformer import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.* import timber.log.Timber diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletButtonsSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletButtonsSubscriber.kt index 21664ba8bd..4751fed097 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletButtonsSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletButtonsSubscriber.kt @@ -5,16 +5,16 @@ import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase import com.tangem.domain.tokens.model.TokenActionsState import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.domain.collectLatest -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetCryptoCurrencyActionsTransformer -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetCryptoCurrencyActionsTransformer +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.* internal class SingleWalletButtonsSubscriber( private val userWallet: UserWallet, private val stateHolder: WalletStateController, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, private val getPrimaryCurrencyStatusUpdatesUseCase: GetPrimaryCurrencyStatusUpdatesUseCase, private val getCryptoCurrencyActionsUseCase: GetCryptoCurrencyActionsUseCase, ) : WalletSubscriber() { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletNotificationsSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletNotificationsSubscriber.kt index edb19f0254..f266b681fd 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletNotificationsSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletNotificationsSubscriber.kt @@ -3,10 +3,10 @@ package com.tangem.feature.wallet.presentation.wallet.subscribers import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetSingleWalletWarningsFactory -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetWarningsTransformer -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetWarningsTransformer +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.collections.immutable.ImmutableList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow @@ -22,7 +22,7 @@ internal class SingleWalletNotificationsSubscriber( private val stateHolder: WalletStateController, private val getSingleWalletWarningsFactory: GetSingleWalletWarningsFactory, private val walletWarningsAnalyticsSender: WalletWarningsAnalyticsSender, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletSubscriber() { override fun create(coroutineScope: CoroutineScope): Flow> { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletWithTokenListSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletWithTokenListSubscriber.kt index 3fe184f524..54c8ca07de 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletWithTokenListSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/SingleWalletWithTokenListSubscriber.kt @@ -5,15 +5,15 @@ import com.tangem.domain.tokens.GetCardTokensListUseCase import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents @Suppress("LongParameterList") internal class SingleWalletWithTokenListSubscriber( private val userWallet: UserWallet, private val getCardTokensListUseCase: GetCardTokensListUseCase, stateHolder: WalletStateController, - clickIntents: WalletClickIntentsV2, + clickIntents: WalletClickIntents, tokenListAnalyticsSender: TokenListAnalyticsSender, walletWithFundsChecker: WalletWithFundsChecker, getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TxHistorySubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TxHistorySubscriber.kt index c30daff4df..7561ea68c5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TxHistorySubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TxHistorySubscriber.kt @@ -14,13 +14,13 @@ import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.domain.collectLatest -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTxHistoryCountErrorTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTxHistoryCountTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTxHistoryItemsErrorTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTxHistoryItemsTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.TxHistoryItemStateConverter -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTxHistoryCountErrorTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTxHistoryCountTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTxHistoryItemsErrorTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTxHistoryItemsTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.TxHistoryItemStateConverter +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -34,7 +34,7 @@ internal class TxHistorySubscriber( private val userWallet: UserWallet, private val isRefresh: Boolean, private val stateHolder: WalletStateController, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, private val getPrimaryCurrencyStatusUpdatesUseCase: GetPrimaryCurrencyStatusUpdatesUseCase, private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/VisaWalletSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/VisaWalletSubscriber.kt index ea540ec981..552dbba1a5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/VisaWalletSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/VisaWalletSubscriber.kt @@ -11,13 +11,13 @@ import com.tangem.domain.visa.GetVisaTxHistoryUseCase import com.tangem.domain.visa.model.VisaCurrency import com.tangem.domain.visa.model.VisaTxHistoryItem import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetBalancesAndLimitsTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTxHistoryCountTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTxHistoryItemsErrorTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTxHistoryItemsTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.VisaTxHistoryItemStateConverter -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetBalancesAndLimitsTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTxHistoryCountTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTxHistoryItemsErrorTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTxHistoryItemsTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.VisaTxHistoryItemStateConverter +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch @@ -31,7 +31,7 @@ internal class VisaWalletSubscriber( private val isRefresh: Boolean, private val getVisaCurrencyUseCase: GetVisaCurrencyUseCase, private val getVisaTxHistoryUseCase: GetVisaTxHistoryUseCase, - private val clickIntents: WalletClickIntentsV2, + private val clickIntents: WalletClickIntents, ) : WalletSubscriber() { override fun create(coroutineScope: CoroutineScope): Flow<*> { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletAlert.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletAlert.kt index 1edcb46df5..ab8a96b36b 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletAlert.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletAlert.kt @@ -6,7 +6,7 @@ import com.tangem.core.ui.components.BasicDialog import com.tangem.core.ui.components.DialogButton import com.tangem.core.ui.extensions.resolveReference import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletAlertState @Composable internal fun WalletAlert(state: WalletAlertState, onDismiss: () -> Unit) { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffect.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffect.kt index dbb5f28cfa..cce277150d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffect.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffect.kt @@ -1,34 +1,33 @@ package com.tangem.feature.wallet.presentation.wallet.ui -import android.app.Activity -import android.content.Context -import android.content.ContextWrapper import android.widget.Toast import androidx.compose.foundation.lazy.LazyListState import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.AnnotatedString -import com.google.android.play.core.review.ReviewInfo -import com.google.android.play.core.review.ReviewManager -import com.google.android.play.core.review.ReviewManagerFactory -import com.google.android.play.core.tasks.Task import com.tangem.core.ui.event.EventEffect import com.tangem.core.ui.event.StateEvent import com.tangem.core.ui.extensions.resolveReference -import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import timber.log.Timber +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletAlertState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent +import com.tangem.feature.wallet.presentation.wallet.ui.utils.ReviewManagerRequester +import com.tangem.feature.wallet.presentation.wallet.ui.utils.animateScrollByIndex +import com.tangem.feature.wallet.presentation.wallet.ui.utils.demonstrateScrolling +@Suppress("LongParameterList") @Composable internal fun WalletEventEffect( walletsListState: LazyListState, snackbarHostState: SnackbarHostState, event: StateEvent, + selectedWalletIndex: Int, onAutoScrollSet: () -> Unit, onAlertConfigSet: (WalletAlertState) -> Unit, ) { + val coroutineScope = rememberCoroutineScope() val context = LocalContext.current val resources = LocalContext.current.resources val clipboardManager = LocalClipboardManager.current @@ -38,7 +37,7 @@ internal fun WalletEventEffect( when (value) { is WalletEvent.ChangeWallet -> { onAutoScrollSet() - walletsListState.animateScrollToItem(index = value.index) + walletsListState.animateScrollByIndex(prevIndex = selectedWalletIndex, newIndex = value.index) } is WalletEvent.ShowError -> { snackbarHostState.showSnackbar(message = value.text.resolveReference(resources)) @@ -52,49 +51,12 @@ internal fun WalletEventEffect( } is WalletEvent.ShowAlert -> onAlertConfigSet(value.state) is WalletEvent.RateApp -> { - val reviewManager = ReviewManagerFactory.create(context) - val requestTask = reviewManager.requestReviewFlow() - - requestTask - .addOnCompleteListener { - handleOnCompleteRequestTask( - reviewManager = reviewManager, - activity = context.findActivity(), - task = it, - onDismissClick = value.onDismissClick, - ) - } - .addOnFailureListener(Timber::e) + ReviewManagerRequester.request(context = context, onDismissClick = value.onDismissClick) + } + is WalletEvent.DemonstrateWalletsScrollPreview -> { + walletsListState.demonstrateScrolling(coroutineScope = coroutineScope, direction = value.direction) } - is WalletEvent.DemonstrateWalletsScrollPreview -> Unit } }, ) -} - -private fun Context.findActivity(): Activity { - var context = this - while (context is ContextWrapper) { - if (context is Activity) return context - context = context.baseContext - } - error("Permissions should be called in the context of an Activity") -} - -private fun handleOnCompleteRequestTask( - reviewManager: ReviewManager, - activity: Activity, - task: Task, - onDismissClick: () -> Unit, -) { - if (task.isSuccessful) { - val reviewFlow = reviewManager.launchReviewFlow(activity, task.result) - reviewFlow - .addOnCompleteListener { resultReviewTask -> - if (!resultReviewTask.isSuccessful) onDismissClick() - } - .addOnFailureListener(Timber::e) - } else { - Timber.e(task.exception) - } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffectV2.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffectV2.kt deleted file mode 100644 index 73d54f4ddc..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffectV2.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.ui - -import android.widget.Toast -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.material3.SnackbarHostState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.ui.platform.LocalClipboardManager -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.text.AnnotatedString -import com.tangem.core.ui.event.EventEffect -import com.tangem.core.ui.event.StateEvent -import com.tangem.core.ui.extensions.resolveReference -import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.ui.utils.ReviewManagerRequester -import com.tangem.feature.wallet.presentation.wallet.ui.utils.animateScrollByIndex -import com.tangem.feature.wallet.presentation.wallet.ui.utils.demonstrateScrolling - -@Suppress("LongParameterList") -@Composable -internal fun WalletEventEffectV2( - walletsListState: LazyListState, - snackbarHostState: SnackbarHostState, - event: StateEvent, - selectedWalletIndex: Int, - onAutoScrollSet: () -> Unit, - onAlertConfigSet: (WalletAlertState) -> Unit, -) { - val coroutineScope = rememberCoroutineScope() - val context = LocalContext.current - val resources = LocalContext.current.resources - val clipboardManager = LocalClipboardManager.current - EventEffect( - event = event, - onTrigger = { value -> - when (value) { - is WalletEvent.ChangeWallet -> { - onAutoScrollSet() - walletsListState.animateScrollByIndex(prevIndex = selectedWalletIndex, newIndex = value.index) - } - is WalletEvent.ShowError -> { - snackbarHostState.showSnackbar(message = value.text.resolveReference(resources)) - } - is WalletEvent.ShowToast -> { - Toast.makeText(context, value.text.resolveReference(resources), Toast.LENGTH_SHORT).show() - } - is WalletEvent.CopyAddress -> { - clipboardManager.setText(AnnotatedString(value.address)) - Toast.makeText(context, value.toast.resolveReference(resources), Toast.LENGTH_SHORT).show() - } - is WalletEvent.ShowAlert -> onAlertConfigSet(value.state) - is WalletEvent.RateApp -> { - ReviewManagerRequester.request(context = context, onDismissClick = value.onDismissClick) - } - is WalletEvent.DemonstrateWalletsScrollPreview -> { - walletsListState.demonstrateScrolling(coroutineScope = coroutineScope, direction = value.direction) - } - } - }, - ) -} \ No newline at end of file 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 cd3312809b..3dcd34d73e 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 @@ -17,9 +17,6 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.tooling.preview.PreviewParameter -import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import androidx.paging.compose.collectAsLazyPagingItems import com.tangem.core.ui.components.PrimaryButton import com.tangem.core.ui.components.bottomsheets.chooseaddress.ChooseAddressBottomSheet @@ -29,249 +26,229 @@ import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBotto import com.tangem.core.ui.components.transactions.state.TxHistoryState 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.* -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletPullToRefreshConfig -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState.OrganizeTokensButtonState +import com.tangem.feature.wallet.presentation.wallet.state.model.* +import com.tangem.feature.wallet.presentation.wallet.state.model.holder.TxHistoryStateHolder import com.tangem.feature.wallet.presentation.wallet.ui.components.TokenActionsBottomSheet 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.organizeTokensButton import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.controlButtons import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.marketPriceBlock +import com.tangem.feature.wallet.presentation.wallet.ui.components.visa.BalancesAndLimitsBottomSheet +import com.tangem.feature.wallet.presentation.wallet.ui.components.visa.balancesAndLimitsBlock +import com.tangem.feature.wallet.presentation.wallet.ui.components.visa.depositButton import com.tangem.feature.wallet.presentation.wallet.ui.utils.changeWalletAnimator +import kotlinx.collections.immutable.toImmutableList -/** - * Wallet screen - * - * @param state screen state - * -[REDACTED_AUTHOR] - */ @Composable -internal fun WalletScreen(state: WalletState) { +internal fun WalletScreen(state: WalletScreenState) { BackHandler(onBack = state.onBackClick) - when (state) { - is WalletState.ContentState -> { - val walletsListState = rememberLazyListState( - initialFirstVisibleItemIndex = state.walletsListConfig.selectedWalletIndex, - ) - val snackbarHostState = remember { SnackbarHostState() } - val isAutoScroll = remember { mutableStateOf(value = false) } + // It means that screen is still initializing + if (state.selectedWalletIndex == NOT_INITIALIZED_WALLET_INDEX) return - WalletContent( - state = state, - walletsListState = walletsListState, - snackbarHostState = snackbarHostState, - isAutoScroll = isAutoScroll, - onAutoScrollReset = { isAutoScroll.value = false }, - ) + val walletsListState = rememberLazyListState(initialFirstVisibleItemIndex = state.selectedWalletIndex) + val snackbarHostState = remember(::SnackbarHostState) + val isAutoScroll = remember { mutableStateOf(value = false) } - var alertConfig by remember { mutableStateOf(value = null) } + WalletContent( + state = state, + walletsListState = walletsListState, + snackbarHostState = snackbarHostState, + isAutoScroll = isAutoScroll, + onAutoScrollReset = { isAutoScroll.value = false }, + ) - WalletEventEffect( - walletsListState = walletsListState, - snackbarHostState = snackbarHostState, - event = state.event, - onAutoScrollSet = { isAutoScroll.value = true }, - onAlertConfigSet = { alertConfig = it }, - ) + var alertConfig by remember { mutableStateOf(value = null) } - alertConfig?.let { - WalletAlert(state = it, onDismiss = { alertConfig = null }) - } - } - is WalletState.Initial -> Unit + alertConfig?.let { + WalletAlert(state = it, onDismiss = { alertConfig = null }) } + + WalletEventEffect( + event = state.event, + selectedWalletIndex = state.selectedWalletIndex, + walletsListState = walletsListState, + snackbarHostState = snackbarHostState, + onAlertConfigSet = { alertConfig = it }, + onAutoScrollSet = { isAutoScroll.value = true }, + ) } +@Suppress("LongMethod") @Composable private fun WalletContent( - state: WalletState.ContentState, + state: WalletScreenState, walletsListState: LazyListState, snackbarHostState: SnackbarHostState, isAutoScroll: State, onAutoScrollReset: () -> Unit, ) { - BaseScaffold(state = state, snackbarHostState) { scaffoldPaddings -> + var selectedWalletIndex by remember { mutableIntStateOf(state.selectedWalletIndex) } + val selectedWallet = state.wallets[selectedWalletIndex] + + BaseScaffold(state = state, selectedWallet = selectedWallet, snackbarHostState = snackbarHostState) { val movableItemModifier = Modifier.changeWalletAnimator(walletsListState) - UpdatableContainer( - pullToRefreshConfig = state.pullToRefreshConfig, - modifier = Modifier.padding(paddingValues = scaffoldPaddings), + val lazyTxHistoryItems = (selectedWallet as? TxHistoryStateHolder)?.let { walletState -> + (walletState.txHistoryState as? TxHistoryState.Content)?.contentItems?.collectAsLazyPagingItems() + } + + val txHistoryItems by remember(selectedWallet.walletCardState.id, lazyTxHistoryItems?.itemCount) { + mutableStateOf(value = lazyTxHistoryItems) + } + + val betweenItemsPadding = TangemTheme.dimens.spacing14 + val horizontalPadding = TangemTheme.dimens.spacing16 + val itemModifier = movableItemModifier + .padding(top = betweenItemsPadding) + .padding(horizontal = horizontalPadding) + + LazyColumn( + modifier = Modifier.fillMaxSize(), + contentPadding = PaddingValues( + top = TangemTheme.dimens.spacing8, + bottom = TangemTheme.dimens.spacing92, + ), + horizontalAlignment = Alignment.CenterHorizontally, ) { - val txHistoryItems = if (state is WalletSingleCurrencyState && - state.txHistoryState is TxHistoryState.Content + item( + key = state.wallets.map { it.walletCardState.id }, + contentType = state.wallets.map { it.walletCardState.id }, ) { - (state.txHistoryState as? TxHistoryState.Content)?.contentItems?.collectAsLazyPagingItems() - } else { - null + WalletsList( + lazyListState = walletsListState, + wallets = state.wallets.map(WalletState::walletCardState).toImmutableList(), + isBalanceHidden = state.isHidingMode, + ) } - val betweenItemsPadding = TangemTheme.dimens.spacing14 - val horizontalPadding = TangemTheme.dimens.spacing16 - val itemModifier = movableItemModifier - .padding(top = betweenItemsPadding) - .padding(horizontal = horizontalPadding) + (selectedWallet as? WalletState.SingleCurrency)?.let { + controlButtons( + configs = it.buttons, + selectedWalletIndex = selectedWalletIndex, + modifier = movableItemModifier.padding(top = betweenItemsPadding), + ) + } - LazyColumn( - modifier = Modifier.fillMaxSize(), - contentPadding = PaddingValues( - top = TangemTheme.dimens.spacing8, - bottom = TangemTheme.dimens.spacing92, - ), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - item { - WalletsList( - config = state.walletsListConfig, - lazyListState = walletsListState, - isBalanceHidden = state.isBalanceHidden, - ) + notifications(configs = selectedWallet.warnings, modifier = itemModifier) + + (selectedWallet as? WalletState.SingleCurrency)?.let { walletState -> + walletState.marketPriceBlockState?.let { marketPriceBlockState -> + marketPriceBlock(state = marketPriceBlockState, modifier = itemModifier) } + } - if (state is WalletSingleCurrencyState) { - controlButtons( - configs = state.buttons, - selectedWalletIndex = state.walletsListConfig.selectedWalletIndex, - modifier = movableItemModifier.padding(top = betweenItemsPadding), - ) - } - - notifications(configs = state.notifications, modifier = itemModifier) - - if (state is WalletSingleCurrencyState.Content) { - marketPriceBlock(state = state.marketPriceBlockState, modifier = itemModifier) - } - - contentItems( - state = state, - txHistoryItems = txHistoryItems, - isBalanceHidden = state.isBalanceHidden, - modifier = movableItemModifier, + (selectedWallet as? WalletState.Visa.Content)?.let { + depositButton( + modifier = itemModifier.fillMaxWidth(), + state = it.depositButtonState, ) - organizeTokens(state = state, itemModifier = itemModifier) + balancesAndLimitsBlock( + modifier = itemModifier, + state = it.balancesAndLimitBlockState, + ) + } + + contentItems( + state = selectedWallet, + txHistoryItems = txHistoryItems, + isBalanceHidden = state.isHidingMode, + modifier = movableItemModifier, + ) + + organizeTokens(state = selectedWallet, itemModifier = itemModifier) + } + + val bottomSheetConfig = selectedWallet.bottomSheetConfig + if (bottomSheetConfig != null) { + when (bottomSheetConfig.content) { + is WalletBottomSheetConfig -> WalletBottomSheet(config = bottomSheetConfig) + is TokenReceiveBottomSheetConfig -> TokenReceiveBottomSheet(config = bottomSheetConfig) + is ActionsBottomSheetConfig -> TokenActionsBottomSheet(config = bottomSheetConfig) + is ChooseAddressBottomSheetConfig -> ChooseAddressBottomSheet(config = bottomSheetConfig) + is BalancesAndLimitsBottomSheetConfig -> BalancesAndLimitsBottomSheet(config = bottomSheetConfig) } } - } - WalletBottomSheets(state = state) - - WalletsListEffects( - lazyListState = walletsListState, - walletsListConfig = state.walletsListConfig, - isAutoScroll = isAutoScroll, - onAutoScrollReset = onAutoScrollReset, - ) -} - -internal fun LazyListScope.organizeTokens(state: WalletState.ContentState, itemModifier: Modifier) { - if (state is WalletMultiCurrencyState) { - val contentTokenListState = state.tokensListState as? WalletTokensListState.ContentState - val organizeTokensButton = contentTokenListState?.organizeTokensButton - - if (organizeTokensButton is OrganizeTokensButtonState.Visible) { - organizeTokensButton( - modifier = itemModifier, - isEnabled = organizeTokensButton.isEnabled, - onClick = organizeTokensButton.onClick, - ) - } + WalletsListEffects( + lazyListState = walletsListState, + selectedWalletIndex = selectedWalletIndex, + onWalletChange = state.onWalletChange, + onSelectedWalletIndexSet = { selectedWalletIndex = it }, + isAutoScroll = isAutoScroll, + onAutoScrollReset = onAutoScrollReset, + ) } } @OptIn(ExperimentalMaterialApi::class) -@Composable -private fun UpdatableContainer( - pullToRefreshConfig: WalletPullToRefreshConfig, - modifier: Modifier = Modifier, - content: @Composable BoxScope.() -> Unit, -) { - val pullRefreshState = rememberPullRefreshState( - refreshing = pullToRefreshConfig.isRefreshing, - onRefresh = pullToRefreshConfig.onRefresh, - ) - - Box(modifier = modifier.pullRefresh(pullRefreshState)) { - content() - - WalletPullToRefreshIndicator( - isRefreshing = pullToRefreshConfig.isRefreshing, - state = pullRefreshState, - modifier = Modifier.align(Alignment.TopCenter), - ) - } -} - @Composable private fun BaseScaffold( - state: WalletState.ContentState, + state: WalletScreenState, + selectedWallet: WalletState, snackbarHostState: SnackbarHostState, - content: @Composable (PaddingValues) -> Unit, + content: @Composable () -> Unit, ) { Scaffold( topBar = { WalletTopBar(config = state.topBarConfig) }, snackbarHost = { SnackbarHost(hostState = snackbarHostState) }, floatingActionButton = { - if (state is WalletMultiCurrencyState.Content && state.isManageTokensAvailable) { - ManageTokensButton(onManageTokensClick = state.onManageTokensClick) + val manageTokensButtonConfig by remember(state.selectedWalletIndex) { + mutableStateOf( + (state.wallets[state.selectedWalletIndex] as? WalletState.MultiCurrency)?.manageTokensButtonConfig, + ) } + + manageTokensButtonConfig?.let { ManageTokensButton(onClick = it.onClick) } }, floatingActionButtonPosition = FabPosition.Center, containerColor = TangemTheme.colors.background.secondary, - content = content, + content = { + val pullRefreshState = rememberPullRefreshState( + refreshing = selectedWallet.pullToRefreshConfig.isRefreshing, + onRefresh = selectedWallet.pullToRefreshConfig.onRefresh, + ) + + Box( + modifier = Modifier + .pullRefresh(pullRefreshState) + .padding(it), + ) { + content() + + WalletPullToRefreshIndicator( + isRefreshing = selectedWallet.pullToRefreshConfig.isRefreshing, + state = pullRefreshState, + modifier = Modifier.align(Alignment.TopCenter), + ) + } + }, ) } @Composable -private fun ManageTokensButton(onManageTokensClick: () -> Unit) { +private fun ManageTokensButton(onClick: () -> Unit) { PrimaryButton( text = stringResource(id = R.string.main_manage_tokens), - onClick = onManageTokensClick, + onClick = onClick, modifier = Modifier .fillMaxWidth() .padding(horizontal = TangemTheme.dimens.spacing16), ) } -@Composable -private fun WalletBottomSheets(state: WalletState) { - val bottomSheetConfig = (state as? WalletState.ContentState)?.bottomSheetConfig - if (bottomSheetConfig != null) { - when (bottomSheetConfig.content) { - is WalletBottomSheetConfig -> WalletBottomSheet(config = bottomSheetConfig) - is TokenReceiveBottomSheetConfig -> TokenReceiveBottomSheet(config = bottomSheetConfig) - is ActionsBottomSheetConfig -> TokenActionsBottomSheet(config = bottomSheetConfig) - is ChooseAddressBottomSheetConfig -> ChooseAddressBottomSheet(config = bottomSheetConfig) +internal fun LazyListScope.organizeTokens(state: WalletState, itemModifier: Modifier) { + (state as? WalletState.MultiCurrency)?.let { + (state.tokensListState as? WalletTokensListState.ContentState)?.let { + it.organizeTokensButtonConfig?.let { config -> + organizeTokensButton( + modifier = itemModifier, + isEnabled = config.isEnabled, + onClick = config.onClick, + ) + } } } -} - -// region Preview -@Preview -@Composable -private fun WalletScreenPreview_Light(@PreviewParameter(WalletScreenParameterProvider::class) state: WalletState) { - TangemTheme { - WalletScreen(state = state) - } -} - -@Preview -@Composable -private fun WalletScreenPreview_Dark(@PreviewParameter(WalletScreenParameterProvider::class) state: WalletState) { - TangemTheme(isDark = true) { - WalletScreen(state = state) - } -} - -private class WalletScreenParameterProvider : CollectionPreviewParameterProvider( - collection = listOf( - WalletPreviewData.multicurrencyWalletScreenState, - WalletPreviewData.singleWalletScreenState, - ), -) -// endregion Preview \ No newline at end of file +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreenV2.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreenV2.kt deleted file mode 100644 index 15e0698e0d..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreenV2.kt +++ /dev/null @@ -1,257 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.ui - -import androidx.activity.compose.BackHandler -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.material.ExperimentalMaterialApi -import androidx.compose.material.pullrefresh.pullRefresh -import androidx.compose.material.pullrefresh.rememberPullRefreshState -import androidx.compose.material3.FabPosition -import androidx.compose.material3.Scaffold -import androidx.compose.material3.SnackbarHost -import androidx.compose.material3.SnackbarHostState -import androidx.compose.runtime.* -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.paging.compose.collectAsLazyPagingItems -import com.tangem.core.ui.components.PrimaryButton -import com.tangem.core.ui.components.bottomsheets.chooseaddress.ChooseAddressBottomSheet -import com.tangem.core.ui.components.bottomsheets.chooseaddress.ChooseAddressBottomSheetConfig -import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheet -import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheetConfig -import com.tangem.core.ui.components.transactions.state.TxHistoryState -import com.tangem.core.ui.res.TangemTheme -import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.state.ActionsBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state2.model.* -import com.tangem.feature.wallet.presentation.wallet.state2.model.holder.TxHistoryStateHolder -import com.tangem.feature.wallet.presentation.wallet.ui.components.TokenActionsBottomSheet -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.organizeTokensButton -import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.controlButtons -import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.marketPriceBlock -import com.tangem.feature.wallet.presentation.wallet.ui.components.visa.BalancesAndLimitsBottomSheet -import com.tangem.feature.wallet.presentation.wallet.ui.components.visa.balancesAndLimitsBlock -import com.tangem.feature.wallet.presentation.wallet.ui.components.visa.depositButton -import com.tangem.feature.wallet.presentation.wallet.ui.utils.changeWalletAnimator -import kotlinx.collections.immutable.toImmutableList - -@Composable -internal fun WalletScreenV2(state: WalletScreenState) { - BackHandler(onBack = state.onBackClick) - - // It means that screen is still initializing - if (state.selectedWalletIndex == NOT_INITIALIZED_WALLET_INDEX) return - - val walletsListState = rememberLazyListState(initialFirstVisibleItemIndex = state.selectedWalletIndex) - val snackbarHostState = remember(::SnackbarHostState) - val isAutoScroll = remember { mutableStateOf(value = false) } - - WalletContent( - state = state, - walletsListState = walletsListState, - snackbarHostState = snackbarHostState, - isAutoScroll = isAutoScroll, - onAutoScrollReset = { isAutoScroll.value = false }, - ) - - var alertConfig by remember { mutableStateOf(value = null) } - - alertConfig?.let { - WalletAlert(state = it, onDismiss = { alertConfig = null }) - } - - WalletEventEffectV2( - event = state.event, - selectedWalletIndex = state.selectedWalletIndex, - walletsListState = walletsListState, - snackbarHostState = snackbarHostState, - onAlertConfigSet = { alertConfig = it }, - onAutoScrollSet = { isAutoScroll.value = true }, - ) -} - -@Suppress("LongMethod") -@Composable -private fun WalletContent( - state: WalletScreenState, - walletsListState: LazyListState, - snackbarHostState: SnackbarHostState, - isAutoScroll: State, - onAutoScrollReset: () -> Unit, -) { - var selectedWalletIndex by remember { mutableIntStateOf(state.selectedWalletIndex) } - val selectedWallet = state.wallets[selectedWalletIndex] - - BaseScaffold(state = state, selectedWallet = selectedWallet, snackbarHostState = snackbarHostState) { - val movableItemModifier = Modifier.changeWalletAnimator(walletsListState) - - val lazyTxHistoryItems = (selectedWallet as? TxHistoryStateHolder)?.let { walletState -> - (walletState.txHistoryState as? TxHistoryState.Content)?.contentItems?.collectAsLazyPagingItems() - } - - val txHistoryItems by remember(selectedWallet.walletCardState.id, lazyTxHistoryItems?.itemCount) { - mutableStateOf(value = lazyTxHistoryItems) - } - - val betweenItemsPadding = TangemTheme.dimens.spacing14 - val horizontalPadding = TangemTheme.dimens.spacing16 - val itemModifier = movableItemModifier - .padding(top = betweenItemsPadding) - .padding(horizontal = horizontalPadding) - - LazyColumn( - modifier = Modifier.fillMaxSize(), - contentPadding = PaddingValues( - top = TangemTheme.dimens.spacing8, - bottom = TangemTheme.dimens.spacing92, - ), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - item( - key = state.wallets.map { it.walletCardState.id }, - contentType = state.wallets.map { it.walletCardState.id }, - ) { - WalletsList( - lazyListState = walletsListState, - wallets = state.wallets.map(WalletState::walletCardState).toImmutableList(), - isBalanceHidden = state.isHidingMode, - ) - } - - (selectedWallet as? WalletState.SingleCurrency)?.let { - controlButtons( - configs = it.buttons, - selectedWalletIndex = selectedWalletIndex, - modifier = movableItemModifier.padding(top = betweenItemsPadding), - ) - } - - notifications(configs = selectedWallet.warnings, modifier = itemModifier) - - (selectedWallet as? WalletState.SingleCurrency)?.let { walletState -> - walletState.marketPriceBlockState?.let { marketPriceBlockState -> - marketPriceBlock(state = marketPriceBlockState, modifier = itemModifier) - } - } - - (selectedWallet as? WalletState.Visa.Content)?.let { - depositButton( - modifier = itemModifier.fillMaxWidth(), - state = it.depositButtonState, - ) - - balancesAndLimitsBlock( - modifier = itemModifier, - state = it.balancesAndLimitBlockState, - ) - } - - contentItemsV2( - state = selectedWallet, - txHistoryItems = txHistoryItems, - isBalanceHidden = state.isHidingMode, - modifier = movableItemModifier, - ) - - organizeTokens(state = selectedWallet, itemModifier = itemModifier) - } - - val bottomSheetConfig = selectedWallet.bottomSheetConfig - if (bottomSheetConfig != null) { - when (bottomSheetConfig.content) { - is WalletBottomSheetConfig -> WalletBottomSheet(config = bottomSheetConfig) - is TokenReceiveBottomSheetConfig -> TokenReceiveBottomSheet(config = bottomSheetConfig) - is ActionsBottomSheetConfig -> TokenActionsBottomSheet(config = bottomSheetConfig) - is ChooseAddressBottomSheetConfig -> ChooseAddressBottomSheet(config = bottomSheetConfig) - is BalancesAndLimitsBottomSheetConfig -> BalancesAndLimitsBottomSheet(config = bottomSheetConfig) - } - } - - WalletsListEffectsV2( - lazyListState = walletsListState, - selectedWalletIndex = selectedWalletIndex, - onWalletChange = state.onWalletChange, - onSelectedWalletIndexSet = { selectedWalletIndex = it }, - isAutoScroll = isAutoScroll, - onAutoScrollReset = onAutoScrollReset, - ) - } -} - -@OptIn(ExperimentalMaterialApi::class) -@Composable -private fun BaseScaffold( - state: WalletScreenState, - selectedWallet: WalletState, - snackbarHostState: SnackbarHostState, - content: @Composable () -> Unit, -) { - Scaffold( - topBar = { WalletTopBar(config = state.topBarConfig) }, - snackbarHost = { SnackbarHost(hostState = snackbarHostState) }, - floatingActionButton = { - val manageTokensButtonConfig by remember(state.selectedWalletIndex) { - mutableStateOf( - (state.wallets[state.selectedWalletIndex] as? WalletState.MultiCurrency)?.manageTokensButtonConfig, - ) - } - - manageTokensButtonConfig?.let { ManageTokensButton(onClick = it.onClick) } - }, - floatingActionButtonPosition = FabPosition.Center, - containerColor = TangemTheme.colors.background.secondary, - content = { - val pullRefreshState = rememberPullRefreshState( - refreshing = selectedWallet.pullToRefreshConfig.isRefreshing, - onRefresh = selectedWallet.pullToRefreshConfig.onRefresh, - ) - - Box( - modifier = Modifier - .pullRefresh(pullRefreshState) - .padding(it), - ) { - content() - - WalletPullToRefreshIndicator( - isRefreshing = selectedWallet.pullToRefreshConfig.isRefreshing, - state = pullRefreshState, - modifier = Modifier.align(Alignment.TopCenter), - ) - } - }, - ) -} - -@Composable -private fun ManageTokensButton(onClick: () -> Unit) { - PrimaryButton( - text = stringResource(id = R.string.main_manage_tokens), - onClick = onClick, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = TangemTheme.dimens.spacing16), - ) -} - -internal fun LazyListScope.organizeTokens(state: WalletState, itemModifier: Modifier) { - (state as? WalletState.MultiCurrency)?.let { - (state.tokensListState as? WalletTokensListState.ContentState)?.let { - it.organizeTokensButtonConfig?.let { config -> - organizeTokensButton( - modifier = itemModifier, - isEnabled = config.isEnabled, - onClick = config.onClick, - ) - } - } - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletsListEffects.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletsListEffects.kt index 482d206fbf..5765897931 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletsListEffects.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletsListEffects.kt @@ -5,24 +5,34 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.State import androidx.compose.runtime.snapshotFlow -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig import com.tangem.feature.wallet.presentation.wallet.ui.utils.ScrollOffsetCollector import com.tangem.feature.wallet.presentation.wallet.ui.utils.WalletsListInteractionsCollector +@Suppress("LongParameterList") @Composable internal fun WalletsListEffects( lazyListState: LazyListState, - walletsListConfig: WalletsListConfig, + selectedWalletIndex: Int, + onWalletChange: (Int) -> Unit, + onSelectedWalletIndexSet: (Int) -> Unit, isAutoScroll: State, onAutoScrollReset: () -> Unit, ) { - LaunchedEffect(key1 = lazyListState, key2 = walletsListConfig.onWalletChange) { + LaunchedEffect(key1 = lazyListState, key2 = onWalletChange) { snapshotFlow { lazyListState.layoutInfo.visibleItemsInfo } .collect( collector = ScrollOffsetCollector( + selectedWalletIndex = selectedWalletIndex, lazyListState = lazyListState, - walletsListConfig = walletsListConfig, - isAutoScroll = isAutoScroll, + onWalletChange = { newIndex -> + // Auto scroll must not change wallet + if (isAutoScroll.value) { + onSelectedWalletIndexSet(newIndex) + } else { + onSelectedWalletIndexSet(newIndex) + onWalletChange(newIndex) + } + }, ), ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletsListEffectsV2.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletsListEffectsV2.kt deleted file mode 100644 index d7dc0bb129..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletsListEffectsV2.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.ui - -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.State -import androidx.compose.runtime.snapshotFlow -import com.tangem.feature.wallet.presentation.wallet.ui.utils.ScrollOffsetCollectorV2 -import com.tangem.feature.wallet.presentation.wallet.ui.utils.WalletsListInteractionsCollector - -@Suppress("LongParameterList") -@Composable -internal fun WalletsListEffectsV2( - lazyListState: LazyListState, - selectedWalletIndex: Int, - onWalletChange: (Int) -> Unit, - onSelectedWalletIndexSet: (Int) -> Unit, - isAutoScroll: State, - onAutoScrollReset: () -> Unit, -) { - LaunchedEffect(key1 = lazyListState, key2 = onWalletChange) { - snapshotFlow { lazyListState.layoutInfo.visibleItemsInfo } - .collect( - collector = ScrollOffsetCollectorV2( - selectedWalletIndex = selectedWalletIndex, - lazyListState = lazyListState, - onWalletChange = { newIndex -> - // Auto scroll must not change wallet - if (isAutoScroll.value) { - onSelectedWalletIndexSet(newIndex) - } else { - onSelectedWalletIndexSet(newIndex) - onWalletChange(newIndex) - } - }, - ), - ) - } - - LaunchedEffect(Unit) { - lazyListState.interactionSource.interactions.collect( - collector = WalletsListInteractionsCollector(onDragStart = onAutoScrollReset), - ) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/TokenActionsBottomSheet.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/TokenActionsBottomSheet.kt index 104b25308d..865a52268f 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/TokenActionsBottomSheet.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/TokenActionsBottomSheet.kt @@ -15,8 +15,8 @@ import com.tangem.core.ui.components.getWarningRowColors 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.ActionsBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state.TokenActionButtonConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.ActionsBottomSheetConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.TokenActionButtonConfig import kotlinx.collections.immutable.ImmutableList @Composable 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 ff70bf8486..455cf810c4 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 @@ -14,7 +14,10 @@ import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalDensity @@ -23,51 +26,20 @@ import androidx.compose.ui.unit.Dp 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.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState import com.tangem.feature.wallet.presentation.wallet.ui.components.common.WalletCard import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toPersistentList private const val SHORT_SNAP_ELEMENT_COUNT = 50 /** * Wallets list component * - * @param config config * @param lazyListState main content container list state * [REDACTED_AUTHOR] */ -@OptIn(ExperimentalFoundationApi::class) -@Composable -internal fun WalletsList(config: WalletsListConfig, lazyListState: LazyListState, isBalanceHidden: Boolean) { - val horizontalCardPadding = TangemTheme.dimens.spacing16 - val screenWidth = LocalConfiguration.current.screenWidthDp.dp - val itemWidth by remember(screenWidth) { derivedStateOf { screenWidth - horizontalCardPadding * 2 } } - - LazyRow( - modifier = Modifier.background(color = TangemTheme.colors.background.secondary), - state = lazyListState, - contentPadding = PaddingValues(horizontal = TangemTheme.dimens.spacing16), - horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing8), - flingBehavior = rememberWalletsFlingBehaviour(lazyListState = lazyListState, itemWidth = itemWidth), - ) { - items( - items = config.wallets, - key = { it.id.stringValue }, - contentType = { it::class.java }, - ) { state -> - WalletCard( - state = state, - isBalanceHidden = isBalanceHidden, - modifier = Modifier - .animateItemPlacement() - .width(itemWidth), - ) - } - } -} - @OptIn(ExperimentalFoundationApi::class) @Composable internal fun WalletsList( @@ -136,8 +108,8 @@ private fun rememberWalletsFlingBehaviour(lazyListState: LazyListState, itemWidt private fun Preview_WalletsList_LightTheme() { TangemTheme(isDark = false) { WalletsList( - config = WalletPreviewData.walletListConfig, lazyListState = rememberLazyListState(), + wallets = WalletPreviewData.wallets.values.toPersistentList(), isBalanceHidden = false, ) } @@ -148,8 +120,8 @@ private fun Preview_WalletsList_LightTheme() { private fun Preview_WalletsList_DarkTheme() { TangemTheme(isDark = true) { WalletsList( - config = WalletPreviewData.walletListConfig, lazyListState = rememberLazyListState(), + wallets = WalletPreviewData.wallets.values.toPersistentList(), isBalanceHidden = false, ) } 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 b77393f8d6..1c16a6fc78 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 @@ -1,7 +1,8 @@ package com.tangem.feature.wallet.presentation.wallet.ui.components.common import androidx.compose.foundation.layout.* -import androidx.compose.material3.* +import androidx.compose.material3.Icon +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -19,7 +20,7 @@ import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig 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.components.WalletBottomSheetConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.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 345627ff8d..35a4a9bb1a 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 @@ -4,8 +4,11 @@ import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.compose.animation.* import androidx.compose.animation.core.tween -import androidx.compose.foundation.* +import androidx.compose.foundation.Image +import androidx.compose.foundation.LocalIndication +import androidx.compose.foundation.background import androidx.compose.foundation.gestures.detectTapGestures +import androidx.compose.foundation.indication import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.PressInteraction import androidx.compose.foundation.layout.* @@ -31,8 +34,13 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider -import androidx.compose.ui.unit.* -import androidx.constraintlayout.compose.* +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.DpOffset +import androidx.compose.ui.unit.IntSize +import androidx.compose.ui.unit.sp +import androidx.constraintlayout.compose.ConstraintLayout +import androidx.constraintlayout.compose.ConstraintLayoutScope +import androidx.constraintlayout.compose.Dimension import com.tangem.common.Strings import com.tangem.core.ui.components.FontSizeRange import com.tangem.core.ui.components.RectangleShimmer @@ -44,7 +52,7 @@ import com.tangem.core.ui.res.TangemDimens 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.components.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState private const val HALF_OF_ITEM_WIDTH = 0.5 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 30cf4bb156..c4ffea5ea7 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 @@ -5,12 +5,8 @@ import androidx.compose.ui.Modifier import androidx.paging.compose.LazyPagingItems import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.core.ui.components.transactions.txHistoryItems -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.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState import com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency.tokensListItems -import com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency.tokensListItemsV2 -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState as WalletStateV2 /** * Wallet content @@ -22,31 +18,19 @@ import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState as [REDACTED_AUTHOR] */ internal fun LazyListScope.contentItems( - state: WalletState.ContentState, + state: WalletState, txHistoryItems: LazyPagingItems?, isBalanceHidden: Boolean, modifier: Modifier = Modifier, ) { when (state) { - is WalletMultiCurrencyState -> tokensListItems(state.tokensListState, modifier, isBalanceHidden) - is WalletSingleCurrencyState -> txHistoryItems(state.txHistoryState, txHistoryItems, isBalanceHidden, modifier) - } -} - -internal fun LazyListScope.contentItemsV2( - state: WalletStateV2, - txHistoryItems: LazyPagingItems?, - isBalanceHidden: Boolean, - modifier: Modifier = Modifier, -) { - when (state) { - is WalletStateV2.MultiCurrency -> { - tokensListItemsV2(state.tokensListState, modifier, isBalanceHidden) + is WalletState.MultiCurrency -> { + tokensListItems(state.tokensListState, modifier, isBalanceHidden) } - is WalletStateV2.SingleCurrency -> { + is WalletState.SingleCurrency -> { txHistoryItems(state.txHistoryState, txHistoryItems, isBalanceHidden, modifier) } - is WalletStateV2.Visa -> { + is WalletState.Visa -> { txHistoryItems(state.txHistoryState, txHistoryItems, isBalanceHidden, modifier) } } 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 f258a71ce9..476f3701e4 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 @@ -7,7 +7,7 @@ import androidx.compose.ui.Modifier import com.tangem.core.ui.components.notifications.Notification import com.tangem.core.ui.components.notifications.NotificationWithBackground import com.tangem.core.ui.res.TangemTheme -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification import kotlinx.collections.immutable.ImmutableList /** 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 d22e971baf..4813eaff9f 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.components.WalletTopBarConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.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 9a855c797d..e0563a4400 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 @@ -17,10 +17,9 @@ import androidx.compose.ui.text.style.TextAlign import com.tangem.core.ui.decorations.roundedShapeItemDecoration import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState.TokensListItemState import kotlinx.collections.immutable.ImmutableList -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensListState as WalletTokensListStateV2 -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensListState.TokensListItemState as TokensListItemStateV2 private const val NON_CONTENT_TOKENS_LIST_KEY = "NON_CONTENT_TOKENS_LIST" @@ -38,56 +37,19 @@ internal fun LazyListScope.tokensListItems( isBalanceHidden: Boolean, ) { when (state) { - is WalletTokensListState.ContentState -> contentItems( - items = state.items, - isBalanceHidden = isBalanceHidden, - modifier = modifier, - ) - WalletTokensListState.Empty -> nonContentItem(modifier = modifier) - } -} - -internal fun LazyListScope.tokensListItemsV2( - state: WalletTokensListStateV2, - modifier: Modifier = Modifier, - isBalanceHidden: Boolean, -) { - when (state) { - is WalletTokensListStateV2.ContentState -> { - contentItemsV2( + is WalletTokensListState.ContentState -> { + contentItems( items = state.items, isBalanceHidden = isBalanceHidden, modifier = modifier, ) } - WalletTokensListStateV2.Empty -> nonContentItem(modifier = modifier) + WalletTokensListState.Empty -> nonContentItem(modifier = modifier) } } private fun LazyListScope.contentItems( - items: ImmutableList, - modifier: Modifier = Modifier, - isBalanceHidden: Boolean, -) { - itemsIndexed( - items = items, - key = { _, item -> item.id }, - contentType = { _, item -> item::class.java }, - itemContent = { index, item -> - MultiCurrencyContentItem( - state = item, - isBalanceHidden = isBalanceHidden, - modifier = modifier.roundedShapeItemDecoration( - currentIndex = index, - lastIndex = items.lastIndex, - ), - ) - }, - ) -} - -private fun LazyListScope.contentItemsV2( - items: ImmutableList, + items: ImmutableList, modifier: Modifier = Modifier, isBalanceHidden: Boolean, ) { 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 d94ee34b63..9d39d7fcbc 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 @@ -5,8 +5,7 @@ import androidx.compose.ui.Modifier import com.tangem.core.ui.extensions.resolveReference 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.components.WalletTokensListState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensListState.TokensListItemState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState.TokensListItemState /** * Multi-currency content item @@ -16,22 +15,6 @@ import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletTokensLi * [REDACTED_AUTHOR] */ -@Composable -internal fun MultiCurrencyContentItem( - state: WalletTokensListState.TokensListItemState, - isBalanceHidden: Boolean, - modifier: Modifier = Modifier, -) { - when (state) { - is WalletTokensListState.TokensListItemState.NetworkGroupTitle -> { - NetworkGroupItem(networkName = state.name.resolveReference(), modifier = modifier) - } - is WalletTokensListState.TokensListItemState.Token -> { - TokenItem(state = state.state, isBalanceHidden = isBalanceHidden, modifier = modifier) - } - } -} - @Composable internal fun MultiCurrencyContentItem( state: TokensListItemState, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyControlButtons.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyControlButtons.kt index af4d8c17ae..4b73b51b81 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyControlButtons.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyControlButtons.kt @@ -6,7 +6,7 @@ import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.ui.Modifier import com.tangem.core.ui.components.buttons.HorizontalActionChips import com.tangem.core.ui.res.TangemTheme -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletManageButton 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/ui/components/visa/BalancesAndLimitsBlock.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/BalancesAndLimitsBlock.kt index 5855ab22f6..6fe4af13e5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/BalancesAndLimitsBlock.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/BalancesAndLimitsBlock.kt @@ -16,7 +16,7 @@ import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameter import com.tangem.core.ui.components.RectangleShimmer import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.state2.model.BalancesAndLimitsBlockState +import com.tangem.feature.wallet.presentation.wallet.state.model.BalancesAndLimitsBlockState private const val BALANCES_AND_LIMITS_BLOCK_KEY = "BalancesAndLimitsBlock" diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/BalancesAndLimitsBottomSheet.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/BalancesAndLimitsBottomSheet.kt index bd590c3ac4..fce6384945 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/BalancesAndLimitsBottomSheet.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/BalancesAndLimitsBottomSheet.kt @@ -21,7 +21,7 @@ import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.state2.model.BalancesAndLimitsBottomSheetConfig +import com.tangem.feature.wallet.presentation.wallet.state.model.BalancesAndLimitsBottomSheetConfig @Composable internal fun BalancesAndLimitsBottomSheet(config: TangemBottomSheetConfig) { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/VisaDepositButton.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/VisaDepositButton.kt index 85dab308e0..30bb253d24 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/VisaDepositButton.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/visa/VisaDepositButton.kt @@ -4,7 +4,7 @@ import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.ui.Modifier import com.tangem.core.ui.components.SecondaryButtonIconStart import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.wallet.state2.model.DepositButtonState +import com.tangem.feature.wallet.presentation.wallet.state.model.DepositButtonState private const val DEPOSIT_BUTTON_CONTENT_TYPE = "DepositButton" diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/ScrollOffsetCollector.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/ScrollOffsetCollector.kt index 2119079f09..939886db4a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/ScrollOffsetCollector.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/ScrollOffsetCollector.kt @@ -2,8 +2,6 @@ package com.tangem.feature.wallet.presentation.wallet.ui.utils import androidx.compose.foundation.lazy.LazyListItemInfo import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.runtime.State -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig import kotlinx.coroutines.flow.FlowCollector import kotlin.math.abs @@ -12,46 +10,40 @@ import kotlin.math.abs * If first visible item offset is greater than half item size, then change selected wallet index. * If last visible item offset is greater than half item size, then change selected wallet index. * + * @param selectedWalletIndex selected wallet index * @property lazyListState lazy list state - * @property walletsListConfig wallets list config - * @property isAutoScroll check if last scrolling is auto scroll + * @property onWalletChange callback that will be invoked on wallet change * [REDACTED_AUTHOR] */ internal class ScrollOffsetCollector( + selectedWalletIndex: Int, private val lazyListState: LazyListState, - private val walletsListConfig: WalletsListConfig, - private val isAutoScroll: State, + private val onWalletChange: (Int) -> Unit, ) : FlowCollector> { private val LazyListItemInfo.halfItemSize get() = size.div(other = 2) - private var currentIndex = walletsListConfig.selectedWalletIndex + private var currentIndex = selectedWalletIndex override suspend fun emit(value: List) { - // Auto scroll must not change wallet - if (isAutoScroll.value) { - currentIndex = walletsListConfig.selectedWalletIndex - return - } - if (!lazyListState.isScrollInProgress || value.size <= 1) return val firstItem = value.firstOrNull() ?: return val lastItem = value.lastOrNull() ?: return if (abs(firstItem.offset) > firstItem.halfItemSize) { - onWalletChange(newIndex = firstItem.index + 1) + selectIndex(newIndex = firstItem.index + 1) } else if (abs(lastItem.offset) > lastItem.halfItemSize) { - onWalletChange(newIndex = lastItem.index - 1) + selectIndex(newIndex = lastItem.index - 1) } } - private fun onWalletChange(newIndex: Int) { + private fun selectIndex(newIndex: Int) { if (currentIndex != newIndex) { currentIndex = newIndex - walletsListConfig.onWalletChange(newIndex) + onWalletChange(newIndex) } } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/ScrollOffsetCollectorV2.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/ScrollOffsetCollectorV2.kt deleted file mode 100644 index 43a4af298b..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/ScrollOffsetCollectorV2.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.ui.utils - -import androidx.compose.foundation.lazy.LazyListItemInfo -import androidx.compose.foundation.lazy.LazyListState -import kotlinx.coroutines.flow.FlowCollector -import kotlin.math.abs - -/** - * Flow collector for scroll items tracking. - * If first visible item offset is greater than half item size, then change selected wallet index. - * If last visible item offset is greater than half item size, then change selected wallet index. - * - * @param selectedWalletIndex selected wallet index - * @property lazyListState lazy list state - * @property onWalletChange callback that will be invoked on wallet change - * -[REDACTED_AUTHOR] - */ -internal class ScrollOffsetCollectorV2( - selectedWalletIndex: Int, - private val lazyListState: LazyListState, - private val onWalletChange: (Int) -> Unit, -) : FlowCollector> { - - private val LazyListItemInfo.halfItemSize - get() = size.div(other = 2) - - private var currentIndex = selectedWalletIndex - - override suspend fun emit(value: List) { - if (!lazyListState.isScrollInProgress || value.size <= 1) return - - val firstItem = value.firstOrNull() ?: return - val lastItem = value.lastOrNull() ?: return - - if (abs(firstItem.offset) > firstItem.halfItemSize) { - selectIndex(newIndex = firstItem.index + 1) - } else if (abs(lastItem.offset) > lastItem.halfItemSize) { - selectIndex(newIndex = lastItem.index - 1) - } - } - - private fun selectIndex(newIndex: Int) { - if (currentIndex != newIndex) { - currentIndex = newIndex - onWalletChange(newIndex) - } - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/WalletsScrollPreviewExt.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/WalletsScrollPreviewExt.kt index 3dbb6ccb11..f75f58b867 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/WalletsScrollPreviewExt.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/utils/WalletsScrollPreviewExt.kt @@ -4,7 +4,7 @@ import androidx.compose.animation.core.Spring import androidx.compose.animation.core.spring import androidx.compose.foundation.gestures.animateScrollBy import androidx.compose.foundation.lazy.LazyListState -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent.DemonstrateWalletsScrollPreview +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent.DemonstrateWalletsScrollPreview import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CryptoCurrencyStatusToTokenItemConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CryptoCurrencyStatusToTokenItemConverter.kt deleted file mode 100644 index e9ef5cc769..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CryptoCurrencyStatusToTokenItemConverter.kt +++ /dev/null @@ -1,122 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.utils - -import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter -import com.tangem.core.ui.components.marketprice.PriceChangeType -import com.tangem.core.ui.utils.BigDecimalFormatter -import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.feature.wallet.presentation.common.state.TokenItemState -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import java.math.BigDecimal - -internal class CryptoCurrencyStatusToTokenItemConverter( - private val appCurrencyProvider: Provider, - private val clickIntents: WalletClickIntents, -) : Converter { - - private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter) - - override fun convert(value: CryptoCurrencyStatus): TokenItemState { - return when (value.value) { - is CryptoCurrencyStatus.Loading -> value.mapToLoadingState() - is CryptoCurrencyStatus.Loaded, - is CryptoCurrencyStatus.Custom, - is CryptoCurrencyStatus.NoQuote, - is CryptoCurrencyStatus.NoAccount, - -> value.mapToTokenItemState() - is CryptoCurrencyStatus.MissedDerivation -> value.mapToNoAddressTokenItemState() - is CryptoCurrencyStatus.Unreachable, - is CryptoCurrencyStatus.NoAmount, - -> value.mapToUnreachableTokenItemState() - } - } - - private fun CryptoCurrencyStatus.mapToLoadingState(): TokenItemState.Loading { - return TokenItemState.Loading( - id = currency.id.value, - iconState = iconStateConverter.convert(value = this), - titleState = TokenItemState.TitleState.Content(text = currency.name), - ) - } - - private fun CryptoCurrencyStatus.mapToTokenItemState(): TokenItemState.Content { - return TokenItemState.Content( - id = currency.id.value, - iconState = iconStateConverter.convert(value = this), - titleState = TokenItemState.TitleState.Content( - text = currency.name, - hasPending = value.hasCurrentNetworkTransactions, - ), - fiatAmountState = TokenItemState.FiatAmountState.Content( - text = getFormattedFiatAmount(), - ), - cryptoAmountState = TokenItemState.CryptoAmountState.Content(text = getFormattedAmount()), - cryptoPriceState = getCryptoPriceState(), - onItemClick = { clickIntents.onTokenItemClick(currency) }, - onItemLongClick = { clickIntents.onTokenItemLongClick(cryptoCurrencyStatus = this) }, - ) - } - - private fun CryptoCurrencyStatus.getFormattedAmount(): String { - val amount = value.amount ?: return TokenItemState.UNKNOWN_AMOUNT_SIGN - - return BigDecimalFormatter.formatCryptoAmount(amount, currency.symbol, currency.decimals) - } - - private fun CryptoCurrencyStatus.getFormattedFiatAmount(): String { - val fiatAmount = value.fiatAmount ?: return TokenItemState.UNKNOWN_AMOUNT_SIGN - val appCurrency = appCurrencyProvider() - - return BigDecimalFormatter.formatFiatAmount(fiatAmount, appCurrency.code, appCurrency.symbol) - } - - private fun CryptoCurrencyStatus.mapToUnreachableTokenItemState() = TokenItemState.Unreachable( - id = currency.id.value, - iconState = iconStateConverter.convert(value = this), - titleState = TokenItemState.TitleState.Content(text = currency.name), - onItemClick = { clickIntents.onTokenItemClick(currency) }, - onItemLongClick = { clickIntents.onTokenItemLongClick(cryptoCurrencyStatus = this) }, - ) - - private fun CryptoCurrencyStatus.mapToNoAddressTokenItemState() = TokenItemState.NoAddress( - id = currency.id.value, - iconState = iconStateConverter.convert(this), - titleState = TokenItemState.TitleState.Content(text = currency.name), - onItemLongClick = { clickIntents.onTokenItemLongClick(cryptoCurrencyStatus = this) }, - ) - - private fun CryptoCurrencyStatus.getCryptoPriceState(): TokenItemState.CryptoPriceState { - val fiatRate = value.fiatRate - val priceChange = value.priceChange - - return if (fiatRate != null && priceChange != null) { - TokenItemState.CryptoPriceState.Content( - price = fiatRate.getFormattedCryptoPrice(), - priceChangePercent = BigDecimalFormatter.formatPercent( - percent = priceChange, - useAbsoluteValue = true, - maxFractionDigits = 1, - minFractionDigits = 1, - ), - type = priceChange.getPriceChangeType(), - ) - } else { - TokenItemState.CryptoPriceState.Unknown - } - } - - private fun BigDecimal.getFormattedCryptoPrice(): String { - val appCurrency = appCurrencyProvider() - return BigDecimalFormatter.formatFiatAmount( - fiatAmount = this, - fiatCurrencyCode = appCurrency.code, - fiatCurrencySymbol = appCurrency.symbol, - ) - } - - private fun BigDecimal.getPriceChangeType(): PriceChangeType { - return if (this > BigDecimal.ZERO) PriceChangeType.UP else PriceChangeType.DOWN - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CurrencyStatusErrorConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CurrencyStatusErrorConverter.kt deleted file mode 100644 index 19f35776b0..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/CurrencyStatusErrorConverter.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.utils - -import com.tangem.domain.tokens.error.CurrencyStatusError -import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter - -// TODO: Implement this -internal class CurrencyStatusErrorConverter( - private val currentStateProvider: Provider, -) : Converter { - - override fun convert(value: CurrencyStatusError): WalletSingleCurrencyState.Content { - return requireNotNull(currentStateProvider() as? WalletSingleCurrencyState.Content) - } -} \ No newline at end of file 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 deleted file mode 100644 index 3bd3dc16d5..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.utils - -import com.tangem.core.ui.utils.BigDecimalFormatter.formatFiatAmount -import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.tokens.model.TokenList.FiatBalance -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.presentation.wallet.domain.WalletAdditionalInfoFactory -import com.tangem.feature.wallet.presentation.wallet.domain.getCardsCount -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter - -internal class FiatBalanceToWalletCardConverter( - private val currentState: WalletCardState, - private val appCurrencyProvider: Provider, - private val currentWalletProvider: Provider, -) : Converter { - - override fun convert(value: FiatBalance): WalletCardState { - return when (value) { - is FiatBalance.Loading -> currentState.toLoadingWalletCardState() - is FiatBalance.Failed -> currentState.toErrorWalletCardState() - is FiatBalance.Loaded -> value.convertToWalletCardState() - } - } - - private fun WalletCardState.toLoadingWalletCardState(): WalletCardState { - return WalletCardState.Loading(id, title, additionalInfo, imageResId, onRenameClick, onDeleteClick) - } - - private fun WalletCardState.toErrorWalletCardState(): WalletCardState { - return WalletCardState.Error( - id = id, - title = title, - additionalInfo = additionalInfo, - imageResId = imageResId, - onDeleteClick = onDeleteClick, - onRenameClick = onRenameClick, - ) - } - - private fun FiatBalance.Loaded.convertToWalletCardState(): WalletCardState { - val appCurrency = appCurrencyProvider() - - return WalletCardState.Content( - id = currentState.id, - title = currentState.title, - additionalInfo = WalletAdditionalInfoFactory.resolve(wallet = currentWalletProvider()), - imageResId = currentState.imageResId, - onRenameClick = currentState.onRenameClick, - onDeleteClick = currentState.onDeleteClick, - balance = formatFiatAmount( - fiatAmount = this.amount, - fiatCurrencyCode = appCurrency.code, - fiatCurrencySymbol = appCurrency.symbol, - ), - cardCount = currentWalletProvider().getCardsCount(), - ) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/HiddenStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/HiddenStateConverter.kt deleted file mode 100644 index 66508d3110..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/HiddenStateConverter.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.utils - -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.WalletState -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter - -internal class HiddenStateConverter( - private val currentStateProvider: Provider, -) : Converter { - - override fun convert(value: Boolean): WalletState { - return when (val state = currentStateProvider() as? WalletState.ContentState) { - is WalletMultiCurrencyState.Content -> { - state.copy(isBalanceHidden = value) - } - - is WalletSingleCurrencyState.Content -> { - state.copy(isBalanceHidden = value) - } - - else -> currentStateProvider() - } - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListErrorConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListErrorConverter.kt deleted file mode 100644 index 512fd08483..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListErrorConverter.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.utils - -import com.tangem.domain.tokens.error.TokenListError -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.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter - -internal class TokenListErrorConverter( - private val currentStateProvider: Provider, -) : Converter { - - override fun convert(value: TokenListError): WalletState { - val state = currentStateProvider() - return when (value) { - is TokenListError.EmptyTokens -> state.mapToEmptyTokensState() - is TokenListError.DataError, - is TokenListError.UnableToSortTokenList, - -> state - } - } - - private fun WalletState.mapToEmptyTokensState(): WalletState { - return when (this) { - is WalletMultiCurrencyState.Content -> copy(tokensListState = WalletTokensListState.Empty) - is WalletMultiCurrencyState.Locked, - is WalletSingleCurrencyState.Content, - is WalletSingleCurrencyState.Locked, - is WalletState.Initial, - -> this - } - } -} \ No newline at end of file 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 deleted file mode 100644 index 0f40074e67..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToContentItemsConverter.kt +++ /dev/null @@ -1,114 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.utils - -import com.tangem.core.ui.extensions.stringReference -import com.tangem.domain.appcurrency.model.AppCurrency -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.components.WalletTokensListState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState.OrganizeTokensButtonState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState.TokensListItemState -import com.tangem.feature.wallet.presentation.wallet.state.factory.TokenListWithWallet -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.PersistentList -import kotlinx.collections.immutable.mutate -import kotlinx.collections.immutable.persistentListOf - -internal class TokenListToContentItemsConverter( - appCurrencyProvider: Provider, - private val clickIntents: WalletClickIntents, -) : Converter { - - private val tokenStatusConverter = CryptoCurrencyStatusToTokenItemConverter( - appCurrencyProvider = appCurrencyProvider, - clickIntents = clickIntents, - ) - - override fun convert(value: TokenListWithWallet): WalletTokensListState { - val isSingleCurrencyWalletWithToken = !value.wallet.isMultiCurrency && - value.wallet.scanResponse.walletData?.token != null - return when (val tokenList = value.tokenList) { - is TokenList.Empty -> WalletTokensListState.Empty - is TokenList.GroupedByNetwork -> WalletTokensListState.Content( - items = tokenList.mapToMultiCurrencyItems(), - organizeTokensButton = tokenList.mapToOrganizeTokensButtonState(isSingleCurrencyWalletWithToken), - ) - is TokenList.Ungrouped -> WalletTokensListState.Content( - items = tokenList.mapToMultiCurrencyItems(), - organizeTokensButton = tokenList.mapToOrganizeTokensButtonState(isSingleCurrencyWalletWithToken), - ) - } - } - - private fun TokenList.GroupedByNetwork.mapToMultiCurrencyItems(): PersistentList { - return groups.fold(initial = persistentListOf()) { acc, group -> - acc.mutate { it.addGroup(group) } - } - } - - private fun TokenList.Ungrouped.mapToMultiCurrencyItems(): PersistentList { - return currencies.fold(initial = persistentListOf()) { acc, token -> - acc.mutate { it.addToken(token) } - } - } - - private fun TokenList.GroupedByNetwork.mapToOrganizeTokensButtonState( - isSingleCurrencyWithTokenWallet: Boolean, - ): OrganizeTokensButtonState { - return getOrganizeTokensButtonState( - isLoading = totalFiatBalance is TokenList.FiatBalance.Loading, - currenciesSize = groups.flatMap(NetworkGroup::currencies).size, - isSingleCurrencyWithTokenWallet = isSingleCurrencyWithTokenWallet, - ) - } - - private fun TokenList.Ungrouped.mapToOrganizeTokensButtonState( - isSingleCurrencyWithTokenWallet: Boolean, - ): OrganizeTokensButtonState { - return getOrganizeTokensButtonState( - isLoading = totalFiatBalance is TokenList.FiatBalance.Loading, - currenciesSize = currencies.size, - isSingleCurrencyWithTokenWallet = isSingleCurrencyWithTokenWallet, - ) - } - - private fun MutableList.addGroup(group: NetworkGroup): List { - val groupTitle = TokensListItemState.NetworkGroupTitle( - id = group.network.hashCode(), - name = stringReference(group.network.name), - ) - - this.add(groupTitle) - - group.currencies.forEach { token -> - this.addToken(token) - } - - return this - } - - private fun MutableList.addToken(token: CryptoCurrencyStatus): List { - val tokenItemState = tokenStatusConverter.convert(token) - - this.add(TokensListItemState.Token(tokenItemState)) - - return this - } - - private fun getOrganizeTokensButtonState( - isLoading: Boolean, - currenciesSize: Int, - isSingleCurrencyWithTokenWallet: Boolean, - ): OrganizeTokensButtonState { - return if (currenciesSize > 1 && !isSingleCurrencyWithTokenWallet) { - OrganizeTokensButtonState.Visible( - isEnabled = !isLoading, - onClick = clickIntents::onOrganizeTokensClick, - ) - } else { - OrganizeTokensButtonState.Hidden - } - } -} \ No newline at end of file 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 deleted file mode 100644 index 823ce6e272..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/TokenListToWalletStateConverter.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.utils - -import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.common.util.cardTypesResolver -import com.tangem.domain.tokens.model.TokenList -import com.tangem.domain.wallets.models.UserWallet -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.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletsListConfig -import com.tangem.feature.wallet.presentation.wallet.state.factory.TokenListWithWallet -import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.toPersistentList - -@Suppress("LongParameterList") -internal class TokenListToWalletStateConverter( - private val currentStateProvider: Provider, - private val currentWalletProvider: Provider, - private val appCurrencyProvider: Provider, - clickIntents: WalletClickIntents, -) : Converter { - - private val tokenListToContentConverter = TokenListToContentItemsConverter( - appCurrencyProvider = appCurrencyProvider, - clickIntents = clickIntents, - ) - - override fun convert(value: TokenListWithWallet): WalletState { - val tokenList = value.tokenList - val isSingleCurrencyWalletWithToken = value.wallet.scanResponse.cardTypesResolver.isSingleWalletWithToken() - return when (val state = currentStateProvider()) { - is WalletMultiCurrencyState.Content -> { - state.copy( - walletsListConfig = state.updateSelectedWallet(fiatBalance = tokenList.totalFiatBalance), - tokensListState = tokenListToContentConverter.convert(value = value), - isManageTokensAvailable = !isSingleCurrencyWalletWithToken, - ) - } - is WalletMultiCurrencyState.Locked, - is WalletSingleCurrencyState.Content, - is WalletSingleCurrencyState.Locked, - is WalletState.Initial, - -> state - } - } - - private fun WalletMultiCurrencyState.updateSelectedWallet(fiatBalance: TokenList.FiatBalance): WalletsListConfig { - val selectedWalletIndex = walletsListConfig.selectedWalletIndex - val selectedWalletCard = walletsListConfig.wallets[selectedWalletIndex] - val converter = FiatBalanceToWalletCardConverter( - currentState = selectedWalletCard, - currentWalletProvider = currentWalletProvider, - appCurrencyProvider = appCurrencyProvider, - ) - - return walletsListConfig.copy( - wallets = walletsListConfig.wallets.toPersistentList() - .set(index = selectedWalletIndex, element = converter.convert(fiatBalance)), - ) - } -} \ No newline at end of file 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 deleted file mode 100644 index dad5efb741..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt +++ /dev/null @@ -1,77 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.viewmodels - -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.domain.wallets.models.UserWalletId - -@Suppress("TooManyFunctions") -internal interface WalletClickIntents { - - fun onBackClick() - - fun onGenerateMissedAddressesClick(missedAddressCurrencies: List) - - fun onScanToUnlockWalletClick() - - fun onDetailsClick() - - fun onBackupCardClick() - - fun onSignedHashesNotificationCloseClick() - - fun onLikeAppClick() - - fun onDislikeAppClick() - - fun onCloseRateAppNotificationClick() - - fun onWalletChange(index: Int) - - fun onRefreshSwipe() - - fun onOrganizeTokensClick() - - fun onUnlockWalletClick() - - fun onUnlockWalletNotificationClick() - - fun onDismissBottomSheet() - - fun onTokenItemClick(currency: CryptoCurrency) - - fun onTokenItemLongClick(cryptoCurrencyStatus: CryptoCurrencyStatus) - - fun onRenameClick(userWalletId: UserWalletId, name: String) - - fun onDeleteBeforeConfirmationClick(userWalletId: UserWalletId) - - fun onDeleteAfterConfirmationClick(userWalletId: UserWalletId) - - fun onSingleCurrencySendClick(cryptoCurrencyStatus: CryptoCurrencyStatus? = null) - - fun onMultiCurrencySendClick(cryptoCurrencyStatus: CryptoCurrencyStatus) - - fun onReceiveClick(cryptoCurrencyStatus: CryptoCurrencyStatus) - - fun onCopyAddressClick(cryptoCurrencyStatus: CryptoCurrencyStatus) - - fun onHideTokensClick(cryptoCurrencyStatus: CryptoCurrencyStatus) - - fun onPerformHideToken(cryptoCurrencyStatus: CryptoCurrencyStatus) - - fun onSellClick(cryptoCurrencyStatus: CryptoCurrencyStatus) - - fun onManageTokensClick() - - fun onBuyClick(cryptoCurrencyStatus: CryptoCurrencyStatus) - - fun onSwapClick(cryptoCurrencyStatus: CryptoCurrencyStatus) - - fun onReloadClick() - - fun onExploreClick() - - fun onTransactionClick(txHash: String) - - fun onCloseSwapPromoNotificationClick() -} \ 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 deleted file mode 100644 index c0145c919b..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt +++ /dev/null @@ -1,230 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.viewmodels - -import arrow.core.Either -import com.tangem.domain.common.CardTypesResolver -import com.tangem.domain.common.util.cardTypesResolver -import com.tangem.domain.demo.IsDemoCardUseCase -import com.tangem.domain.settings.IsReadyToShowRateAppUseCase -import com.tangem.domain.settings.ShouldShowSwapPromoWalletUseCase -import com.tangem.domain.tokens.GetMissedAddressesCryptoCurrenciesUseCase -import com.tangem.domain.tokens.error.GetCurrenciesError -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.usecase.IsNeedToBackupUseCase -import com.tangem.feature.wallet.presentation.wallet.domain.HasSingleWalletSignedHashesUseCase -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletNotification -import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.toImmutableList -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.conflate -import kotlinx.coroutines.flow.flowOf - -/** - * Wallet notifications list factory - * - * @property isDemoCardUseCase use case that checks if card is demo - * @property isReadyToShowRateAppUseCase use case that checks if card is user already rate app - * @property isNeedToBackupUseCase use case that checks if wallet need backup cards - * @property getMissedAddressCryptoCurrenciesUseCase use case that gets missed address crypto currencies - * @property hasSingleWalletSignedHashesUseCase use case that checks if single wallet signed hashes - * @property shouldShowSwapPromoWalletUseCase use case that checks if should show swap promo - * @property clickIntents screen click intents - * -[REDACTED_AUTHOR] - */ -@Suppress("LongParameterList") -internal class WalletNotificationsListFactory( - private val isDemoCardUseCase: IsDemoCardUseCase, - private val isReadyToShowRateAppUseCase: IsReadyToShowRateAppUseCase, - private val isNeedToBackupUseCase: IsNeedToBackupUseCase, - private val getMissedAddressCryptoCurrenciesUseCase: GetMissedAddressesCryptoCurrenciesUseCase, - private val hasSingleWalletSignedHashesUseCase: HasSingleWalletSignedHashesUseCase, - private val shouldShowSwapPromoWalletUseCase: ShouldShowSwapPromoWalletUseCase, - private val clickIntents: WalletClickIntents, -) { - - private var readyForRateAppNotification = false - - fun create( - selectedWallet: UserWallet, - cryptoCurrencyList: List, - ): Flow> { - val cardTypesResolver = selectedWallet.scanResponse.cardTypesResolver - return combine( - flow = hasSingleWalletSignedHashesFlow(selectedWallet, cryptoCurrencyList), - flow2 = isReadyToShowRateAppUseCase().conflate(), - flow3 = isNeedToBackupUseCase(selectedWallet.walletId).conflate(), - flow4 = getMissedAddressCryptoCurrenciesUseCase(selectedWallet.walletId).conflate(), - flow5 = shouldShowSwapPromoWalletUseCase().conflate(), - ) { hasSignedHashes, isReadyToShowRating, isNeedToBackup, maybeMissedAddressCurrencies, isShowSwapPromo -> - readyForRateAppNotification = true - buildList { - addSwapPromoNotification(isShowSwapPromo, cardTypesResolver) - - addCriticalNotifications(cardTypesResolver) - - addInformationalNotifications(cardTypesResolver, maybeMissedAddressCurrencies) - - addWarningNotifications(cardTypesResolver, cryptoCurrencyList, hasSignedHashes, isNeedToBackup) - - addRateTheAppNotification(isReadyToShowRating) - }.toImmutableList() - } - } - - private fun hasSingleWalletSignedHashesFlow( - selectedWallet: UserWallet, - cryptoCurrencyList: List, - ): Flow { - return if (selectedWallet.scanResponse.cardTypesResolver.isMultiwalletAllowed()) { - flowOf(value = false) - } else { - val network = requireNotNull(cryptoCurrencyList.firstOrNull()?.currency?.network) - hasSingleWalletSignedHashesUseCase(userWallet = selectedWallet, network = network).conflate() - } - } - - private fun MutableList.addSwapPromoNotification( - showSwapPromo: Boolean, - cardTypesResolver: CardTypesResolver, - ) { - addIf( - element = WalletNotification.SwapPromo( - clickIntents::onCloseSwapPromoNotificationClick, - ), - condition = showSwapPromo && cardTypesResolver.isMultiwalletAllowed(), - ) - } - - private fun MutableList.addCriticalNotifications(cardTypesResolver: CardTypesResolver) { - addIf( - element = WalletNotification.Critical.DevCard, - condition = !cardTypesResolver.isReleaseFirmwareType(), - ) - - addIf( - element = WalletNotification.Critical.FailedCardValidation, - condition = cardTypesResolver.isReleaseFirmwareType() && cardTypesResolver.isAttestationFailed(), - ) - - cardTypesResolver.getRemainingSignatures()?.let { remainingSignatures -> - addIf( - element = WalletNotification.Warning.LowSignatures(count = remainingSignatures), - condition = remainingSignatures <= MAX_REMAINING_SIGNATURES_COUNT, - ) - } - } - - private fun MutableList.addRateTheAppNotification(isReadyToShowRating: Boolean) { - addIf( - element = WalletNotification.RateApp( - onLikeClick = clickIntents::onLikeAppClick, - onDislikeClick = clickIntents::onDislikeAppClick, - onCloseClick = clickIntents::onCloseRateAppNotificationClick, - ), - condition = isReadyToShowRating && readyForRateAppNotification, - ) - } - - private fun MutableList.addWarningNotifications( - cardTypesResolver: CardTypesResolver, - cryptoCurrencyList: List, - hasSignedHashes: Boolean, - isNeedToBackup: Boolean, - ) { - addIf( - element = WalletNotification.Warning.MissingBackup( - onStartBackupClick = clickIntents::onBackupCardClick, - ), - condition = isNeedToBackup, - ) - - addIf( - element = WalletNotification.Warning.TestNetCard, - condition = cardTypesResolver.isTestCard(), - ) - - if (cardTypesResolver.isMultiwalletAllowed()) { - addIf( - element = WalletNotification.Warning.SomeNetworksUnreachable, - condition = cryptoCurrencyList.hasUnreachableNetworks(), - ) - } else { - addIf( - element = WalletNotification.Warning.NetworksUnreachable, - condition = cryptoCurrencyList.hasUnreachableNetworks(), - ) - - addNoAccountWarning(cryptoCurrencyList) - - addIf( - element = WalletNotification.Warning.NumberOfSignedHashesIncorrect( - onCloseClick = clickIntents::onSignedHashesNotificationCloseClick, - ), - condition = hasSignedHashes, - ) - } - } - - private fun MutableList.addInformationalNotifications( - cardTypesResolver: CardTypesResolver, - maybeMissedAddressCurrencies: Either>, - ) { - addIf( - element = WalletNotification.Informational.DemoCard, - condition = isDemoCardUseCase(cardId = cardTypesResolver.getCardId()), - ) - - addMissingAddressesNotification(maybeMissedAddressCurrencies) - } - - private fun MutableList.addIf(element: WalletNotification, condition: Boolean) { - if (condition) { - add(element = element) - if (element is WalletNotification.Critical || element is WalletNotification.Warning) { - readyForRateAppNotification = false - } - } - } - - private fun MutableList.addMissingAddressesNotification( - maybeCurrencies: Either>, - ) { - val missingAddressCurrencies = (maybeCurrencies as? Either.Right)?.value ?: return - - addIf( - element = WalletNotification.Informational.MissingAddresses( - missingAddressesCount = missingAddressCurrencies.count(), - onGenerateClick = { - clickIntents.onGenerateMissedAddressesClick(missedAddressCurrencies = missingAddressCurrencies) - }, - ), - condition = missingAddressCurrencies.isNotEmpty(), - ) - } - - private fun List.hasUnreachableNetworks(): Boolean { - return any { it.value is CryptoCurrencyStatus.Unreachable } - } - - private fun MutableList.addNoAccountWarning(cryptoCurrencyList: List) { - val noAccountNetwork = cryptoCurrencyList.firstOrNull { it.value is CryptoCurrencyStatus.NoAccount } - if (noAccountNetwork != null) { - val amountToCreateAccount = (noAccountNetwork.value as? CryptoCurrencyStatus.NoAccount) - ?.amountToCreateAccount.toString() - add( - element = WalletNotification.Informational.NoAccount( - network = noAccountNetwork.currency.name, - amount = amountToCreateAccount, - symbol = noAccountNetwork.currency.symbol, - ), - ) - } - } - - private companion object { - const val MAX_REMAINING_SIGNATURES_COUNT = 10 - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateCache.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateCache.kt deleted file mode 100644 index 0c81b8e3ee..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateCache.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.viewmodels - -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state.WalletState - -/** - * Wallet state cache. It allows to switch the wallets without additional loading like a PagerView. - * -[REDACTED_AUTHOR] - */ -internal object WalletStateCache { - - private val states = mutableMapOf() - - /** Get state by [userWalletId] */ - fun getState(userWalletId: UserWalletId): WalletState.ContentState? = states[userWalletId] - - /** Add or update [state] by [userWalletId] */ - fun update(userWalletId: UserWalletId, state: WalletState.ContentState) { - states[userWalletId] = state - } - - /** Update all content states */ - fun updateAll(block: (WalletState.ContentState.() -> WalletState.ContentState)) { - states.keys.forEach { - states[it] = block(requireNotNull(states[it])) - } - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateHolder.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateHolder.kt deleted file mode 100644 index 59c1f39f13..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateHolder.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.viewmodels - -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue -import com.tangem.feature.wallet.presentation.wallet.state.WalletState - -/** - * Wallet state holder - * - * @param initialState initial ui state - * -[REDACTED_AUTHOR] - */ -internal class WalletStateHolder(initialState: WalletState) { - - /** Screen state */ - var uiState: WalletState by mutableStateOf(initialState) - private set - - /** Set screen [state] */ - fun setState(state: WalletState) { - when (state) { - is WalletState.ContentState -> { - cache(state = state) - - uiState = state - } - is WalletState.Initial -> Unit - } - } - - /** Cache [state] [WalletState.ContentState] to [WalletStateCache] */ - private fun cache(state: WalletState.ContentState) { - val selectedWalletIndex = state.walletsListConfig.selectedWalletIndex - val selectedWalletId = state.walletsListConfig.wallets[selectedWalletIndex].id - - WalletStateCache.update(userWalletId = selectedWalletId, state = state) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateHolderDelegate.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateHolderDelegate.kt deleted file mode 100644 index 25c3d12698..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletStateHolderDelegate.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.viewmodels - -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -import kotlin.properties.ReadWriteProperty -import kotlin.reflect.KProperty - -internal class WalletStateHolderDelegate( - private val uiStateHolder: WalletStateHolder, -) : ReadWriteProperty { - - override fun getValue(thisRef: Any?, property: KProperty<*>): WalletState = uiStateHolder.uiState - - override fun setValue(thisRef: Any?, property: KProperty<*>, value: WalletState) { - uiStateHolder.setState(value) - } -} - -internal fun uiStateHolder(initialState: WalletState): ReadWriteProperty { - return WalletStateHolderDelegate(uiStateHolder = WalletStateHolder(initialState = initialState)) -} \ 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 71d9d95d97..6c4a46d2ee 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 @@ -1,1340 +1,319 @@ package com.tangem.feature.wallet.presentation.wallet.viewmodels -import androidx.lifecycle.* -import androidx.paging.cachedIn -import arrow.core.Either -import arrow.core.getOrElse -import arrow.core.right -import com.tangem.blockchain.common.address.AddressType -import com.tangem.common.extensions.isZero +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.core.analytics.models.AnalyticsParam -import com.tangem.core.navigation.AppScreen -import com.tangem.core.ui.components.bottomsheets.chooseaddress.ChooseAddressBottomSheetConfig -import com.tangem.core.ui.components.bottomsheets.tokenreceive.AddressModel -import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheetConfig -import com.tangem.core.ui.components.bottomsheets.tokenreceive.mapToAddressModels -import com.tangem.core.ui.components.transactions.state.TxHistoryState -import com.tangem.core.ui.extensions.TextReference -import com.tangem.core.ui.extensions.WrappedList -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.domain.analytics.ChangeCardAnalyticsContextUseCase -import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase -import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase -import com.tangem.domain.card.SetCardWasScannedUseCase -import com.tangem.domain.common.CardTypesResolver -import com.tangem.domain.common.util.cardTypesResolver -import com.tangem.domain.demo.IsDemoCardUseCase -import com.tangem.domain.redux.LegacyAction import com.tangem.domain.redux.ReduxStateHolder -import com.tangem.domain.settings.* -import com.tangem.domain.tokens.* -import com.tangem.domain.tokens.error.TokenListError -import com.tangem.domain.tokens.legacy.TradeCryptoAction -import com.tangem.domain.tokens.model.* -import com.tangem.domain.tokens.models.analytics.TokenReceiveAnalyticsEvent -import com.tangem.domain.tokens.models.analytics.TokenScreenAnalyticsEvent -import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase -import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase -import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase +import com.tangem.domain.settings.CanUseBiometryUseCase +import com.tangem.domain.settings.IsWalletsScrollPreviewEnabled +import com.tangem.domain.settings.ShouldShowSaveWalletScreenUseCase import com.tangem.domain.walletconnect.WalletConnectActions -import com.tangem.domain.walletmanager.WalletManagersFacade -import com.tangem.domain.wallets.models.UnlockWalletsError -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.domain.wallets.usecase.* -import com.tangem.feature.wallet.impl.R +import com.tangem.domain.wallets.usecase.GetSelectedWalletUseCase +import com.tangem.domain.wallets.usecase.GetWalletsUseCase +import com.tangem.domain.wallets.usecase.ShouldSaveUserWalletsUseCase +import com.tangem.feature.wallet.presentation.deeplink.WalletDeepLinksHandler import com.tangem.feature.wallet.presentation.router.InnerWalletRouter -import com.tangem.feature.wallet.presentation.wallet.analytics.PortfolioEvent import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent -import com.tangem.feature.wallet.presentation.wallet.domain.HasSingleWalletSignedHashesUseCase -import com.tangem.feature.wallet.presentation.wallet.domain.ScanCardToUnlockWalletClickHandler -import com.tangem.feature.wallet.presentation.wallet.domain.ScanCardToUnlockWalletError -import com.tangem.feature.wallet.presentation.wallet.state.* -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state.factory.TokenListWithWallet -import com.tangem.feature.wallet.presentation.wallet.state.factory.WalletStateFactory -import com.tangem.feature.wallet.presentation.wallet.subscribers.MaybeTokenListFlow +import com.tangem.feature.wallet.presentation.wallet.analytics.utils.SelectedWalletAnalyticsSender +import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent.DemonstrateWalletsScrollPreview.Direction +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.transformers.* +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletEventSender +import com.tangem.feature.wallet.presentation.wallet.utils.ScreenLifecycleProvider +import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import com.tangem.utils.Provider import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.JobHolder import com.tangem.utils.coroutines.saveIn -import com.tangem.utils.extensions.DELAY_SDK_DIALOG_CLOSE import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.delay import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import java.math.BigDecimal +import timber.log.Timber import javax.inject.Inject -import kotlin.properties.Delegates -/** - * Wallet screen view model - * -[REDACTED_AUTHOR] - */ -@Suppress("LargeClass", "LongParameterList", "TooManyFunctions") +@Suppress("LongParameterList") @HiltViewModel internal class WalletViewModel @Inject constructor( - // region Parameters + private val stateHolder: WalletStateController, + private val clickIntents: WalletClickIntents, + private val walletEventSender: WalletEventSender, + private val walletsUpdateActionResolver: WalletsUpdateActionResolver, + private val walletScreenContentLoader: WalletScreenContentLoader, + private val getSelectedWalletUseCase: GetSelectedWalletUseCase, private val getWalletsUseCase: GetWalletsUseCase, - getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, - private val selectWalletUseCase: SelectWalletUseCase, - private val updateWalletUseCase: UpdateWalletUseCase, - private val deleteWalletUseCase: DeleteWalletUseCase, - private val getTokenListUseCase: GetTokenListUseCase, - private val getCardTokensListUseCase: GetCardTokensListUseCase, - private val fetchTokenListUseCase: FetchTokenListUseCase, - private val fetchCardTokenListUseCase: FetchCardTokenListUseCase, - private val getPrimaryCurrencyStatusUpdatesUseCase: GetPrimaryCurrencyStatusUpdatesUseCase, - private val fetchCurrencyStatusUseCase: FetchCurrencyStatusUseCase, - private val getNetworkCoinStatusUseCase: GetNetworkCoinStatusUseCase, - private val txHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, - private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase, - private val getExploreUrlUseCase: GetExploreUrlUseCase, - private val unlockWalletsUseCase: UnlockWalletsUseCase, - private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, - private val getCryptoCurrencyActionsUseCase: GetCryptoCurrencyActionsUseCase, - private val getFeePaidCryptoCurrencyStatusSyncUseCase: GetFeePaidCryptoCurrencyStatusSyncUseCase, private val shouldShowSaveWalletScreenUseCase: ShouldShowSaveWalletScreenUseCase, private val canUseBiometryUseCase: CanUseBiometryUseCase, private val shouldSaveUserWalletsUseCase: ShouldSaveUserWalletsUseCase, + private val isWalletsScrollPreviewEnabled: IsWalletsScrollPreviewEnabled, private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, - private val removeCurrencyUseCase: RemoveCurrencyUseCase, - private val isCryptoCurrencyCoinCouldHide: IsCryptoCurrencyCoinCouldHideUseCase, - private val walletManagersFacade: WalletManagersFacade, - private val reduxStateHolder: ReduxStateHolder, + analyticsEventsHandler: AnalyticsEventHandler, private val dispatchers: CoroutineDispatcherProvider, - private val analyticsEventsHandler: AnalyticsEventHandler, - private val changeCardAnalyticsContextUseCase: ChangeCardAnalyticsContextUseCase, - private val setCardWasScannedUseCase: SetCardWasScannedUseCase, - private val remindToRateAppLaterUseCase: RemindToRateAppLaterUseCase, - private val neverToSuggestRateAppUseCase: NeverToSuggestRateAppUseCase, - private val setWalletWithFundsFoundUseCase: SetWalletWithFundsFoundUseCase, - private val getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase, - private val isDemoCardUseCase: IsDemoCardUseCase, - private val scanCardToUnlockWalletUseCase: ScanCardToUnlockWalletClickHandler, - private val shouldShowSwapPromoWalletUseCase: ShouldShowSwapPromoWalletUseCase, - isReadyToShowRateAppUseCase: IsReadyToShowRateAppUseCase, - isNeedToBackupUseCase: IsNeedToBackupUseCase, - getMissedAddressesCryptoCurrenciesUseCase: GetMissedAddressesCryptoCurrenciesUseCase, - hasSingleWalletSignedHashesUseCase: HasSingleWalletSignedHashesUseCase, - // endregion Parameters -) : ViewModel(), DefaultLifecycleObserver, WalletClickIntents { + private val reduxStateHolder: ReduxStateHolder, + private val screenLifecycleProvider: ScreenLifecycleProvider, + private val selectedWalletAnalyticsSender: SelectedWalletAnalyticsSender, + private val walletDeepLinksHandler: WalletDeepLinksHandler, +) : ViewModel() { - /** Feature router */ - var router: InnerWalletRouter by Delegates.notNull() + val uiState: StateFlow = stateHolder.uiState - private val selectedAppCurrencyFlow: StateFlow = createSelectedAppCurrencyFlow() + private lateinit var router: InnerWalletRouter + private var walletsUpdateJobHolder: JobHolder = JobHolder() - private val notificationsListFactory = WalletNotificationsListFactory( - isDemoCardUseCase = isDemoCardUseCase, - isReadyToShowRateAppUseCase = isReadyToShowRateAppUseCase, - isNeedToBackupUseCase = isNeedToBackupUseCase, - getMissedAddressCryptoCurrenciesUseCase = getMissedAddressesCryptoCurrenciesUseCase, - hasSingleWalletSignedHashesUseCase = hasSingleWalletSignedHashesUseCase, - shouldShowSwapPromoWalletUseCase = shouldShowSwapPromoWalletUseCase, - clickIntents = this, - ) - - private var isBalanceHidden = true - - private val stateFactory = WalletStateFactory( - currentStateProvider = Provider { uiState }, - currentCardTypeResolverProvider = Provider { - getCardTypeResolver( - index = requireNotNull(uiState as? WalletState.ContentState).walletsListConfig.selectedWalletIndex, - ) - }, - currentWalletProvider = Provider { - wallets[requireNotNull(uiState as? WalletState.ContentState).walletsListConfig.selectedWalletIndex] - }, - appCurrencyProvider = Provider(selectedAppCurrencyFlow::value), - isBalanceHiddenProvider = Provider { isBalanceHidden }, - clickIntents = this, - ) - - /** Screen state */ - var uiState: WalletState by uiStateHolder(initialState = stateFactory.getInitialState()) - - private var wallets: List by Delegates.notNull() - private var singleWalletCryptoCurrencyStatus: CryptoCurrencyStatus? = null - - private val tokensJobHolder = JobHolder() - private val updateWcJobHolder = JobHolder() - private val marketPriceJobHolder = JobHolder() - private val buttonsJobHolder = JobHolder() - private val notificationsJobHolder = JobHolder() - private val refreshContentJobHolder = JobHolder() - private val onWalletChangeJobHolder = JobHolder() - - private val walletsUpdateActionResolver = WalletsUpdateActionResolver( - currentStateProvider = Provider { uiState }, - getSelectedWalletSyncUseCase = getSelectedWalletSyncUseCase, - ) - - override fun onCreate(owner: LifecycleOwner) { + init { analyticsEventsHandler.send(WalletScreenAnalyticsEvent.MainScreen.ScreenOpened) + suggestToEnableBiometrics() + + subscribeOnWalletsUpdateFlow() + subscribeOnBalanceHiding() + subscribeOnSelectedWalletFlow() + } + + fun setWalletRouter(router: InnerWalletRouter) { + this.router = router + clickIntents.initialize(router, viewModelScope) + } + + fun subscribeToLifecycle(lifecycleOwner: LifecycleOwner) { + lifecycleOwner.lifecycle.addObserver(screenLifecycleProvider) + } + + override fun onCleared() { + super.onCleared() + stateHolder.clear() + walletScreenContentLoader.cancelAll() + } + + private fun suggestToEnableBiometrics() { viewModelScope.launch(dispatchers.main) { - delay(timeMillis = 1_800) + withContext(dispatchers.io) { delay(timeMillis = 1_800) } - if (router.isWalletLastScreen() && shouldShowSaveWalletScreenUseCase() && canUseBiometryUseCase()) { - router.openSaveUserWalletScreen() - } + if (isShowSaveWalletScreenEnabled()) router.openSaveUserWalletScreen() } + } - viewModelScope.launch(dispatchers.io) { + private suspend fun isShowSaveWalletScreenEnabled(): Boolean { + return router.isWalletLastScreen() && shouldShowSaveWalletScreenUseCase() && canUseBiometryUseCase() + } + + private fun subscribeOnWalletsUpdateFlow() { + viewModelScope.launch(dispatchers.main) { shouldSaveUserWalletsUseCase() - .flowWithLifecycle(owner.lifecycle) - .collectLatest { - getWalletsUseCase() - .flowWithLifecycle(owner.lifecycle) - .distinctUntilChanged() - .onEach(::updateWallets) - .flowOn(dispatchers.io) - .launchIn(viewModelScope) - } + .conflate() + .distinctUntilChanged() + .collectLatest(::subscribeToUserWalletsUpdates) } + } - getBalanceHidingSettingsUseCase() - .flowWithLifecycle(owner.lifecycle) - .onEach { - isBalanceHidden = it.isBalanceHidden - WalletStateCache.updateAll { copySealed(isBalanceHidden = it.isBalanceHidden) } - uiState = stateFactory.getHiddenBalanceState(isBalanceHidden = it.isBalanceHidden) + private fun subscribeToUserWalletsUpdates(shouldSaveUserWallet: Boolean) { + getWalletsUseCase() + .conflate() + .distinctUntilChanged() + .map { + walletsUpdateActionResolver.resolve( + wallets = it, + currentState = stateHolder.value, + canSaveWallets = shouldSaveUserWallet, + ) } + .onEach(::updateWallets) + .flowOn(dispatchers.main) + .launchIn(viewModelScope) + .saveIn(walletsUpdateJobHolder) + } + + private fun subscribeOnBalanceHiding() { + getBalanceHidingSettingsUseCase() + .conflate() + .distinctUntilChanged() + .onEach { + stateHolder.update(transformer = UpdateBalanceHidingModeTransformer(it.isBalanceHidden)) + } + .flowOn(dispatchers.main) .launchIn(viewModelScope) } - private fun updateWallets(sourceList: List) { - wallets = sourceList + private fun subscribeOnSelectedWalletFlow() { + getSelectedWalletUseCase().onRight { + it + .conflate() + .distinctUntilChanged() + .onEach { selectedWallet -> + if (selectedWallet.isMultiCurrency) { + Timber.d("WalletConnect: initialize and setup networks for ${selectedWallet.walletId}") - if (sourceList.isEmpty()) return + reduxStateHolder.dispatch( + action = WalletConnectActions.New.Initialize(userWallet = selectedWallet), + ) - when (val action = walletsUpdateActionResolver.resolve(sourceList)) { - is WalletsUpdateActionResolver.Action.Initialize -> { - initializeAndLoadState(selectedWalletIndex = action.selectedWalletIndex) + reduxStateHolder.dispatch( + action = WalletConnectActions.New.SetupUserChains(userWallet = selectedWallet), + ) + + selectedWalletAnalyticsSender.send(selectedWallet) + } + + walletDeepLinksHandler.registerForSingleCurrencyWallets( + viewModel = this, + userWallet = selectedWallet, + ) + } + .flowOn(dispatchers.main) + .launchIn(viewModelScope) + } + } + + private fun updateWallets(action: WalletsUpdateActionResolver.Action) { + when (action) { + is WalletsUpdateActionResolver.Action.InitializeWallets -> initializeWallets(action) + is WalletsUpdateActionResolver.Action.ReinitializeWallets -> { + walletScreenContentLoader.load( + userWallet = action.selectedWallet, + clickIntents = clickIntents, + isRefresh = true, + coroutineScope = viewModelScope, + ) + } + is WalletsUpdateActionResolver.Action.ReinitializeWallet -> reinitializeWallet(action) + is WalletsUpdateActionResolver.Action.AddWallet -> addWallet(action) + is WalletsUpdateActionResolver.Action.DeleteWallet -> deleteWallet(action) + is WalletsUpdateActionResolver.Action.UnlockWallet -> unlockWallet(action) + is WalletsUpdateActionResolver.Action.UpdateWalletCardCount -> { + stateHolder.update(transformer = UpdateWalletCardsCountTransformer(action.selectedWallet)) } is WalletsUpdateActionResolver.Action.UpdateWalletName -> { - uiState = stateFactory.getStateWithUpdatedWalletName(name = action.name) - } - is WalletsUpdateActionResolver.Action.UnlockWallet -> { - uiState = stateFactory.getUnlockedState(action) - - getContentItemsUpdates(index = action.selectedWalletIndex) - } - is WalletsUpdateActionResolver.Action.DeleteWallet -> { - deleteWalletAndUpdateState(action = action) - } - is WalletsUpdateActionResolver.Action.AddWallet -> { - scrollAndUpdateState(action.selectedWalletIndex) - } - is WalletsUpdateActionResolver.Action.UpdateWalletCardCount -> { - uiState = stateFactory.getStateWithUpdatedWalletCardCount() + stateHolder.update(transformer = RenameWalletTransformer(action.selectedWalletId, action.name)) } is WalletsUpdateActionResolver.Action.Unknown -> Unit } } - private fun initializeAndLoadState(selectedWalletIndex: Int) { - uiState = stateFactory.getSkeletonState(wallets = wallets, selectedWalletIndex = selectedWalletIndex) - - getContentItemsUpdates(index = selectedWalletIndex) - } - - private fun deleteWalletAndUpdateState(action: WalletsUpdateActionResolver.Action.DeleteWallet) { - val cacheState = WalletStateCache.getState(userWalletId = action.selectedWalletId) - if (cacheState != null) { - uiState = stateFactory.getStateWithoutDeletedWallet(cacheState, action) - - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.ChangeWallet(action.selectedWalletIndex), - setUiState = { uiState = it }, - ) - getContentItemsUpdates(action.selectedWalletIndex) - } else { - /* It's impossible case because user can delete only visible state, but we support this case */ - scrollAndUpdateState(selectedWalletIndex = action.selectedWalletIndex) - } - } - - private fun scrollAndUpdateState(selectedWalletIndex: Int) { - uiState = stateFactory.getSkeletonState( - wallets = wallets, - selectedWalletIndex = selectedWalletIndex, + private fun initializeWallets(action: WalletsUpdateActionResolver.Action.InitializeWallets) { + walletScreenContentLoader.load( + userWallet = action.selectedWallet, + clickIntents = clickIntents, + coroutineScope = viewModelScope, ) - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.ChangeWallet(index = selectedWalletIndex), - setUiState = { uiState = it }, - ) - - getContentItemsUpdates(index = selectedWalletIndex) - } - - override fun onBackClick() { - router.popBackStack() - } - - override fun onGenerateMissedAddressesClick(missedAddressCurrencies: List) { - // TODO: delete [REDACTED_JIRA] - // val state = uiState as? WalletState.ContentState ?: return - // - // analyticsEventsHandler.send(WalletScreenAnalyticsEvent.Basic.CardWasScanned(AnalyticsParam.ScannedFrom.Main)) - // analyticsEventsHandler.send(WalletScreenAnalyticsEvent.MainScreen.NoticeScanYourCardTapped) - // - // viewModelScope.launch(dispatchers.io) { - // val userWallet = getWallet(index = state.walletsListConfig.selectedWalletIndex) - // - // deriveMissingCurrencies( - // scanResponse = userWallet.scanResponse, - // currencyList = missedAddressCurrencies, - // ) { scannedCardResponse -> - // updateWalletUseCase( - // userWalletId = userWallet.walletId, - // update = { it.copy(scanResponse = scannedCardResponse) }, - // ) - // .onRight { - // fetchTokenListUseCase(userWalletId = it.walletId) - // } - // } - // } - } - - override fun onScanToUnlockWalletClick() { - val state = uiState as? WalletState.ContentState ?: return - - analyticsEventsHandler.send(event = WalletScreenAnalyticsEvent.MainScreen.WalletUnlockTapped) - - val lockedWallet = getWallet(index = state.walletsListConfig.selectedWalletIndex) - - viewModelScope.launch(dispatchers.main) { - scanCardToUnlockWalletUseCase(walletId = lockedWallet.walletId) - .onLeft { error -> - when (error) { - ScanCardToUnlockWalletError.WrongCardIsScanned -> { - delay(timeMillis = DELAY_SDK_DIALOG_CLOSE) - - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.ShowAlert(state = WalletAlertState.WrongCardIsScanned), - setUiState = { uiState = it }, - ) - } - ScanCardToUnlockWalletError.ManyScanFails -> { - router.openScanFailedDialog() - } - } - } - } - } - - override fun onDetailsClick() = router.openDetailsScreen() - - override fun onBackupCardClick() { - analyticsEventsHandler.send(WalletScreenAnalyticsEvent.MainScreen.NoticeBackupYourWalletTapped) - reduxStateHolder.dispatch( - LegacyAction.StartOnboardingProcess( - scanResponse = getSelectedWallet().scanResponse, - canSkipBackup = false, + stateHolder.update( + transformer = InitializeWalletsTransformer( + selectedWalletIndex = action.selectedWalletIndex, + selectedWallet = action.selectedWallet, + wallets = action.wallets, + clickIntents = clickIntents, ), ) - router.openOnboardingScreen() + + viewModelScope.launch(dispatchers.main) { + if (action.wallets.size > 1 && isWalletsScrollPreviewEnabled()) { + withContext(dispatchers.io) { + delay(timeMillis = 1_800) + } + + walletEventSender.send( + event = WalletEvent.DemonstrateWalletsScrollPreview( + direction = if (action.selectedWalletIndex == action.wallets.lastIndex) { + Direction.RIGHT + } else { + Direction.LEFT + }, + ), + ) + } + } } - override fun onSignedHashesNotificationCloseClick() { - val state = uiState as? WalletState.ContentState ?: return + private fun reinitializeWallet(action: WalletsUpdateActionResolver.Action.ReinitializeWallet) { viewModelScope.launch(dispatchers.main) { - setCardWasScannedUseCase( - cardId = getWallet(index = state.walletsListConfig.selectedWalletIndex).cardId, + walletScreenContentLoader.cancel(action.prevWalletId) + + walletScreenContentLoader.load( + userWallet = action.selectedWallet, + clickIntents = clickIntents, + coroutineScope = viewModelScope, + ) + + stateHolder.update( + ReinitializeWalletTransformer(userWallet = action.selectedWallet, clickIntents = clickIntents), ) } } - override fun onLikeAppClick() { - analyticsEventsHandler.send( - WalletScreenAnalyticsEvent.MainScreen.NoticeRateAppButton(AnalyticsParam.RateApp.Liked), - ) - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.RateApp( - onDismissClick = { - viewModelScope.launch(dispatchers.main) { - neverToSuggestRateAppUseCase() - } - }, + private fun addWallet(action: WalletsUpdateActionResolver.Action.AddWallet) { + viewModelScope.launch(dispatchers.main) { + stateHolder.update( + AddWalletTransformer( + userWallet = action.selectedWallet, + clickIntents = clickIntents, + ), + ) + + walletScreenContentLoader.load( + userWallet = action.selectedWallet, + clickIntents = clickIntents, + coroutineScope = viewModelScope, + ) + + withContext(dispatchers.io) { delay(timeMillis = 700) } + + scrollToWallet(index = action.selectedWalletIndex) + } + } + + private fun deleteWallet(action: WalletsUpdateActionResolver.Action.DeleteWallet) { + viewModelScope.launch(dispatchers.main) { + walletScreenContentLoader.load( + userWallet = action.selectedWallet, + clickIntents = clickIntents, + coroutineScope = viewModelScope, + ) + + scrollToWallet(index = action.selectedWalletIndex) + + withContext(dispatchers.io) { delay(timeMillis = 700) } + + stateHolder.update( + DeleteWalletTransformer( + selectedWalletIndex = action.selectedWalletIndex, + deletedWalletId = action.deletedWalletId, + ), + ) + } + } + + private fun unlockWallet(action: WalletsUpdateActionResolver.Action.UnlockWallet) { + viewModelScope.launch(dispatchers.main) { + withContext(dispatchers.io) { delay(timeMillis = 700) } + + stateHolder.update( + transformer = UnlockWalletTransformer( + unlockedWallets = action.unlockedWallets, + clickIntents = clickIntents, + ), + ) + + walletScreenContentLoader.load( + userWallet = action.selectedWallet, + clickIntents = clickIntents, + coroutineScope = viewModelScope, + ) + } + } + + private fun scrollToWallet(index: Int) { + stateHolder.update( + ScrollToWalletTransformer( + index = index, + currentStateProvider = Provider(action = stateHolder::value), + stateUpdater = { newState -> stateHolder.update { newState } }, ), - setUiState = { uiState = it }, ) } - - override fun onDislikeAppClick() { - analyticsEventsHandler.send( - WalletScreenAnalyticsEvent.MainScreen.NoticeRateAppButton(AnalyticsParam.RateApp.Disliked), - ) - viewModelScope.launch(dispatchers.main) { - neverToSuggestRateAppUseCase() - - reduxStateHolder.dispatch(LegacyAction.SendEmailRateCanBeBetter) - } - } - - override fun onCloseRateAppNotificationClick() { - analyticsEventsHandler.send( - WalletScreenAnalyticsEvent.MainScreen.NoticeRateAppButton(AnalyticsParam.RateApp.Closed), - ) - viewModelScope.launch(dispatchers.main) { - remindToRateAppLaterUseCase() - } - } - - override fun onWalletChange(index: Int) { - val state = uiState as? WalletState.ContentState ?: return - if (state.walletsListConfig.selectedWalletIndex == index) return - - changeCardAnalyticsContextUseCase(scanResponse = getWallet(index).scanResponse) - analyticsEventsHandler.send(WalletScreenAnalyticsEvent.MainScreen.WalletSwipe) - - // Reset the job to avoid a redundant state updating - onWalletChangeJobHolder.update(null) - - /* - * When wallet is changed it's necessary to stop the last jobs. - * If jobs aren't stopped and wallet is changed then it will update state for the prev wallet. - */ - tokensJobHolder.update(job = null) - updateWcJobHolder.update(job = null) - marketPriceJobHolder.update(job = null) - buttonsJobHolder.update(job = null) - notificationsJobHolder.update(job = null) - refreshContentJobHolder.update(job = null) - - viewModelScope.launch(dispatchers.main) { - val userWallet = state.walletsListConfig.wallets[index] - - withContext(dispatchers.io) { - selectWalletUseCase(userWallet.id) - } - - val cacheState = WalletStateCache.getState(userWalletId = userWallet.id) - if (cacheState != null && cacheState !is WalletLockedState) { - uiState = cacheState.copySealed( - walletsListConfig = state.walletsListConfig.copy( - selectedWalletIndex = index, - wallets = state.walletsListConfig.wallets - .mapIndexed { mapIndex, currentWallet -> - val cacheWallet = cacheState.walletsListConfig.wallets.getOrNull(mapIndex) - - if (currentWallet is WalletCardState.Loading && cacheWallet != null && - cacheWallet.isLoaded() - ) { - cacheWallet - } else { - currentWallet - } - } - .toImmutableList(), - ), - pullToRefreshConfig = cacheState.pullToRefreshConfig.copy(isRefreshing = false), - ) - - getContentItemsUpdates(index) - } else { - initializeAndLoadState(selectedWalletIndex = index) - } - } - .saveIn(onWalletChangeJobHolder) - } - - private fun WalletCardState.isLoaded(): Boolean { - return this !is WalletCardState.Loading && this !is WalletCardState.LockedContent - } - - override fun onRefreshSwipe() { - val selectedWalletIndex = (uiState as? WalletState.ContentState) - ?.walletsListConfig - ?.selectedWalletIndex - ?: return - - when (uiState) { - is WalletMultiCurrencyState.Content -> { - analyticsEventsHandler.send(PortfolioEvent.Refreshed) - refreshMultiCurrencyContent(selectedWalletIndex) - } - is WalletSingleCurrencyState.Content -> { - analyticsEventsHandler.send(PortfolioEvent.Refreshed) - refreshSingleCurrencyContent(selectedWalletIndex) - } - is WalletState.Initial, - is WalletMultiCurrencyState.Locked, - is WalletSingleCurrencyState.Locked, - -> Unit - } - } - - private fun refreshMultiCurrencyContent(walletIndex: Int) { - uiState = stateFactory.getRefreshingState() - - viewModelScope.launch(dispatchers.main) { - val wallet = getWallet(walletIndex) - - val maybeFetchResult = if (wallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) { - fetchCardTokenListUseCase(userWalletId = wallet.walletId, refresh = true) - } else { - fetchTokenListUseCase(userWalletId = wallet.walletId, refresh = true) - } - - maybeFetchResult.onLeft { uiState = stateFactory.getStateByTokenListError(it) } - - uiState = stateFactory.getRefreshedState() - }.saveIn(refreshContentJobHolder) - } - - override fun onOrganizeTokensClick() { - analyticsEventsHandler.send(PortfolioEvent.OrganizeTokens) - - val state = requireNotNull(uiState as? WalletState.ContentState) - val index = state.walletsListConfig.selectedWalletIndex - val walletId = state.walletsListConfig.wallets[index].id - - router.openOrganizeTokensScreen(walletId) - } - - override fun onBuyClick(cryptoCurrencyStatus: CryptoCurrencyStatus) { - val state = uiState as? WalletState.ContentState ?: return - - analyticsEventsHandler.send( - event = TokenScreenAnalyticsEvent.ButtonBuy(cryptoCurrencyStatus.currency.symbol), - ) - - showErrorIfDemoModeOrElse { - reduxStateHolder.dispatch( - TradeCryptoAction.Buy( - userWallet = getWallet(index = state.walletsListConfig.selectedWalletIndex), - cryptoCurrencyStatus = cryptoCurrencyStatus, - appCurrencyCode = selectedAppCurrencyFlow.value.code, - ), - ) - } - } - - override fun onSwapClick(cryptoCurrencyStatus: CryptoCurrencyStatus) { - analyticsEventsHandler.send( - event = TokenScreenAnalyticsEvent.ButtonExchange(cryptoCurrencyStatus.currency.symbol), - ) - - reduxStateHolder.dispatch(TradeCryptoAction.Swap(cryptoCurrencyStatus.currency)) - } - - override fun onSingleCurrencySendClick(cryptoCurrencyStatus: CryptoCurrencyStatus?) { - val state = uiState as? WalletState.ContentState ?: return - - val userWallet = getWallet(index = state.walletsListConfig.selectedWalletIndex) - val coinStatus = if (userWallet.isMultiCurrency) cryptoCurrencyStatus else singleWalletCryptoCurrencyStatus - coinStatus ?: return - - analyticsEventsHandler.send( - event = TokenScreenAnalyticsEvent.ButtonSend(coinStatus.currency.symbol), - ) - - viewModelScope.launch(dispatchers.main) { - val maybeFeeCurrencyStatus = - getFeePaidCryptoCurrencyStatusSyncUseCase(userWallet.walletId, coinStatus).getOrNull() - reduxStateHolder.dispatch( - action = TradeCryptoAction.SendCoin( - userWallet = userWallet, - coinStatus = coinStatus, - feeCurrencyStatus = maybeFeeCurrencyStatus, - ), - ) - } - } - - override fun onMultiCurrencySendClick(cryptoCurrencyStatus: CryptoCurrencyStatus) { - val state = uiState as? WalletState.ContentState ?: return - - analyticsEventsHandler.send( - event = TokenScreenAnalyticsEvent.ButtonSend(cryptoCurrencyStatus.currency.symbol), - ) - - val userWallet = getWallet(index = state.walletsListConfig.selectedWalletIndex) - viewModelScope.launch(dispatchers.main) { - val maybeFeeCurrencyStatus = - getFeePaidCryptoCurrencyStatusSyncUseCase(userWallet.walletId, cryptoCurrencyStatus).getOrNull() - when (cryptoCurrencyStatus.currency) { - is CryptoCurrency.Coin -> { - uiState = stateFactory.getStateWithClosedBottomSheet() - reduxStateHolder.dispatch( - action = TradeCryptoAction.SendCoin( - userWallet = userWallet, - coinStatus = cryptoCurrencyStatus, - feeCurrencyStatus = maybeFeeCurrencyStatus, - ), - ) - } - is CryptoCurrency.Token -> sendToken(userWallet, cryptoCurrencyStatus, maybeFeeCurrencyStatus) - } - } - } - - private fun sendToken( - userWallet: UserWallet, - cryptoCurrencyStatus: CryptoCurrencyStatus, - feeCurrencyStatus: CryptoCurrencyStatus?, - ) { - viewModelScope.launch(dispatchers.io) { - getNetworkCoinStatusUseCase( - userWalletId = userWallet.walletId, - networkId = cryptoCurrencyStatus.currency.network.id, - derivationPath = cryptoCurrencyStatus.currency.network.derivationPath, - isSingleWalletWithTokens = userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(), - ) - .take(count = 1) - .collectLatest { - it.onRight { coinStatus -> - uiState = stateFactory.getStateWithClosedBottomSheet() - reduxStateHolder.dispatchWithMain( - action = TradeCryptoAction.SendToken( - userWallet = userWallet, - tokenCurrency = requireNotNull(cryptoCurrencyStatus.currency as? CryptoCurrency.Token), - tokenFiatRate = cryptoCurrencyStatus.value.fiatRate, - coinFiatRate = coinStatus.value.fiatRate, - feeCurrencyStatus = feeCurrencyStatus, - ), - ) - } - } - } - } - - override fun onReceiveClick(cryptoCurrencyStatus: CryptoCurrencyStatus) { - analyticsEventsHandler.send( - event = TokenScreenAnalyticsEvent.ButtonReceive(cryptoCurrencyStatus.currency.symbol), - ) - - viewModelScope.launch(dispatchers.io) { - analyticsEventsHandler.send(event = TokenReceiveAnalyticsEvent.ReceiveScreenOpened) - - val currency = cryptoCurrencyStatus.currency - uiState = stateFactory.getStateWithOpenWalletBottomSheet( - content = TokenReceiveBottomSheetConfig( - name = currency.name, - symbol = currency.symbol, - network = currency.network.name, - addresses = cryptoCurrencyStatus.value.networkAddress - ?.availableAddresses - ?.mapToAddressModels(currency) - .orEmpty() - .toImmutableList(), - onCopyClick = { - analyticsEventsHandler.send(TokenReceiveAnalyticsEvent.ButtonCopyAddress(currency.symbol)) - }, - onShareClick = { - analyticsEventsHandler.send(TokenReceiveAnalyticsEvent.ButtonShareAddress(currency.symbol)) - }, - ), - ) - } - } - - override fun onCopyAddressClick(cryptoCurrencyStatus: CryptoCurrencyStatus) { - val state = uiState as? WalletState.ContentState ?: return - - analyticsEventsHandler.send( - event = TokenScreenAnalyticsEvent.ButtonCopyAddress(cryptoCurrencyStatus.currency.symbol), - ) - - viewModelScope.launch(dispatchers.main) { - val userWallet = getWallet(index = state.walletsListConfig.selectedWalletIndex) - - val defaultAddress = walletManagersFacade.getAddress( - userWalletId = userWallet.walletId, - network = cryptoCurrencyStatus.currency.network, - ).find { it.type == AddressType.Default } - - defaultAddress?.value?.let { address -> - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.CopyAddress( - address = address, - toast = resourceReference(R.string.wallet_notification_address_copied), - ), - setUiState = { uiState = it }, - ) - } - } - } - - override fun onSellClick(cryptoCurrencyStatus: CryptoCurrencyStatus) { - analyticsEventsHandler.send( - event = TokenScreenAnalyticsEvent.ButtonSell(cryptoCurrencyStatus.currency.symbol), - ) - - showErrorIfDemoModeOrElse { - reduxStateHolder.dispatch( - action = TradeCryptoAction.Sell( - cryptoCurrencyStatus = cryptoCurrencyStatus, - appCurrencyCode = selectedAppCurrencyFlow.value.code, - ), - ) - } - } - - override fun onManageTokensClick() { - analyticsEventsHandler.send(PortfolioEvent.ButtonManageTokens) - reduxStateHolder.dispatch(action = TokensAction.SetArgs.ManageAccess) - router.openManageTokensScreen() - } - - override fun onReloadClick() { - val selectedWalletIndex = (uiState as? WalletSingleCurrencyState) - ?.walletsListConfig - ?.selectedWalletIndex - ?: return - - refreshSingleCurrencyContent(selectedWalletIndex) - } - - override fun onCloseSwapPromoNotificationClick() { - viewModelScope.launch(dispatchers.main) { - shouldShowSwapPromoWalletUseCase.neverToShow() - } - } - - // FIXME: refreshSingleCurrencyContent mustn't update the TxHistory and Buttons. It only must fetch primary - // currency. Now it not works because GetPrimaryCurrency's subscriber uses .distinctUntilChanged() - private fun refreshSingleCurrencyContent(walletIndex: Int) { - uiState = stateFactory.getRefreshingState() - val wallet = getWallet(walletIndex) - - viewModelScope.launch(dispatchers.main) { - singleWalletCryptoCurrencyStatus?.let { - updateButtons(userWallet = wallet, currencyStatus = it) - } - val result = fetchCurrencyStatusUseCase(wallet.walletId, refresh = true) - - uiState = stateFactory.getRefreshedState() - uiState = result.fold(stateFactory::getStateByCurrencyStatusError) { uiState } - - singleWalletCryptoCurrencyStatus?.let { - val singleCurrencyState = uiState as WalletSingleCurrencyState - if (singleCurrencyState.txHistoryState !is TxHistoryState.Content) { - // show loading indicator while refreshing in non content state - uiState = stateFactory.getLoadingTxHistoryState( - itemsCountEither = 1.right(), - pendingTransactions = it.value.pendingTransactions, - ) - } - updateTxHistory(userWalletId = wallet.walletId, currencyStatus = it, refresh = true) - } - }.saveIn(refreshContentJobHolder) - } - - override fun onExploreClick() { - showErrorIfDemoModeOrElse(action = ::openExplorer) - } - - private fun openExplorer() { - val state = uiState as? WalletState.ContentState ?: return - val currencyStatus = singleWalletCryptoCurrencyStatus ?: return - val currency = currencyStatus.currency - - viewModelScope.launch(dispatchers.main) { - val userWalletId = getWallet(state.walletsListConfig.selectedWalletIndex).walletId - - when (val addresses = currencyStatus.value.networkAddress) { - is NetworkAddress.Selectable -> { - uiState = stateFactory.getStateWithOpenWalletBottomSheet( - ChooseAddressBottomSheetConfig( - addressModels = addresses.availableAddresses - .mapToAddressModels(currency) - .toImmutableList(), - onClick = { - onAddressTypeSelected( - userWalletId = userWalletId, - currency = currency, - addressModel = it, - ) - }, - ), - ) - } - is NetworkAddress.Single -> { - router.openUrl( - url = getExploreUrlUseCase( - userWalletId = userWalletId, - currency = currency, - addressType = AddressType.Default, - ), - ) - } - null -> Unit - } - } - } - - private fun onAddressTypeSelected( - userWalletId: UserWalletId, - currency: CryptoCurrency, - addressModel: AddressModel, - ) { - viewModelScope.launch(dispatchers.main) { - router.openUrl( - url = getExploreUrlUseCase( - userWalletId = userWalletId, - currency = currency, - addressType = AddressType.valueOf(addressModel.type.name), - ), - ) - uiState = stateFactory.getStateWithClosedBottomSheet() - } - } - - private fun showErrorIfDemoModeOrElse(action: () -> Unit) { - val state = uiState as? WalletState.ContentState ?: return - val cardId = getWallet(index = state.walletsListConfig.selectedWalletIndex).cardId - - if (isDemoCardUseCase(cardId = cardId)) { - uiState = stateFactory.getStateWithClosedBottomSheet() - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.ShowError( - text = resourceReference(id = R.string.alert_demo_feature_disabled), - ), - setUiState = { uiState = it }, - ) - } else { - action() - } - } - - override fun onUnlockWalletClick() { - analyticsEventsHandler.send(WalletScreenAnalyticsEvent.MainScreen.NoticeWalletLocked) - - viewModelScope.launch(dispatchers.main) { - unlockWalletsUseCase(throwIfNotAllWalletsUnlocked = true) - .onLeft(::handleUnlockWalletsError) - } - } - - private fun handleUnlockWalletsError(error: UnlockWalletsError) { - val event = when (error) { - is UnlockWalletsError.DataError, - is UnlockWalletsError.UnableToUnlockWallets, - -> WalletEvent.ShowToast(resourceReference(R.string.user_wallet_list_error_unable_to_unlock)) - is UnlockWalletsError.NoUserWalletSelected, - is UnlockWalletsError.NotAllUserWalletsUnlocked, - -> WalletEvent.ShowAlert(WalletAlertState.RescanWallets) - } - - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = event, - setUiState = { uiState = it }, - ) - } - - override fun onUnlockWalletNotificationClick() { - val state = requireNotNull(uiState as? WalletLockedState) { - "Impossible to unlock wallet if state isn't WalletLockedState" - } - - uiState = stateFactory.getStateWithOpenWalletBottomSheet( - content = when (state) { - is WalletMultiCurrencyState.Locked -> state.bottomSheetConfig.content - is WalletSingleCurrencyState.Locked -> state.bottomSheetConfig.content - }, - ) - } - - override fun onTokenItemClick(currency: CryptoCurrency) { - analyticsEventsHandler.send(PortfolioEvent.TokenTapped) - router.openTokenDetails(getSelectedWallet().walletId, currency) - } - - override fun onTokenItemLongClick(cryptoCurrencyStatus: CryptoCurrencyStatus) { - val userWallet = getSelectedWallet() - viewModelScope.launch(dispatchers.io) { - getCryptoCurrencyActionsUseCase( - userWallet = userWallet, - cryptoCurrencyStatus = cryptoCurrencyStatus, - ) - .take(count = 1) - .collectLatest { - uiState = stateFactory.getStateWithTokenActionBottomSheet(it) - } - } - } - - override fun onRenameClick(userWalletId: UserWalletId, name: String) { - viewModelScope.launch(dispatchers.io) { - updateWalletUseCase(userWalletId = userWalletId, update = { it.copy(name) }) - } - } - - override fun onDeleteBeforeConfirmationClick(userWalletId: UserWalletId) { - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.ShowAlert( - state = WalletAlertState.RemoveWalletAlert( - onConfirmClick = { onDeleteAfterConfirmationClick(userWalletId) }, - ), - ), - setUiState = { uiState = it }, - ) - } - - override fun onDeleteAfterConfirmationClick(userWalletId: UserWalletId) { - val state = uiState as? WalletState.ContentState ?: return - viewModelScope.launch(dispatchers.io) { - deleteWalletUseCase(userWalletId) - - popBackIfAllWalletsIsLocked(wallets = state.walletsListConfig.wallets) - } - } - - private fun popBackIfAllWalletsIsLocked(wallets: List) { - val unlockedWallet = wallets.count { it !is WalletCardState.LockedContent } - - if (unlockedWallet == 1) { - router.popBackStack( - screen = if (wallets.size > 1) AppScreen.Welcome else AppScreen.Home, - ) - } - } - - override fun onPerformHideToken(cryptoCurrencyStatus: CryptoCurrencyStatus) { - val state = uiState as? WalletState.ContentState ?: return - val userWallet = getWallet(state.walletsListConfig.selectedWalletIndex) - viewModelScope.launch(dispatchers.io) { - removeCurrencyUseCase(userWallet.walletId, cryptoCurrencyStatus.currency) - .fold( - ifLeft = { showToast(resourceReference(R.string.common_error)) }, - ifRight = { uiState = stateFactory.getStateWithClosedBottomSheet() }, - ) - } - } - - override fun onHideTokensClick(cryptoCurrencyStatus: CryptoCurrencyStatus) { - analyticsEventsHandler.send( - event = TokenScreenAnalyticsEvent.ButtonRemoveToken(cryptoCurrencyStatus.currency.symbol), - ) - - viewModelScope.launch(dispatchers.main) { - val state = uiState as? WalletState.ContentState ?: return@launch - val userWallet = getWallet(state.walletsListConfig.selectedWalletIndex) - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = getHideTokeAlert(userWallet.walletId, cryptoCurrencyStatus), - setUiState = { uiState = it }, - ) - } - } - - override fun onDismissBottomSheet() { - uiState = stateFactory.getStateWithClosedBottomSheet() - } - - override fun onTransactionClick(txHash: String) { - singleWalletCryptoCurrencyStatus?.let { currencyStatus -> - router.openUrl( - url = getExplorerTransactionUrlUseCase( - txHash = txHash, - networkId = currencyStatus.currency.network.id, - ), - ) - } - } - - private suspend fun getHideTokeAlert( - userWalletId: UserWalletId, - cryptoCurrencyStatus: CryptoCurrencyStatus, - ): WalletEvent.ShowAlert { - val currency = cryptoCurrencyStatus.currency - return if (currency is CryptoCurrency.Coin && !isCryptoCurrencyCoinCouldHide(userWalletId, currency)) { - WalletEvent.ShowAlert( - state = WalletAlertState.DefaultAlert( - title = resourceReference( - id = R.string.token_details_unable_hide_alert_title, - formatArgs = WrappedList(listOf(cryptoCurrencyStatus.currency.name)), - ), - message = resourceReference( - id = R.string.token_details_unable_hide_alert_message, - formatArgs = WrappedList( - listOf( - cryptoCurrencyStatus.currency.name, - cryptoCurrencyStatus.currency.network.name, - ), - ), - ), - onConfirmClick = null, - ), - ) - } else { - WalletEvent.ShowAlert( - state = WalletAlertState.DefaultAlert( - title = resourceReference( - id = R.string.token_details_hide_alert_title, - formatArgs = WrappedList(listOf(cryptoCurrencyStatus.currency.name)), - ), - message = resourceReference(R.string.token_details_hide_alert_message), - onConfirmClick = { onPerformHideToken(cryptoCurrencyStatus) }, - ), - ) - } - } - - private fun showToast(message: TextReference) { - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.ShowToast(message), - setUiState = { uiState = it }, - ) - } - - private fun getContentItemsUpdates(index: Int) { - /* - * When wallet is changed it's necessary to stop the last jobs. - * If jobs aren't stopped and wallet is changed then it will update state for the prev wallet. - */ - tokensJobHolder.update(job = null) - updateWcJobHolder.update(job = null) - marketPriceJobHolder.update(job = null) - buttonsJobHolder.update(job = null) - notificationsJobHolder.update(job = null) - refreshContentJobHolder.update(job = null) - - val wallet = getWallet(index) - - when { - wallet.isLocked -> { - uiState = stateFactory.getLockedState() - } - wallet.isMultiCurrency -> getMultiCurrencyContent(wallet, index) - wallet.scanResponse.cardTypesResolver.isSingleWalletWithToken() -> getSingleCurrencyWithTokenContent(index) - !wallet.isMultiCurrency -> getSingleCurrencyContent(index) - } - } - - private fun getMultiCurrencyContent(wallet: UserWallet, walletIndex: Int) { - val state = requireNotNull(uiState as? WalletMultiCurrencyState) { - "Impossible to get a token list updates if state isn't WalletMultiCurrencyState" - } - - val tokenListFlow = getTokenListUseCase(userWalletId = state.walletsListConfig.wallets[walletIndex].id) - .shareIn(viewModelScope, SharingStarted.WhileSubscribed()) - - initAndSetupWc(tokenListFlow, wallet) - - tokenListFlow - .conflate() - .distinctUntilChanged() - .onEach { maybeTokenList -> - uiState = stateFactory.getStateByTokensList(maybeTokenList.getTokenListWithWallet(wallet)) - - maybeTokenList.onRight { - analyticsEventsHandler.sendBalanceLoadedEvent(it) - checkMultiWalletWithFunds(it) - } - - updateNotifications( - index = walletIndex, - tokenList = maybeTokenList.fold(ifLeft = { null }, ifRight = { it }), - ) - } - .flowOn(dispatchers.io) - .launchIn(viewModelScope) - .saveIn(tokensJobHolder) - } - - private suspend fun checkMultiWalletWithFunds(tokenList: TokenList) { - val hasNonZeroWallets = when (tokenList) { - is TokenList.GroupedByNetwork -> { - tokenList.groups - .flatMap(NetworkGroup::currencies) - .hasNonZeroWallets() - } - is TokenList.Ungrouped -> tokenList.currencies.hasNonZeroWallets() - is TokenList.Empty -> false - } - - if (hasNonZeroWallets) { - setWalletWithFundsFoundUseCase() - } - } - - private fun initAndSetupWc(tokenListFlow: MaybeTokenListFlow, wallet: UserWallet) { - viewModelScope - .launch(dispatchers.main) { - initWalletConnectForWallet(wallet) - - tokenListFlow - .filterLoadedTokenList() - .take(count = 1) - .collect { setupWalletConnectOnWallet(wallet) } - } - .saveIn(updateWcJobHolder) - } - - private fun initWalletConnectForWallet(userWallet: UserWallet) { - reduxStateHolder.dispatch( - action = WalletConnectActions.New.Initialize(userWallet = userWallet), - ) - } - - private suspend fun setupWalletConnectOnWallet(userWallet: UserWallet) { - reduxStateHolder.dispatchWithMain( - action = WalletConnectActions.New.SetupUserChains(userWallet = userWallet), - ) - } - - private fun List.isAllCurrenciesLoaded(): Boolean { - return !this.any { it.value is CryptoCurrencyStatus.Loading } - } - - private fun MaybeTokenListFlow.filterLoadedTokenList(): MaybeTokenListFlow { - return filter { either -> - either.fold( - ifRight = { list -> - when (list) { - is TokenList.Ungrouped -> { - list.currencies.isAllCurrenciesLoaded() - } - is TokenList.GroupedByNetwork -> { - list.groups.flatMap(NetworkGroup::currencies).isAllCurrenciesLoaded() - } - else -> false - } - }, - ifLeft = { false }, - ) - } - } - - private fun List.hasNonZeroWallets(): Boolean { - return any { - val amount = it.value.amount ?: return@any false - !amount.isZero() - } - } - - private fun Either.getTokenListWithWallet( - userWallet: UserWallet, - ): Either { - return this.map { - TokenListWithWallet(it, userWallet) - } - } - - private fun getSingleCurrencyContent(index: Int) { - val wallet = getWallet(index) - getPrimaryCurrencyStatusUpdatesUseCase(wallet.walletId) - .conflate() - .distinctUntilChanged() - .onEach { maybeCryptoCurrencyStatus -> - uiState = stateFactory.getSingleCurrencyLoadedBalanceState(maybeCryptoCurrencyStatus) - - maybeCryptoCurrencyStatus.onRight { status -> - val fiatAmount = status.value.fiatAmount - - val cardBalanceState = when (status.value) { - is CryptoCurrencyStatus.Loaded, - is CryptoCurrencyStatus.NoAccount, - is CryptoCurrencyStatus.NoAmount, - -> { - when { - fiatAmount == null -> null - fiatAmount.isZero() -> AnalyticsParam.CardBalanceState.Empty - else -> AnalyticsParam.CardBalanceState.Full - } - } - is CryptoCurrencyStatus.NoQuote -> AnalyticsParam.CardBalanceState.NoRate - is CryptoCurrencyStatus.Unreachable, - -> AnalyticsParam.CardBalanceState.BlockchainError - is CryptoCurrencyStatus.MissedDerivation, - is CryptoCurrencyStatus.Loading, - is CryptoCurrencyStatus.Custom, - -> null - } - - cardBalanceState?.let { - analyticsEventsHandler.send( - event = WalletScreenAnalyticsEvent.Basic.BalanceLoaded(balance = it), - ) - } - - singleWalletCryptoCurrencyStatus = status - - if (status.value.amount?.isZero() == false) { - setWalletWithFundsFoundUseCase() - } - - updateNotifications(index) - updateButtons(userWallet = wallet, currencyStatus = status) - updateTxHistory(userWalletId = wallet.walletId, currencyStatus = status, refresh = false) - } - } - .flowOn(dispatchers.io) - .launchIn(viewModelScope) - .saveIn(marketPriceJobHolder) - } - - private fun getSingleCurrencyWithTokenContent(walletIndex: Int) { - val state = requireNotNull(uiState as? WalletMultiCurrencyState) { - "Impossible to get a token list updates if state isn't WalletMultiCurrencyState" - } - - val wallet = getWallet(walletIndex) - - getCardTokensListUseCase(userWalletId = state.walletsListConfig.wallets[walletIndex].id) - .conflate() - .distinctUntilChanged() - .onEach { maybeTokenList -> - uiState = stateFactory.getStateByTokensList(maybeTokenList.getTokenListWithWallet(wallet)) - - maybeTokenList.onRight { tokenList -> - analyticsEventsHandler.sendBalanceLoadedEvent(tokenList) - checkMultiWalletWithFunds(tokenList) - } - - updateNotifications( - index = walletIndex, - tokenList = maybeTokenList.fold(ifLeft = { null }, ifRight = { it }), - ) - } - .flowOn(dispatchers.io) - .launchIn(viewModelScope) - .saveIn(tokensJobHolder) - } - - private fun AnalyticsEventHandler.sendBalanceLoadedEvent(tokenList: TokenList) { - val cardBalanceState = when (val fiatBalance = tokenList.totalFiatBalance) { - is TokenList.FiatBalance.Failed -> { - val currenciesStatuses = when (tokenList) { - is TokenList.Empty -> emptyList() - is TokenList.GroupedByNetwork -> tokenList.groups.flatMap(NetworkGroup::currencies) - is TokenList.Ungrouped -> tokenList.currencies - } - - when { - currenciesStatuses.isEmpty() -> AnalyticsParam.CardBalanceState.Empty - currenciesStatuses.any { it.value is CryptoCurrencyStatus.NoQuote } -> { - AnalyticsParam.CardBalanceState.NoRate - } - else -> AnalyticsParam.CardBalanceState.BlockchainError - } - } - is TokenList.FiatBalance.Loaded -> { - if (fiatBalance.amount > BigDecimal.ZERO) { - AnalyticsParam.CardBalanceState.Full - } else if (fiatBalance.amount.isZero()) { - AnalyticsParam.CardBalanceState.Empty - } else { - null - } - } - TokenList.FiatBalance.Loading -> null - } - - cardBalanceState?.let { - send(event = WalletScreenAnalyticsEvent.Basic.BalanceLoaded(balance = it)) - } - } - - private fun updateTxHistory(userWalletId: UserWalletId, currencyStatus: CryptoCurrencyStatus, refresh: Boolean) { - viewModelScope.launch(dispatchers.io) { - val txHistoryItemsCountEither = txHistoryItemsCountUseCase( - userWalletId = userWalletId, - currency = currencyStatus.currency, - ) - - uiState = stateFactory.getLoadingTxHistoryState( - itemsCountEither = txHistoryItemsCountEither, - pendingTransactions = currencyStatus.value.pendingTransactions, - ) - - txHistoryItemsCountEither.onRight { - uiState = stateFactory.getLoadedTxHistoryState( - txHistoryEither = txHistoryItemsUseCase( - userWalletId = userWalletId, - currency = currencyStatus.currency, - refresh = refresh, - ).map { - it.cachedIn(viewModelScope) - }, - ) - } - } - } - - private fun updateButtons(userWallet: UserWallet, currencyStatus: CryptoCurrencyStatus) { - getCryptoCurrencyActionsUseCase( - userWallet = userWallet, - cryptoCurrencyStatus = currencyStatus, - ) - .conflate() - .distinctUntilChanged() - .onEach { uiState = stateFactory.getSingleCurrencyManageButtonsState(actionsState = it) } - .flowOn(dispatchers.io) - .launchIn(viewModelScope) - .saveIn(buttonsJobHolder) - } - - private fun updateNotifications(index: Int, tokenList: TokenList? = null) { - notificationsListFactory.create( - selectedWallet = getWallet(index), - cryptoCurrencyList = if (tokenList != null) { - when (tokenList) { - is TokenList.GroupedByNetwork -> { - tokenList.groups - .flatMap(NetworkGroup::currencies) - } - is TokenList.Ungrouped -> tokenList.currencies - is TokenList.Empty -> emptyList() - } - } else { - listOfNotNull(singleWalletCryptoCurrencyStatus) - }, - ) - .conflate() - .distinctUntilChanged() - .onEach { uiState = stateFactory.getStateByNotifications(notifications = it) } - .flowOn(dispatchers.io) - .launchIn(viewModelScope) - .saveIn(notificationsJobHolder) - } - - private fun createSelectedAppCurrencyFlow(): StateFlow { - return getSelectedAppCurrencyUseCase() - .map { maybeAppCurrency -> - maybeAppCurrency.getOrElse { AppCurrency.Default } - } - .stateIn( - scope = viewModelScope, - started = SharingStarted.Eagerly, - initialValue = AppCurrency.Default, - ) - } - - private fun getWallet(index: Int): UserWallet { - return requireNotNull( - value = wallets.getOrNull(index), - lazyMessage = { "WalletsList doesn't contain element with index = $index" }, - ) - } - - private fun getSelectedWallet(): UserWallet { - val state = uiState as? WalletState.ContentState - ?: error("Unable to get selected user wallet") - - return getWallet(state.walletsListConfig.selectedWalletIndex) - } - - private fun getCardTypeResolver(index: Int): CardTypesResolver = getWallet(index).scanResponse.cardTypesResolver } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModelV2.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModelV2.kt deleted file mode 100644 index 418da4487e..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModelV2.kt +++ /dev/null @@ -1,319 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.viewmodels - -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase -import com.tangem.domain.redux.ReduxStateHolder -import com.tangem.domain.settings.CanUseBiometryUseCase -import com.tangem.domain.settings.IsWalletsScrollPreviewEnabled -import com.tangem.domain.settings.ShouldShowSaveWalletScreenUseCase -import com.tangem.domain.walletconnect.WalletConnectActions -import com.tangem.domain.wallets.usecase.GetSelectedWalletUseCase -import com.tangem.domain.wallets.usecase.GetWalletsUseCase -import com.tangem.domain.wallets.usecase.ShouldSaveUserWalletsUseCase -import com.tangem.feature.wallet.presentation.deeplink.WalletDeepLinksHandler -import com.tangem.feature.wallet.presentation.router.InnerWalletRouter -import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent -import com.tangem.feature.wallet.presentation.wallet.analytics.utils.SelectedWalletAnalyticsSender -import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent.DemonstrateWalletsScrollPreview.Direction -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.* -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletEventSender -import com.tangem.feature.wallet.presentation.wallet.utils.ScreenLifecycleProvider -import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2 -import com.tangem.utils.Provider -import com.tangem.utils.coroutines.CoroutineDispatcherProvider -import com.tangem.utils.coroutines.JobHolder -import com.tangem.utils.coroutines.saveIn -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.* -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import timber.log.Timber -import javax.inject.Inject - -@Suppress("LongParameterList") -@HiltViewModel -internal class WalletViewModelV2 @Inject constructor( - private val stateHolder: WalletStateController, - private val clickIntents: WalletClickIntentsV2, - private val walletEventSender: WalletEventSender, - private val walletsUpdateActionResolver: WalletsUpdateActionResolverV2, - private val walletScreenContentLoader: WalletScreenContentLoader, - private val getSelectedWalletUseCase: GetSelectedWalletUseCase, - private val getWalletsUseCase: GetWalletsUseCase, - private val shouldShowSaveWalletScreenUseCase: ShouldShowSaveWalletScreenUseCase, - private val canUseBiometryUseCase: CanUseBiometryUseCase, - private val shouldSaveUserWalletsUseCase: ShouldSaveUserWalletsUseCase, - private val isWalletsScrollPreviewEnabled: IsWalletsScrollPreviewEnabled, - private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, - analyticsEventsHandler: AnalyticsEventHandler, - private val dispatchers: CoroutineDispatcherProvider, - private val reduxStateHolder: ReduxStateHolder, - private val screenLifecycleProvider: ScreenLifecycleProvider, - private val selectedWalletAnalyticsSender: SelectedWalletAnalyticsSender, - private val walletDeepLinksHandler: WalletDeepLinksHandler, -) : ViewModel() { - - val uiState: StateFlow = stateHolder.uiState - - private lateinit var router: InnerWalletRouter - private var walletsUpdateJobHolder: JobHolder = JobHolder() - - init { - analyticsEventsHandler.send(WalletScreenAnalyticsEvent.MainScreen.ScreenOpened) - - suggestToEnableBiometrics() - - subscribeOnWalletsUpdateFlow() - subscribeOnBalanceHiding() - subscribeOnSelectedWalletFlow() - } - - fun setWalletRouter(router: InnerWalletRouter) { - this.router = router - clickIntents.initialize(router, viewModelScope) - } - - fun subscribeToLifecycle(lifecycleOwner: LifecycleOwner) { - lifecycleOwner.lifecycle.addObserver(screenLifecycleProvider) - } - - override fun onCleared() { - super.onCleared() - stateHolder.clear() - walletScreenContentLoader.cancelAll() - } - - private fun suggestToEnableBiometrics() { - viewModelScope.launch(dispatchers.main) { - withContext(dispatchers.io) { delay(timeMillis = 1_800) } - - if (isShowSaveWalletScreenEnabled()) router.openSaveUserWalletScreen() - } - } - - private suspend fun isShowSaveWalletScreenEnabled(): Boolean { - return router.isWalletLastScreen() && shouldShowSaveWalletScreenUseCase() && canUseBiometryUseCase() - } - - private fun subscribeOnWalletsUpdateFlow() { - viewModelScope.launch(dispatchers.main) { - shouldSaveUserWalletsUseCase() - .conflate() - .distinctUntilChanged() - .collectLatest(::subscribeToUserWalletsUpdates) - } - } - - private fun subscribeToUserWalletsUpdates(shouldSaveUserWallet: Boolean) { - getWalletsUseCase() - .conflate() - .distinctUntilChanged() - .map { - walletsUpdateActionResolver.resolve( - wallets = it, - currentState = stateHolder.value, - canSaveWallets = shouldSaveUserWallet, - ) - } - .onEach(::updateWallets) - .flowOn(dispatchers.main) - .launchIn(viewModelScope) - .saveIn(walletsUpdateJobHolder) - } - - private fun subscribeOnBalanceHiding() { - getBalanceHidingSettingsUseCase() - .conflate() - .distinctUntilChanged() - .onEach { - stateHolder.update(transformer = UpdateBalanceHidingModeTransformer(it.isBalanceHidden)) - } - .flowOn(dispatchers.main) - .launchIn(viewModelScope) - } - - private fun subscribeOnSelectedWalletFlow() { - getSelectedWalletUseCase().onRight { - it - .conflate() - .distinctUntilChanged() - .onEach { selectedWallet -> - if (selectedWallet.isMultiCurrency) { - Timber.d("WalletConnect: initialize and setup networks for ${selectedWallet.walletId}") - - reduxStateHolder.dispatch( - action = WalletConnectActions.New.Initialize(userWallet = selectedWallet), - ) - - reduxStateHolder.dispatch( - action = WalletConnectActions.New.SetupUserChains(userWallet = selectedWallet), - ) - - selectedWalletAnalyticsSender.send(selectedWallet) - } - - walletDeepLinksHandler.registerForSingleCurrencyWallets( - viewModel = this, - userWallet = selectedWallet, - ) - } - .flowOn(dispatchers.main) - .launchIn(viewModelScope) - } - } - - private fun updateWallets(action: WalletsUpdateActionResolverV2.Action) { - when (action) { - is WalletsUpdateActionResolverV2.Action.InitializeWallets -> initializeWallets(action) - is WalletsUpdateActionResolverV2.Action.ReinitializeWallets -> { - walletScreenContentLoader.load( - userWallet = action.selectedWallet, - clickIntents = clickIntents, - isRefresh = true, - coroutineScope = viewModelScope, - ) - } - is WalletsUpdateActionResolverV2.Action.ReinitializeWallet -> reinitializeWallet(action) - is WalletsUpdateActionResolverV2.Action.AddWallet -> addWallet(action) - is WalletsUpdateActionResolverV2.Action.DeleteWallet -> deleteWallet(action) - is WalletsUpdateActionResolverV2.Action.UnlockWallet -> unlockWallet(action) - is WalletsUpdateActionResolverV2.Action.UpdateWalletCardCount -> { - stateHolder.update(transformer = UpdateWalletCardsCountTransformer(action.selectedWallet)) - } - is WalletsUpdateActionResolverV2.Action.UpdateWalletName -> { - stateHolder.update(transformer = RenameWalletTransformer(action.selectedWalletId, action.name)) - } - is WalletsUpdateActionResolverV2.Action.Unknown -> Unit - } - } - - private fun initializeWallets(action: WalletsUpdateActionResolverV2.Action.InitializeWallets) { - walletScreenContentLoader.load( - userWallet = action.selectedWallet, - clickIntents = clickIntents, - coroutineScope = viewModelScope, - ) - - stateHolder.update( - transformer = InitializeWalletsTransformer( - selectedWalletIndex = action.selectedWalletIndex, - selectedWallet = action.selectedWallet, - wallets = action.wallets, - clickIntents = clickIntents, - ), - ) - - viewModelScope.launch(dispatchers.main) { - if (action.wallets.size > 1 && isWalletsScrollPreviewEnabled()) { - withContext(dispatchers.io) { - delay(timeMillis = 1_800) - } - - walletEventSender.send( - event = WalletEvent.DemonstrateWalletsScrollPreview( - direction = if (action.selectedWalletIndex == action.wallets.lastIndex) { - Direction.RIGHT - } else { - Direction.LEFT - }, - ), - ) - } - } - } - - private fun reinitializeWallet(action: WalletsUpdateActionResolverV2.Action.ReinitializeWallet) { - viewModelScope.launch(dispatchers.main) { - walletScreenContentLoader.cancel(action.prevWalletId) - - walletScreenContentLoader.load( - userWallet = action.selectedWallet, - clickIntents = clickIntents, - coroutineScope = viewModelScope, - ) - - stateHolder.update( - ReinitializeWalletTransformer(userWallet = action.selectedWallet, clickIntents = clickIntents), - ) - } - } - - private fun addWallet(action: WalletsUpdateActionResolverV2.Action.AddWallet) { - viewModelScope.launch(dispatchers.main) { - stateHolder.update( - AddWalletTransformer( - userWallet = action.selectedWallet, - clickIntents = clickIntents, - ), - ) - - walletScreenContentLoader.load( - userWallet = action.selectedWallet, - clickIntents = clickIntents, - coroutineScope = viewModelScope, - ) - - withContext(dispatchers.io) { delay(timeMillis = 700) } - - scrollToWallet(index = action.selectedWalletIndex) - } - } - - private fun deleteWallet(action: WalletsUpdateActionResolverV2.Action.DeleteWallet) { - viewModelScope.launch(dispatchers.main) { - walletScreenContentLoader.load( - userWallet = action.selectedWallet, - clickIntents = clickIntents, - coroutineScope = viewModelScope, - ) - - scrollToWallet(index = action.selectedWalletIndex) - - withContext(dispatchers.io) { delay(timeMillis = 700) } - - stateHolder.update( - DeleteWalletTransformer( - selectedWalletIndex = action.selectedWalletIndex, - deletedWalletId = action.deletedWalletId, - ), - ) - } - } - - private fun unlockWallet(action: WalletsUpdateActionResolverV2.Action.UnlockWallet) { - viewModelScope.launch(dispatchers.main) { - withContext(dispatchers.io) { delay(timeMillis = 700) } - - stateHolder.update( - transformer = UnlockWalletTransformer( - unlockedWallets = action.unlockedWallets, - clickIntents = clickIntents, - ), - ) - - walletScreenContentLoader.load( - userWallet = action.selectedWallet, - clickIntents = clickIntents, - coroutineScope = viewModelScope, - ) - } - } - - private fun scrollToWallet(index: Int) { - stateHolder.update( - ScrollToWalletTransformer( - index = index, - currentStateProvider = Provider(action = stateHolder::value), - stateUpdater = { newState -> stateHolder.update { newState } }, - ), - ) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolver.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolver.kt index c8a6e6ca23..bdfd27558d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolver.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolver.kt @@ -4,140 +4,190 @@ import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase import com.tangem.feature.wallet.presentation.wallet.domain.getCardsCount -import com.tangem.feature.wallet.presentation.wallet.state.WalletLockedState -import com.tangem.feature.wallet.presentation.wallet.state.WalletState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.utils.Provider +import com.tangem.feature.wallet.presentation.wallet.state.model.NOT_INITIALIZED_WALLET_INDEX +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import dagger.hilt.android.scopes.ViewModelScoped +import timber.log.Timber +import javax.inject.Inject /** * Resolver that determines which update action will be performed * - * @property currentStateProvider current state provider * @property getSelectedWalletSyncUseCase use case that returns selected wallet */ -internal class WalletsUpdateActionResolver( - private val currentStateProvider: Provider, +@ViewModelScoped +internal class WalletsUpdateActionResolver @Inject constructor( private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, ) { - fun resolve(wallets: List): Action { - val selectedWallet = wallets.getSelectedWallet() + private var isInitialized: Boolean = false + private var canSaveWallets: Boolean = false - return when (val state = currentStateProvider()) { - is WalletState.Initial -> { - Action.Initialize( - selectedWalletIndex = wallets.indexOfWallet(id = selectedWallet.walletId), - ) + fun resolve(wallets: List, currentState: WalletScreenState, canSaveWallets: Boolean): Action { + val selectedWallet = wallets.getSelectedWallet() ?: return Action.Unknown + + val action = when { + isFirstInitialization(currentState) -> { + createInitializeWalletsAction(wallets, selectedWallet, canSaveWallets) } - is WalletState.ContentState -> { - getActionToUpdateContent(state = state, wallets = wallets, selectedWallet = selectedWallet) + isReinitialization(canSaveWallets) -> { + this.canSaveWallets = canSaveWallets + Action.ReinitializeWallets(selectedWallet = selectedWallet) } + else -> getUpdateContentAction(currentState, wallets, selectedWallet) + } + + Timber.d("Resolved action: $action") + + return action + } + + private fun List.getSelectedWallet(): UserWallet? { + return when { + isEmpty() -> null + size == 1 -> first() + else -> getSelectedWalletSyncUseCase().fold(ifLeft = { null }, ifRight = { it }) } } - private fun List.getSelectedWallet(): UserWallet { - val hasUnlockedWallet = any { !it.isLocked } - return if (hasUnlockedWallet) { - val selectedWalletId = getSelectedWalletSyncUseCase().fold(ifLeft = ::error, ifRight = UserWallet::walletId) - - firstOrNull { it.walletId == selectedWalletId } - ?: error("Wallets don't contain a wallet with id: $selectedWalletId") - } else { - lastOrNull() ?: error("Wallets is empty") - } + private fun isFirstInitialization(state: WalletScreenState): Boolean { + return state.selectedWalletIndex == NOT_INITIALIZED_WALLET_INDEX } - private fun getActionToUpdateContent( - state: WalletState.ContentState, + private fun createInitializeWalletsAction( + wallets: List, + selectedWallet: UserWallet, + canSaveWallets: Boolean, + ): Action { + this.isInitialized = true + this.canSaveWallets = canSaveWallets + + return Action.InitializeWallets( + selectedWalletIndex = wallets.indexOfWallet(selectedWallet.walletId), + selectedWallet = selectedWallet, + wallets = wallets, + ) + } + + private fun isReinitialization(canSaveWallets: Boolean): Boolean { + return isInitialized && this.canSaveWallets != canSaveWallets + } + + private fun getUpdateContentAction( + state: WalletScreenState, wallets: List, selectedWallet: UserWallet, ): Action { return when { isWalletsCountChanged(state, wallets) -> { - getActionToChangeWallets(state = state, wallets = wallets, selectedWallet = selectedWallet) + getChangeWalletsListAction(state, wallets, selectedWallet) } - isSelectedWalletChanged(state, selectedWallet) -> { - Action.Initialize(wallets.indexOfWallet(selectedWallet.walletId)) + isAnotherWalletSelected(state, selectedWallet) -> { + Action.ReinitializeWallet( + prevWalletId = state.getPrevSelectedWallet().id, + selectedWallet = selectedWallet, + ) } - else -> getActionToUpdateCurrentWallet(state = state, wallets = wallets, selectedWallet = selectedWallet) + else -> getUpdateSelectedWalletAction(state, wallets, selectedWallet) } } - private fun isWalletsCountChanged(state: WalletState.ContentState, wallets: List): Boolean { - val prevWalletsSize = state.walletsListConfig.wallets.size + private fun isWalletsCountChanged(state: WalletScreenState, wallets: List): Boolean { + val prevWalletsSize = state.wallets.size val walletsSize = wallets.size return prevWalletsSize != walletsSize } - private fun getActionToChangeWallets( - state: WalletState.ContentState, + private fun getChangeWalletsListAction( + state: WalletScreenState, wallets: List, selectedWallet: UserWallet, ): Action { - val prevWalletsSize = state.walletsListConfig.wallets.size + val prevWalletsSize = state.wallets.size return when { prevWalletsSize > wallets.size -> { Action.DeleteWallet( - selectedWalletId = selectedWallet.walletId, + selectedWallet = selectedWallet, selectedWalletIndex = wallets.indexOfWallet(id = selectedWallet.walletId), - deletedWalletId = state.walletsListConfig.wallets.getDeletedWalletId(wallets), + deletedWalletId = state.wallets.getDeletedWalletId(wallets), ) } prevWalletsSize < wallets.size -> { + val newUserWallet = state.wallets.getAddedWallet(wallets) Action.AddWallet( - selectedWalletIndex = wallets.indexOfWallet(id = selectedWallet.walletId), + selectedWalletIndex = wallets.indexOfWallet(id = newUserWallet.walletId), + selectedWallet = newUserWallet, ) } - else -> Action.Unknown + else -> error("Wallets list is not changed") } } - private fun List.getDeletedWalletId(wallets: List): UserWalletId { + private fun List.getDeletedWalletId(wallets: List): UserWalletId { return this - .map(WalletCardState::id) + .map { it.walletCardState.id } .firstOrNull { !wallets.map(UserWallet::walletId).contains(it) } ?: error("Deleted wallet id is not found. Wallets contains all previous wallets ids") } - private fun isSelectedWalletChanged(state: WalletState.ContentState, selectedWallet: UserWallet): Boolean { + private fun List.getAddedWallet(wallets: List): UserWallet { + return wallets + .firstOrNull { wallet -> !this.map { it.walletCardState.id }.contains(wallet.walletId) } + ?: error("Added wallet id is not found. Wallets contains all previous wallets ids") + } + + private fun isAnotherWalletSelected(state: WalletScreenState, selectedWallet: UserWallet): Boolean { return state.getPrevSelectedWallet().id != selectedWallet.walletId } - private fun getActionToUpdateCurrentWallet( - state: WalletState.ContentState, + private fun getUpdateSelectedWalletAction( + state: WalletScreenState, wallets: List, selectedWallet: UserWallet, ): Action { - val selectedWalletName = selectedWallet.name - val previousWalletState = state.getPrevSelectedWallet() return when { - previousWalletState.title != selectedWalletName -> { - Action.UpdateWalletName(selectedWalletName) + isSelectedWalletNameChanged(state, selectedWallet) -> { + Action.UpdateWalletName(selectedWalletId = selectedWallet.walletId, name = selectedWallet.name) } - - state is WalletLockedState && !selectedWallet.isLocked -> { + isSelectedWalletUnlocked(state, selectedWallet) -> { Action.UnlockWallet( - selectedWalletIndex = wallets.indexOfWallet(id = selectedWallet.walletId), selectedWallet = selectedWallet, unlockedWallets = wallets.filterNot(UserWallet::isLocked), ) } - - previousWalletState is WalletCardState.Content && - previousWalletState.cardCount != selectedWallet.getCardsCount() -> { - Action.UpdateWalletCardCount - } - + isSelectedWalletCardsCountChanged(state, selectedWallet) -> Action.UpdateWalletCardCount(selectedWallet) else -> Action.Unknown } } - private fun WalletState.ContentState.getPrevSelectedWallet(): WalletCardState { - val prevSelectedWalletIndex = walletsListConfig.selectedWalletIndex + private fun isSelectedWalletNameChanged(state: WalletScreenState, selectedWallet: UserWallet): Boolean { + return state.getPrevSelectedWallet().title != selectedWallet.name + } - return walletsListConfig.wallets.getOrNull(prevSelectedWalletIndex) + private fun isSelectedWalletUnlocked(state: WalletScreenState, selectedWallet: UserWallet): Boolean { + return state.isSelectedWalletLocked() && !selectedWallet.isLocked + } + + private fun isSelectedWalletCardsCountChanged(state: WalletScreenState, selectedWallet: UserWallet): Boolean { + val prevSelectedWallet = state.getPrevSelectedWallet() + return prevSelectedWallet is WalletCardState.Content && + prevSelectedWallet.cardCount != selectedWallet.getCardsCount() + } + + private fun WalletScreenState.isSelectedWalletLocked(): Boolean { + val selectedWalletState = wallets.getOrNull(selectedWalletIndex) ?: error("Selected wallet is not found") + return selectedWalletState is WalletState.MultiCurrency.Locked || + selectedWalletState is WalletState.SingleCurrency.Locked + } + + private fun WalletScreenState.getPrevSelectedWallet(): WalletCardState { + return wallets + .map(WalletState::walletCardState) + .getOrNull(selectedWalletIndex) ?: error("Previous selected wallet is not found") } @@ -153,26 +203,110 @@ internal class WalletsUpdateActionResolver( sealed class Action { - data class Initialize(val selectedWalletIndex: Int) : Action() - - data class UpdateWalletName(val name: String) : Action() - - data class UnlockWallet( + data class InitializeWallets( val selectedWalletIndex: Int, val selectedWallet: UserWallet, - val unlockedWallets: List, - ) : Action() + val wallets: List, + ) : Action() { + + override fun toString(): String { + return """ + InitializeWallets( + selectedWalletIndex = $selectedWalletIndex, + selectedWallet = ${selectedWallet.walletId}, + wallets = ${wallets.joinToString { it.walletId.toString() }} + ) + """.trimIndent() + } + } + + /** + * Reinitialize wallets. Example, if user turned on wallets saving + * + * @property selectedWallet selected wallet + */ + data class ReinitializeWallets(val selectedWallet: UserWallet) : Action() { + + override fun toString(): String { + return "ReinitializeWallets(selectedWallet = ${selectedWallet.walletId})" + } + } + + /** + * Reinitialize selected wallet. Example, scanning a new card if wallets saving is turned off + * + * @property prevWalletId previous selected wallet id + * @property selectedWallet selected wallet + */ + data class ReinitializeWallet(val prevWalletId: UserWalletId, val selectedWallet: UserWallet) : Action() { + + override fun toString(): String { + return "ReinitializeWallet(prevWalletId = $prevWalletId, selectedWallet = ${selectedWallet.walletId})" + } + } + + data class UpdateWalletName(val selectedWalletId: UserWalletId, val name: String) : Action() { + + override fun toString(): String { + return "UpdateWalletName(selectedWalletId = $selectedWalletId, name = $name)" + } + } + + data class UnlockWallet(val selectedWallet: UserWallet, val unlockedWallets: List) : Action() { + + override fun toString(): String { + return """ + UnlockWallet( + selectedWallet = ${selectedWallet.walletId}, + unlockedWallets = ${unlockedWallets.joinToString { it.walletId.toString() }} + ) + """.trimIndent() + } + } data class DeleteWallet( - val selectedWalletId: UserWalletId, + val selectedWallet: UserWallet, val selectedWalletIndex: Int, val deletedWalletId: UserWalletId, - ) : Action() + ) : Action() { - data class AddWallet(val selectedWalletIndex: Int) : Action() + override fun toString(): String { + return """ + DeleteWallet( + selectedWallet = ${selectedWallet.walletId}, + selectedWalletIndex = $selectedWalletIndex, + deletedWalletId = $deletedWalletId + ) + """.trimIndent() + } + } - object UpdateWalletCardCount : Action() + data class AddWallet(val selectedWalletIndex: Int, val selectedWallet: UserWallet) : Action() { - object Unknown : Action() + override fun toString(): String { + return """ + AddWallet( + selectedWalletIndex = $selectedWalletIndex, + selectedWallet = ${selectedWallet.walletId} + ) + """.trimIndent() + } + } + + /** + * Update wallet card count. Example, if user backed up wallet + * + * @property selectedWallet selected wallet + */ + data class UpdateWalletCardCount(val selectedWallet: UserWallet) : Action() { + + override fun toString(): String { + return "UpdateWalletCardCount(selectedWallet = ${selectedWallet.walletId})" + } + } + + object Unknown : Action() { + override fun toString(): String = "Unknown" + } } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolverV2.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolverV2.kt deleted file mode 100644 index 1c8a3f7b26..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolverV2.kt +++ /dev/null @@ -1,312 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.viewmodels - -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase -import com.tangem.feature.wallet.presentation.wallet.domain.getCardsCount -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state2.model.NOT_INITIALIZED_WALLET_INDEX -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletScreenState -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import dagger.hilt.android.scopes.ViewModelScoped -import timber.log.Timber -import javax.inject.Inject - -/** - * Resolver that determines which update action will be performed - * - * @property getSelectedWalletSyncUseCase use case that returns selected wallet - */ -@ViewModelScoped -internal class WalletsUpdateActionResolverV2 @Inject constructor( - private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, -) { - - private var isInitialized: Boolean = false - private var canSaveWallets: Boolean = false - - fun resolve(wallets: List, currentState: WalletScreenState, canSaveWallets: Boolean): Action { - val selectedWallet = wallets.getSelectedWallet() ?: return Action.Unknown - - val action = when { - isFirstInitialization(currentState) -> { - createInitializeWalletsAction(wallets, selectedWallet, canSaveWallets) - } - isReinitialization(canSaveWallets) -> { - this.canSaveWallets = canSaveWallets - Action.ReinitializeWallets(selectedWallet = selectedWallet) - } - else -> getUpdateContentAction(currentState, wallets, selectedWallet) - } - - Timber.d("Resolved action: $action") - - return action - } - - private fun List.getSelectedWallet(): UserWallet? { - return when { - isEmpty() -> null - size == 1 -> first() - else -> getSelectedWalletSyncUseCase().fold(ifLeft = { null }, ifRight = { it }) - } - } - - private fun isFirstInitialization(state: WalletScreenState): Boolean { - return state.selectedWalletIndex == NOT_INITIALIZED_WALLET_INDEX - } - - private fun createInitializeWalletsAction( - wallets: List, - selectedWallet: UserWallet, - canSaveWallets: Boolean, - ): Action { - this.isInitialized = true - this.canSaveWallets = canSaveWallets - - return Action.InitializeWallets( - selectedWalletIndex = wallets.indexOfWallet(selectedWallet.walletId), - selectedWallet = selectedWallet, - wallets = wallets, - ) - } - - private fun isReinitialization(canSaveWallets: Boolean): Boolean { - return isInitialized && this.canSaveWallets != canSaveWallets - } - - private fun getUpdateContentAction( - state: WalletScreenState, - wallets: List, - selectedWallet: UserWallet, - ): Action { - return when { - isWalletsCountChanged(state, wallets) -> { - getChangeWalletsListAction(state, wallets, selectedWallet) - } - isAnotherWalletSelected(state, selectedWallet) -> { - Action.ReinitializeWallet( - prevWalletId = state.getPrevSelectedWallet().id, - selectedWallet = selectedWallet, - ) - } - else -> getUpdateSelectedWalletAction(state, wallets, selectedWallet) - } - } - - private fun isWalletsCountChanged(state: WalletScreenState, wallets: List): Boolean { - val prevWalletsSize = state.wallets.size - val walletsSize = wallets.size - - return prevWalletsSize != walletsSize - } - - private fun getChangeWalletsListAction( - state: WalletScreenState, - wallets: List, - selectedWallet: UserWallet, - ): Action { - val prevWalletsSize = state.wallets.size - - return when { - prevWalletsSize > wallets.size -> { - Action.DeleteWallet( - selectedWallet = selectedWallet, - selectedWalletIndex = wallets.indexOfWallet(id = selectedWallet.walletId), - deletedWalletId = state.wallets.getDeletedWalletId(wallets), - ) - } - prevWalletsSize < wallets.size -> { - val newUserWallet = state.wallets.getAddedWallet(wallets) - Action.AddWallet( - selectedWalletIndex = wallets.indexOfWallet(id = newUserWallet.walletId), - selectedWallet = newUserWallet, - ) - } - else -> error("Wallets list is not changed") - } - } - - private fun List.getDeletedWalletId(wallets: List): UserWalletId { - return this - .map { it.walletCardState.id } - .firstOrNull { !wallets.map(UserWallet::walletId).contains(it) } - ?: error("Deleted wallet id is not found. Wallets contains all previous wallets ids") - } - - private fun List.getAddedWallet(wallets: List): UserWallet { - return wallets - .firstOrNull { wallet -> !this.map { it.walletCardState.id }.contains(wallet.walletId) } - ?: error("Added wallet id is not found. Wallets contains all previous wallets ids") - } - - private fun isAnotherWalletSelected(state: WalletScreenState, selectedWallet: UserWallet): Boolean { - return state.getPrevSelectedWallet().id != selectedWallet.walletId - } - - private fun getUpdateSelectedWalletAction( - state: WalletScreenState, - wallets: List, - selectedWallet: UserWallet, - ): Action { - return when { - isSelectedWalletNameChanged(state, selectedWallet) -> { - Action.UpdateWalletName(selectedWalletId = selectedWallet.walletId, name = selectedWallet.name) - } - isSelectedWalletUnlocked(state, selectedWallet) -> { - Action.UnlockWallet( - selectedWallet = selectedWallet, - unlockedWallets = wallets.filterNot(UserWallet::isLocked), - ) - } - isSelectedWalletCardsCountChanged(state, selectedWallet) -> Action.UpdateWalletCardCount(selectedWallet) - else -> Action.Unknown - } - } - - private fun isSelectedWalletNameChanged(state: WalletScreenState, selectedWallet: UserWallet): Boolean { - return state.getPrevSelectedWallet().title != selectedWallet.name - } - - private fun isSelectedWalletUnlocked(state: WalletScreenState, selectedWallet: UserWallet): Boolean { - return state.isSelectedWalletLocked() && !selectedWallet.isLocked - } - - private fun isSelectedWalletCardsCountChanged(state: WalletScreenState, selectedWallet: UserWallet): Boolean { - val prevSelectedWallet = state.getPrevSelectedWallet() - return prevSelectedWallet is WalletCardState.Content && - prevSelectedWallet.cardCount != selectedWallet.getCardsCount() - } - - private fun WalletScreenState.isSelectedWalletLocked(): Boolean { - val selectedWalletState = wallets.getOrNull(selectedWalletIndex) ?: error("Selected wallet is not found") - return selectedWalletState is WalletState.MultiCurrency.Locked || - selectedWalletState is WalletState.SingleCurrency.Locked - } - - private fun WalletScreenState.getPrevSelectedWallet(): WalletCardState { - return wallets - .map(WalletState::walletCardState) - .getOrNull(selectedWalletIndex) - ?: error("Previous selected wallet is not found") - } - - private fun List.indexOfWallet(id: UserWalletId): Int { - val selectedIndex = indexOfFirst { it.walletId == id } - - return if (selectedIndex == -1) { - error("Wallets don't contain a wallet with id: $id") - } else { - selectedIndex - } - } - - sealed class Action { - - data class InitializeWallets( - val selectedWalletIndex: Int, - val selectedWallet: UserWallet, - val wallets: List, - ) : Action() { - - override fun toString(): String { - return """ - InitializeWallets( - selectedWalletIndex = $selectedWalletIndex, - selectedWallet = ${selectedWallet.walletId}, - wallets = ${wallets.joinToString { it.walletId.toString() }} - ) - """.trimIndent() - } - } - - /** - * Reinitialize wallets. Example, if user turned on wallets saving - * - * @property selectedWallet selected wallet - */ - data class ReinitializeWallets(val selectedWallet: UserWallet) : Action() { - - override fun toString(): String { - return "ReinitializeWallets(selectedWallet = ${selectedWallet.walletId})" - } - } - - /** - * Reinitialize selected wallet. Example, scanning a new card if wallets saving is turned off - * - * @property prevWalletId previous selected wallet id - * @property selectedWallet selected wallet - */ - data class ReinitializeWallet(val prevWalletId: UserWalletId, val selectedWallet: UserWallet) : Action() { - - override fun toString(): String { - return "ReinitializeWallet(prevWalletId = $prevWalletId, selectedWallet = ${selectedWallet.walletId})" - } - } - - data class UpdateWalletName(val selectedWalletId: UserWalletId, val name: String) : Action() { - - override fun toString(): String { - return "UpdateWalletName(selectedWalletId = $selectedWalletId, name = $name)" - } - } - - data class UnlockWallet(val selectedWallet: UserWallet, val unlockedWallets: List) : Action() { - - override fun toString(): String { - return """ - UnlockWallet( - selectedWallet = ${selectedWallet.walletId}, - unlockedWallets = ${unlockedWallets.joinToString { it.walletId.toString() }} - ) - """.trimIndent() - } - } - - data class DeleteWallet( - val selectedWallet: UserWallet, - val selectedWalletIndex: Int, - val deletedWalletId: UserWalletId, - ) : Action() { - - override fun toString(): String { - return """ - DeleteWallet( - selectedWallet = ${selectedWallet.walletId}, - selectedWalletIndex = $selectedWalletIndex, - deletedWalletId = $deletedWalletId - ) - """.trimIndent() - } - } - - data class AddWallet(val selectedWalletIndex: Int, val selectedWallet: UserWallet) : Action() { - - override fun toString(): String { - return """ - AddWallet( - selectedWalletIndex = $selectedWalletIndex, - selectedWallet = ${selectedWallet.walletId} - ) - """.trimIndent() - } - } - - /** - * Update wallet card count. Example, if user backed up wallet - * - * @property selectedWallet selected wallet - */ - data class UpdateWalletCardCount(val selectedWallet: UserWallet) : Action() { - - override fun toString(): String { - return "UpdateWalletCardCount(selectedWallet = ${selectedWallet.walletId})" - } - } - - object Unknown : Action() { - override fun toString(): String = "Unknown" - } - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/VisaWalletIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/VisaWalletIntents.kt index 00c4927cde..f2f28ea189 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/VisaWalletIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/VisaWalletIntents.kt @@ -8,9 +8,9 @@ import com.tangem.domain.tokens.GetCryptoCurrencyStatusSyncUseCase import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.visa.GetVisaCurrencyUseCase import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.BalancesAndLimitsBottomSheetConverter -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletEventSender +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.BalancesAndLimitsBottomSheetConverter +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletEventSender import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.collections.immutable.toImmutableList diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt index e1866a709c..f3ae886366 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt @@ -7,12 +7,12 @@ import com.tangem.domain.wallets.usecase.DeleteWalletUseCase import com.tangem.domain.wallets.usecase.UpdateWalletUseCase import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent.MainScreen import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader -import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletEventSender +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletAlertState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletEventSender import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.launch import timber.log.Timber diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntentsV2.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt similarity index 92% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntentsV2.kt rename to features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt index 19c3f6130f..c27ff4424e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntentsV2.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt @@ -12,10 +12,10 @@ import com.tangem.feature.wallet.presentation.router.InnerWalletRouter import com.tangem.feature.wallet.presentation.wallet.analytics.PortfolioEvent import com.tangem.feature.wallet.presentation.wallet.domain.unwrap import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.model.WalletState -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetRefreshStateTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.SetTokenListErrorTransformer +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetRefreshStateTransformer +import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTokenListErrorTransformer import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.coroutines.CoroutineScope @@ -24,7 +24,7 @@ import javax.inject.Inject @Suppress("LongParameterList") @ViewModelScoped -internal class WalletClickIntentsV2 @Inject constructor( +internal class WalletClickIntents @Inject constructor( private val walletCardClickIntentsImplementor: WalletCardClickIntentsImplementor, private val warningsClickIntentsImplementer: WalletWarningsClickIntentsImplementer, private val currencyActionsClickIntentsImplementor: WalletCurrencyActionsClickIntentsImplementor, @@ -70,7 +70,7 @@ internal class WalletClickIntentsV2 @Inject constructor( maybeUserWallet.onRight { walletScreenContentLoader.load( userWallet = it, - clickIntents = this@WalletClickIntentsV2, + clickIntents = this@WalletClickIntents, coroutineScope = viewModelScope, ) } @@ -138,7 +138,7 @@ internal class WalletClickIntentsV2 @Inject constructor( walletScreenContentLoader.load( userWallet = userWallet, - clickIntents = this@WalletClickIntentsV2, + clickIntents = this@WalletClickIntents, isRefresh = true, coroutineScope = viewModelScope, ) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletContentClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletContentClickIntents.kt index 6768550c5a..86e51c62e7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletContentClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletContentClickIntents.kt @@ -13,9 +13,9 @@ import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase import com.tangem.feature.wallet.presentation.wallet.analytics.PortfolioEvent import com.tangem.feature.wallet.presentation.wallet.domain.unwrap -import com.tangem.feature.wallet.presentation.wallet.state.ActionsBottomSheetConfig -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.converter.MultiWalletCurrencyActionsConverter +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.ActionsBottomSheetConfig +import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.MultiWalletCurrencyActionsConverter import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.coroutines.flow.collectLatest diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt index 25c2b29527..243f372827 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt @@ -28,11 +28,11 @@ import com.tangem.domain.wallets.usecase.GetExploreUrlUseCase import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.wallet.domain.unwrap -import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.CloseBottomSheetTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletEventSender +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletAlertState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent +import com.tangem.feature.wallet.presentation.wallet.state.transformers.CloseBottomSheetTransformer +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletEventSender import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.collections.immutable.toImmutableList diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt index 0a09fcf2c4..e9e03ac291 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt @@ -20,11 +20,11 @@ import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnaly import com.tangem.feature.wallet.presentation.wallet.domain.ScanCardToUnlockWalletClickHandler import com.tangem.feature.wallet.presentation.wallet.domain.ScanCardToUnlockWalletError import com.tangem.feature.wallet.presentation.wallet.domain.unwrap -import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState -import com.tangem.feature.wallet.presentation.wallet.state.WalletEvent -import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController -import com.tangem.feature.wallet.presentation.wallet.state2.transformers.CloseBottomSheetTransformer -import com.tangem.feature.wallet.presentation.wallet.state2.utils.WalletEventSender +import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletAlertState +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent +import com.tangem.feature.wallet.presentation.wallet.state.transformers.CloseBottomSheetTransformer +import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletEventSender import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.scopes.ViewModelScoped import kotlinx.coroutines.launch