Updated on 2026-08-14
This commit is contained in:
parent
7571527c23
commit
a1e86cb6fc
8 changed files with 1731 additions and 34 deletions
|
|
@ -9,6 +9,7 @@ import com.squareup.moshi.Types
|
|||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.Token
|
||||
import com.tangem.common.card.FirmwareVersion
|
||||
import com.tangem.common.json.MoshiJsonConverter
|
||||
import com.tangem.tap.common.extensions.readJsonFileToString
|
||||
import com.tangem.tap.network.createMoshi
|
||||
|
||||
|
|
@ -113,24 +114,28 @@ class CurrenciesRepository(val context: Application) {
|
|||
if (isTestNet) BSC_TESTNET_TOKENS_FILE_NAME else BSC_TOKENS_FILE_NAME
|
||||
val binanceTokensFileName =
|
||||
if (isTestNet) BINANCE_TESTNET_TOKENS_FILE_NAME else BINANCE_TOKENS_FILE_NAME
|
||||
val avalancheTokensFileName =
|
||||
if (isTestNet) AVALANCHE_TESTNET_TOKENS_FILE_NAME else AVALANCHE_TOKENS_FILE_NAME
|
||||
|
||||
val ethereumTokensJson = context.assets.readJsonFileToString(ethereumTokensFileName)
|
||||
val bscTokensJson = context.assets.readJsonFileToString(bscTokensFileName)
|
||||
val binanceTokensJson = context.assets.readJsonFileToString(binanceTokensFileName)
|
||||
val avalancheTokensJson = context.assets.readJsonFileToString(avalancheTokensFileName)
|
||||
|
||||
return tokensAdapter.fromJson(ethereumTokensJson)!!.map { it.toToken() } +
|
||||
tokensAdapter.fromJson(bscTokensJson)!!.map { it.toToken() } +
|
||||
tokensAdapter.fromJson(binanceTokensJson)!!.mapNotNull {
|
||||
// temporary exclude Binance BEP-8 tokens
|
||||
if (it.type != null && it.type == BINANCE_TOKEN_TYPE_BEP8) null else it.toToken()
|
||||
}
|
||||
tokensAdapter.fromJson(bscTokensJson)!!.map { it.toToken() } +
|
||||
tokensAdapter.fromJson(binanceTokensJson)!!.mapNotNull {
|
||||
// temporary exclude Binance BEP-8 tokens
|
||||
if (it.type != null && it.type == BINANCE_TOKEN_TYPE_BEP8) null else it.toToken()
|
||||
} +
|
||||
tokensAdapter.fromJson(avalancheTokensJson)!!.map { it.toToken() }
|
||||
}
|
||||
|
||||
fun getBlockchains(
|
||||
cardFirmware: FirmwareVersion?,
|
||||
cardFirmware: FirmwareVersion,
|
||||
isTestNet: Boolean = false
|
||||
): List<Blockchain> {
|
||||
return if (cardFirmware == null || cardFirmware < FirmwareVersion.MultiWalletAvailable) {
|
||||
return if (cardFirmware < FirmwareVersion.MultiWalletAvailable) {
|
||||
Blockchain.secp256k1Blockchains(isTestNet)
|
||||
} else {
|
||||
Blockchain.secp256k1Blockchains(isTestNet) + Blockchain.ed25519OnlyBlockchains(isTestNet)
|
||||
|
|
@ -144,6 +149,9 @@ class CurrenciesRepository(val context: Application) {
|
|||
private const val BSC_TESTNET_TOKENS_FILE_NAME = "bsc_tokens_testnet"
|
||||
private const val BINANCE_TOKENS_FILE_NAME = "binance_tokens"
|
||||
private const val BINANCE_TESTNET_TOKENS_FILE_NAME = "binance_tokens_testnet"
|
||||
private const val AVALANCHE_TOKENS_FILE_NAME = "avalanche_tokens"
|
||||
private const val AVALANCHE_TESTNET_TOKENS_FILE_NAME = "avalanche_tokens_testnet"
|
||||
|
||||
private const val FILE_NAME_PREFIX_TOKENS = "tokens"
|
||||
private const val FILE_NAME_PREFIX_BLOCKCHAINS = "blockchains"
|
||||
|
||||
|
|
@ -152,6 +160,18 @@ class CurrenciesRepository(val context: Application) {
|
|||
fun getFileNameForTokens(cardId: String): String = "${FILE_NAME_PREFIX_TOKENS}_$cardId"
|
||||
fun getFileNameForBlockchains(cardId: String): String =
|
||||
"${FILE_NAME_PREFIX_BLOCKCHAINS}_$cardId"
|
||||
|
||||
fun injectDaoBlockchain(context: Context, tokenFileName: String, blockchain: Blockchain): String? {
|
||||
val tokenJson = context.assets.readJsonFileToString(tokenFileName)
|
||||
val converter = MoshiJsonConverter.default()
|
||||
val rawTokensList = converter.fromJson<List<MutableMap<String, Any>>>(tokenJson) ?: return null
|
||||
|
||||
rawTokensList.forEach {
|
||||
it["blockchain"] = BlockchainDao.fromBlockchain(blockchain)
|
||||
}
|
||||
|
||||
return converter.toJson(rawTokensList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -205,8 +225,7 @@ data class BlockchainDao(
|
|||
companion object {
|
||||
fun fromBlockchain(blockchain: Blockchain): BlockchainDao {
|
||||
val name = blockchain.name.removeSuffix("Testnet").lowercase()
|
||||
val isTestnet = blockchain.name.endsWith("Testnet")
|
||||
return BlockchainDao(name, isTestnet)
|
||||
return BlockchainDao(name, blockchain.isTestnet())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,22 +23,28 @@ sealed class CurrencyListItem {
|
|||
blockchains: List<Blockchain>,
|
||||
tokens: List<Token>,
|
||||
): List<CurrencyListItem> {
|
||||
val blockchainsTitle = R.string.add_tokens_subtitle_blockchains
|
||||
val ethereumTokensTitle = R.string.add_tokens_subtitle_ethereum_tokens
|
||||
val bscTokensTitle = R.string.add_tokens_subtitle_bsc_tokens
|
||||
val binanceTokensTitle = R.string.add_tokens_subtitle_binance_tokens
|
||||
return createBlockchainList(blockchains) +
|
||||
createTokensList(R.string.add_tokens_subtitle_ethereum_tokens, Blockchain.Ethereum, tokens) +
|
||||
createTokensList(R.string.add_tokens_subtitle_bsc_tokens, Blockchain.BSC, tokens) +
|
||||
createTokensList(R.string.add_tokens_subtitle_binance_tokens, Blockchain.Binance, tokens) +
|
||||
createTokensList(R.string.add_tokens_subtitle_avalanche_tokens, Blockchain.Avalanche, tokens)
|
||||
}
|
||||
|
||||
val ethereumTokens = tokens.filter { it.blockchain == Blockchain.Ethereum }
|
||||
val bscTokens = tokens.filter { it.blockchain == Blockchain.BSC }
|
||||
val binanceTokens = tokens.filter { it.blockchain == Blockchain.Binance }
|
||||
return listOf(TitleListItem(blockchainsTitle)) +
|
||||
blockchains.map { BlockchainListItem(it) } +
|
||||
listOf(TitleListItem(ethereumTokensTitle, blockchain = Blockchain.Ethereum)) +
|
||||
ethereumTokens.map { TokenListItem(it) } +
|
||||
listOf(TitleListItem(bscTokensTitle, blockchain = Blockchain.BSC)) +
|
||||
bscTokens.map { TokenListItem(it) } +
|
||||
listOf(TitleListItem(binanceTokensTitle, blockchain = Blockchain.Binance)) +
|
||||
binanceTokens.map { TokenListItem(it) }
|
||||
private fun createBlockchainList(blockchains: List<Blockchain>): List<CurrencyListItem> {
|
||||
val blockchainsTitle = R.string.add_tokens_subtitle_blockchains
|
||||
return listOf(TitleListItem(blockchainsTitle)) + blockchains.map { BlockchainListItem(it) }
|
||||
}
|
||||
|
||||
private fun createTokensList(
|
||||
@StringRes titleResId: Int,
|
||||
blockchain: Blockchain,
|
||||
tokens: List<Token>
|
||||
): List<CurrencyListItem> {
|
||||
val filteredTokens = tokens.filter {
|
||||
it.blockchain == blockchain || it.blockchain == blockchain.getTestnetVersion()
|
||||
}
|
||||
val tokensListItem = filteredTokens.map { TokenListItem(it) }
|
||||
return listOf(TitleListItem(titleResId, blockchain = blockchain)) + tokensListItem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue