Updated on 2026-08-14
This commit is contained in:
commit
0241322257
11 changed files with 112 additions and 56 deletions
|
|
@ -25,7 +25,7 @@ class FetchCardTokenListUseCase(
|
|||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId, refresh: Boolean = false): Either<TokenListError, Unit> {
|
||||
return either {
|
||||
val currencies = fetchCurrencies(userWalletId = userWalletId)
|
||||
val currencies = fetchCurrencies(userWalletId = userWalletId, refresh = refresh)
|
||||
|
||||
coroutineScope {
|
||||
val fetchStatuses = async {
|
||||
|
|
@ -53,9 +53,17 @@ class FetchCardTokenListUseCase(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun Raise<TokenListError>.fetchCurrencies(userWalletId: UserWalletId): List<CryptoCurrency> {
|
||||
private suspend fun Raise<TokenListError>.fetchCurrencies(
|
||||
userWalletId: UserWalletId,
|
||||
refresh: Boolean = false,
|
||||
): List<CryptoCurrency> {
|
||||
return catch(
|
||||
block = { currenciesRepository.getSingleCurrencyWalletWithCardCurrencies(userWalletId = userWalletId) },
|
||||
block = {
|
||||
currenciesRepository.getSingleCurrencyWalletWithCardCurrencies(
|
||||
userWalletId = userWalletId,
|
||||
refresh = refresh,
|
||||
)
|
||||
},
|
||||
catch = { raise(TokenListError.DataError(it)) },
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class FetchCurrencyStatusUseCase(
|
|||
refresh: Boolean = false,
|
||||
): Either<CurrencyStatusError, Unit> {
|
||||
return either {
|
||||
val currency = getPrimaryCurrency(userWalletId)
|
||||
val currency = getPrimaryCurrency(userWalletId, refresh)
|
||||
|
||||
fetchCurrencyStatus(userWalletId, currency, refresh)
|
||||
}
|
||||
|
|
@ -102,8 +102,11 @@ class FetchCurrencyStatusUseCase(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun Raise<CurrencyStatusError>.getPrimaryCurrency(userWalletId: UserWalletId): CryptoCurrency {
|
||||
return catch({ currenciesRepository.getSingleCurrencyWalletPrimaryCurrency(userWalletId) }) {
|
||||
private suspend fun Raise<CurrencyStatusError>.getPrimaryCurrency(
|
||||
userWalletId: UserWalletId,
|
||||
refresh: Boolean = false,
|
||||
): CryptoCurrency {
|
||||
return catch({ currenciesRepository.getSingleCurrencyWalletPrimaryCurrency(userWalletId, refresh) }) {
|
||||
raise(CurrencyStatusError.DataError(it))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,21 +86,29 @@ interface CurrenciesRepository {
|
|||
* Retrieves the primary cryptocurrency for a specific single-currency user wallet.
|
||||
*
|
||||
* @param userWalletId The unique identifier of the user wallet.
|
||||
* @param refresh Indicates whether to force a refresh of the status data.
|
||||
* @return The primary cryptocurrency associated with the user wallet.
|
||||
* @throws DataError.UserWalletError.WrongUserWallet If multi-currency user wallet
|
||||
* ID provided.
|
||||
*/
|
||||
suspend fun getSingleCurrencyWalletPrimaryCurrency(userWalletId: UserWalletId): CryptoCurrency
|
||||
suspend fun getSingleCurrencyWalletPrimaryCurrency(
|
||||
userWalletId: UserWalletId,
|
||||
refresh: Boolean = false,
|
||||
): CryptoCurrency
|
||||
|
||||
/**
|
||||
* Retrieves the cryptocurrencies for a specific single-currency user wallet with tokens on the card.
|
||||
*
|
||||
* @param userWalletId The unique identifier of the user wallet.
|
||||
* @param refresh Indicates whether to force a refresh of the status data.
|
||||
* @return The primary cryptocurrency associated with the user wallet.
|
||||
* @throws DataError.UserWalletError.WrongUserWallet If multi-currency user wallet
|
||||
* ID provided.
|
||||
*/
|
||||
suspend fun getSingleCurrencyWalletWithCardCurrencies(userWalletId: UserWalletId): List<CryptoCurrency>
|
||||
suspend fun getSingleCurrencyWalletWithCardCurrencies(
|
||||
userWalletId: UserWalletId,
|
||||
refresh: Boolean = false,
|
||||
): List<CryptoCurrency>
|
||||
|
||||
/**
|
||||
* Retrieves the cryptocurrency for a specific single-currency user old wallet
|
||||
|
|
|
|||
|
|
@ -70,11 +70,17 @@ internal class MockCurrenciesRepository(
|
|||
return tokens.first().getOrElse { e -> throw e }
|
||||
}
|
||||
|
||||
override suspend fun getSingleCurrencyWalletPrimaryCurrency(userWalletId: UserWalletId): CryptoCurrency {
|
||||
override suspend fun getSingleCurrencyWalletPrimaryCurrency(
|
||||
userWalletId: UserWalletId,
|
||||
refresh: Boolean,
|
||||
): CryptoCurrency {
|
||||
return token.getOrElse { e -> throw e }
|
||||
}
|
||||
|
||||
override suspend fun getSingleCurrencyWalletWithCardCurrencies(userWalletId: UserWalletId): List<CryptoCurrency> {
|
||||
override suspend fun getSingleCurrencyWalletWithCardCurrencies(
|
||||
userWalletId: UserWalletId,
|
||||
refresh: Boolean,
|
||||
): List<CryptoCurrency> {
|
||||
return tokens.first().getOrElse { e -> throw e }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue