Updated on 2026-08-14
This commit is contained in:
parent
296df28f0a
commit
bc70ed5327
8 changed files with 57 additions and 41 deletions
|
|
@ -9,7 +9,6 @@ import com.tangem.domain.nft.models.NFTSalePrice
|
|||
import com.tangem.domain.tokens.model.Network
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
internal class DefaultNFTRuntimeStore(
|
||||
|
|
@ -25,9 +24,7 @@ internal class DefaultNFTRuntimeStore(
|
|||
|
||||
override fun getCollections(): Flow<NFTCollections> = collectionsRuntimeStore
|
||||
.get()
|
||||
.combine(pricesRuntimeStore.get(), ::Pair)
|
||||
.map {
|
||||
val (collectionsData, prices) = it
|
||||
.combine(pricesRuntimeStore.get()) { collectionsData, prices ->
|
||||
collectionsData.mergeWithPrices(prices)
|
||||
}
|
||||
|
||||
|
|
@ -48,9 +45,7 @@ internal class DefaultNFTRuntimeStore(
|
|||
override fun getAsset(collectionId: NFTCollection.Identifier, assetId: NFTAsset.Identifier): Flow<NFTAsset> =
|
||||
collectionsRuntimeStore
|
||||
.get()
|
||||
.combine(getSalePrice(assetId), ::Pair)
|
||||
.map {
|
||||
val (collectionsData, price) = it
|
||||
.combine(getSalePrice(assetId)) { collectionsData, price ->
|
||||
collectionsData
|
||||
.getCollection(collectionId)
|
||||
?.getAsset(assetId)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,17 @@ class NFTPersistenceStoreFactory @Inject constructor(
|
|||
) {
|
||||
|
||||
fun provide(network: Network): NFTPersistenceStore {
|
||||
val networkStringIdentifier = listOfNotNull(
|
||||
network.id.value,
|
||||
network.derivationPath.value,
|
||||
).joinToString("_") {
|
||||
// remove all non-alphanumeric characters
|
||||
it
|
||||
.toCharArray()
|
||||
.filter(Char::isLetterOrDigit)
|
||||
.joinToString("")
|
||||
.lowercase()
|
||||
}
|
||||
return DefaultNFTPersistenceStore(
|
||||
collectionsPersistenceStore = DataStoreFactory.create(
|
||||
serializer = MoshiDataStoreSerializer(
|
||||
|
|
@ -34,7 +45,7 @@ class NFTPersistenceStoreFactory @Inject constructor(
|
|||
defaultValue = emptyList(),
|
||||
),
|
||||
produceFile = {
|
||||
context.dataStoreFile(fileName = "nft_${network.name}_${network.derivationPath}_collections")
|
||||
context.dataStoreFile(fileName = "nft_${networkStringIdentifier}_collections")
|
||||
},
|
||||
scope = CoroutineScope(context = dispatchers.io + SupervisorJob()),
|
||||
),
|
||||
|
|
@ -45,7 +56,7 @@ class NFTPersistenceStoreFactory @Inject constructor(
|
|||
defaultValue = emptyMap(),
|
||||
),
|
||||
produceFile = {
|
||||
context.dataStoreFile(fileName = "nft_${network.name}_${network.derivationPath}_prices")
|
||||
context.dataStoreFile(fileName = "nft_${networkStringIdentifier}_prices")
|
||||
},
|
||||
scope = CoroutineScope(context = dispatchers.io + SupervisorJob()),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import com.tangem.domain.nft.models.NFTAsset
|
|||
import com.tangem.utils.converter.TwoWayConverter
|
||||
import com.tangem.blockchain.nft.models.NFTAsset as SdkNFTAsset
|
||||
|
||||
class NFTSdkAssetIdentifierConverter : TwoWayConverter<SdkNFTAsset.Identifier, NFTAsset.Identifier> {
|
||||
object NFTSdkAssetIdentifierConverter : TwoWayConverter<SdkNFTAsset.Identifier, NFTAsset.Identifier> {
|
||||
override fun convert(value: SdkNFTAsset.Identifier): NFTAsset.Identifier = when (value) {
|
||||
is SdkNFTAsset.Identifier.EVM -> NFTAsset.Identifier.EVM(
|
||||
tokenId = value.tokenId,
|
||||
|
|
@ -13,7 +13,7 @@ class NFTSdkAssetIdentifierConverter : TwoWayConverter<SdkNFTAsset.Identifier, N
|
|||
is SdkNFTAsset.Identifier.TON -> NFTAsset.Identifier.TON(
|
||||
tokenAddress = value.tokenAddress,
|
||||
)
|
||||
is SdkNFTAsset.Identifier.Unknown -> error("unknown asset id")
|
||||
is SdkNFTAsset.Identifier.Unknown -> NFTAsset.Identifier.Unknown
|
||||
}
|
||||
|
||||
override fun convertBack(value: NFTAsset.Identifier): SdkNFTAsset.Identifier = when (value) {
|
||||
|
|
@ -24,5 +24,6 @@ class NFTSdkAssetIdentifierConverter : TwoWayConverter<SdkNFTAsset.Identifier, N
|
|||
is NFTAsset.Identifier.TON -> SdkNFTAsset.Identifier.TON(
|
||||
tokenAddress = value.tokenAddress,
|
||||
)
|
||||
is NFTAsset.Identifier.Unknown -> SdkNFTAsset.Identifier.Unknown
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.datasource.local.nft.converter
|
||||
|
||||
import com.tangem.domain.nft.models.NFTAsset
|
||||
import com.tangem.domain.nft.models.NFTCollection
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
|
@ -19,9 +20,13 @@ class NFTSdkCollectionConverter(
|
|||
description = collection.description,
|
||||
logoUrl = collection.logoUrl,
|
||||
count = collection.count,
|
||||
assets = collection.assets.map { asset ->
|
||||
nftSdkAssetConverter.convert(network to asset)
|
||||
},
|
||||
assets = collection.assets
|
||||
.map { asset ->
|
||||
nftSdkAssetConverter.convert(network to asset)
|
||||
}
|
||||
.filter {
|
||||
it.id !is NFTAsset.Identifier.Unknown
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import com.tangem.domain.nft.models.NFTCollection
|
|||
import com.tangem.utils.converter.TwoWayConverter
|
||||
import com.tangem.blockchain.nft.models.NFTCollection as SdkNFTCollection
|
||||
|
||||
class NFTSdkCollectionIdentifierConverter : TwoWayConverter<SdkNFTCollection.Identifier, NFTCollection.Identifier> {
|
||||
object NFTSdkCollectionIdentifierConverter : TwoWayConverter<SdkNFTCollection.Identifier, NFTCollection.Identifier> {
|
||||
override fun convert(value: SdkNFTCollection.Identifier): NFTCollection.Identifier = when (value) {
|
||||
is SdkNFTCollection.Identifier.EVM -> NFTCollection.Identifier.EVM(
|
||||
tokenAddress = value.tokenAddress,
|
||||
|
|
@ -12,7 +12,7 @@ class NFTSdkCollectionIdentifierConverter : TwoWayConverter<SdkNFTCollection.Ide
|
|||
is SdkNFTCollection.Identifier.TON -> NFTCollection.Identifier.TON(
|
||||
contractAddress = value.contractAddress,
|
||||
)
|
||||
is SdkNFTCollection.Identifier.Unknown -> error("unknown collection id")
|
||||
is SdkNFTCollection.Identifier.Unknown -> NFTCollection.Identifier.Unknown
|
||||
}
|
||||
|
||||
override fun convertBack(value: NFTCollection.Identifier): SdkNFTCollection.Identifier = when (value) {
|
||||
|
|
@ -22,5 +22,6 @@ class NFTSdkCollectionIdentifierConverter : TwoWayConverter<SdkNFTCollection.Ide
|
|||
is NFTCollection.Identifier.TON -> SdkNFTCollection.Identifier.TON(
|
||||
contractAddress = value.contractAddress,
|
||||
)
|
||||
is NFTCollection.Identifier.Unknown -> SdkNFTCollection.Identifier.Unknown
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue