Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-02 11:24:49 +03:00
parent 45db7c879f
commit e20f932081
52 changed files with 1676 additions and 813 deletions

View file

@ -91,9 +91,14 @@ internal class DefaultMarketsTokenRepository(
).toBatchFlow()
}
override suspend fun getChart(interval: PriceChangeInterval, tokenId: String): TokenChart {
override suspend fun getChart(
fiatCurrencyCode: String,
interval: PriceChangeInterval,
tokenId: String,
): TokenChart {
val response = marketsApi.getCoinChart(
currency = tokenId,
currency = fiatCurrencyCode,
coinId = tokenId,
interval = interval.toRequestParam(),
)

View file

@ -20,7 +20,7 @@ fun TokenMarketListConfig.Order.toRequestParam(): String = when (this) {
fun PriceChangeInterval.toRequestParam(): String = when (this) {
PriceChangeInterval.H24 -> "24h"
PriceChangeInterval.WEEK -> "1w"
PriceChangeInterval.MONTH -> "30d"
PriceChangeInterval.MONTH -> "1m"
PriceChangeInterval.MONTH3 -> "3m"
PriceChangeInterval.MONTH6 -> "6m"
PriceChangeInterval.YEAR -> "1y"

View file

@ -3,6 +3,7 @@ package com.tangem.data.markets.converters
import com.tangem.datasource.api.markets.models.response.TokenMarketChartListResponse
import com.tangem.domain.markets.PriceChangeInterval
import com.tangem.domain.markets.TokenMarket
import com.tangem.domain.markets.TokenMarketListConfig
class TokenMarketChartsConverter(
private val tokenChartConverter: TokenChartConverter,
@ -11,23 +12,29 @@ class TokenMarketChartsConverter(
fun convert(
chartsToCopy: TokenMarket.Charts,
tokenId: String,
interval: PriceChangeInterval,
interval: TokenMarketListConfig.Interval,
value: TokenMarketChartListResponse,
): TokenMarket.Charts {
val prices = requireNotNull(value[tokenId]) {
"$tokenId is not found in the response. This shouldn't have happened."
}
return when (interval) {
PriceChangeInterval.H24 -> chartsToCopy.copy(
h24 = tokenChartConverter.convert(interval, prices),
TokenMarketListConfig.Interval.H24 -> chartsToCopy.copy(
h24 = tokenChartConverter.convert(interval.toPriceChangeInterval(), prices),
)
PriceChangeInterval.WEEK -> chartsToCopy.copy(
week = tokenChartConverter.convert(interval, prices),
TokenMarketListConfig.Interval.WEEK -> chartsToCopy.copy(
week = tokenChartConverter.convert(interval.toPriceChangeInterval(), prices),
)
PriceChangeInterval.MONTH -> chartsToCopy.copy(
month = tokenChartConverter.convert(interval, prices),
TokenMarketListConfig.Interval.MONTH -> chartsToCopy.copy(
month = tokenChartConverter.convert(interval.toPriceChangeInterval(), prices),
)
else -> error("unsupported interval=$interval. This shouldn't have happened.")
}
}
private fun TokenMarketListConfig.Interval.toPriceChangeInterval(): PriceChangeInterval = when (this) {
TokenMarketListConfig.Interval.H24 -> PriceChangeInterval.H24
TokenMarketListConfig.Interval.WEEK -> PriceChangeInterval.WEEK
TokenMarketListConfig.Interval.MONTH -> PriceChangeInterval.MONTH
}
}