Updated on 2026-08-14

This commit is contained in:
Tangem 2023-09-26 18:26:31 +03:00
parent c215778788
commit d1c77b00cf
14 changed files with 44 additions and 85 deletions

View file

@ -16,7 +16,7 @@ internal class CryptoCurrenciesIdsResolver {
val currenciesStatuses = when (tokenList) {
is TokenList.GroupedByNetwork -> tokenList.groups.flatMap { it.currencies }
is TokenList.Ungrouped -> tokenList.currencies
is TokenList.NotInitialized,
is TokenList.Empty,
null,
-> return emptyList()
}

View file

@ -7,6 +7,6 @@ internal fun TokenList.disableSortingByBalance(): TokenList {
return when (this) {
is TokenList.GroupedByNetwork -> this.copy(sortedBy = SortType.NONE)
is TokenList.Ungrouped -> this.copy(sortedBy = SortType.NONE)
is TokenList.NotInitialized -> this
is TokenList.Empty -> this
}
}

View file

@ -17,7 +17,7 @@ internal class TokenListToListStateConverter(
return when (value) {
is TokenList.GroupedByNetwork -> createListState(value)
is TokenList.Ungrouped -> createListState(value)
is TokenList.NotInitialized -> createEmptyListState()
is TokenList.Empty -> createEmptyListState()
}
}

View file

@ -29,7 +29,7 @@ internal class TokenListToContentItemsConverter(
override fun convert(value: TokenList): WalletTokensListState {
return when (value) {
is TokenList.NotInitialized -> WalletTokensListState.Loading()
is TokenList.Empty -> WalletTokensListState.Empty
is TokenList.GroupedByNetwork -> WalletTokensListState.Content(
items = value.mapToMultiCurrencyItems(),
organizeTokensButton = value.mapToOrganizeTokensButtonState(),

View file

@ -241,7 +241,7 @@ internal class WalletViewModel @Inject constructor(
if (cacheState != null) {
uiState = stateFactory.getStateWithoutDeletedWallet(cacheState, action)
if (cacheState.isLoadingState()) {
if (cacheState.isLoadingOrEmptyState()) {
uiState = stateFactory.getStateAndTriggerEvent(
state = uiState,
event = WalletEvent.ChangeWallet(action.selectedWalletIndex),
@ -509,7 +509,7 @@ internal class WalletViewModel @Inject constructor(
pullToRefreshConfig = cacheState.pullToRefreshConfig.copy(isRefreshing = false),
)
if (cacheState.isLoadingState()) {
if (cacheState.isLoadingOrEmptyState()) {
getContentItemsUpdates(index)
}
} else {
@ -904,7 +904,7 @@ internal class WalletViewModel @Inject constructor(
.hasNonZeroWallets()
}
is TokenList.Ungrouped -> tokenList.currencies.hasNonZeroWallets()
TokenList.NotInitialized -> false
is TokenList.Empty -> false
}
if (hasNonZeroWallets) {
@ -984,7 +984,7 @@ internal class WalletViewModel @Inject constructor(
.flatMap(NetworkGroup::currencies)
}
is TokenList.Ungrouped -> tokenList.currencies
is TokenList.NotInitialized -> emptyList()
is TokenList.Empty -> emptyList()
}
} else {
listOfNotNull(singleWalletCryptoCurrencyStatus)
@ -1033,7 +1033,7 @@ internal class WalletViewModel @Inject constructor(
)
}
private fun WalletState.isLoadingState(): Boolean {
private fun WalletState.isLoadingOrEmptyState(): Boolean {
// Check the base components
if (this is WalletState.ContentState &&
walletsListConfig.wallets[walletsListConfig.selectedWalletIndex] is WalletCardState.Loading
@ -1044,12 +1044,13 @@ internal class WalletViewModel @Inject constructor(
// 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<WalletTokensListState.TokensListItemState.Token>()
.any { it.state is TokenItemState.Loading }
tokensListState is WalletTokensListState.Loading || hasLoadingTokens
isTokensEmpty || tokensListState is WalletTokensListState.Loading || hasLoadingTokens
}
is WalletSingleCurrencyState -> {
this is WalletSingleCurrencyState.Content && marketPriceBlockState is MarketPriceBlockState.Loading