Updated on 2026-08-14
This commit is contained in:
parent
eb96c3be40
commit
def92569d3
13 changed files with 196 additions and 73 deletions
|
|
@ -1,11 +1,11 @@
|
|||
package com.tangem.tap.di.domain
|
||||
|
||||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
|
||||
import com.tangem.domain.account.supplier.SingleAccountListSupplier
|
||||
import com.tangem.domain.networks.single.SingleNetworkStatusSupplier
|
||||
import com.tangem.domain.nft.*
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.nft.utils.NFTCleaner
|
||||
import com.tangem.domain.quotes.single.SingleQuoteStatusFetcher
|
||||
import com.tangem.domain.quotes.single.SingleQuoteStatusSupplier
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
||||
|
|
@ -27,12 +27,12 @@ internal object NFTDomainModule {
|
|||
fun providesGetNFTCollectionsUseCase(
|
||||
currenciesRepository: CurrenciesRepository,
|
||||
nftRepository: NFTRepository,
|
||||
singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
|
||||
singleAccountListSupplier: SingleAccountListSupplier,
|
||||
accountsFeatureToggles: AccountsFeatureToggles,
|
||||
): GetNFTCollectionsUseCase = GetNFTCollectionsUseCase(
|
||||
currenciesRepository = currenciesRepository,
|
||||
nftRepository = nftRepository,
|
||||
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
|
||||
singleAccountListSupplier = singleAccountListSupplier,
|
||||
accountsFeatureToggles = accountsFeatureToggles,
|
||||
)
|
||||
|
||||
|
|
@ -67,12 +67,12 @@ internal object NFTDomainModule {
|
|||
@Singleton
|
||||
fun providesGetNFTAvailableNetworksUseCase(
|
||||
nftRepository: NFTRepository,
|
||||
singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
|
||||
singleAccountListSupplier: SingleAccountListSupplier,
|
||||
currenciesRepository: CurrenciesRepository,
|
||||
): GetNFTNetworksUseCase = GetNFTNetworksUseCase(
|
||||
currenciesRepository = currenciesRepository,
|
||||
nftRepository = nftRepository,
|
||||
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
|
||||
singleAccountListSupplier = singleAccountListSupplier,
|
||||
)
|
||||
|
||||
@Provides
|
||||
|
|
@ -126,13 +126,13 @@ internal object NFTDomainModule {
|
|||
@Singleton
|
||||
fun provideDisableWalletNFTUseCase(
|
||||
walletsRepository: WalletsRepository,
|
||||
nftRepository: NFTRepository,
|
||||
multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
nftCleaner: NFTCleaner,
|
||||
): DisableWalletNFTUseCase {
|
||||
return DisableWalletNFTUseCase(
|
||||
walletsRepository = walletsRepository,
|
||||
nftRepository = nftRepository,
|
||||
multiWalletCryptoCurrenciesSupplier = multiWalletCryptoCurrenciesSupplier,
|
||||
nftCleaner = nftCleaner,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -145,13 +145,13 @@ internal object NFTDomainModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun provideClearNFTCacheUseCase(
|
||||
nftRepository: NFTRepository,
|
||||
nftCleaner: NFTCleaner,
|
||||
currenciesRepository: CurrenciesRepository,
|
||||
accountsFeatureToggles: AccountsFeatureToggles,
|
||||
singleAccountListSupplier: SingleAccountListSupplier,
|
||||
): ObserveAndClearNFTCacheIfNeedUseCase {
|
||||
return ObserveAndClearNFTCacheIfNeedUseCase(
|
||||
nftRepository = nftRepository,
|
||||
nftCleaner = nftCleaner,
|
||||
currenciesRepository = currenciesRepository,
|
||||
accountsFeatureToggles = accountsFeatureToggles,
|
||||
singleAccountListSupplier = singleAccountListSupplier,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ android {
|
|||
namespace = "com.tangem.data.nft"
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
/** Project - Data */
|
||||
|
|
@ -53,4 +57,8 @@ dependencies {
|
|||
/** DI */
|
||||
implementation(deps.hilt.android)
|
||||
kapt(deps.hilt.kapt)
|
||||
|
||||
testImplementation(projects.test.core)
|
||||
testImplementation(projects.common.test)
|
||||
testRuntimeOnly(deps.test.junit5.engine)
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.data.nft
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import arrow.core.Either
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
|
|
@ -26,15 +27,19 @@ import com.tangem.domain.nft.models.NFTCollection
|
|||
import com.tangem.domain.nft.models.NFTCollections
|
||||
import com.tangem.domain.nft.models.NFTSalePrice
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.nft.utils.NFTCleaner
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import com.tangem.utils.coroutines.JobHolder
|
||||
import com.tangem.utils.coroutines.runSuspendCatching
|
||||
import com.tangem.utils.coroutines.saveIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.inject.Inject
|
||||
import com.tangem.blockchain.nft.models.NFTAsset as SdkNFTAsset
|
||||
|
|
@ -49,9 +54,10 @@ internal class DefaultNFTRepository @Inject constructor(
|
|||
private val userWalletsStore: UserWalletsStore,
|
||||
private val networkFactory: NetworkFactory,
|
||||
private val excludedBlockchains: ExcludedBlockchains,
|
||||
resources: Resources,
|
||||
) : NFTRepository {
|
||||
@ApplicationContext private val context: Context,
|
||||
) : NFTRepository, NFTCleaner {
|
||||
|
||||
private val resources: Resources by lazy { context.resources }
|
||||
private val networkJobs = ConcurrentHashMap<Network, JobHolder>()
|
||||
private val collectionJobs = ConcurrentHashMap<NFTCollection.Identifier, JobHolder>()
|
||||
private val cryptoCurrencyFactory = CryptoCurrencyFactory(excludedBlockchains)
|
||||
|
|
@ -218,10 +224,22 @@ internal class DefaultNFTRepository @Inject constructor(
|
|||
assetIdentifier = assetIdConverter.convertBack(assetIdentifier),
|
||||
)
|
||||
|
||||
override suspend fun clearCache(userWalletId: UserWalletId, networks: List<Network>) {
|
||||
networks.forEach {
|
||||
getNFTPersistenceStore(userWalletId, it).clear()
|
||||
getNFTRuntimeStore(userWalletId, it).clear()
|
||||
// NFTCleaner implementation
|
||||
override suspend fun invoke(userWalletId: UserWalletId, networks: Set<Network>) {
|
||||
if (networks.isEmpty()) {
|
||||
Timber.d("No networks to clear for wallet: $userWalletId")
|
||||
return
|
||||
}
|
||||
|
||||
networks.forEach { network ->
|
||||
runSuspendCatching {
|
||||
getNFTPersistenceStore(userWalletId = userWalletId, network = network).clear()
|
||||
// FIXME: nftRuntimeStore is created with only network, so clearing it may affect other wallets
|
||||
// nftRuntimeStoreFactory.provide(network = network).clear()
|
||||
}
|
||||
.onFailure { throwable ->
|
||||
Timber.e(throwable, "Failed to clear NFT data for network $network for wallet: $userWalletId")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,23 @@
|
|||
package com.tangem.data.nft.di
|
||||
|
||||
import android.content.Context
|
||||
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
|
||||
import com.tangem.data.common.network.NetworkFactory
|
||||
import com.tangem.data.nft.DefaultNFTRepository
|
||||
import com.tangem.datasource.local.nft.NFTPersistenceStoreFactory
|
||||
import com.tangem.datasource.local.nft.NFTRuntimeStoreFactory
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import com.tangem.domain.nft.utils.NFTCleaner
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal object NFTDataModule {
|
||||
internal interface NFTDataModule {
|
||||
|
||||
@Provides
|
||||
@Binds
|
||||
@Singleton
|
||||
fun provideNFTRepository(
|
||||
@ApplicationContext context: Context,
|
||||
nftPersistenceStoreFactory: NFTPersistenceStoreFactory,
|
||||
nftRuntimeStoreFactory: NFTRuntimeStoreFactory,
|
||||
walletManagersFacade: WalletManagersFacade,
|
||||
dispatchers: CoroutineDispatcherProvider,
|
||||
excludedBlockchains: ExcludedBlockchains,
|
||||
userWalletsStore: UserWalletsStore,
|
||||
networkFactory: NetworkFactory,
|
||||
): NFTRepository = DefaultNFTRepository(
|
||||
nftPersistenceStoreFactory = nftPersistenceStoreFactory,
|
||||
nftRuntimeStoreFactory = nftRuntimeStoreFactory,
|
||||
walletManagersFacade = walletManagersFacade,
|
||||
dispatchers = dispatchers,
|
||||
excludedBlockchains = excludedBlockchains,
|
||||
userWalletsStore = userWalletsStore,
|
||||
networkFactory = networkFactory,
|
||||
resources = context.resources,
|
||||
)
|
||||
fun bindNFTRepository(defaultNFTRepository: DefaultNFTRepository): NFTRepository
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindNFTCleaner(defaultNFTRepository: DefaultNFTRepository): NFTCleaner
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package com.tangem.data.nft
|
||||
|
||||
import com.tangem.common.test.domain.token.MockCryptoCurrencyFactory
|
||||
import com.tangem.datasource.local.nft.NFTPersistenceStore
|
||||
import com.tangem.datasource.local.nft.NFTPersistenceStoreFactory
|
||||
import com.tangem.datasource.local.nft.NFTRuntimeStore
|
||||
import com.tangem.datasource.local.nft.NFTRuntimeStoreFactory
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import io.mockk.*
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class NFTCleanerTest {
|
||||
|
||||
private val nftPersistenceStoreFactory: NFTPersistenceStoreFactory = mockk()
|
||||
private val nftRuntimeStoreFactory: NFTRuntimeStoreFactory = mockk()
|
||||
|
||||
private val nftCleaner = DefaultNFTRepository(
|
||||
nftPersistenceStoreFactory = nftPersistenceStoreFactory,
|
||||
nftRuntimeStoreFactory = nftRuntimeStoreFactory,
|
||||
walletManagersFacade = mockk(),
|
||||
dispatchers = mockk(),
|
||||
userWalletsStore = mockk(),
|
||||
networkFactory = mockk(),
|
||||
excludedBlockchains = mockk(),
|
||||
context = mockk(),
|
||||
)
|
||||
|
||||
private val userWalletId = UserWalletId("011")
|
||||
|
||||
@AfterEach
|
||||
fun tearDown() {
|
||||
clearMocks(nftPersistenceStoreFactory, nftRuntimeStoreFactory)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should call invoke with multiple networks`() = runTest {
|
||||
// Arrange
|
||||
val mockCryptoCurrencyFactory = MockCryptoCurrencyFactory()
|
||||
val networks = mockCryptoCurrencyFactory.ethereumAndStellar.map(CryptoCurrency.Coin::network)
|
||||
val persistenceByNetwork = networks.associateWith { mockk<NFTPersistenceStore>(relaxUnitFun = true) }
|
||||
val runtimeByNetwork = networks.associateWith { mockk<NFTRuntimeStore>(relaxUnitFun = true) }
|
||||
|
||||
networks.forEach { network ->
|
||||
every { nftPersistenceStoreFactory.provide(userWalletId, network) } returns persistenceByNetwork[network]!!
|
||||
every { nftRuntimeStoreFactory.provide(network) } returns runtimeByNetwork[network]!!
|
||||
}
|
||||
|
||||
// Act
|
||||
nftCleaner.invoke(userWalletId = userWalletId, networks = networks.toSet())
|
||||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
networks.forEach { network ->
|
||||
nftPersistenceStoreFactory.provide(userWalletId, network)
|
||||
persistenceByNetwork[network]!!.clear()
|
||||
// nftRuntimeStoreFactory.provide(network)
|
||||
// runtimeByNetwork[network]!!.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should handle empty networks set`() = runTest {
|
||||
// Act
|
||||
nftCleaner.invoke(userWalletId, emptySet())
|
||||
|
||||
// Assert
|
||||
coVerify(inverse = true) {
|
||||
nftPersistenceStoreFactory.provide(userWalletId = any(), network = any())
|
||||
nftRuntimeStoreFactory.provide(network = any())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ dependencies {
|
|||
api(projects.domain.quotes)
|
||||
api(projects.domain.models)
|
||||
api(projects.domain.networks)
|
||||
api(projects.domain.nft)
|
||||
api(projects.domain.referral)
|
||||
api(projects.domain.staking)
|
||||
api(projects.domain.tokens)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ dependencies {
|
|||
|
||||
// region Project – Domain
|
||||
implementation(projects.domain.core)
|
||||
implementation(projects.domain.account.status)
|
||||
implementation(projects.domain.account)
|
||||
implementation(projects.domain.models)
|
||||
implementation(projects.domain.networks)
|
||||
implementation(projects.domain.nft.models)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package com.tangem.domain.nft
|
||||
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.nft.utils.NFTCleaner
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesProducer
|
||||
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
||||
import com.tangem.domain.wallets.repository.WalletsRepository
|
||||
|
||||
class DisableWalletNFTUseCase(
|
||||
private val walletsRepository: WalletsRepository,
|
||||
private val nftRepository: NFTRepository,
|
||||
private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
|
||||
private val nftCleaner: NFTCleaner,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId) {
|
||||
|
|
@ -20,7 +21,7 @@ class DisableWalletNFTUseCase(
|
|||
)
|
||||
.orEmpty()
|
||||
|
||||
val networks = currencies.map { it.network }
|
||||
nftRepository.clearCache(userWalletId, networks)
|
||||
val networks = currencies.mapTo(destination = hashSetOf(), transform = CryptoCurrency::network)
|
||||
nftCleaner(userWalletId, networks)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package com.tangem.domain.nft
|
||||
|
||||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
|
||||
import com.tangem.domain.account.supplier.SingleAccountListSupplier
|
||||
import com.tangem.domain.models.account.Account
|
||||
import com.tangem.domain.models.account.AccountStatus
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.nft.models.NFTCollections
|
||||
|
|
@ -16,7 +15,7 @@ import kotlinx.coroutines.flow.*
|
|||
class GetNFTCollectionsUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val nftRepository: NFTRepository,
|
||||
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
|
||||
private val singleAccountListSupplier: SingleAccountListSupplier,
|
||||
private val accountsFeatureToggles: AccountsFeatureToggles,
|
||||
) {
|
||||
|
||||
|
|
@ -33,13 +32,17 @@ class GetNFTCollectionsUseCase(
|
|||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun invokeForAccounts(userWalletId: UserWalletId): Flow<WalletNFTCollections> {
|
||||
fun AccountStatus.flowOfNFTCollections(): Flow<Pair<Account, List<NFTCollections>>> =
|
||||
nftCollections(userWalletId, this.flattenCurrencies().map { it.currency })
|
||||
.map { nfts -> this.account to nfts }
|
||||
fun Account.flowOfNFTCollections(): Flow<Pair<Account, List<NFTCollections>>> {
|
||||
val currencies = (this as? Account.CryptoPortfolio)?.cryptoCurrencies.orEmpty()
|
||||
|
||||
return singleAccountStatusListSupplier(userWalletId)
|
||||
.mapLatest { statusList -> statusList.accountStatuses.map { it.flowOfNFTCollections() } }
|
||||
return nftCollections(userWalletId = userWalletId, cryptoCurrencies = currencies.toList())
|
||||
.map { nfts -> this to nfts }
|
||||
}
|
||||
|
||||
return singleAccountListSupplier(userWalletId)
|
||||
.mapLatest { statusList -> statusList.accounts.map { it.flowOfNFTCollections() } }
|
||||
.flatMapLatest { flows -> combine(flows) { WalletNFTCollections(it.toMap()) } }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package com.tangem.domain.nft
|
||||
|
||||
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
|
||||
import com.tangem.domain.account.supplier.SingleAccountListSupplier
|
||||
import com.tangem.domain.models.PortfolioId
|
||||
import com.tangem.domain.models.account.Account
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.nft.models.NFTNetworks
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
|
|
@ -14,19 +16,25 @@ import kotlinx.coroutines.flow.mapNotNull
|
|||
|
||||
class GetNFTNetworksUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
|
||||
private val singleAccountListSupplier: SingleAccountListSupplier,
|
||||
private val nftRepository: NFTRepository,
|
||||
) {
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
operator fun invoke(portfolioId: PortfolioId): Flow<NFTNetworks> = when (portfolioId) {
|
||||
is PortfolioId.Account -> singleAccountStatusListSupplier(portfolioId.userWalletId)
|
||||
.map { it.accountStatuses }
|
||||
.mapNotNull { accountStatuses -> accountStatuses.find { it.account.accountId == portfolioId.accountId } }
|
||||
.map { accountStatus -> accountStatus.flattenCurrencies().map { it.currency } }
|
||||
.mapLatest { it.toNFTNetworks(portfolioId.userWalletId) }
|
||||
is PortfolioId.Wallet ->
|
||||
is PortfolioId.Account -> {
|
||||
singleAccountListSupplier(portfolioId.userWalletId)
|
||||
.mapNotNull { accountList ->
|
||||
val account = accountList.accounts.find { it.accountId == portfolioId.accountId }
|
||||
|
||||
(account as? Account.CryptoPortfolio)?.cryptoCurrencies?.toList()
|
||||
}
|
||||
.mapLatest { it.toNFTNetworks(portfolioId.userWalletId) }
|
||||
}
|
||||
is PortfolioId.Wallet -> {
|
||||
currenciesRepository
|
||||
.getWalletCurrenciesUpdates(portfolioId.userWalletId)
|
||||
.map { cryptoCurrencies -> cryptoCurrencies.toNFTNetworks(portfolioId.userWalletId) }
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun List<CryptoCurrency>.toNFTNetworks(userWalletId: UserWalletId): NFTNetworks {
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ 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.nft.utils.NFTCleaner
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
class ObserveAndClearNFTCacheIfNeedUseCase(
|
||||
private val nftRepository: NFTRepository,
|
||||
private val nftCleaner: NFTCleaner,
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val accountsFeatureToggles: AccountsFeatureToggles,
|
||||
private val singleAccountListSupplier: SingleAccountListSupplier,
|
||||
|
|
@ -26,7 +26,7 @@ class ObserveAndClearNFTCacheIfNeedUseCase(
|
|||
.distinctUntilChanged()
|
||||
.onEach { removedNetworks ->
|
||||
if (removedNetworks.isNotEmpty()) {
|
||||
nftRepository.clearCache(userWalletId, removedNetworks.toList())
|
||||
nftCleaner(userWalletId, removedNetworks)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ package com.tangem.domain.nft.repository
|
|||
|
||||
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.models.NFTAsset
|
||||
import com.tangem.domain.nft.models.NFTCollection
|
||||
import com.tangem.domain.nft.models.NFTCollections
|
||||
import com.tangem.domain.nft.models.NFTSalePrice
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface NFTRepository {
|
||||
|
|
@ -32,6 +32,4 @@ interface NFTRepository {
|
|||
suspend fun getNFTSupportedNetworks(userWalletId: UserWalletId): List<Network>
|
||||
|
||||
suspend fun getNFTExploreUrl(network: Network, assetIdentifier: NFTAsset.Identifier): String?
|
||||
|
||||
suspend fun clearCache(userWalletId: UserWalletId, networks: List<Network>)
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.tangem.domain.nft.utils
|
||||
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
|
||||
/**
|
||||
* Cleans up NFT data for a given user wallet and network(s).
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
interface NFTCleaner {
|
||||
|
||||
/**
|
||||
* Cleans up NFT data for a given user wallet and single network.
|
||||
*
|
||||
* @param userWalletId the user wallet id
|
||||
* @param network the network to clean up
|
||||
*/
|
||||
suspend operator fun invoke(userWalletId: UserWalletId, network: Network) {
|
||||
invoke(userWalletId = userWalletId, networks = setOf(network))
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up NFT data for a given user wallet and multiple networks.
|
||||
*
|
||||
* @param userWalletId the user wallet id
|
||||
* @param networks the set of networks to clean up
|
||||
*/
|
||||
suspend operator fun invoke(userWalletId: UserWalletId, networks: Set<Network>)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue