Updated on 2026-08-14
This commit is contained in:
parent
04ce95d61a
commit
1d374e5d07
3 changed files with 25 additions and 14 deletions
|
|
@ -38,6 +38,8 @@ import kotlinx.coroutines.coroutineScope
|
|||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
|
@ -63,6 +65,7 @@ internal class DefaultNFTRepository @Inject constructor(
|
|||
private val cryptoCurrencyFactory = CryptoCurrencyFactory(excludedBlockchains)
|
||||
|
||||
private val nftRuntimeStores = ConcurrentHashMap<String, NFTRuntimeStore>()
|
||||
private val nftRuntimeStoresMutex = Mutex()
|
||||
private val nftPersistenceStores = ConcurrentHashMap<String, NFTPersistenceStore>()
|
||||
|
||||
private val collectionIdConverter = NFTSdkCollectionIdentifierConverter
|
||||
|
|
@ -426,16 +429,17 @@ internal class DefaultNFTRepository @Inject constructor(
|
|||
|
||||
private suspend fun getNFTRuntimeStore(userWalletId: UserWalletId, network: Network): NFTRuntimeStore {
|
||||
val storeId = (userWalletId to network).formatted()
|
||||
return nftRuntimeStores.getOrPut(storeId) {
|
||||
nftRuntimeStoreFactory.provide(network).also {
|
||||
nftRuntimeStores[storeId] = it
|
||||
val storedCollections = getStoredCollections(userWalletId, network)
|
||||
val storedPrices = getStoredPrices(userWalletId, network)
|
||||
it.initialize(
|
||||
collections = storedCollections,
|
||||
prices = storedPrices,
|
||||
)
|
||||
}
|
||||
return nftRuntimeStoresMutex.withLock {
|
||||
nftRuntimeStores[storeId]?.let { return it }
|
||||
val store = nftRuntimeStoreFactory.provide(network)
|
||||
val storedCollections = getStoredCollections(userWalletId, network)
|
||||
val storedPrices = getStoredPrices(userWalletId, network)
|
||||
store.initialize(
|
||||
collections = storedCollections,
|
||||
prices = storedPrices,
|
||||
)
|
||||
nftRuntimeStores[storeId] = store
|
||||
store
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,15 +34,15 @@ class GetNFTCollectionsUseCase(
|
|||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun invokeForAccounts(userWalletId: UserWalletId): Flow<WalletNFTCollections> {
|
||||
fun Account.flowOfNFTCollections(): Flow<Pair<Account, List<NFTCollections>>> {
|
||||
fun Account.flowOfNFTCollections(): Flow<Pair<Account, List<NFTCollections>>>? {
|
||||
val currencies = (this as? Account.CryptoPortfolio)?.cryptoCurrencies.orEmpty()
|
||||
|
||||
if (currencies.isEmpty()) return null
|
||||
return nftCollections(userWalletId = userWalletId, cryptoCurrencies = currencies.toList())
|
||||
.map { nfts -> this to nfts }
|
||||
}
|
||||
|
||||
return singleAccountListSupplier(userWalletId)
|
||||
.mapLatest { statusList -> statusList.accounts.map { it.flowOfNFTCollections() } }
|
||||
.mapLatest { statusList -> statusList.accounts.mapNotNull { it.flowOfNFTCollections() } }
|
||||
.flatMapLatest { flows -> combine(flows) { WalletNFTCollections(it.toMap()) } }
|
||||
}
|
||||
|
||||
|
|
@ -53,6 +53,7 @@ class GetNFTCollectionsUseCase(
|
|||
val networks = cryptoCurrencies
|
||||
.map { cryptoCurrency -> cryptoCurrency.network }
|
||||
.distinct()
|
||||
if (networks.isEmpty()) return flowOf(emptyList())
|
||||
return nftRepository.observeCollections(userWalletId, networks)
|
||||
}
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ internal class UpdateDataStateTransformer(
|
|||
if (isAccountMode) {
|
||||
val result = mutableListOf<NFTCollectionItem>()
|
||||
walletNFTCollections.collections.forEach { (account, nfts) ->
|
||||
if (nfts.isEmpty()) return@forEach
|
||||
if (nfts.hasNoContentCollections()) return@forEach
|
||||
result.add(account.toAccountPortfolioUM())
|
||||
result.addAll(createNFTsUM(nfts))
|
||||
}
|
||||
|
|
@ -105,6 +105,12 @@ internal class UpdateDataStateTransformer(
|
|||
),
|
||||
)
|
||||
|
||||
private fun List<NFTCollections>.hasNoContentCollections() = this
|
||||
.all { it.contentCollections().isEmpty() }
|
||||
|
||||
private fun NFTCollections.contentCollections() = (this.content as? NFTCollections.Content.Collections)
|
||||
?.collections.orEmpty()
|
||||
|
||||
private fun NFTCollectionsStateUM.createNFTsUM(nftCollections: List<NFTCollections>): Sequence<NFTCollectionUM> =
|
||||
nftCollections
|
||||
.map { it.content }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue