Updated on 2026-08-14

This commit is contained in:
Tangem 2025-04-28 09:56:19 +03:00
parent d65b4039da
commit f49f013aa2
2 changed files with 15 additions and 7 deletions

View file

@ -64,13 +64,23 @@ internal class DefaultQuotesStoreV2(
}
override suspend fun storeError(currenciesIds: Set<CryptoCurrency.RawID>) {
updateStatusSourceInRuntime(currenciesIds = currenciesIds, source = StatusSource.ONLY_CACHE)
updateStatusSourceInRuntime(
currenciesIds = currenciesIds,
ifNotFound = Quote::Empty,
source = StatusSource.ONLY_CACHE,
)
}
private suspend fun updateStatusSourceInRuntime(currenciesIds: Set<CryptoCurrency.RawID>, source: StatusSource) {
private suspend fun updateStatusSourceInRuntime(
currenciesIds: Set<CryptoCurrency.RawID>,
ifNotFound: (CryptoCurrency.RawID) -> Quote? = { null },
source: StatusSource,
) {
runtimeStore.update(default = emptySet()) { stored ->
val updatedQuotes = currenciesIds.mapTo(hashSetOf()) { id ->
val quote = stored.firstOrNull { it.rawCurrencyId == id } ?: Quote.Empty(id)
val updatedQuotes = currenciesIds.mapNotNullTo(hashSetOf()) { id ->
val quote = stored.firstOrNull { it.rawCurrencyId == id }
?: ifNotFound(id)
?: return@mapNotNullTo null
quote.copySealed(source = source)
}

View file

@ -37,9 +37,7 @@ internal class QuotesStoreUpdateMethodsTest {
store.refresh(currenciesIds = currenciesIds)
val runtimeExpected = currenciesIds.map(Quote::Empty).toSet()
Truth.assertThat(runtimeStore.getSyncOrNull()).isEqualTo(runtimeExpected)
Truth.assertThat(runtimeStore.getSyncOrNull()).isEqualTo(emptySet<Quote>())
Truth.assertThat(persistenceStore.data.firstOrNull()).isEqualTo(emptyMap<String, Set<Quote>>())
}