Updated on 2026-08-14

This commit is contained in:
Tangem 2023-03-02 15:57:52 +03:00
parent 21f575fb13
commit 95fea5388f
7 changed files with 81 additions and 48 deletions

View file

@ -35,8 +35,24 @@ internal class SwapRepositoryImpl @Inject constructor(
private val approveConverter = ApproveConverter()
override suspend fun getRates(currencyId: String, tokenIds: List<String>): Map<String, Double> {
// workaround cause backend do not return arbitrum and optimism rates
val addedTokens = if (tokenIds.contains(OPTIMISM_ID) || tokenIds.contains(ARBITRUM_ID)) {
tokenIds.toMutableList().apply {
add(ETHEREUM_ID)
}
} else {
tokenIds
}
return withContext(coroutineDispatcher.io) {
tangemTechApi.getRates(currencyId.lowercase(), tokenIds.joinToString(",")).rates
val rates = tangemTechApi.getRates(currencyId.lowercase(), addedTokens.joinToString(",")).rates
val ethRate = rates[ETHEREUM_ID]
rates.mapValues {
if (it.key == OPTIMISM_ID || it.key == ARBITRUM_ID) {
ethRate ?: 0.0
} else {
it.value
}
}
}
}
@ -136,4 +152,11 @@ internal class SwapRepositoryImpl @Inject constructor(
private fun getOneInchApi(networkId: String): OneInchApi {
return oneInchApiFactory.getApi(networkId)
}
companion object {
// TODO("get this ids from blockchain enum later")
private const val OPTIMISM_ID = "optimistic-ethereum"
private const val ARBITRUM_ID = "arbitrum-one"
private const val ETHEREUM_ID = "ethereum"
}
}