Updated on 2026-08-14
This commit is contained in:
parent
98915e2507
commit
1cdc5b5ab9
4 changed files with 31 additions and 20 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<TxHistoryItemState> {
|
||||
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<TxHistoryStateError, Int>)
|
||||
|
|
|
|||
|
|
@ -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<PagingData<TxHistoryItem>>): 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]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue