Updated on 2026-08-14
This commit is contained in:
parent
f8cfde3dc9
commit
dbc5600e9a
7 changed files with 32 additions and 53 deletions
File diff suppressed because one or more lines are too long
|
|
@ -179,7 +179,7 @@ class CurrenciesRepository(val context: Application) {
|
|||
fun getSupportedTokens(isTestNet: Boolean = false): List<Currency> {
|
||||
val fileName = if (isTestNet) "testnet_tokens" else "tokens"
|
||||
val json = context.assets.readJsonFileToString(fileName)
|
||||
return currenciesAdapter.fromJson(json)!!.tokens
|
||||
return currenciesAdapter.fromJson(json)!!.coins
|
||||
.map { Currency.fromJsonObject(it) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,20 +9,20 @@ data class CurrencyFromJson(
|
|||
val id: String,
|
||||
val name: String,
|
||||
val symbol: String,
|
||||
val contracts: List<ContractFromJson>? = null
|
||||
val networks: List<ContractFromJson>? = null
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class ContractFromJson(
|
||||
val networkId: String,
|
||||
val address: String,
|
||||
val decimalCount: Int
|
||||
val contractAddress: String?,
|
||||
val decimalCount: Int?
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class CurrenciesFromJson(
|
||||
val imageHost: String?,
|
||||
val tokens: List<CurrencyFromJson>
|
||||
val coins: List<CurrencyFromJson>
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -45,26 +45,17 @@ data class Currency(
|
|||
name = currency.name,
|
||||
symbol = currency.symbol,
|
||||
iconUrl = getIconUrl(currency.id),
|
||||
contracts = prepareListOfContracts(currency.contracts, currency.id)
|
||||
contracts = currency.networks?.toContracts() ?: emptyList()
|
||||
)
|
||||
}
|
||||
|
||||
private fun prepareListOfContracts(
|
||||
contractsFromJson: List<ContractFromJson>?,
|
||||
currencyId: String,
|
||||
): List<Contract> {
|
||||
val mainNetwork = Contract.fromCurrencyId(currencyId)
|
||||
val contracts = contractsFromJson?.toContracts() ?: emptyList()
|
||||
return (listOfNotNull(mainNetwork) + contracts).distinct()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class Contract(
|
||||
val networkId: String,
|
||||
val blockchain: Blockchain,
|
||||
val address: String,
|
||||
val decimalCount: Int,
|
||||
val address: String?,
|
||||
val decimalCount: Int?,
|
||||
val iconUrl: String,
|
||||
) {
|
||||
|
||||
|
|
@ -74,23 +65,11 @@ data class Contract(
|
|||
return Contract(
|
||||
networkId = contract.networkId,
|
||||
blockchain = blockchain,
|
||||
address = contract.address,
|
||||
address = contract.contractAddress,
|
||||
decimalCount = contract.decimalCount,
|
||||
iconUrl = getIconUrl(contract.networkId)
|
||||
)
|
||||
}
|
||||
|
||||
fun fromCurrencyId(currencyId: String): Contract? {
|
||||
val blockchain = Blockchain.fromNetworkId(currencyId) ?: return null
|
||||
return Contract(
|
||||
networkId = currencyId,
|
||||
blockchain = blockchain,
|
||||
address = blockchain.currency,
|
||||
decimalCount = blockchain.decimals(),
|
||||
iconUrl = getIconUrl(currencyId)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,9 +69,9 @@ fun CollapsedCurrencyItem(
|
|||
Row {
|
||||
if (!currency.contracts.isNullOrEmpty()) {
|
||||
currency.contracts.map { contract ->
|
||||
if (contract.address == currency.symbol) {
|
||||
if (contract.address == null) {
|
||||
BlockchainNetworkItem(
|
||||
blockchain = Blockchain.fromNetworkId(contract.networkId),
|
||||
blockchain = contract.blockchain,
|
||||
isMainNetwork = true,
|
||||
addedBlockchains = addedBlockchains
|
||||
)
|
||||
|
|
|
|||
|
|
@ -132,12 +132,13 @@ fun ExpandedCurrencyItem(
|
|||
) {
|
||||
blockchains.map { blockchain ->
|
||||
val contract = currency.contracts.firstOrNull { it.blockchain == blockchain }
|
||||
val added = if (contract != null && contract.address != currency.symbol) {
|
||||
?: return@map
|
||||
val added = if (contract.address != null) {
|
||||
addedTokens.map { it.token.contractAddress }.contains(contract.address)
|
||||
} else {
|
||||
addedBlockchains.contains(blockchain)
|
||||
}
|
||||
val canBeRemoved = if (contract != null && contract.address != currency.symbol) {
|
||||
val canBeRemoved = if (contract.address != null) {
|
||||
!nonRemovableTokens.contains(contract.address)
|
||||
} else {
|
||||
!nonRemovableBlockchains.contains(blockchain)
|
||||
|
|
|
|||
|
|
@ -32,31 +32,30 @@ import com.tangem.tap.features.tokens.redux.TokenWithBlockchain
|
|||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun NetworkItem(
|
||||
currency: Currency, contract: Contract?,
|
||||
currency: Currency, contract: Contract,
|
||||
blockchain: Blockchain, allowToAdd: Boolean,
|
||||
added: Boolean, canBeRemoved: Boolean,
|
||||
onAddCurrencyToggled: (Currency, TokenWithBlockchain?) -> Unit,
|
||||
onNetworkItemClicked: (ContractAddress) -> Unit
|
||||
) {
|
||||
|
||||
val isBlockchain = contract == null || contract.address == currency.symbol
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.combinedClickable(
|
||||
enabled = allowToAdd,
|
||||
onLongClick = {
|
||||
if (!isBlockchain) onNetworkItemClicked(contract!!.address)
|
||||
contract.address?.let { onNetworkItemClicked(it) }
|
||||
},
|
||||
onClick = {},
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() }
|
||||
)
|
||||
) {
|
||||
Box(modifier = Modifier
|
||||
.align(Alignment.CenterVertically)
|
||||
.padding(start = 8.dp, top = 16.dp, bottom = 16.dp, end = 6.dp)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterVertically)
|
||||
.padding(start = 8.dp, top = 16.dp, bottom = 16.dp, end = 6.dp)
|
||||
) {
|
||||
SubcomposeAsyncImage(
|
||||
model = if (added) blockchain.getRoundIconRes() else blockchain.getGreyedOutIconRes(),
|
||||
|
|
@ -66,7 +65,7 @@ fun NetworkItem(
|
|||
modifier = Modifier
|
||||
.size(20.dp)
|
||||
)
|
||||
if (isBlockchain) {
|
||||
if (contract.address == null) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
|
|
@ -98,29 +97,29 @@ fun NetworkItem(
|
|||
)
|
||||
Spacer(modifier = Modifier.size(3.dp))
|
||||
Text(
|
||||
text = if (isBlockchain) "MAIN" else blockchain.getNetworkName().uppercase(),
|
||||
text = if (contract.address == null) "MAIN" else blockchain.getNetworkName().uppercase(),
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
color = if (!isBlockchain) Color(0xFF8E8E93) else Color(0xFF1ACE80),
|
||||
color = if (contract.address != null) Color(0xFF8E8E93) else Color(0xFF1ACE80),
|
||||
)
|
||||
}
|
||||
|
||||
if (allowToAdd) {
|
||||
val token = if (!isBlockchain) {
|
||||
val token = if (contract.address != null) {
|
||||
Token(
|
||||
id = currency.id,
|
||||
name = currency.name,
|
||||
symbol = currency.symbol,
|
||||
contractAddress = contract!!.address,
|
||||
decimals = contract.decimalCount,
|
||||
contractAddress = contract.address,
|
||||
decimals = contract.decimalCount!!,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val tokenWithBlockchain =
|
||||
token?.let { TokenWithBlockchain(token, contract!!.blockchain) }
|
||||
token?.let { TokenWithBlockchain(token, contract.blockchain) }
|
||||
|
||||
val currencyToSave = if (isBlockchain && contract != null) {
|
||||
val currencyToSave = if (contract.address == null) {
|
||||
currency.copy(id = contract.networkId)
|
||||
} else {
|
||||
currency
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ fun Blockchain.Companion.fromNetworkId(networkId: String): Blockchain? {
|
|||
"dogecoin" -> Blockchain.Dogecoin
|
||||
"ducatus" -> Blockchain.Ducatus
|
||||
"litecoin" -> Blockchain.Litecoin
|
||||
"rsk" -> Blockchain.RSK
|
||||
"rootstock" -> Blockchain.RSK
|
||||
"stellar" -> Blockchain.Stellar
|
||||
"stellar/test" -> Blockchain.StellarTestnet
|
||||
"tezos" -> Blockchain.Tezos
|
||||
"ripple" -> Blockchain.XRP
|
||||
"xrp" -> Blockchain.XRP
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ fun Blockchain.toNetworkId(): String {
|
|||
Blockchain.Solana -> "solana"
|
||||
Blockchain.SolanaTestnet -> "solana/test"
|
||||
Blockchain.Tezos -> "tezos"
|
||||
Blockchain.XRP -> "ripple"
|
||||
Blockchain.XRP -> "xrp"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue