Updated on 2026-08-14
This commit is contained in:
parent
3a4ba6dd5a
commit
3920719b01
6 changed files with 123 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ import com.tangem.domain.wallets.models.UserWalletId
|
|||
import com.tangem.pagination.*
|
||||
import com.tangem.pagination.fetcher.LimitOffsetBatchFetcher
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
|
||||
|
|
@ -262,6 +263,14 @@ internal class DefaultMarketsTokenRepository(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun getTokenExchanges(tokenId: String): List<TokenMarketExchange> {
|
||||
return withContext(dispatcherProvider.io) {
|
||||
val response = marketsApi.getCoinExchanges(coinId = tokenId).getOrThrow()
|
||||
|
||||
TokenMarketExchangeConverter.convertList(input = response.exchanges)
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <T> catchApiErrorAndSendEvent(errorEvent: MarketsDataAnalyticsEvent, block: () -> T): T {
|
||||
return try {
|
||||
block()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package com.tangem.data.markets.converters
|
||||
|
||||
import com.tangem.datasource.api.markets.models.response.TokenMarketExchangesResponse
|
||||
import com.tangem.domain.markets.TokenMarketExchange
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
||||
/**
|
||||
* Converter from [TokenMarketExchangesResponse.Exchange] to [TokenMarketExchange]
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal object TokenMarketExchangeConverter : Converter<TokenMarketExchangesResponse.Exchange, TokenMarketExchange> {
|
||||
|
||||
private val RISKY_INTERVAL = 0..3
|
||||
private val CAUTION_INTERVAL = 4..7
|
||||
|
||||
override fun convert(value: TokenMarketExchangesResponse.Exchange): TokenMarketExchange {
|
||||
return with(value) {
|
||||
TokenMarketExchange(
|
||||
id = id,
|
||||
name = name,
|
||||
imageUrl = imageUrl,
|
||||
isCentralized = isCentralized,
|
||||
volumeInUsd = volumeInUsd,
|
||||
trustScore = when (trustScore) {
|
||||
null,
|
||||
in RISKY_INTERVAL,
|
||||
-> TokenMarketExchange.TrustScore.Risky
|
||||
in CAUTION_INTERVAL -> TokenMarketExchange.TrustScore.Caution
|
||||
else -> TokenMarketExchange.TrustScore.Trusted
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue