Updated on 2026-08-14

This commit is contained in:
Tangem 2022-02-23 17:27:29 +03:00
parent 3e65b44408
commit 6d91b2e30b
9 changed files with 338 additions and 31 deletions

View file

@ -15,6 +15,7 @@ import com.tangem.tap.domain.extensions.getCustomIconUrl
import com.tangem.tap.domain.extensions.setCustomIconUrl
import com.tangem.tap.features.demo.DemoHelper
import com.tangem.tap.network.createMoshi
import timber.log.Timber
class CurrenciesRepository(val context: Application) {
@ -122,16 +123,21 @@ class CurrenciesRepository(val context: Application) {
getSupportedTokens()
}
val blockchainTokens = supportedTokens.map {
fromJsonToTokensDao(loadTokensJson(it), it)
val blockchainTokens = supportedTokens.mapNotNull { blockchain ->
loadTokensJson(blockchain)?.let { fromJsonToTokensDao(it, blockchain) }
}
val tokens = blockchainTokens.flatten().map { it.toToken() }
return tokens
}
private fun loadTokensJson(blockchain: Blockchain): String {
private fun loadTokensJson(blockchain: Blockchain): String? {
val fileName = getFileName(blockchain)
return context.assets.readJsonFileToString(fileName)
return try {
context.assets.readJsonFileToString(fileName)
} catch (ex: Exception) {
Timber.e(ex, "Tokens with the file name %s not found", fileName)
null
}
}
private fun getFileName(blockchain: Blockchain): String {
@ -148,12 +154,12 @@ class CurrenciesRepository(val context: Application) {
private fun getSupportedTokens(): List<Blockchain> {
return listOf(
Blockchain.Avalanche,
Blockchain.Binance,
Blockchain.BSC,
Blockchain.Ethereum,
Blockchain.BSC,
Blockchain.Binance,
Blockchain.Polygon,
Blockchain.Solana,
Blockchain.Avalanche,
Blockchain.Fantom,
)
}
@ -169,10 +175,11 @@ class CurrenciesRepository(val context: Application) {
return excludeUnsupportedBlockchains(blockchains)
}
// Use this list to temporarily exclude a blockchain from the list of tokens.
private fun excludeUnsupportedBlockchains(blockchains: List<Blockchain>): List<Blockchain> {
return blockchains.toMutableList().apply {
removeAll(listOf(
// Blockchain.Fantom, Blockchain.FantomTestnet
// Any blockchain
))
}
}
@ -187,6 +194,13 @@ class CurrenciesRepository(val context: Application) {
}
}
fun Blockchain.getTokensName(): String {
return when (this) {
Blockchain.Fantom -> "Fantom Opera"
else -> this.fullName
}
}
@JsonClass(generateAdapter = true)
data class TokenDao(
val name: String,