Updated on 2026-08-14
This commit is contained in:
parent
b1e7add18e
commit
8d84420ca7
4 changed files with 60 additions and 35 deletions
|
|
@ -63,7 +63,7 @@ private fun AllInOne() {
|
|||
address = "0x1111111111111111112111111111111111111113"
|
||||
)
|
||||
ContractAddressButton(
|
||||
name = "full unk",
|
||||
name = "full custom",
|
||||
address = "0x3019BF2a2eF8040C242C9a4c5c4BD4C81678b2A1",
|
||||
tokenNetwork = Blockchain.Ethereum,
|
||||
tokenName = "Test unknown",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package com.tangem.domain.features.addCustomToken
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.common.services.Result
|
||||
import com.tangem.domain.common.extensions.toNetworkId
|
||||
import com.tangem.network.api.tangemTech.CoinsResponse
|
||||
import com.tangem.network.api.tangemTech.TangemTechService
|
||||
|
||||
|
|
@ -10,7 +8,8 @@ import com.tangem.network.api.tangemTech.TangemTechService
|
|||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class AddCustomTokenService(
|
||||
private val tangemTechService: TangemTechService
|
||||
private val tangemTechService: TangemTechService,
|
||||
private val supportedTokenNetworkIds: List<String>,
|
||||
) {
|
||||
|
||||
suspend fun findToken(
|
||||
|
|
@ -26,8 +25,7 @@ class AddCustomTokenService(
|
|||
val networksWithTheSameAddress = coin.networks
|
||||
.filter { it.contractAddress != null || it.decimalCount != null }
|
||||
.filter { it.contractAddress == contractAddress }
|
||||
//TODO: Solana token
|
||||
.filter { it.networkId != Blockchain.Solana.toNetworkId() }
|
||||
.filter { supportedTokenNetworkIds.contains(it.networkId) }
|
||||
if (networksWithTheSameAddress.isNotEmpty()) {
|
||||
val newToken = coin.copy(networks = networksWithTheSameAddress)
|
||||
coinsList.add(newToken)
|
||||
|
|
|
|||
|
|
@ -530,7 +530,11 @@ internal class AddCustomTokenHub : BaseStoreHub<AddCustomTokenState>("AddCustomT
|
|||
}
|
||||
is OnCreate -> {
|
||||
val card = requireNotNull(globalState.scanResponse?.card)
|
||||
val tangemTechServiceManager = AddCustomTokenService(globalState.networkServices.tangemTechService)
|
||||
val supportedTokenNetworkIds = AddCustomTokenState.getSupportedTokens().map { it.toNetworkId() }
|
||||
val tangemTechServiceManager = AddCustomTokenService(
|
||||
tangemTechService = globalState.networkServices.tangemTechService,
|
||||
supportedTokenNetworkIds = supportedTokenNetworkIds
|
||||
)
|
||||
|
||||
var derivationPathState = state.screenState.derivationPath
|
||||
derivationPathState = when (card.derivationStyle) {
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ data class AddCustomTokenState(
|
|||
}
|
||||
|
||||
fun getNetworks(type: CustomTokenType): List<Blockchain> {
|
||||
return getSupportedNetworks(type)
|
||||
return getNetworksList(type)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
@ -141,7 +141,7 @@ data class AddCustomTokenState(
|
|||
* If an user select derivation path (derivationNetwork) as Blockchain.Unknown,
|
||||
* then we should use a blockchain from the mainNetwork to determine a DerivationPath
|
||||
*/
|
||||
fun getDerivationPath(
|
||||
internal fun getDerivationPath(
|
||||
mainNetwork: Blockchain,
|
||||
derivationNetwork: Blockchain,
|
||||
derivationStyle: DerivationStyle?
|
||||
|
|
@ -153,7 +153,7 @@ data class AddCustomTokenState(
|
|||
internal fun createFormFields(type: CustomTokenType): List<DataField<*>> {
|
||||
return listOf(
|
||||
TokenField(ContractAddress),
|
||||
TokenBlockchainField(Network, getSupportedNetworks(type)),
|
||||
TokenBlockchainField(Network, getNetworksList(type)),
|
||||
TokenField(Name),
|
||||
TokenField(Symbol),
|
||||
TokenField(Decimals),
|
||||
|
|
@ -161,6 +161,54 @@ data class AddCustomTokenState(
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves to determine the tokens that can be received from the TangemTech service
|
||||
*/
|
||||
internal fun getSupportedTokens(): List<Blockchain> {
|
||||
val supportedBlockchains = getNetworksList(CustomTokenType.Token).toMutableList()
|
||||
supportedBlockchains.remove(Blockchain.Unknown)
|
||||
return supportedBlockchains
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves to determine the networks (blockchains & tokens) that can be selected by Form.Networks.
|
||||
* Blockchain.Unknown - is the default selection
|
||||
*/
|
||||
internal fun getNetworksList(type: CustomTokenType): List<Blockchain> {
|
||||
val default = Blockchain.Unknown
|
||||
|
||||
val evmBlockchains = Blockchain.values()
|
||||
.filter { it.isEvm() }
|
||||
.filter { !it.isTestnet() }
|
||||
|
||||
val additionalBlockchains = listOf(
|
||||
Blockchain.Binance,
|
||||
Blockchain.Solana,
|
||||
)
|
||||
|
||||
val networks = (evmBlockchains + additionalBlockchains).toMutableList()
|
||||
networks.add(0, default)
|
||||
|
||||
//life hack
|
||||
val fwCardVersion = domainStore.state.globalState.scanResponse?.card?.firmwareVersion
|
||||
?: FirmwareVersion(0, 0)
|
||||
|
||||
val solanaUnsupportedByCard = fwCardVersion < FirmwareVersion.SolanaAvailable
|
||||
val solanaTokensUnsupportedByCard = fwCardVersion < FirmwareVersion.SolanaTokensAvailable
|
||||
if (solanaUnsupportedByCard || solanaTokensUnsupportedByCard) networks.remove(Blockchain.Solana)
|
||||
|
||||
networks.removeAll(getNetworksUnsupportedByApp(type))
|
||||
|
||||
return networks
|
||||
}
|
||||
|
||||
private fun getNetworksUnsupportedByApp(type: CustomTokenType): List<Blockchain> {
|
||||
return when (type) {
|
||||
CustomTokenType.Token -> listOf(Blockchain.Solana)
|
||||
CustomTokenType.Blockchain -> emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createFormValidators(): Map<CustomTokenFieldId, CustomTokenValidator<out Any>> {
|
||||
return mapOf(
|
||||
ContractAddress to TokenContractAddressValidator(),
|
||||
|
|
@ -171,31 +219,6 @@ data class AddCustomTokenState(
|
|||
)
|
||||
}
|
||||
|
||||
private fun getSupportedNetworks(type: CustomTokenType): List<Blockchain> {
|
||||
val networks = mutableListOf(
|
||||
Blockchain.Unknown,
|
||||
Blockchain.Ethereum,
|
||||
Blockchain.BSC,
|
||||
Blockchain.Polygon,
|
||||
Blockchain.Avalanche,
|
||||
Blockchain.Fantom,
|
||||
Blockchain.Binance, // not evm
|
||||
Blockchain.Solana, // not evm
|
||||
)
|
||||
//life hack
|
||||
val fwCardVersion = domainStore.state.globalState.scanResponse?.card?.firmwareVersion
|
||||
?: FirmwareVersion(0, 0)
|
||||
|
||||
val solanaUnsupportedByCard = fwCardVersion < FirmwareVersion.SolanaAvailable
|
||||
val solanaTokensUnsupportedByCard = fwCardVersion < FirmwareVersion.SolanaTokensAvailable
|
||||
if (solanaUnsupportedByCard || solanaTokensUnsupportedByCard) networks.remove(Blockchain.Solana)
|
||||
|
||||
//TODO: Solana
|
||||
if (type == CustomTokenType.Token) networks.remove(Blockchain.Solana)
|
||||
|
||||
return networks
|
||||
}
|
||||
|
||||
private fun getSupportedDerivations(): List<Blockchain> {
|
||||
val evmBlockchains = Blockchain.values().filter {
|
||||
!it.isTestnet() && it.getChainId() != null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue