Updated on 2026-08-14

This commit is contained in:
Tangem 2023-01-23 17:01:05 +03:00
parent 8f78031374
commit 2756dc5687
24 changed files with 843 additions and 314 deletions

View file

@ -24,6 +24,14 @@ class OneInchApisModule {
apiFactory.putApi(ETH_NETWORK, createOneInchApiWithUrl(ONE_INCH_BASE_URL + ONE_INCH_ETH_PATH, moshi))
apiFactory.putApi(BSC_NETWORK, createOneInchApiWithUrl(ONE_INCH_BASE_URL + ONE_INCH_BSC_PATH, moshi))
apiFactory.putApi(POLYGON_NETWORK, createOneInchApiWithUrl(ONE_INCH_BASE_URL + ONE_INCH_POLYGON_PATH, moshi))
apiFactory.putApi(OPTIMISM_NETWORK, createOneInchApiWithUrl(ONE_INCH_BASE_URL + ONE_INCH_OPTIMISM_PATH, moshi))
apiFactory.putApi(ARBITRUM_NETWORK, createOneInchApiWithUrl(ONE_INCH_BASE_URL + ONE_INCH_ARBITRUM_PATH, moshi))
apiFactory.putApi(GNOSIS_NETWORK, createOneInchApiWithUrl(ONE_INCH_BASE_URL + ONE_INCH_GNOSIS_PATH, moshi))
apiFactory.putApi(
AVALANCHE_NETWORK,
createOneInchApiWithUrl(ONE_INCH_BASE_URL + ONE_INCH_AVALANCHE_PATH, moshi),
)
apiFactory.putApi(FANTOM_NETWORK, createOneInchApiWithUrl(ONE_INCH_BASE_URL + ONE_INCH_FANTOM_PATH, moshi))
return apiFactory
}
@ -47,9 +55,19 @@ class OneInchApisModule {
private const val ONE_INCH_ETH_PATH = "1/"
private const val ONE_INCH_BSC_PATH = "56/"
private const val ONE_INCH_POLYGON_PATH = "137/"
private const val ONE_INCH_OPTIMISM_PATH = "10/"
private const val ONE_INCH_ARBITRUM_PATH = "42161/"
private const val ONE_INCH_GNOSIS_PATH = "100/"
private const val ONE_INCH_AVALANCHE_PATH = "43114/"
private const val ONE_INCH_FANTOM_PATH = "250/"
private const val ETH_NETWORK = "ethereum"
private const val BSC_NETWORK = "binance-smart-chain"
private const val POLYGON_NETWORK = "polygon-pos"
private const val OPTIMISM_NETWORK = "optimistic-ethereum"
private const val ARBITRUM_NETWORK = "arbitrum-one"
private const val GNOSIS_NETWORK = "xdai"
private const val AVALANCHE_NETWORK = "avalanche"
private const val FANTOM_NETWORK = "fantom"
}
}

View file

@ -23,6 +23,25 @@ fun BigDecimal.toFormattedString(
return df.format(this)
}
@Suppress("MagicNumber")
fun BigDecimal.toFormattedCurrencyString(
decimals: Int,
currency: String,
roundingMode: RoundingMode = RoundingMode.DOWN,
limitNumberOfDecimals: Boolean = true,
): String {
val decimalsForRounding = if (limitNumberOfDecimals) {
if (decimals > 8) 8 else decimals
} else {
decimals
}
val formattedAmount = this.toFormattedString(
decimals = decimalsForRounding,
roundingMode = roundingMode,
)
return "$formattedAmount $currency"
}
fun BigDecimal.toFiatString(
rateValue: BigDecimal,
fiatCurrencyName: String,