Updated on 2026-08-14
This commit is contained in:
parent
e8d294efe1
commit
91b8f48839
2 changed files with 15 additions and 14 deletions
|
|
@ -7,6 +7,7 @@ import arrow.core.raise.catch
|
|||
import arrow.core.raise.ensure
|
||||
import arrow.core.raise.ensureNotNull
|
||||
import com.tangem.data.common.api.safeApiCallWithTimeout
|
||||
import com.tangem.data.common.quote.DefaultQuotesFetcher.Companion.tenSecInMillis
|
||||
import com.tangem.data.common.quote.QuotesFetcher.Error
|
||||
import com.tangem.data.common.quote.QuotesFetcher.Field
|
||||
import com.tangem.data.common.quote.utils.combine
|
||||
|
|
@ -18,6 +19,7 @@ import kotlinx.coroutines.sync.Mutex
|
|||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.joda.time.DateTime
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
|
|
@ -181,11 +183,24 @@ internal class DefaultQuotesFetcher(
|
|||
fields = fields.combine(),
|
||||
)
|
||||
.bind()
|
||||
.addSkippedIfHas(currenciesIds)
|
||||
},
|
||||
onError = { raise(Error.ApiOperationError(it)) },
|
||||
)
|
||||
}
|
||||
|
||||
private fun QuotesResponse.addSkippedIfHas(ids: Set<String>): QuotesResponse {
|
||||
val skippedIds = ids.filterNot(quotes.keys::contains).ifEmpty {
|
||||
return this
|
||||
}
|
||||
|
||||
Timber.d("Some quotes are missing from the server response: $skippedIds")
|
||||
|
||||
val emptyQuotes = skippedIds.associateWith { QuotesResponse.Quote.EMPTY }
|
||||
|
||||
return copy(quotes = quotes + emptyQuotes)
|
||||
}
|
||||
|
||||
private fun saveQuotes(fiatCurrencyId: String, response: QuotesResponse) {
|
||||
val newQuotes = response.quotes.mapTo(destination = hashSetOf()) { (currencyId, quote) ->
|
||||
QuoteMetadata(
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import com.tangem.data.quotes.store.QuotesStatusesStore
|
|||
import com.tangem.data.quotes.store.setSourceAsCache
|
||||
import com.tangem.data.quotes.store.setSourceAsOnlyCache
|
||||
import com.tangem.data.quotes.utils.QuotesUnsupportedCurrenciesIdAdapter
|
||||
import com.tangem.datasource.api.tangemTech.models.QuotesResponse
|
||||
import com.tangem.datasource.appcurrency.AppCurrencyResponseStore
|
||||
import com.tangem.domain.core.utils.catchOn
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
|
|
@ -59,7 +58,6 @@ internal class DefaultMultiQuoteStatusFetcher @Inject constructor(
|
|||
fields = setOf(Field.PRICE, Field.PRICE_CHANGE_24H),
|
||||
)
|
||||
.getOrElse { error("Cause: $it") }
|
||||
.addSkippedIfHas(ids = replacementIdsResult.idsForRequest)
|
||||
|
||||
val updatedResponse = QuotesUnsupportedCurrenciesIdAdapter.getResponseWithUnsupportedCurrencies(
|
||||
response = response,
|
||||
|
|
@ -86,16 +84,4 @@ internal class DefaultMultiQuoteStatusFetcher @Inject constructor(
|
|||
|
||||
return appCurrencyId
|
||||
}
|
||||
|
||||
private fun QuotesResponse.addSkippedIfHas(ids: Set<String>): QuotesResponse {
|
||||
val skippedIds = ids.filterNot(quotes.keys::contains).ifEmpty {
|
||||
return this
|
||||
}
|
||||
|
||||
Timber.d("Some quotes are missing from the server response: $skippedIds")
|
||||
|
||||
val emptyQuotes = skippedIds.associateWith { QuotesResponse.Quote.EMPTY }
|
||||
|
||||
return copy(quotes = quotes + emptyQuotes)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue