Updated on 2026-08-14
This commit is contained in:
parent
bb5e12fcfe
commit
5b49d1fbf6
4 changed files with 36 additions and 4 deletions
|
|
@ -290,6 +290,21 @@ internal class DefaultCurrenciesRepository(
|
|||
responseCurrenciesFactory.createCurrencies(storedTokens, userWallet.scanResponse)
|
||||
}
|
||||
|
||||
override suspend fun getMultiCurrencyWalletCachedCurrenciesSync(userWalletId: UserWalletId) =
|
||||
withContext(dispatchers.io) {
|
||||
val userWallet = getUserWallet(userWalletId)
|
||||
ensureIsCorrectUserWallet(userWallet, isMultiCurrencyWalletExpected = true)
|
||||
|
||||
val storedTokens = requireNotNull(
|
||||
value = getSavedUserTokensResponseSync(key = userWallet.walletId),
|
||||
lazyMessage = {
|
||||
"Unable to find tokens response for user wallet with provided ID: $userWalletId"
|
||||
},
|
||||
)
|
||||
|
||||
responseCurrenciesFactory.createCurrencies(storedTokens, userWallet.scanResponse)
|
||||
}
|
||||
|
||||
override suspend fun getMultiCurrencyWalletCurrency(
|
||||
userWalletId: UserWalletId,
|
||||
id: CryptoCurrency.ID,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class RefreshMultiCurrencyWalletQuotesUseCase(
|
|||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId): Either<QuotesError, Unit> {
|
||||
return either {
|
||||
val currencies = fetchCurrencies(userWalletId = userWalletId)
|
||||
val currencies = getCurrencies(userWalletId = userWalletId)
|
||||
.getOrElse { raise(QuotesError.DataError(it)) }
|
||||
|
||||
coroutineScope {
|
||||
|
|
@ -35,10 +35,10 @@ class RefreshMultiCurrencyWalletQuotesUseCase(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun fetchCurrencies(userWalletId: UserWalletId): Either<Throwable, List<CryptoCurrency>> {
|
||||
private suspend fun getCurrencies(userWalletId: UserWalletId): Either<Throwable, List<CryptoCurrency>> {
|
||||
return either {
|
||||
catch(
|
||||
block = { currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId, false) },
|
||||
block = { currenciesRepository.getMultiCurrencyWalletCachedCurrenciesSync(userWalletId) },
|
||||
catch = { raise(it) },
|
||||
)
|
||||
}
|
||||
|
|
@ -46,7 +46,9 @@ class RefreshMultiCurrencyWalletQuotesUseCase(
|
|||
|
||||
private suspend fun fetchQuotes(currenciesIds: Set<CryptoCurrency.ID>) {
|
||||
catch(
|
||||
block = { quotesRepository.fetchQuotes(currenciesIds) },
|
||||
block = {
|
||||
quotesRepository.fetchQuotes(currenciesIds)
|
||||
},
|
||||
catch = { /* Ignore error */ },
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,6 +148,17 @@ interface CurrenciesRepository {
|
|||
refresh: Boolean = false,
|
||||
): List<CryptoCurrency>
|
||||
|
||||
/**
|
||||
* Retrieves the list of cryptocurrencies within a multi-currency wallet.
|
||||
* Returns previously loaded currencies or empty list
|
||||
*
|
||||
* @param userWalletId The unique identifier of the user wallet.
|
||||
* @return A list of [CryptoCurrency].
|
||||
* @throws DataError.UserWalletError.WrongUserWallet If single-currency user wallet
|
||||
* ID provided.
|
||||
*/
|
||||
suspend fun getMultiCurrencyWalletCachedCurrenciesSync(userWalletId: UserWalletId): List<CryptoCurrency>
|
||||
|
||||
/**
|
||||
* Retrieves the cryptocurrency for a specific multi-currency user wallet.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@ internal class MockCurrenciesRepository(
|
|||
return tokens.first().getOrElse { e -> throw e }
|
||||
}
|
||||
|
||||
override suspend fun getMultiCurrencyWalletCachedCurrenciesSync(userWalletId: UserWalletId): List<CryptoCurrency> {
|
||||
return tokens.first().getOrElse { e -> throw e }
|
||||
}
|
||||
|
||||
override suspend fun getSingleCurrencyWalletPrimaryCurrency(userWalletId: UserWalletId): CryptoCurrency {
|
||||
return token.getOrElse { e -> throw e }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue