Updated on 2026-08-14

This commit is contained in:
Tangem 2023-08-16 16:53:42 +03:00
parent 72a1365157
commit f4ab3116fe
6 changed files with 27 additions and 39 deletions

View file

@ -10,9 +10,9 @@ import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.appcurrency.repository.AppCurrencyRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEmpty
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.joda.time.Duration
import timber.log.Timber
@ -27,11 +27,18 @@ internal class DefaultAppCurrencyRepository(
private val appCurrencyConverter = AppCurrencyConverter()
override fun getSelectedAppCurrency(): Flow<AppCurrency> {
return selectedAppCurrencyStore.get()
.onEmpty { fetchDefaultAppCurrency() }
.map(appCurrencyConverter::convert)
.flowOn(dispatchers.io)
override fun getSelectedAppCurrency(): Flow<AppCurrency> = channelFlow {
launch(dispatchers.io) {
selectedAppCurrencyStore.get()
.map(appCurrencyConverter::convert)
.collect(::send)
}
launch(dispatchers.io) {
if (selectedAppCurrencyStore.isEmpty()) {
fetchDefaultAppCurrency()
}
}
}
override suspend fun getAvailableAppCurrencies(): List<AppCurrency> {

View file

@ -8,8 +8,8 @@ import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
import com.tangem.datasource.local.token.UserTokensStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.core.error.DataError
import com.tangem.domain.common.util.derivationStyleProvider
import com.tangem.domain.core.error.DataError
import com.tangem.domain.demo.DemoConfig
import com.tangem.domain.tokens.models.CryptoCurrency
import com.tangem.domain.tokens.repository.CurrenciesRepository
@ -164,7 +164,7 @@ internal class DefaultCurrenciesRepository(
tangemTechApi.saveUserTokens(userWallet.walletId.stringValue, response)
} else {
throw error
Timber.e(error, "Unable to fetch currencies for: ${userWallet.walletId}")
}
}