Updated on 2026-08-14

This commit is contained in:
Tangem 2023-08-11 08:26:23 +03:00
parent b284a8195a
commit 9b70e5bc82
14 changed files with 116 additions and 77 deletions

View file

@ -3,6 +3,7 @@ package com.tangem.datasource.local.quote
import com.tangem.datasource.api.tangemTech.models.QuotesResponse
import com.tangem.datasource.local.datastore.core.StringKeyDataStore
import com.tangem.datasource.local.quote.model.StoredQuote
import com.tangem.domain.tokens.models.CryptoCurrency
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
@ -10,9 +11,9 @@ internal class DefaultQuotesStore(
private val dataStore: StringKeyDataStore<StoredQuote>,
) : QuotesStore {
override fun get(rawCurrenciesIds: Set<String>): Flow<Set<StoredQuote>> {
val flows = rawCurrenciesIds.map { rawCurrencyId ->
dataStore.get(rawCurrencyId)
override fun get(currenciesIds: Set<CryptoCurrency.ID>): Flow<Set<StoredQuote>> {
val flows = currenciesIds.mapNotNull { currencyId ->
dataStore.get(currencyId.rawCurrencyId ?: return@mapNotNull null)
}
return combine(flows) { quotes -> quotes.toSet() }

View file

@ -2,11 +2,12 @@ package com.tangem.datasource.local.quote
import com.tangem.datasource.api.tangemTech.models.QuotesResponse
import com.tangem.datasource.local.quote.model.StoredQuote
import com.tangem.domain.tokens.models.CryptoCurrency
import kotlinx.coroutines.flow.Flow
interface QuotesStore {
fun get(rawCurrenciesIds: Set<String>): Flow<Set<StoredQuote>>
fun get(currenciesIds: Set<CryptoCurrency.ID>): Flow<Set<StoredQuote>>
suspend fun store(response: QuotesResponse)
}