Updated on 2026-08-14
This commit is contained in:
parent
d65b4039da
commit
f49f013aa2
2 changed files with 15 additions and 7 deletions
|
|
@ -64,13 +64,23 @@ internal class DefaultQuotesStoreV2(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun storeError(currenciesIds: Set<CryptoCurrency.RawID>) {
|
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 ->
|
runtimeStore.update(default = emptySet()) { stored ->
|
||||||
val updatedQuotes = currenciesIds.mapTo(hashSetOf()) { id ->
|
val updatedQuotes = currenciesIds.mapNotNullTo(hashSetOf()) { id ->
|
||||||
val quote = stored.firstOrNull { it.rawCurrencyId == id } ?: Quote.Empty(id)
|
val quote = stored.firstOrNull { it.rawCurrencyId == id }
|
||||||
|
?: ifNotFound(id)
|
||||||
|
?: return@mapNotNullTo null
|
||||||
|
|
||||||
quote.copySealed(source = source)
|
quote.copySealed(source = source)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,7 @@ internal class QuotesStoreUpdateMethodsTest {
|
||||||
|
|
||||||
store.refresh(currenciesIds = currenciesIds)
|
store.refresh(currenciesIds = currenciesIds)
|
||||||
|
|
||||||
val runtimeExpected = currenciesIds.map(Quote::Empty).toSet()
|
Truth.assertThat(runtimeStore.getSyncOrNull()).isEqualTo(emptySet<Quote>())
|
||||||
|
|
||||||
Truth.assertThat(runtimeStore.getSyncOrNull()).isEqualTo(runtimeExpected)
|
|
||||||
Truth.assertThat(persistenceStore.data.firstOrNull()).isEqualTo(emptyMap<String, Set<Quote>>())
|
Truth.assertThat(persistenceStore.data.firstOrNull()).isEqualTo(emptyMap<String, Set<Quote>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue