diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/quote/DefaultQuotesStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/quote/DefaultQuotesStore.kt index 8cc69f2fda..09d14bde66 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/quote/DefaultQuotesStore.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/quote/DefaultQuotesStore.kt @@ -7,6 +7,7 @@ import com.tangem.datasource.local.quote.converter.QuoteConverter import com.tangem.domain.models.StatusSource import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.Quote +import com.tangem.utils.extensions.addOrReplace import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch @@ -110,7 +111,7 @@ internal class DefaultQuotesStore( private suspend fun storeInRuntimeStore(values: Set) { runtimeStore.update(default = emptySet()) { saved -> - (saved + values).distinctBy { it.rawCurrencyId }.toSet() + saved.addOrReplace(items = values) { prev, new -> prev.rawCurrencyId == new.rawCurrencyId } } } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchTokenListUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchTokenListUseCase.kt index 9b8dea0263..eafad782ed 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchTokenListUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchTokenListUseCase.kt @@ -52,14 +52,14 @@ class FetchTokenListUseCase( coroutineScope { val fetchStatuses = async { fetchNetworksStatuses( - userWalletId, - currencies.mapTo(hashSetOf()) { it.network }, + userWalletId = userWalletId, + networks = currencies.mapTo(hashSetOf()) { it.network }, refresh = mode.refreshNetworksStatuses, ) } val fetchQuotes = async { fetchQuotes( - currencies.mapTo(hashSetOf()) { it.id }, + currenciesIds = currencies.mapTo(hashSetOf()) { it.id }, refresh = mode.refreshQuotes, ) } 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 7756255af2..5a5fa3536e 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 @@ -10,6 +10,7 @@ import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.TokenList +import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.wallets.models.SeedPhraseNotificationsStatus import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.usecase.IsNeedToBackupUseCase @@ -68,17 +69,18 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private fun MutableList.addUsedOutdatedDataNotification( maybeTokenList: Lce, ) { - val tokenList = maybeTokenList.getOrNull(isPartialContentAccepted = false)?.flattenCurrencies().orEmpty() - - val hasOnlyCachedData = tokenList.any { - when (val value = it.value) { - is CryptoCurrencyStatus.Loaded -> value.source == StatusSource.ONLY_CACHE - is CryptoCurrencyStatus.NoAccount -> value.source == StatusSource.ONLY_CACHE - else -> false - } - } - - addIf(element = WalletNotification.UsedOutdatedData, condition = hasOnlyCachedData) + addIf( + element = WalletNotification.UsedOutdatedData, + condition = maybeTokenList.fold( + ifLoading = { + (it?.totalFiatBalance as? TotalFiatBalance.Loaded)?.source == StatusSource.ONLY_CACHE + }, + ifContent = { + (it.totalFiatBalance as? TotalFiatBalance.Loaded)?.source == StatusSource.ONLY_CACHE + }, + ifError = { false }, + ), + ) } private fun MutableList.addCriticalNotifications( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt index 9e7b87a25c..1c218be754 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt @@ -122,7 +122,7 @@ internal class WalletClickIntents @Inject constructor( SetRefreshStateTransformer(userWalletId = userWallet.walletId, isRefreshing = showRefreshState), ) - viewModelScope.launch(dispatchers.main) { + viewModelScope.launch { val maybeFetchResult = if (userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) { fetchCardTokenListUseCase(userWalletId = userWallet.walletId, refresh = true) } else {