From 477bff1de0f967e20446a21434e9d30c7fee299e Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 4 Oct 2023 15:43:19 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../wallet/viewmodels/WalletViewModel.kt | 47 +++---------------- 1 file changed, 7 insertions(+), 40 deletions(-) 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 09b9aff20b..3dcfdd7311 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 @@ -17,7 +17,6 @@ import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.navigation.AppScreen import com.tangem.core.ui.components.bottomsheets.tokenreceive.AddressModel import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheetConfig -import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.WrappedList import com.tangem.core.ui.extensions.resourceReference @@ -54,13 +53,11 @@ 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.feature.wallet.presentation.common.state.TokenItemState 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.state.* import com.tangem.feature.wallet.presentation.wallet.state.components.WalletCardState -import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState import com.tangem.feature.wallet.presentation.wallet.state.factory.WalletStateFactory import com.tangem.operations.derivation.ExtendedPublicKeysMap import com.tangem.utils.coroutines.CoroutineDispatcherProvider @@ -246,14 +243,12 @@ internal class WalletViewModel @Inject constructor( if (cacheState != null) { uiState = stateFactory.getStateWithoutDeletedWallet(cacheState, action) - if (cacheState.isLoadingOrEmptyState()) { - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.ChangeWallet(action.selectedWalletIndex), - setUiState = { uiState = it }, - ) - getContentItemsUpdates(action.selectedWalletIndex) - } + 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) @@ -495,9 +490,7 @@ internal class WalletViewModel @Inject constructor( pullToRefreshConfig = cacheState.pullToRefreshConfig.copy(isRefreshing = false), ) - if (cacheState.isLoadingOrEmptyState()) { - getContentItemsUpdates(index) - } + getContentItemsUpdates(index) } else { initializeAndLoadState(selectedWalletIndex = index) } @@ -1035,32 +1028,6 @@ internal class WalletViewModel @Inject constructor( ) } - private fun WalletState.isLoadingOrEmptyState(): Boolean { - // Check the base components - if (this is WalletState.ContentState && - walletsListConfig.wallets[walletsListConfig.selectedWalletIndex] is WalletCardState.Loading - ) { - return true - } - - // Check the special components - return when (this) { - is WalletMultiCurrencyState -> { - val isTokensEmpty = tokensListState is WalletTokensListState.Empty - val hasLoadingTokens = tokensListState is WalletTokensListState.ContentState && - (tokensListState as WalletTokensListState.ContentState).items - .filterIsInstance() - .any { it.state is TokenItemState.Loading } - - isTokensEmpty || tokensListState is WalletTokensListState.Loading || hasLoadingTokens - } - is WalletSingleCurrencyState -> { - this is WalletSingleCurrencyState.Content && marketPriceBlockState is MarketPriceBlockState.Loading - } - is WalletState.Initial -> false - } - } - private fun getWallet(index: Int): UserWallet { return requireNotNull( value = wallets.getOrNull(index),