Updated on 2026-08-14
This commit is contained in:
parent
0bd68de818
commit
546a9decb0
7 changed files with 42 additions and 20 deletions
|
|
@ -37,7 +37,7 @@ internal object NFTDomainModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providesRefreshAllUseCase(
|
||||
fun providesRefreshAllNFTUseCase(
|
||||
currenciesRepository: CurrenciesRepository,
|
||||
nftRepository: NFTRepository,
|
||||
): RefreshAllNFTUseCase = RefreshAllNFTUseCase(
|
||||
|
|
|
|||
|
|
@ -96,21 +96,33 @@ internal class DefaultNFTRuntimeStore(
|
|||
|
||||
private fun NFTCollections.Content.Collections.mergeWithPrices(prices: Map<NFTAsset.Identifier, NFTSalePrice>) =
|
||||
copy(
|
||||
collections = this.collections?.map { data ->
|
||||
data.copy(
|
||||
assets = when (val assets = data.assets) {
|
||||
collections = this.collections
|
||||
?.map { data ->
|
||||
val assets = when (val assets = data.assets) {
|
||||
is NFTCollection.Assets.Empty,
|
||||
is NFTCollection.Assets.Loading,
|
||||
is NFTCollection.Assets.Failed,
|
||||
-> assets
|
||||
is NFTCollection.Assets.Value -> assets.copy(
|
||||
items = assets.items.map { asset ->
|
||||
asset.mergeWithPrice(prices[asset.id] ?: NFTSalePrice.Empty(asset.id))
|
||||
},
|
||||
items = assets.items
|
||||
.filter { !it.name.isNullOrEmpty() }
|
||||
.sortedBy { it.name }
|
||||
.map { asset ->
|
||||
asset.mergeWithPrice(prices[asset.id] ?: NFTSalePrice.Empty(asset.id))
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
},
|
||||
}
|
||||
val assetsCount = when (assets) {
|
||||
is NFTCollection.Assets.Value -> assets.items.size
|
||||
else -> data.count
|
||||
}
|
||||
data.copy(
|
||||
assets = assets,
|
||||
count = assetsCount,
|
||||
)
|
||||
}
|
||||
?.filter { it.count > 0 }
|
||||
?.sortedBy { it.name },
|
||||
source = this.source,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.domain.nft
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.nft.repository.NFTRepository
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
|
@ -9,7 +10,7 @@ class RefreshAllNFTUseCase(
|
|||
private val nftRepository: NFTRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(userWalletId: UserWalletId) {
|
||||
suspend operator fun invoke(userWalletId: UserWalletId): Either<Throwable, Unit> = Either.catch {
|
||||
val currencies = currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId)
|
||||
nftRepository.refreshAll(userWalletId, currencies.map { it.network }.distinct())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ dependencies {
|
|||
implementation(deps.androidx.datastore)
|
||||
|
||||
/** Other libraries */
|
||||
implementation(deps.arrow.core)
|
||||
implementation(deps.kotlin.immutable.collections)
|
||||
implementation(deps.kotlin.serialization)
|
||||
implementation(deps.timber)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ import com.tangem.utils.transformer.Transformer
|
|||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
internal class ChangeCollectionExpandedStateTransformer(
|
||||
private val collectionId: NFTCollection.Identifier,
|
||||
private val collection: NFTCollection,
|
||||
private val collectionIdProvider: NFTCollection.() -> String,
|
||||
private val onFirstExpanded: () -> Unit,
|
||||
) : Transformer<NFTCollectionsStateUM> {
|
||||
|
||||
|
|
@ -19,7 +20,8 @@ internal class ChangeCollectionExpandedStateTransformer(
|
|||
-> prevState.content
|
||||
is NFTCollectionsUM.Content -> prevState.content.copy(
|
||||
collections = prevState.content.collections.map {
|
||||
if (it.id == collectionId.toString()) {
|
||||
val collectionId = collection.collectionIdProvider()
|
||||
if (it.id == collectionId) {
|
||||
if (!it.isExpanded) {
|
||||
onFirstExpanded()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ internal class UpdateDataStateTransformer(
|
|||
private val onRetryAssetsClick: (NFTCollection) -> Unit,
|
||||
private val onAssetClick: (NFTAsset, String) -> Unit,
|
||||
private val initialSearchBarFactory: () -> SearchBarUM,
|
||||
private val collectionIdProvider: NFTCollection.() -> String,
|
||||
) : Transformer<NFTCollectionsStateUM> {
|
||||
|
||||
override fun transform(prevState: NFTCollectionsStateUM): NFTCollectionsStateUM {
|
||||
|
|
@ -47,9 +48,7 @@ internal class UpdateDataStateTransformer(
|
|||
else -> {
|
||||
NFTCollectionsUM.Content(
|
||||
search = if (prevState.content is NFTCollectionsUM.Content) {
|
||||
prevState.content.search.copy(
|
||||
query = searchQuery,
|
||||
)
|
||||
prevState.content.search
|
||||
} else {
|
||||
initialSearchBarFactory()
|
||||
},
|
||||
|
|
@ -100,7 +99,7 @@ internal class UpdateDataStateTransformer(
|
|||
|
||||
if (collectionFulfillQuery || assetsFulfillQuery) {
|
||||
NFTCollectionUM(
|
||||
id = it.id.toString(),
|
||||
id = it.collectionIdProvider(),
|
||||
networkIconId = getActiveIconRes(it.network.id.value),
|
||||
name = it.name,
|
||||
description = TextReference.PluralRes(
|
||||
|
|
@ -165,7 +164,7 @@ internal class UpdateDataStateTransformer(
|
|||
private fun NFTCollection.isExpanded(state: NFTCollectionsStateUM): Boolean =
|
||||
(state.content as? NFTCollectionsUM.Content)
|
||||
?.collections
|
||||
?.firstOrNull { it.id == id.toString() }
|
||||
?.firstOrNull { it.id == this.collectionIdProvider() }
|
||||
?.isExpanded
|
||||
?: false
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ import com.tangem.features.nft.impl.R
|
|||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
|
|
@ -57,9 +58,12 @@ internal class NFTCollectionsModel @Inject constructor(
|
|||
),
|
||||
),
|
||||
)
|
||||
|
||||
val state: StateFlow<NFTCollectionsStateUM> get() = _state
|
||||
|
||||
private val collectionIdProvider: NFTCollection.() -> String = {
|
||||
"${network.name}_${network.derivationPath.value}_$id"
|
||||
}
|
||||
|
||||
init {
|
||||
subscribeToNFTCollections()
|
||||
}
|
||||
|
|
@ -83,6 +87,7 @@ internal class NFTCollectionsModel @Inject constructor(
|
|||
params.onAssetClick(asset, collectionName)
|
||||
},
|
||||
initialSearchBarFactory = ::getInitialSearchBar,
|
||||
collectionIdProvider = collectionIdProvider,
|
||||
).transform(it)
|
||||
}
|
||||
}
|
||||
|
|
@ -95,6 +100,7 @@ internal class NFTCollectionsModel @Inject constructor(
|
|||
_state.update { ChangeRefreshingStateTransformer(true).transform(it) }
|
||||
try {
|
||||
refreshAllNFTUseCase(params.userWalletId)
|
||||
.onLeft { Timber.e(it) }
|
||||
} finally {
|
||||
_state.update { ChangeRefreshingStateTransformer(false).transform(it) }
|
||||
}
|
||||
|
|
@ -126,7 +132,8 @@ internal class NFTCollectionsModel @Inject constructor(
|
|||
private fun onExpandCollectionClick(collection: NFTCollection) {
|
||||
_state.update {
|
||||
ChangeCollectionExpandedStateTransformer(
|
||||
collectionId = collection.id,
|
||||
collection = collection,
|
||||
collectionIdProvider = collectionIdProvider,
|
||||
onFirstExpanded = { onFirstExpanded(collection) },
|
||||
).transform(it)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue