Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-28 15:46:27 +03:00
parent 297a006e3d
commit 7b7cece46f
35 changed files with 436 additions and 422 deletions

View file

@ -7,8 +7,10 @@ import kotlinx.coroutines.yield
import timber.log.Timber
import kotlin.coroutines.cancellation.CancellationException
@Suppress("UnconditionalJumpStatementInLoop")
suspend fun <T> retryOnError(priority: Boolean = false, call: suspend () -> T): T {
@Suppress("UnconditionalJumpStatementInLoop", "MagicNumber")
suspend fun <T> retryOnError(priority: Boolean = false, startRetryDelay: Int = 500, call: suspend () -> T): T {
var currentDelay = startRetryDelay
var priorityCounter = 5
while (true) {
return try {
call()
@ -19,9 +21,12 @@ suspend fun <T> retryOnError(priority: Boolean = false, call: suspend () -> T):
Timber.e(e, "Error occurred during retryOnError block")
if (priority.not()) {
if (priority && priorityCounter > 0) {
--priorityCounter
} else {
yield()
delay(timeMillis = 500)
delay(timeMillis = currentDelay.toLong())
currentDelay *= 2
}
continue

View file

@ -57,6 +57,7 @@ internal object TokenMarketInfoConverter : Converter<TokenMarketInfoResponse, To
liquidityChange = liquidityChange?.convert(),
buyPressureChange = buyPressureChange?.convert(),
experiencedBuyerChange = experiencedBuyerChange?.convert(),
sourceNetworks = sourceNetworks.orEmpty().map { TokenMarketInfo.Insights.SourceNetwork(it.id, it.name) },
)
}

View file

@ -37,14 +37,14 @@ internal class DefaultQuotesRepository(
private val mutex = Mutex()
@OptIn(ExperimentalCoroutinesApi::class)
override fun getQuotesUpdates(currenciesIds: Set<CryptoCurrency.ID>): Flow<Set<Quote>> {
override fun getQuotesUpdates(currenciesIds: Set<CryptoCurrency.ID>, refresh: Boolean): Flow<Set<Quote>> {
return appPreferencesStore.getObject<CurrenciesResponse.Currency>(
key = PreferencesKeys.SELECTED_APP_CURRENCY_KEY,
)
.distinctUntilChanged()
.filterNotNull()
.flatMapLatest { appCurrency ->
fetchExpiredQuotes(currenciesIds, appCurrency.id, refresh = false)
fetchExpiredQuotes(currenciesIds, appCurrency.id, refresh = refresh)
quotesStore.get(currenciesIds).map(quotesConverter::convertSet)
}
.cancellable()