Updated on 2026-08-14

This commit is contained in:
Tangem 2024-07-29 14:14:28 +03:00
parent 258af22842
commit eeec58e676
47 changed files with 658 additions and 123 deletions

View file

@ -19,6 +19,7 @@ internal class DefaultMarketsTokenRepository(
) : MarketsTokenRepository {
private val tokenListConverter = TokenMarketListConverter()
private val tokenChartConverter = TokenChartConverter()
private fun createTokenMarketsFetcher(firstBatchSize: Int, nextBatchSize: Int) = LimitOffsetBatchFetcher(
prefetchDistance = firstBatchSize,
@ -89,4 +90,13 @@ internal class DefaultMarketsTokenRepository(
updateFetcher = tokenMarketsUpdateFetcher,
).toBatchFlow()
}
override suspend fun getChart(interval: PriceChangeInterval, tokenId: String): TokenChart {
val response = marketsApi.getCoinChart(
currency = tokenId,
interval = interval.toRequestParam(),
)
return tokenChartConverter.convert(interval, response.getOrThrow())
}
}

View file

@ -1,6 +1,6 @@
package com.tangem.data.markets
import com.tangem.data.markets.converters.TokenListChartConverter
import com.tangem.data.markets.converters.TokenChartConverter
import com.tangem.data.markets.converters.TokenMarketChartsConverter
import com.tangem.data.markets.converters.TokenQuotesConverter
import com.tangem.data.markets.converters.toRequestParam
@ -21,7 +21,7 @@ internal class MarketsBatchUpdateFetcher(
private val tangemTechApi: TangemTechApi,
) : BatchUpdateFetcher<Int, List<TokenMarket>, TokenMarketUpdateRequest> {
private val tokenListChartsConverter = TokenMarketChartsConverter(TokenListChartConverter())
private val tokenListChartsConverter = TokenMarketChartsConverter(TokenChartConverter())
private val tokenQuotesConverter = TokenQuotesConverter()
override suspend fun BatchUpdateFetcher.UpdateContext<Int, List<TokenMarket>>.fetchUpdateAsync(

View file

@ -4,13 +4,13 @@ import com.tangem.datasource.api.markets.models.response.TokenMarketChartRespons
import com.tangem.domain.markets.PriceChangeInterval
import com.tangem.domain.markets.TokenChart
class TokenListChartConverter {
class TokenChartConverter {
fun convert(interval: PriceChangeInterval, value: TokenMarketChartResponse): TokenChart {
return TokenChart(
interval = interval,
priceY = value.prices.values.toList(),
timeStamp = value.prices.keys.toList(),
timeStamps = value.prices.keys.toList(),
)
}
}

View file

@ -5,7 +5,7 @@ import com.tangem.domain.markets.PriceChangeInterval
import com.tangem.domain.markets.TokenMarket
class TokenMarketChartsConverter(
private val tokenListChartConverter: TokenListChartConverter,
private val tokenChartConverter: TokenChartConverter,
) {
fun convert(
@ -19,13 +19,13 @@ class TokenMarketChartsConverter(
}
return when (interval) {
PriceChangeInterval.H24 -> chartsToCopy.copy(
h24 = tokenListChartConverter.convert(interval, prices),
h24 = tokenChartConverter.convert(interval, prices),
)
PriceChangeInterval.WEEK -> chartsToCopy.copy(
week = tokenListChartConverter.convert(interval, prices),
week = tokenChartConverter.convert(interval, prices),
)
PriceChangeInterval.MONTH -> chartsToCopy.copy(
month = tokenListChartConverter.convert(interval, prices),
month = tokenChartConverter.convert(interval, prices),
)
else -> error("unsupported interval=$interval. This shouldn't have happened.")
}