Updated on 2026-08-14
This commit is contained in:
parent
400d625df1
commit
a6141bbbe5
18 changed files with 175 additions and 59 deletions
|
|
@ -2,14 +2,16 @@ package com.tangem.tap.network.coinmarketcap
|
|||
|
||||
import com.tangem.commands.common.network.Result
|
||||
import com.tangem.commands.common.network.performRequest
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.math.BigDecimal
|
||||
|
||||
class CoinMarketCapService {
|
||||
private val api: CoinMarketCapApi by lazy { CoinMarketCapApi.create() }
|
||||
|
||||
suspend fun getRate(currency: String): Result<BigDecimal> {
|
||||
suspend fun getRate(currency: String): Result<BigDecimal> = withContext(Dispatchers.IO) {
|
||||
val response = performRequest { api.getRateInfo(1, currency) }
|
||||
return when (response) {
|
||||
return@withContext when (response) {
|
||||
is Result.Success -> Result.Success(response.data.data.quote.usd.price)
|
||||
is Result.Failure -> response
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue