Updated on 2026-08-14
This commit is contained in:
parent
9a574200b5
commit
b9d30a4d55
3 changed files with 29 additions and 3 deletions
|
|
@ -39,8 +39,9 @@ internal object TokensDomainModule {
|
|||
currenciesRepository: CurrenciesRepository,
|
||||
quotesRepository: QuotesRepository,
|
||||
networksRepository: NetworksRepository,
|
||||
stakingRepository: StakingRepository,
|
||||
): FetchTokenListUseCase {
|
||||
return FetchTokenListUseCase(currenciesRepository, networksRepository, quotesRepository)
|
||||
return FetchTokenListUseCase(currenciesRepository, networksRepository, quotesRepository, stakingRepository)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import arrow.core.raise.catch
|
|||
import arrow.core.raise.either
|
||||
import arrow.core.raise.ensureNotNull
|
||||
import arrow.core.toNonEmptyListOrNull
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
|
|
@ -24,12 +25,14 @@ import kotlinx.coroutines.coroutineScope
|
|||
* @param currenciesRepository The repository for retrieving currency-related data.
|
||||
* @param networksRepository The repository for retrieving network-related data.
|
||||
* @param quotesRepository The repository for retrieving cryptocurrency quotes.
|
||||
* @param stakingRepository The repository for retrieving staking-related data.
|
||||
*/
|
||||
// TODO: Add tests
|
||||
class FetchTokenListUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val networksRepository: NetworksRepository,
|
||||
private val quotesRepository: QuotesRepository,
|
||||
private val stakingRepository: StakingRepository,
|
||||
) {
|
||||
|
||||
/**
|
||||
|
|
@ -59,7 +62,15 @@ class FetchTokenListUseCase(
|
|||
)
|
||||
}
|
||||
|
||||
awaitAll(fetchStatuses, fetchQuotes)
|
||||
val yieldBalances = async {
|
||||
fetchYieldBalances(
|
||||
userWalletId = userWalletId,
|
||||
currencies = currencies,
|
||||
refresh = refresh,
|
||||
)
|
||||
}
|
||||
|
||||
awaitAll(fetchStatuses, fetchQuotes, yieldBalances)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -98,4 +109,15 @@ class FetchTokenListUseCase(
|
|||
/* Ignore error */
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun fetchYieldBalances(
|
||||
userWalletId: UserWalletId,
|
||||
currencies: List<CryptoCurrency>,
|
||||
refresh: Boolean,
|
||||
) {
|
||||
catch(
|
||||
block = { stakingRepository.fetchMultiYieldBalance(userWalletId, currencies, refresh) },
|
||||
catch = { /* Ignore error */ },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -126,7 +126,10 @@ internal class WalletWarningsClickIntentsImplementor @Inject constructor(
|
|||
userWalletId = userWallet.walletId,
|
||||
currencies = missedAddressCurrencies,
|
||||
)
|
||||
.onRight { fetchTokenListUseCase(userWalletId = userWallet.walletId) }
|
||||
.onRight {
|
||||
// Refresh must be set to true to ensure that yield balances are updated
|
||||
fetchTokenListUseCase(userWalletId = userWallet.walletId, refresh = true)
|
||||
}
|
||||
.onLeft { Timber.e("Failed to derive public keys: $it") }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue