From 1cdc5b5ab9ea614fdafdeed9504e0cbce6751bc5 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 11 Oct 2023 18:27:56 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../viewmodels/TokenDetailsViewModel.kt | 1 - .../WalletLoadingTxHistoryConverter.kt | 35 +++++++++++-------- .../WalletTxHistoryItemFlowConverter.kt | 8 ++--- .../wallet/viewmodels/WalletViewModel.kt | 7 ++++ 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt index 493e8fa532..6c131e438b 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt @@ -178,7 +178,6 @@ internal class TokenDetailsViewModel @Inject constructor( * @param refresh - invalidate cache and get data from remote * @param showItemsLoading - show loading items placeholder. */ - @Suppress("UnusedPrivateMember") // will be removed after implement caching private fun updateTxHistory(refresh: Boolean, showItemsLoading: Boolean) { viewModelScope.launch(dispatchers.io) { val txHistoryItemsCountEither = txHistoryItemsCountUseCase( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt index 65e92212f3..f0db791f6f 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt @@ -10,6 +10,7 @@ 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 kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update /** @@ -52,23 +53,29 @@ internal class WalletLoadingTxHistoryConverter( private fun convertRight(value: Int): WalletState { val state = currentStateProvider() - val txHistoryContent = (state as? WalletSingleCurrencyState.Content)?.txHistoryState as? Content - - txHistoryContent?.contentItems?.update { - PagingData.from( - data = listOf(TxHistoryItemState.Title(onExploreClick = clickIntents::onExploreClick)) + - MutableList( - size = value, - init = { - TxHistoryItemState.Transaction( - state = TransactionState.Loading(it.toString()), - ) - }, - ), + 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) } + } - return state + 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) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt index 245cfa94e8..e8e5b65758 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt @@ -17,10 +17,7 @@ import com.tangem.utils.extensions.isToday import com.tangem.utils.extensions.isYesterday import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.flow.update +import kotlinx.coroutines.flow.* import org.joda.time.DateTime import org.joda.time.DateTimeZone @@ -49,7 +46,8 @@ internal class WalletTxHistoryItemFlowConverter( override fun convert(value: Flow>): TxHistoryState? { val state = currentStateProvider() as? WalletSingleCurrencyState ?: return null - val txHistoryContent = state.txHistoryState as? TxHistoryState.Content ?: return state.txHistoryState + val txHistoryContent = state.txHistoryState as? TxHistoryState.Content + ?: TxHistoryState.Content(contentItems = MutableStateFlow(PagingData.empty())) // FIXME: TxHistoryRepository should send loading transactions // [REDACTED_JIRA] 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 b27abb5602..f0b0798819 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.* import androidx.paging.cachedIn import arrow.core.Either import arrow.core.getOrElse +import arrow.core.right import com.tangem.blockchain.blockchains.cardano.CardanoUtils import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.address.AddressType @@ -18,6 +19,7 @@ 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.transactions.state.TxHistoryState import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.WrappedList import com.tangem.core.ui.extensions.resourceReference @@ -1163,6 +1165,11 @@ internal class WalletViewModel @Inject constructor( 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(1.right()) + } updateTxHistory(wallet.walletId, it.currency, refresh = true) } }.saveIn(refreshContentJobHolder)