Updated on 2026-08-14
This commit is contained in:
parent
eb800d32cc
commit
797d11bd8c
2 changed files with 26 additions and 4 deletions
|
|
@ -35,7 +35,7 @@ data class Currency(
|
|||
val name: String,
|
||||
val symbol: String,
|
||||
val iconUrl: String,
|
||||
val contracts: List<Contract>?
|
||||
val contracts: List<Contract>
|
||||
) {
|
||||
|
||||
companion object {
|
||||
|
|
@ -45,9 +45,19 @@ data class Currency(
|
|||
name = currency.name,
|
||||
symbol = currency.symbol,
|
||||
iconUrl = getIconUrl(currency.id),
|
||||
contracts = currency.contracts?.toContracts(isTestNet)
|
||||
contracts = prepareListOfContracts(currency.contracts, currency.id, isTestNet)
|
||||
)
|
||||
}
|
||||
|
||||
private fun prepareListOfContracts(
|
||||
contractsFromJson: List<ContractFromJson>?,
|
||||
currencyId: String,
|
||||
isTestNet: Boolean
|
||||
): List<Contract> {
|
||||
val mainNetwork = Contract.fromCurrencyId(currencyId, isTestNet)
|
||||
val contracts = contractsFromJson?.toContracts(isTestNet) ?: emptyList()
|
||||
return (listOfNotNull(mainNetwork) + contracts).distinct()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,6 +82,18 @@ data class Contract(
|
|||
)
|
||||
}
|
||||
|
||||
fun fromCurrencyId(currencyId: String, isTestNet: Boolean): Contract? {
|
||||
val networkId = if (isTestNet) currencyId + TESTNET else currencyId
|
||||
val blockchain = Blockchain.fromNetworkId(networkId) ?: return null
|
||||
return Contract(
|
||||
networkId = networkId,
|
||||
blockchain = blockchain,
|
||||
address = blockchain.currency,
|
||||
decimalCount = blockchain.decimals(),
|
||||
iconUrl = getIconUrl(networkId)
|
||||
)
|
||||
}
|
||||
|
||||
const val TESTNET = "-testnet"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import com.tangem.blockchain.common.Blockchain
|
|||
|
||||
fun Blockchain.Companion.fromNetworkId(networkId: String): Blockchain? {
|
||||
return when (networkId) {
|
||||
"avalanche" -> Blockchain.Avalanche
|
||||
"avalanche-testnet" -> Blockchain.AvalancheTestnet
|
||||
"avalanche", "avalanche-2" -> Blockchain.Avalanche
|
||||
"avalanche-testnet", "avalanche-2-testnet" -> Blockchain.AvalancheTestnet
|
||||
"binancecoin" -> Blockchain.Binance
|
||||
"binancecoin-testnet" -> Blockchain.BinanceTestnet
|
||||
"binance-smart-chain" -> Blockchain.BSC
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue