Updated on 2026-08-14
This commit is contained in:
parent
d614f69161
commit
4aa74c4b70
21 changed files with 397 additions and 70 deletions
|
|
@ -0,0 +1,13 @@
|
|||
package com.tangem.datasource.api.common.adapter
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.math.BigInteger
|
||||
|
||||
internal class BigIntegerAdapter {
|
||||
@FromJson
|
||||
fun fromJson(value: String) = BigInteger(value)
|
||||
|
||||
@ToJson
|
||||
fun toJson(value: BigInteger) = value.toString()
|
||||
}
|
||||
|
|
@ -6,10 +6,7 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
|||
import com.tangem.blockchain.nft.models.NFTAsset
|
||||
import com.tangem.blockchain.nft.models.NFTCollection
|
||||
import com.tangem.common.json.MoshiJsonConverter
|
||||
import com.tangem.datasource.api.common.adapter.BigDecimalAdapter
|
||||
import com.tangem.datasource.api.common.adapter.DateTimeAdapter
|
||||
import com.tangem.datasource.api.common.adapter.LocalDateAdapter
|
||||
import com.tangem.datasource.api.common.adapter.addStakeKitEnumFallbackAdapters
|
||||
import com.tangem.datasource.api.common.adapter.*
|
||||
import com.tangem.datasource.local.config.providers.models.ProviderModel
|
||||
import com.tangem.datasource.local.network.entity.NetworkStatusDM
|
||||
import com.tangem.domain.models.scan.serialization.*
|
||||
|
|
@ -38,6 +35,7 @@ class MoshiModule {
|
|||
.withDefaultValue(ProviderModel.UnsupportedType),
|
||||
)
|
||||
.add(BigDecimalAdapter())
|
||||
.add(BigIntegerAdapter())
|
||||
.add(LocalDateAdapter())
|
||||
.add(DateTimeAdapter())
|
||||
.add(VisaActivationRemoteState.jsonAdapter)
|
||||
|
|
@ -73,6 +71,7 @@ class MoshiModule {
|
|||
val adapters = MoshiJsonConverter.getTangemSdkAdapters() +
|
||||
listOf(
|
||||
BigDecimalAdapter(),
|
||||
BigIntegerAdapter(),
|
||||
WalletDerivedKeysMapAdapter(),
|
||||
ScanResponseDerivedKeysMapAdapter(),
|
||||
ByteArrayKeyAdapter(),
|
||||
|
|
@ -100,6 +99,7 @@ class MoshiModule {
|
|||
adapters = MoshiJsonConverter.getTangemSdkAdapters() +
|
||||
listOf(
|
||||
BigDecimalAdapter(),
|
||||
BigIntegerAdapter(),
|
||||
WalletDerivedKeysMapAdapter(),
|
||||
ScanResponseDerivedKeysMapAdapter(),
|
||||
ByteArrayKeyAdapter(),
|
||||
|
|
|
|||
|
|
@ -4,14 +4,17 @@ import com.tangem.domain.models.StatusSource
|
|||
import com.tangem.domain.nft.models.NFTAsset
|
||||
import com.tangem.domain.nft.models.NFTSalePrice
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
import com.tangem.utils.converter.Converter
|
||||
import com.tangem.utils.converter.TwoWayConverter
|
||||
import com.tangem.blockchain.nft.models.NFTAsset as SdkNFTAsset
|
||||
|
||||
object NFTSdkAssetConverter : Converter<Pair<Network, SdkNFTAsset>, NFTAsset> {
|
||||
object NFTSdkAssetConverter : TwoWayConverter<Pair<Network, SdkNFTAsset>, NFTAsset> {
|
||||
override fun convert(value: Pair<Network, SdkNFTAsset>): NFTAsset {
|
||||
val (network, asset) = value
|
||||
val assetId = NFTSdkAssetIdentifierConverter.convert(asset.identifier)
|
||||
val collectionId = NFTSdkCollectionIdentifierConverter.convert(asset.collectionIdentifier)
|
||||
val salePrice = asset.salePrice?.let { NFTSdkAssetSalePriceConverter(assetId).convert(it) }
|
||||
?: NFTSalePrice.Empty(assetId)
|
||||
|
||||
return NFTAsset(
|
||||
id = assetId,
|
||||
collectionId = collectionId,
|
||||
|
|
@ -20,13 +23,9 @@ object NFTSdkAssetConverter : Converter<Pair<Network, SdkNFTAsset>, NFTAsset> {
|
|||
owner = asset.owner,
|
||||
name = asset.name,
|
||||
description = asset.description,
|
||||
salePrice = asset.salePrice?.let {
|
||||
NFTSalePrice.Value(
|
||||
assetId = assetId,
|
||||
value = it.value,
|
||||
symbol = it.symbol,
|
||||
)
|
||||
} ?: NFTSalePrice.Empty(assetId = assetId),
|
||||
amount = asset.amount,
|
||||
decimals = asset.decimals,
|
||||
salePrice = salePrice,
|
||||
rarity = asset.rarity?.let {
|
||||
NFTAsset.Rarity(
|
||||
rank = it.rank,
|
||||
|
|
@ -48,4 +47,42 @@ object NFTSdkAssetConverter : Converter<Pair<Network, SdkNFTAsset>, NFTAsset> {
|
|||
source = StatusSource.CACHE,
|
||||
)
|
||||
}
|
||||
|
||||
override fun convertBack(value: NFTAsset): Pair<Network, SdkNFTAsset> {
|
||||
val assetId = NFTSdkAssetIdentifierConverter.convertBack(value.id)
|
||||
val collectionId = NFTSdkCollectionIdentifierConverter.convertBack(value.collectionId)
|
||||
val salePrice = (value.salePrice as? NFTSalePrice.Value)?.let {
|
||||
NFTSdkAssetSalePriceConverter(value.id).convertBack(it)
|
||||
}
|
||||
return value.network to SdkNFTAsset(
|
||||
identifier = assetId,
|
||||
collectionIdentifier = collectionId,
|
||||
blockchainId = value.network.id.value,
|
||||
contractType = value.contractType,
|
||||
owner = value.owner,
|
||||
name = value.name,
|
||||
description = value.description,
|
||||
amount = value.amount,
|
||||
decimals = value.decimals,
|
||||
salePrice = salePrice,
|
||||
rarity = value.rarity?.let {
|
||||
SdkNFTAsset.Rarity(
|
||||
rank = it.rank,
|
||||
label = it.label,
|
||||
)
|
||||
},
|
||||
media = value.media?.let {
|
||||
SdkNFTAsset.Media(
|
||||
url = it.url,
|
||||
mimetype = it.mimetype,
|
||||
)
|
||||
},
|
||||
traits = value.traits.map {
|
||||
SdkNFTAsset.Trait(
|
||||
name = it.name,
|
||||
value = it.value,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ object NFTSdkAssetIdentifierConverter : TwoWayConverter<SdkNFTAsset.Identifier,
|
|||
is SdkNFTAsset.Identifier.EVM -> NFTAsset.Identifier.EVM(
|
||||
tokenId = value.tokenId,
|
||||
tokenAddress = value.tokenAddress,
|
||||
contractType = NFTAsset.Identifier.EVM.ContractType.valueOf(value.contractType.name),
|
||||
)
|
||||
is SdkNFTAsset.Identifier.TON -> NFTAsset.Identifier.TON(
|
||||
tokenAddress = value.tokenAddress,
|
||||
|
|
@ -24,6 +25,7 @@ object NFTSdkAssetIdentifierConverter : TwoWayConverter<SdkNFTAsset.Identifier,
|
|||
is NFTAsset.Identifier.EVM -> SdkNFTAsset.Identifier.EVM(
|
||||
tokenId = value.tokenId,
|
||||
tokenAddress = value.tokenAddress,
|
||||
contractType = SdkNFTAsset.Identifier.EVM.ContractType.valueOf(value.contractType.name),
|
||||
)
|
||||
is NFTAsset.Identifier.TON -> SdkNFTAsset.Identifier.TON(
|
||||
tokenAddress = value.tokenAddress,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package com.tangem.datasource.local.nft.converter
|
||||
|
||||
import com.tangem.domain.nft.models.NFTAsset
|
||||
import com.tangem.domain.nft.models.NFTSalePrice
|
||||
import com.tangem.utils.converter.TwoWayConverter
|
||||
import com.tangem.blockchain.nft.models.NFTAsset.SalePrice as SDKSalePrice
|
||||
|
||||
internal class NFTSdkAssetSalePriceConverter(
|
||||
private val assetId: NFTAsset.Identifier,
|
||||
) : TwoWayConverter<SDKSalePrice, NFTSalePrice.Value> {
|
||||
override fun convert(value: SDKSalePrice): NFTSalePrice.Value {
|
||||
return NFTSalePrice.Value(
|
||||
assetId = assetId,
|
||||
value = value.value,
|
||||
symbol = value.symbol,
|
||||
)
|
||||
}
|
||||
|
||||
override fun convertBack(value: NFTSalePrice.Value): SDKSalePrice {
|
||||
return SDKSalePrice(
|
||||
symbol = value.symbol,
|
||||
value = value.value,
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue