Updated on 2026-08-14
This commit is contained in:
parent
2d3e5fdb7a
commit
dd0add894f
20 changed files with 118 additions and 57 deletions
|
|
@ -20,6 +20,7 @@ class GetNFTCollectionsUseCase(
|
|||
private val accountsFeatureToggles: AccountsFeatureToggles,
|
||||
) {
|
||||
|
||||
@Deprecated("Use invokeForAccounts instead")
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
operator fun invoke(userWalletId: UserWalletId): Flow<List<NFTCollections>> =
|
||||
if (accountsFeatureToggles.isFeatureEnabled) {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,23 @@
|
|||
package com.tangem.domain.nft
|
||||
|
||||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.account.models.AccountList
|
||||
import com.tangem.domain.account.supplier.SingleAccountListSupplier
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
class ObserveAndClearNFTCacheIfNeedUseCase(
|
||||
private val nftRepository: NFTRepository,
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val accountsFeatureToggles: AccountsFeatureToggles,
|
||||
private val singleAccountListSupplier: SingleAccountListSupplier,
|
||||
) {
|
||||
operator fun invoke(userWalletId: UserWalletId): Flow<Set<Network>> = currenciesRepository
|
||||
.getWalletCurrenciesUpdates(userWalletId)
|
||||
|
||||
operator fun invoke(userWalletId: UserWalletId): Flow<Set<Network>> = getCryptoCurrencies(userWalletId)
|
||||
.map { it.map(CryptoCurrency::network) }
|
||||
.mapDiff { old, new ->
|
||||
// calculate networks sets difference to determine which networks were removed
|
||||
|
|
@ -25,6 +30,14 @@ class ObserveAndClearNFTCacheIfNeedUseCase(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getCryptoCurrencies(userWalletId: UserWalletId): Flow<Collection<CryptoCurrency>> {
|
||||
return if (accountsFeatureToggles.isFeatureEnabled) {
|
||||
singleAccountListSupplier(userWalletId).map(AccountList::flattenCurrencies)
|
||||
} else {
|
||||
currenciesRepository.getWalletCurrenciesUpdates(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T, R> Flow<T>.mapDiff(diff: (old: T, new: T) -> R): Flow<R> = flow {
|
||||
var previous: T? = null
|
||||
collect { current ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue