Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-12 14:38:46 +03:00
parent 54800d32cc
commit faa58cf142
39 changed files with 722 additions and 245 deletions

View file

@ -8,7 +8,7 @@ data class TokenMarket(
val symbol: String,
val marketRating: Int?,
val marketCap: BigDecimal?,
val tokenQuotes: TokenQuotes,
val tokenQuotesShort: TokenQuotesShort,
val tokenCharts: Charts,
private val imageHost: String,
) {

View file

@ -6,8 +6,7 @@ data class TokenMarketInfo(
val id: String,
val name: String,
val symbol: String,
val currentPrice: BigDecimal,
val priceChangePercentage: PriceChangePercentage?,
val quotes: TokenQuotes,
val networks: List<Network>?,
val shortDescription: String?,
val fullDescription: String?,
@ -16,16 +15,6 @@ data class TokenMarketInfo(
val links: Links?,
val pricePerformance: PricePerformance?,
) {
data class PriceChangePercentage(
val day: BigDecimal?,
val week: BigDecimal?,
val month: BigDecimal?,
val threeMonths: BigDecimal?,
val sixMonths: BigDecimal?,
val year: BigDecimal?,
val allTime: BigDecimal?,
)
data class Network(
val networkId: String,
val exchangeable: Boolean,

View file

@ -4,15 +4,11 @@ import java.math.BigDecimal
data class TokenQuotes(
val currentPrice: BigDecimal,
private val priceChanges: Map<PriceChangeInterval, BigDecimal>,
) {
init {
require(priceChanges.containsKey(PriceChangeInterval.H24))
require(priceChanges.containsKey(PriceChangeInterval.WEEK))
require(priceChanges.containsKey(PriceChangeInterval.MONTH))
}
fun h24Percent() = priceChanges[PriceChangeInterval.H24]!!
fun weekPercent() = priceChanges[PriceChangeInterval.WEEK]!!
fun monthPercent() = priceChanges[PriceChangeInterval.MONTH]!!
}
val h24ChangePercent: BigDecimal?,
val weekChangePercent: BigDecimal?,
val monthChangePercent: BigDecimal?,
val m3ChangePercent: BigDecimal?,
val m6ChangePercent: BigDecimal?,
val yearChangePercent: BigDecimal?,
val allTimeChangePercent: BigDecimal?,
)

View file

@ -0,0 +1,10 @@
package com.tangem.domain.markets
import java.math.BigDecimal
data class TokenQuotesShort(
val currentPrice: BigDecimal,
val h24ChangePercent: BigDecimal,
val weekChangePercent: BigDecimal,
val monthChangePercent: BigDecimal,
)

View file

@ -0,0 +1,19 @@
package com.tangem.domain.markets
import arrow.core.Either
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.markets.repositories.MarketsTokenRepository
class GetTokenQuotesUseCase(
private val marketsTokenRepository: MarketsTokenRepository,
) {
suspend operator fun invoke(appCurrency: AppCurrency, tokenId: String): Either<Unit, TokenQuotes> {
return Either.catch {
marketsTokenRepository.getTokenQuotes(
fiatCurrencyCode = appCurrency.code,
tokenId = tokenId,
)
}.mapLeft {}
}
}

View file

@ -13,4 +13,6 @@ interface MarketsTokenRepository {
suspend fun getChart(fiatCurrencyCode: String, interval: PriceChangeInterval, tokenId: String): TokenChart
suspend fun getTokenInfo(fiatCurrencyCode: String, tokenId: String, languageCode: String): TokenMarketInfo
suspend fun getTokenQuotes(fiatCurrencyCode: String, tokenId: String): TokenQuotes
}