From f76f28ae0c3fb4165e2a6bc53799a0247cf02b0f Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 8 Jul 2025 16:02:56 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../transformer/NFTPriceChangeTransformer.kt | 69 ++++++++++++------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/features/nft/impl/src/main/kotlin/com/tangem/features/nft/details/entity/transformer/NFTPriceChangeTransformer.kt b/features/nft/impl/src/main/kotlin/com/tangem/features/nft/details/entity/transformer/NFTPriceChangeTransformer.kt index 8ab05b6d7b..ff99321696 100644 --- a/features/nft/impl/src/main/kotlin/com/tangem/features/nft/details/entity/transformer/NFTPriceChangeTransformer.kt +++ b/features/nft/impl/src/main/kotlin/com/tangem/features/nft/details/entity/transformer/NFTPriceChangeTransformer.kt @@ -1,5 +1,6 @@ package com.tangem.features.nft.details.entity.transformer +import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.format.bigdecimal.crypto import com.tangem.core.ui.format.bigdecimal.fiat @@ -8,6 +9,7 @@ import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.nft.models.NFTSalePrice import com.tangem.features.nft.details.entity.NFTAssetUM import com.tangem.features.nft.details.entity.NFTDetailsUM +import com.tangem.features.nft.impl.R import com.tangem.utils.transformer.Transformer internal class NFTPriceChangeTransformer( @@ -18,35 +20,50 @@ internal class NFTPriceChangeTransformer( override fun transform(prevState: NFTDetailsUM): NFTDetailsUM { val topInfo = prevState.nftAsset.topInfo as? NFTAssetUM.TopInfo.Content ?: return prevState - return prevState.copy( - nftAsset = prevState.nftAsset.copy( - topInfo = topInfo.copy( - salePrice = when (nftSalePrice) { - is NFTSalePrice.Empty, - is NFTSalePrice.Error, - -> NFTAssetUM.SalePrice.Empty - is NFTSalePrice.Loading -> NFTAssetUM.SalePrice.Loading - is NFTSalePrice.Value -> NFTAssetUM.SalePrice.Content( - isFlickering = false, - cryptoPrice = stringReference( - nftSalePrice.value.format { - crypto( - symbol = nftSalePrice.symbol, - decimals = nftSalePrice.decimals, - ) - }, - ), - fiatPrice = stringReference( - nftSalePrice.fiatValue.format { - fiat( - fiatCurrencyCode = appCurrency.code, - fiatCurrencySymbol = appCurrency.symbol, - ) - }, - ), + val salePrice = when (nftSalePrice) { + is NFTSalePrice.Empty, + is NFTSalePrice.Error, + -> NFTAssetUM.SalePrice.Empty + is NFTSalePrice.Loading -> NFTAssetUM.SalePrice.Loading + is NFTSalePrice.Value -> NFTAssetUM.SalePrice.Content( + isFlickering = false, + cryptoPrice = stringReference( + nftSalePrice.value.format { + crypto( + symbol = nftSalePrice.symbol, + decimals = nftSalePrice.decimals, ) }, ), + fiatPrice = stringReference( + nftSalePrice.fiatValue.format { + fiat( + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, + ) + }, + ), + ) + } + + val hasSalePrice = salePrice !is NFTAssetUM.SalePrice.Empty + + val newTopInfo = if ( + topInfo.rarity is NFTAssetUM.Rarity.Empty && + topInfo.description.isNullOrEmpty() && + !hasSalePrice + ) { + NFTAssetUM.TopInfo.Empty + } else { + topInfo.copy( + title = resourceReference(R.string.nft_details_last_sale_price).takeIf { hasSalePrice }, + salePrice = salePrice, + ) + } + + return prevState.copy( + nftAsset = prevState.nftAsset.copy( + topInfo = newTopInfo, ), ) }