Updated on 2026-08-14
This commit is contained in:
parent
ba65a2f344
commit
93ff2d98c9
15 changed files with 167 additions and 35 deletions
|
|
@ -7,6 +7,8 @@ import com.tangem.domain.managetokens.model.ManagedCryptoCurrency
|
|||
import com.tangem.domain.managetokens.repository.CustomTokensRepository
|
||||
import com.tangem.domain.networks.multi.MultiNetworkStatusFetcher
|
||||
import com.tangem.domain.quotes.multi.MultiQuoteFetcher
|
||||
import com.tangem.domain.staking.fetcher.YieldBalanceFetcherParams
|
||||
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.tokens.TokensFeatureToggles
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
|
|
@ -28,6 +30,7 @@ class SaveManagedTokensUseCase(
|
|||
private val quotesRepository: QuotesRepository,
|
||||
private val multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
|
||||
private val multiQuoteFetcher: MultiQuoteFetcher,
|
||||
private val multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -118,11 +121,20 @@ class SaveManagedTokensUseCase(
|
|||
userWalletId: UserWalletId,
|
||||
existingCurrencies: List<CryptoCurrency>,
|
||||
) {
|
||||
stakingRepository.fetchMultiYieldBalance(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencies = existingCurrencies,
|
||||
refresh = true,
|
||||
)
|
||||
if (tokensFeatureToggles.isStakingLoadingRefactoringEnabled) {
|
||||
multiYieldBalanceFetcher(
|
||||
params = YieldBalanceFetcherParams.Multi(
|
||||
userWalletId = userWalletId,
|
||||
currencyIdWithNetworkMap = existingCurrencies.associateTo(hashMapOf()) { it.id to it.network },
|
||||
),
|
||||
)
|
||||
} else {
|
||||
stakingRepository.fetchMultiYieldBalance(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencies = existingCurrencies,
|
||||
refresh = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun refreshUpdatedQuotes(addedCurrencies: List<CryptoCurrency>) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import com.tangem.domain.card.repository.DerivationsRepository
|
|||
import com.tangem.domain.markets.repositories.MarketsTokenRepository
|
||||
import com.tangem.domain.networks.multi.MultiNetworkStatusFetcher
|
||||
import com.tangem.domain.quotes.multi.MultiQuoteFetcher
|
||||
import com.tangem.domain.staking.fetcher.YieldBalanceFetcherParams
|
||||
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.tokens.TokensFeatureToggles
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
|
|
@ -33,6 +35,7 @@ class SaveMarketTokensUseCase(
|
|||
private val quotesRepository: QuotesRepository,
|
||||
private val multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
|
||||
private val multiQuoteFetcher: MultiQuoteFetcher,
|
||||
private val multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -100,11 +103,20 @@ class SaveMarketTokensUseCase(
|
|||
userWalletId: UserWalletId,
|
||||
existingCurrencies: List<CryptoCurrency>,
|
||||
) {
|
||||
stakingRepository.fetchMultiYieldBalance(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencies = existingCurrencies,
|
||||
refresh = true,
|
||||
)
|
||||
if (tokensFeatureToggles.isStakingLoadingRefactoringEnabled) {
|
||||
multiYieldBalanceFetcher(
|
||||
params = YieldBalanceFetcherParams.Multi(
|
||||
userWalletId = userWalletId,
|
||||
currencyIdWithNetworkMap = existingCurrencies.associateTo(hashMapOf()) { it.id to it.network },
|
||||
),
|
||||
)
|
||||
} else {
|
||||
stakingRepository.fetchMultiYieldBalance(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencies = existingCurrencies,
|
||||
refresh = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun refreshUpdatedQuotes(addedCurrencies: List<CryptoCurrency>) {
|
||||
|
|
|
|||
|
|
@ -3,30 +3,44 @@ package com.tangem.domain.staking
|
|||
import arrow.core.Either
|
||||
import arrow.core.raise.catch
|
||||
import arrow.core.raise.either
|
||||
import com.tangem.domain.staking.fetcher.YieldBalanceFetcherParams
|
||||
import com.tangem.domain.staking.model.stakekit.StakingError
|
||||
import com.tangem.domain.staking.repositories.StakingErrorResolver
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.staking.single.SingleYieldBalanceFetcher
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
||||
class FetchStakingYieldBalanceUseCase(
|
||||
private val stakingRepository: StakingRepository,
|
||||
private val stakingErrorResolver: StakingErrorResolver,
|
||||
private val singleYieldBalanceFetcher: SingleYieldBalanceFetcher,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
isRefactoringEnabled: Boolean,
|
||||
refresh: Boolean = false,
|
||||
): Either<StakingError, Unit> {
|
||||
return either {
|
||||
catch(
|
||||
block = {
|
||||
stakingRepository.fetchSingleYieldBalance(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
refresh = refresh,
|
||||
)
|
||||
if (isRefactoringEnabled) {
|
||||
singleYieldBalanceFetcher(
|
||||
params = YieldBalanceFetcherParams.Single(
|
||||
userWalletId = userWalletId,
|
||||
currencyId = cryptoCurrency.id,
|
||||
network = cryptoCurrency.network,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
stakingRepository.fetchSingleYieldBalance(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
refresh = refresh,
|
||||
)
|
||||
}
|
||||
},
|
||||
catch = { stakingErrorResolver.resolve(it) },
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ import arrow.core.raise.catch
|
|||
import arrow.core.raise.either
|
||||
import com.tangem.domain.networks.multi.MultiNetworkStatusFetcher
|
||||
import com.tangem.domain.quotes.multi.MultiQuoteFetcher
|
||||
import com.tangem.domain.staking.fetcher.YieldBalanceFetcherParams
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.staking.single.SingleYieldBalanceFetcher
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
|
|
@ -32,6 +34,7 @@ class AddCryptoCurrenciesUseCase(
|
|||
private val quotesRepository: QuotesRepository,
|
||||
private val multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
|
||||
private val multiQuoteFetcher: MultiQuoteFetcher,
|
||||
private val singleYieldBalanceFetcher: SingleYieldBalanceFetcher,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -159,11 +162,21 @@ class AddCryptoCurrenciesUseCase(
|
|||
}
|
||||
|
||||
private suspend fun refreshUpdatedYieldBalances(userWalletId: UserWalletId, addedCurrency: CryptoCurrency) {
|
||||
stakingRepository.fetchSingleYieldBalance(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = addedCurrency,
|
||||
refresh = true,
|
||||
)
|
||||
if (tokensFeatureToggles.isStakingLoadingRefactoringEnabled) {
|
||||
singleYieldBalanceFetcher(
|
||||
params = YieldBalanceFetcherParams.Single(
|
||||
userWalletId = userWalletId,
|
||||
currencyId = addedCurrency.id,
|
||||
network = addedCurrency.network,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
stakingRepository.fetchSingleYieldBalance(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = addedCurrency,
|
||||
refresh = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun refreshUpdatedQuotes(currencyToAdd: CryptoCurrency) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import arrow.core.raise.catch
|
|||
import arrow.core.raise.either
|
||||
import com.tangem.domain.networks.multi.MultiNetworkStatusFetcher
|
||||
import com.tangem.domain.quotes.multi.MultiQuoteFetcher
|
||||
import com.tangem.domain.staking.fetcher.YieldBalanceFetcherParams
|
||||
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
|
|
@ -26,6 +28,7 @@ class FetchCardTokenListUseCase(
|
|||
private val stakingRepository: StakingRepository,
|
||||
private val multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
|
||||
private val multiQuoteFetcher: MultiQuoteFetcher,
|
||||
private val multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -110,9 +113,18 @@ class FetchCardTokenListUseCase(
|
|||
currencies: List<CryptoCurrency>,
|
||||
refresh: Boolean,
|
||||
) {
|
||||
catch(
|
||||
block = { stakingRepository.fetchMultiYieldBalance(userWalletId, currencies, refresh) },
|
||||
catch = { /* Ignore error */ },
|
||||
)
|
||||
if (tokensFeatureToggles.isStakingLoadingRefactoringEnabled) {
|
||||
multiYieldBalanceFetcher(
|
||||
params = YieldBalanceFetcherParams.Multi(
|
||||
userWalletId = userWalletId,
|
||||
currencyIdWithNetworkMap = currencies.associateTo(hashMapOf()) { it.id to it.network },
|
||||
),
|
||||
)
|
||||
} else {
|
||||
catch(
|
||||
block = { stakingRepository.fetchMultiYieldBalance(userWalletId, currencies, refresh) },
|
||||
catch = { /* Ignore error */ },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,9 @@ import arrow.core.raise.catch
|
|||
import arrow.core.raise.either
|
||||
import com.tangem.domain.networks.single.SingleNetworkStatusFetcher
|
||||
import com.tangem.domain.quotes.multi.MultiQuoteFetcher
|
||||
import com.tangem.domain.staking.fetcher.YieldBalanceFetcherParams
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.staking.single.SingleYieldBalanceFetcher
|
||||
import com.tangem.domain.tokens.error.CurrencyStatusError
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
|
|
@ -36,6 +38,7 @@ class FetchCurrencyStatusUseCase(
|
|||
private val stakingRepository: StakingRepository,
|
||||
private val singleNetworkStatusFetcher: SingleNetworkStatusFetcher,
|
||||
private val multiQuoteFetcher: MultiQuoteFetcher,
|
||||
private val singleYieldBalanceFetcher: SingleYieldBalanceFetcher,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -158,10 +161,20 @@ class FetchCurrencyStatusUseCase(
|
|||
cryptoCurrency: CryptoCurrency,
|
||||
refresh: Boolean,
|
||||
) {
|
||||
catch(
|
||||
block = { stakingRepository.fetchSingleYieldBalance(userWalletId, cryptoCurrency, refresh) },
|
||||
) {
|
||||
raise(CurrencyStatusError.DataError(it))
|
||||
if (tokensFeatureToggles.isStakingLoadingRefactoringEnabled) {
|
||||
singleYieldBalanceFetcher(
|
||||
params = YieldBalanceFetcherParams.Single(
|
||||
userWalletId = userWalletId,
|
||||
currencyId = cryptoCurrency.id,
|
||||
network = cryptoCurrency.network,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
catch(
|
||||
block = { stakingRepository.fetchSingleYieldBalance(userWalletId, cryptoCurrency, refresh) },
|
||||
) {
|
||||
raise(CurrencyStatusError.DataError(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ import arrow.core.raise.ensureNotNull
|
|||
import arrow.core.toNonEmptyListOrNull
|
||||
import com.tangem.domain.networks.multi.MultiNetworkStatusFetcher
|
||||
import com.tangem.domain.quotes.multi.MultiQuoteFetcher
|
||||
import com.tangem.domain.staking.fetcher.YieldBalanceFetcherParams
|
||||
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
|
|
@ -38,6 +40,7 @@ class FetchTokenListUseCase(
|
|||
private val stakingRepository: StakingRepository,
|
||||
private val multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
|
||||
private val multiQuoteFetcher: MultiQuoteFetcher,
|
||||
private val multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -152,10 +155,19 @@ class FetchTokenListUseCase(
|
|||
currencies: List<CryptoCurrency>,
|
||||
refresh: Boolean,
|
||||
) {
|
||||
catch(
|
||||
block = { stakingRepository.fetchMultiYieldBalance(userWalletId, currencies, refresh) },
|
||||
catch = { /* Ignore error */ },
|
||||
)
|
||||
if (tokensFeatureToggles.isStakingLoadingRefactoringEnabled) {
|
||||
multiYieldBalanceFetcher(
|
||||
params = YieldBalanceFetcherParams.Multi(
|
||||
userWalletId = userWalletId,
|
||||
currencyIdWithNetworkMap = currencies.associateTo(hashMapOf()) { it.id to it.network },
|
||||
),
|
||||
)
|
||||
} else {
|
||||
catch(
|
||||
block = { stakingRepository.fetchMultiYieldBalance(userWalletId, currencies, refresh) },
|
||||
catch = { /* Ignore error */ },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@ import com.tangem.domain.quotes.QuotesRepositoryV2
|
|||
import com.tangem.domain.quotes.multi.MultiQuoteFetcher
|
||||
import com.tangem.domain.quotes.single.SingleQuoteProducer
|
||||
import com.tangem.domain.quotes.single.SingleQuoteSupplier
|
||||
import com.tangem.domain.staking.fetcher.YieldBalanceFetcherParams
|
||||
import com.tangem.domain.staking.model.stakekit.YieldBalance
|
||||
import com.tangem.domain.staking.model.stakekit.YieldBalanceList
|
||||
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.staking.single.SingleYieldBalanceProducer
|
||||
import com.tangem.domain.staking.single.SingleYieldBalanceSupplier
|
||||
|
|
@ -49,6 +51,7 @@ class CachedCurrenciesStatusesOperations(
|
|||
private val multiQuoteFetcher: MultiQuoteFetcher,
|
||||
private val singleQuoteSupplier: SingleQuoteSupplier,
|
||||
private val singleYieldBalanceSupplier: SingleYieldBalanceSupplier,
|
||||
private val multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) : BaseCurrenciesStatusesOperations,
|
||||
BaseCurrencyStatusOperations(
|
||||
|
|
@ -200,7 +203,18 @@ class CachedCurrenciesStatusesOperations(
|
|||
quotesRepository.fetchQuotes(rawCurrenciesIds)
|
||||
}
|
||||
},
|
||||
async { stakingRepository.fetchMultiYieldBalance(userWalletId, currencies) },
|
||||
async {
|
||||
if (tokensFeatureToggles.isStakingLoadingRefactoringEnabled) {
|
||||
multiYieldBalanceFetcher(
|
||||
params = YieldBalanceFetcherParams.Multi(
|
||||
userWalletId = userWalletId,
|
||||
currencyIdWithNetworkMap = currencies.associateTo(hashMapOf()) { it.id to it.network },
|
||||
),
|
||||
)
|
||||
} else {
|
||||
stakingRepository.fetchMultiYieldBalance(userWalletId, currencies)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
.map { }
|
||||
|
|
|
|||
|
|
@ -190,6 +190,7 @@ internal class GetPrimaryCurrencyStatusUpdatesUseCaseTest {
|
|||
singleQuoteSupplier = mockk(),
|
||||
quotesRepositoryV2 = mockk(),
|
||||
singleYieldBalanceSupplier = mockk(),
|
||||
multiYieldBalanceFetcher = mockk(),
|
||||
),
|
||||
dispatchers = dispatchers,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue