Updated on 2026-08-14

This commit is contained in:
Tangem 2025-06-27 15:59:43 +03:00
commit 71748eff67
517 changed files with 14212 additions and 3419 deletions

View file

@ -3,11 +3,11 @@ package com.tangem.domain.nft
import arrow.core.Either
import com.tangem.domain.models.network.Network
import com.tangem.domain.nft.repository.NFTRepository
import com.tangem.domain.quotes.single.SingleQuoteFetcher
import com.tangem.domain.quotes.single.SingleQuoteStatusFetcher
class FetchNFTPriceUseCase(
private val nftRepository: NFTRepository,
private val singleQuoteFetcher: SingleQuoteFetcher,
private val singleQuoteStatusFetcher: SingleQuoteStatusFetcher,
) {
suspend operator fun invoke(network: Network, appCurrencyId: String?): Either<Throwable, Unit> {
@ -15,8 +15,8 @@ class FetchNFTPriceUseCase(
val nftCurrency = nftRepository.getNFTCurrency(network)
val rawId = nftCurrency.id.rawCurrencyId ?: error("Invalid nft currency id")
singleQuoteFetcher(
params = SingleQuoteFetcher.Params(
singleQuoteStatusFetcher(
params = SingleQuoteStatusFetcher.Params(
rawCurrencyId = rawId,
appCurrencyId = appCurrencyId,
),

View file

@ -1,19 +1,19 @@
package com.tangem.domain.nft
import arrow.core.Either
import com.tangem.domain.models.quote.fold
import com.tangem.domain.nft.models.NFTAsset
import com.tangem.domain.nft.models.NFTSalePrice
import com.tangem.domain.nft.repository.NFTRepository
import com.tangem.domain.quotes.single.SingleQuoteProducer
import com.tangem.domain.quotes.single.SingleQuoteSupplier
import com.tangem.domain.tokens.model.Quote
import com.tangem.domain.quotes.single.SingleQuoteStatusProducer
import com.tangem.domain.quotes.single.SingleQuoteStatusSupplier
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
class GetNFTPriceUseCase(
private val nftRepository: NFTRepository,
private val singleQuoteSupplier: SingleQuoteSupplier,
private val singleQuoteStatusSupplier: SingleQuoteStatusSupplier,
) {
suspend operator fun invoke(userWalletId: UserWalletId, nftAsset: NFTAsset): Either<Throwable, Flow<NFTSalePrice>> {
@ -21,8 +21,8 @@ class GetNFTPriceUseCase(
val nftCurrency = nftRepository.getNFTCurrency(nftAsset.network)
val rawId = nftCurrency.id.rawCurrencyId ?: error("Invalid nft currency id")
singleQuoteSupplier(
params = SingleQuoteProducer.Params(rawCurrencyId = rawId),
singleQuoteStatusSupplier(
params = SingleQuoteStatusProducer.Params(rawCurrencyId = rawId),
).map { quote ->
val nftPrice = nftRepository.getNFTSalePrice(
userWalletId = userWalletId,
@ -31,12 +31,15 @@ class GetNFTPriceUseCase(
assetId = nftAsset.id,
)
val quoteValue = quote as? Quote.Value
if (nftPrice !is NFTSalePrice.Value) {
nftPrice
} else {
nftPrice.copy(fiatValue = quoteValue?.fiatRate?.multiply(nftPrice.value))
nftPrice.copy(
fiatValue = quote.fold(
onData = { fiatRate.multiply(nftPrice.value) },
onEmpty = { null },
),
)
}
}
}