Updated on 2026-08-14

This commit is contained in:
Tangem 2022-04-18 15:35:49 +04:00
parent eb800d32cc
commit 797d11bd8c
2 changed files with 26 additions and 4 deletions

View file

@ -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"
}
}