Updated on 2026-08-14

This commit is contained in:
Tangem 2025-05-16 12:52:27 +05:00
parent 7be6ce9dba
commit 0cd80d7c50
13 changed files with 109 additions and 5 deletions

View file

@ -6,6 +6,7 @@ import com.tangem.domain.nft.repository.NFTRepository
import com.tangem.domain.quotes.single.SingleQuoteFetcher
import com.tangem.domain.quotes.single.SingleQuoteSupplier
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.wallets.repository.WalletsRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.Module
import dagger.Provides
@ -104,4 +105,26 @@ internal object NFTDomainModule {
): FetchNFTPriceUseCase {
return FetchNFTPriceUseCase(nftRepository, singleQuoteFetcher)
}
@Provides
@Singleton
fun provideEnableWalletNFTUseCase(walletsRepository: WalletsRepository): EnableWalletNFTUseCase {
return EnableWalletNFTUseCase(walletsRepository)
}
@Provides
@Singleton
fun provideDisableWalletNFTUseCase(
walletsRepository: WalletsRepository,
nftRepository: NFTRepository,
currenciesRepository: CurrenciesRepository,
): DisableWalletNFTUseCase {
return DisableWalletNFTUseCase(walletsRepository, nftRepository, currenciesRepository)
}
@Provides
@Singleton
fun provideGetWalletNFTEnabledUseCase(walletsRepository: WalletsRepository): GetWalletNFTEnabledUseCase {
return GetWalletNFTEnabledUseCase(walletsRepository)
}
}

View file

@ -47,5 +47,10 @@ internal class DefaultNFTPersistenceStore(
}
}
override suspend fun clear() {
collectionsPersistenceStore.updateData { emptyList() }
pricesPersistenceStore.updateData { emptyList() }
}
private fun NFTCollection.getAsset(assetId: NFTAsset.Identifier) = assets.firstOrNull { it.identifier == assetId }
}

View file

@ -71,6 +71,16 @@ internal class DefaultNFTRuntimeStore(
}
}
override suspend fun clear() {
collectionsRuntimeStore.store(
NFTCollections(
network = network,
content = NFTCollections.Content.Collections(null, StatusSource.ONLY_CACHE),
),
)
pricesRuntimeStore.store(emptyMap())
}
private fun NFTCollections.getCollection(collectionId: NFTCollection.Identifier): NFTCollection? =
(content as? NFTCollections.Content.Collections)
?.collections

View file

@ -18,4 +18,6 @@ interface NFTPersistenceStore {
suspend fun saveCollections(collections: List<NFTCollection>)
suspend fun saveSalePrice(assetId: NFTAsset.Identifier, salePrice: NFTAsset.SalePrice)
suspend fun clear()
}

View file

@ -23,4 +23,6 @@ interface NFTRuntimeStore {
suspend fun saveCollections(collections: NFTCollections)
suspend fun saveSalePrice(salePrice: NFTSalePrice)
suspend fun clear()
}

View file

@ -215,6 +215,13 @@ 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()
}
}
private suspend fun refreshCollectionsInternal(
userWalletId: UserWalletId,
networks: List<Network>,

View file

@ -23,6 +23,7 @@ dependencies {
implementation(projects.domain.quotes)
implementation(projects.domain.tokens)
implementation(projects.domain.tokens.models)
implementation(projects.domain.wallets)
implementation(projects.domain.wallets.models)
// endregion

View file

@ -0,0 +1,21 @@
package com.tangem.domain.nft
import com.tangem.domain.nft.repository.NFTRepository
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.repository.WalletsRepository
class DisableWalletNFTUseCase(
private val walletsRepository: WalletsRepository,
private val nftRepository: NFTRepository,
private val currenciesRepository: CurrenciesRepository,
) {
suspend operator fun invoke(userWalletId: UserWalletId) {
walletsRepository.disableNFT(userWalletId)
val currencies = currenciesRepository.getMultiCurrencyWalletCachedCurrenciesSync(userWalletId)
val networks = currencies.map { it.network }
nftRepository.clearCache(userWalletId, networks)
}
}

View file

@ -0,0 +1,13 @@
package com.tangem.domain.nft
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.repository.WalletsRepository
class EnableWalletNFTUseCase(
private val walletsRepository: WalletsRepository,
) {
suspend operator fun invoke(userWalletId: UserWalletId) {
walletsRepository.enableNFT(userWalletId)
}
}

View file

@ -0,0 +1,13 @@
package com.tangem.domain.nft
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.repository.WalletsRepository
import kotlinx.coroutines.flow.Flow
class GetWalletNFTEnabledUseCase(
private val walletsRepository: WalletsRepository,
) {
operator fun invoke(userWalletId: UserWalletId): Flow<Boolean> = walletsRepository
.nftEnabledStatus(userWalletId)
}

View file

@ -32,4 +32,6 @@ 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>)
}

View file

@ -34,6 +34,7 @@ dependencies {
implementation(projects.domain.wallets)
implementation(projects.domain.wallets.models)
implementation(projects.domain.demo)
implementation(projects.domain.nft)
/* AndroidX */
implementation(deps.androidx.fragment.ktx)

View file

@ -19,8 +19,10 @@ import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.demo.IsDemoCardUseCase
import com.tangem.domain.models.scan.CardDTO
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.nft.DisableWalletNFTUseCase
import com.tangem.domain.nft.EnableWalletNFTUseCase
import com.tangem.domain.nft.GetWalletNFTEnabledUseCase
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.repository.WalletsRepository
import com.tangem.domain.wallets.usecase.DeleteWalletUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.domain.wallets.usecase.ShouldSaveUserWalletsSyncUseCase
@ -54,8 +56,10 @@ internal class WalletSettingsModel @Inject constructor(
private val analyticsContextProxy: AnalyticsContextProxy,
private val getShouldSaveUserWalletsSyncUseCase: ShouldSaveUserWalletsSyncUseCase,
private val isDemoCardUseCase: IsDemoCardUseCase,
private val walletsRepository: WalletsRepository,
private val nftFeatureToggles: NFTFeatureToggles,
private val getWalletNFTEnabledUseCase: GetWalletNFTEnabledUseCase,
private val enableWalletNFTUseCase: EnableWalletNFTUseCase,
private val disableWalletNFTUseCase: DisableWalletNFTUseCase,
) : Model() {
val params: WalletSettingsComponent.Params = paramsContainer.require()
@ -71,7 +75,7 @@ internal class WalletSettingsModel @Inject constructor(
init {
getWalletUseCase.invokeFlow(params.userWalletId)
.distinctUntilChanged()
.combine(walletsRepository.nftEnabledStatus(params.userWalletId)) { maybeWallet, nftEnabled ->
.combine(getWalletNFTEnabledUseCase.invoke(params.userWalletId)) { maybeWallet, nftEnabled ->
val wallet = maybeWallet.getOrNull() ?: return@combine
val isRenameWalletAvailable = getShouldSaveUserWalletsSyncUseCase()
state.update { value ->
@ -169,9 +173,9 @@ internal class WalletSettingsModel @Inject constructor(
private fun onCheckedNFTChange(isChecked: Boolean) {
modelScope.launch {
if (isChecked) {
walletsRepository.enableNFT(params.userWalletId)
enableWalletNFTUseCase.invoke(params.userWalletId)
} else {
walletsRepository.disableNFT(params.userWalletId)
disableWalletNFTUseCase.invoke(params.userWalletId)
}
}
}