Updated on 2026-08-14
This commit is contained in:
parent
3d3a7771a5
commit
4edbc8d918
28 changed files with 400 additions and 81 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.domain.core.flow
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
|
||||
/**
|
||||
* [Flow] supplier
|
||||
|
|
@ -14,4 +15,9 @@ interface FlowSupplier<Params : Any, Data : Any> {
|
|||
|
||||
/** Supply [Flow] by [params] */
|
||||
operator fun invoke(params: Params): Flow<Data>
|
||||
|
||||
/** Get first [Data] by [params] or null if [Flow] is empty */
|
||||
suspend fun getSyncOrNull(params: Params): Data? {
|
||||
return invoke(params).firstOrNull()
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,8 @@ import com.tangem.domain.networks.multi.MultiNetworkStatusFetcher
|
|||
import com.tangem.domain.quotes.multi.MultiQuoteStatusFetcher
|
||||
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesProducer
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
||||
import com.tangem.domain.tokens.TokensFeatureToggles
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
|
|
@ -26,6 +28,7 @@ class SaveManagedTokensUseCase(
|
|||
private val multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
|
||||
private val multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
|
||||
private val multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -42,7 +45,14 @@ class SaveManagedTokensUseCase(
|
|||
networks = currenciesToAdd.values.flatten(),
|
||||
)
|
||||
|
||||
val existingCurrencies = currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
val existingCurrencies = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier
|
||||
.getSyncOrNull(params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId))
|
||||
.orEmpty()
|
||||
.toList()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
}
|
||||
|
||||
val newCurrenciesList = existingCurrencies
|
||||
.filterNot(removingCurrencies::contains)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package com.tangem.domain.nft
|
||||
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesProducer
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
||||
import com.tangem.domain.tokens.TokensFeatureToggles
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.domain.wallets.repository.WalletsRepository
|
||||
|
|
@ -9,12 +12,22 @@ class DisableWalletNFTUseCase(
|
|||
private val walletsRepository: WalletsRepository,
|
||||
private val nftRepository: NFTRepository,
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId) {
|
||||
walletsRepository.disableNFT(userWalletId)
|
||||
|
||||
val currencies = currenciesRepository.getMultiCurrencyWalletCachedCurrenciesSync(userWalletId)
|
||||
val currencies = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCachedCurrenciesSync(userWalletId)
|
||||
}
|
||||
|
||||
val networks = currencies.map { it.network }
|
||||
nftRepository.clearCache(userWalletId, networks)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,29 @@
|
|||
package com.tangem.domain.nft
|
||||
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesProducer
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
||||
import com.tangem.domain.tokens.TokensFeatureToggles
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
||||
class FetchNFTCollectionsUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
private val nftRepository: NFTRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId) {
|
||||
val currencies = currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
val currencies = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
}
|
||||
|
||||
nftRepository.refreshCollections(userWalletId, currencies.map { it.network }.distinct())
|
||||
}
|
||||
}
|
||||
|
|
@ -2,16 +2,29 @@ package com.tangem.domain.nft
|
|||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesProducer
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
||||
import com.tangem.domain.tokens.TokensFeatureToggles
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
||||
class RefreshAllNFTUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
private val nftRepository: NFTRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId): Either<Throwable, Unit> = Either.catch {
|
||||
val currencies = currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
val currencies = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
}
|
||||
|
||||
nftRepository.refreshAll(userWalletId, currencies.map { it.network }.distinct())
|
||||
}
|
||||
}
|
||||
|
|
@ -30,6 +30,7 @@ class AddCryptoCurrenciesUseCase(
|
|||
private val multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
|
||||
private val multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
|
||||
private val singleYieldBalanceFetcher: SingleYieldBalanceFetcher,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -87,10 +88,21 @@ class AddCryptoCurrenciesUseCase(
|
|||
contractAddress: String,
|
||||
networkId: String,
|
||||
): Either<Throwable, CryptoCurrency> = either {
|
||||
val existingCurrencies =
|
||||
catch({ currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId) }) {
|
||||
raise(it)
|
||||
}
|
||||
val existingCurrencies = catch(
|
||||
block = {
|
||||
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
.toList()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
}
|
||||
},
|
||||
catch = ::raise,
|
||||
)
|
||||
|
||||
val foundToken = existingCurrencies
|
||||
.filterIsInstance<CryptoCurrency.Token>()
|
||||
.firstOrNull {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ import kotlin.collections.set
|
|||
|
||||
class ApplyTokenListSortingUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) {
|
||||
|
||||
|
|
@ -87,7 +89,14 @@ class ApplyTokenListSortingUseCase(
|
|||
private suspend fun Raise<TokenListSortingError>.getCurrencies(userWalletId: UserWalletId): List<CryptoCurrency> {
|
||||
val tokens = catch(
|
||||
block = {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId, refresh = false)
|
||||
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId, refresh = false)
|
||||
}
|
||||
},
|
||||
catch = { raise(TokenListSortingError.DataError(it)) },
|
||||
)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class FetchCurrencyStatusUseCase(
|
|||
private val singleNetworkStatusFetcher: SingleNetworkStatusFetcher,
|
||||
private val multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
|
||||
private val singleYieldBalanceFetcher: SingleYieldBalanceFetcher,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -99,7 +100,17 @@ class FetchCurrencyStatusUseCase(
|
|||
id: CryptoCurrency.ID,
|
||||
): CryptoCurrency {
|
||||
return catch(
|
||||
block = { currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId = userWalletId, id = id) },
|
||||
block = {
|
||||
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
?.firstOrNull { it.id == id }
|
||||
?: error("Unable to find currency with ID: $id")
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId = userWalletId, id = id)
|
||||
}
|
||||
},
|
||||
) {
|
||||
raise(CurrencyStatusError.DataError(it))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ import java.math.BigDecimal
|
|||
*/
|
||||
class GetBalanceNotEnoughForFeeWarningUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) {
|
||||
suspend operator fun invoke(
|
||||
|
|
@ -69,13 +71,21 @@ class GetBalanceNotEnoughForFeeWarningUseCase(
|
|||
tokenStatus: CryptoCurrencyStatus,
|
||||
feePaidToken: FeePaidCurrency.Token,
|
||||
): CryptoCurrencyWarning {
|
||||
val token = currenciesRepository
|
||||
.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
.find {
|
||||
it is CryptoCurrency.Token &&
|
||||
it.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) &&
|
||||
it.network.derivationPath == tokenStatus.currency.network.derivationPath
|
||||
}
|
||||
val tokens = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
}
|
||||
|
||||
val token = tokens.find {
|
||||
it is CryptoCurrency.Token &&
|
||||
it.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) &&
|
||||
it.network.derivationPath == tokenStatus.currency.network.derivationPath
|
||||
}
|
||||
|
||||
return if (token != null) {
|
||||
CryptoCurrencyWarning.CustomTokenNotEnoughForFee(
|
||||
currency = tokenStatus.currency,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import com.tangem.domain.wallets.models.isMultiCurrency
|
|||
|
||||
class GetCryptoCurrencyUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
/**
|
||||
|
|
@ -53,7 +55,15 @@ class GetCryptoCurrencyUseCase(
|
|||
): CryptoCurrency {
|
||||
return catch(
|
||||
block = {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId, id)
|
||||
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
?.firstOrNull { it.id.value == id }
|
||||
?: error("Unable to find currency with ID: $id")
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId, id)
|
||||
}
|
||||
},
|
||||
catch = { raise(CurrencyStatusError.DataError(it)) },
|
||||
)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ class GetCurrencyWarningsUseCase(
|
|||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
private val currencyChecksRepository: CurrencyChecksRepository,
|
||||
private val currencyStatusOperations: BaseCurrencyStatusOperations,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
|
|
@ -150,13 +152,21 @@ class GetCurrencyWarningsUseCase(
|
|||
tokenStatus: CryptoCurrencyStatus,
|
||||
feePaidToken: FeePaidCurrency.Token,
|
||||
): CryptoCurrencyWarning {
|
||||
val token = currenciesRepository
|
||||
.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
.find {
|
||||
it is CryptoCurrency.Token &&
|
||||
it.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) &&
|
||||
it.network.derivationPath == tokenStatus.currency.network.derivationPath
|
||||
}
|
||||
val tokens = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
}
|
||||
|
||||
val token = tokens.find {
|
||||
it is CryptoCurrency.Token &&
|
||||
it.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) &&
|
||||
it.network.derivationPath == tokenStatus.currency.network.derivationPath
|
||||
}
|
||||
|
||||
return if (token != null) {
|
||||
CryptoCurrencyWarning.CustomTokenNotEnoughForFee(
|
||||
currency = tokenStatus.currency,
|
||||
|
|
|
|||
|
|
@ -6,12 +6,22 @@ import com.tangem.domain.wallets.models.UserWalletId
|
|||
|
||||
class IsCryptoCurrencyCoinCouldHideUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId, cryptoCurrencyCoin: CryptoCurrency.Coin): Boolean {
|
||||
return currenciesRepository.getMultiCurrencyWalletCurrenciesSync(
|
||||
userWalletId = userWalletId,
|
||||
refresh = false,
|
||||
).none { it is CryptoCurrency.Token && it.network == cryptoCurrencyCoin.network }
|
||||
return if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(
|
||||
userWalletId = userWalletId,
|
||||
refresh = false,
|
||||
)
|
||||
}
|
||||
.none { it is CryptoCurrency.Token && it.network == cryptoCurrencyCoin.network }
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,8 @@ import kotlinx.coroutines.coroutineScope
|
|||
class RefreshMultiCurrencyWalletQuotesUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId): Either<QuotesError, Unit> {
|
||||
|
|
@ -38,8 +40,18 @@ class RefreshMultiCurrencyWalletQuotesUseCase(
|
|||
private suspend fun getCurrencies(userWalletId: UserWalletId): Either<Throwable, List<CryptoCurrency>> {
|
||||
return either {
|
||||
catch(
|
||||
block = { currenciesRepository.getMultiCurrencyWalletCachedCurrenciesSync(userWalletId) },
|
||||
catch = { raise(it) },
|
||||
block = {
|
||||
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
.toList()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCachedCurrenciesSync(userWalletId)
|
||||
}
|
||||
},
|
||||
catch = ::raise,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import com.tangem.domain.wallets.models.UserWalletId
|
|||
class RemoveCurrencyUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val walletManagersFacade: WalletManagersFacade,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
|
|
@ -44,10 +46,17 @@ class RemoveCurrencyUseCase(
|
|||
suspend fun hasLinkedTokens(userWalletId: UserWalletId, currency: CryptoCurrency): Boolean {
|
||||
return when (currency) {
|
||||
is CryptoCurrency.Coin -> {
|
||||
val walletCurrencies = currenciesRepository.getMultiCurrencyWalletCurrenciesSync(
|
||||
userWalletId = userWalletId,
|
||||
refresh = false,
|
||||
)
|
||||
val walletCurrencies = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
.orEmpty()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(
|
||||
userWalletId = userWalletId,
|
||||
refresh = false,
|
||||
)
|
||||
}
|
||||
|
||||
walletCurrencies.any { it is CryptoCurrency.Token && it.network == currency.network }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import com.tangem.domain.staking.model.stakekit.YieldBalanceList
|
|||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import com.tangem.domain.staking.single.SingleYieldBalanceProducer
|
||||
import com.tangem.domain.staking.single.SingleYieldBalanceSupplier
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesProducer
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
||||
import com.tangem.domain.tokens.TokensFeatureToggles
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.tokens.operations.CurrenciesStatusesOperations.Error
|
||||
|
|
@ -47,6 +49,7 @@ abstract class BaseCurrencyStatusOperations(
|
|||
private val singleNetworkStatusSupplier: SingleNetworkStatusSupplier,
|
||||
private val singleQuoteStatusSupplier: SingleQuoteStatusSupplier,
|
||||
private val singleYieldBalanceSupplier: SingleYieldBalanceSupplier,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -176,7 +179,7 @@ abstract class BaseCurrencyStatusOperations(
|
|||
val currency = if (isSingleWalletWithTokens) {
|
||||
currenciesRepository.getSingleCurrencyWalletWithCardCurrency(userWalletId, cryptoCurrencyId)
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId, cryptoCurrencyId)
|
||||
getMultiCurrencyWalletCurrency(userWalletId, cryptoCurrencyId)
|
||||
}
|
||||
|
||||
val quote = cryptoCurrencyId.rawCurrencyId?.let { rawId ->
|
||||
|
|
@ -240,9 +243,16 @@ abstract class BaseCurrencyStatusOperations(
|
|||
return either {
|
||||
catch(
|
||||
block = {
|
||||
val nonEmptyCurrencies =
|
||||
val nonEmptyCurrencies = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
?.toNonEmptyListOrNull()
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId).toNonEmptyListOrNull()
|
||||
?: return emptyList<CryptoCurrencyStatus>().right()
|
||||
}
|
||||
?: return emptyList<CryptoCurrencyStatus>().right()
|
||||
|
||||
val (_, currenciesIds) = getIds(nonEmptyCurrencies)
|
||||
val rawIds = currenciesIds.mapNotNull { it.rawCurrencyId }.toSet()
|
||||
|
||||
|
|
@ -303,7 +313,15 @@ abstract class BaseCurrencyStatusOperations(
|
|||
currencyId: CryptoCurrency.ID,
|
||||
): CryptoCurrency {
|
||||
return Either.catch {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId = userWalletId, id = currencyId)
|
||||
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
?.firstOrNull { it.id == currencyId }
|
||||
?: error("Unable to find currency with ID: $currencyId")
|
||||
} else {
|
||||
currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId = userWalletId, id = currencyId)
|
||||
}
|
||||
}
|
||||
.mapLeft(Error::DataError)
|
||||
.bind()
|
||||
|
|
@ -352,7 +370,17 @@ abstract class BaseCurrencyStatusOperations(
|
|||
networkId: Network.ID,
|
||||
derivationPath: Network.DerivationPath,
|
||||
): CryptoCurrency {
|
||||
return Either.catch { currenciesRepository.getNetworkCoin(userWalletId, networkId, derivationPath) }
|
||||
return Either.catch {
|
||||
if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
?.firstOrNull { it.network.id == networkId && it.network.derivationPath == derivationPath }
|
||||
?: error("Unable to create network coin with ID: $networkId and derivation path: $derivationPath")
|
||||
} else {
|
||||
currenciesRepository.getNetworkCoin(userWalletId, networkId, derivationPath)
|
||||
}
|
||||
}
|
||||
.mapLeft { Error.DataError(it) }
|
||||
.bind()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ 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
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
||||
import com.tangem.domain.tokens.TokensFeatureToggles
|
||||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
|
|
@ -54,6 +55,7 @@ class CachedCurrenciesStatusesOperations(
|
|||
private val singleQuoteStatusSupplier: SingleQuoteStatusSupplier,
|
||||
private val singleYieldBalanceSupplier: SingleYieldBalanceSupplier,
|
||||
private val multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
|
||||
multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) : BaseCurrenciesStatusesOperations,
|
||||
BaseCurrencyStatusOperations(
|
||||
|
|
@ -64,6 +66,7 @@ class CachedCurrenciesStatusesOperations(
|
|||
singleNetworkStatusSupplier = singleNetworkStatusSupplier,
|
||||
singleQuoteStatusSupplier = singleQuoteStatusSupplier,
|
||||
singleYieldBalanceSupplier = singleYieldBalanceSupplier,
|
||||
multiWalletCryptoCurrenciesSupplier = multiWalletCryptoCurrenciesSupplier,
|
||||
tokensFeatureToggles = tokensFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.tangem.domain.tokens.mock.MockTokens
|
|||
import com.tangem.domain.tokens.repository.MockCurrenciesRepository
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
|
||||
import io.mockk.mockk
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
|
|
@ -186,6 +187,8 @@ internal class ApplyTokenListSortingUseCaseTest {
|
|||
ApplyTokenListSortingUseCase(
|
||||
currenciesRepository = tokensRepository,
|
||||
dispatchers = TestingCoroutineDispatcherProvider(),
|
||||
multiWalletCryptoCurrenciesSupplier = mockk(),
|
||||
tokensFeatureToggles = mockk(),
|
||||
)
|
||||
|
||||
private fun getTokensRepository(
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ import com.tangem.domain.models.currency.CryptoCurrency
|
|||
import com.tangem.domain.models.network.NetworkStatus
|
||||
import com.tangem.domain.networks.single.SingleNetworkStatusProducer
|
||||
import com.tangem.domain.networks.single.SingleNetworkStatusSupplier
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesProducer
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
||||
import com.tangem.domain.tokens.TokensFeatureToggles
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.transaction.error.AssociateAssetError
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
|
|
@ -21,6 +24,8 @@ class AssociateAssetUseCase(
|
|||
private val walletManagersFacade: WalletManagersFacade,
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val singleNetworkStatusSupplier: SingleNetworkStatusSupplier,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val tokensFeatureToggles: TokensFeatureToggles,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
|
|
@ -28,11 +33,22 @@ class AssociateAssetUseCase(
|
|||
currency: CryptoCurrency,
|
||||
): Either<AssociateAssetError, Unit> {
|
||||
return either {
|
||||
val networkCoin = currenciesRepository.getNetworkCoin(
|
||||
userWalletId = userWalletId,
|
||||
networkId = currency.network.id,
|
||||
derivationPath = currency.network.derivationPath,
|
||||
)
|
||||
val networkCoin = if (tokensFeatureToggles.isWalletBalanceFetcherEnabled) {
|
||||
multiWalletCryptoCurrenciesSupplier.getSyncOrNull(
|
||||
params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId),
|
||||
)
|
||||
?.firstOrNull {
|
||||
val network = currency.network
|
||||
it.network.id == network.id && it.network.derivationPath == network.derivationPath
|
||||
}
|
||||
?: error("Unable to create network coin for currencyID: ${currency.id}")
|
||||
} else {
|
||||
currenciesRepository.getNetworkCoin(
|
||||
userWalletId = userWalletId,
|
||||
networkId = currency.network.id,
|
||||
derivationPath = currency.network.derivationPath,
|
||||
)
|
||||
}
|
||||
if (isBalanceZero(userWalletId, networkCoin)) {
|
||||
raise(AssociateAssetError.NotEnoughBalance(networkCoin))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue