Updated on 2026-08-14

This commit is contained in:
Tangem 2022-04-29 14:58:00 +03:00
commit 6852fbf37a
2 changed files with 18 additions and 15 deletions

View file

@ -530,7 +530,9 @@ internal class AddCustomTokenHub : BaseStoreHub<AddCustomTokenState>("AddCustomT
} }
is OnCreate -> { is OnCreate -> {
val card = requireNotNull(globalState.scanResponse?.card) val card = requireNotNull(globalState.scanResponse?.card)
val supportedTokenNetworkIds = AddCustomTokenState.getSupportedTokens().map { it.toNetworkId() } val supportedTokenNetworkIds = AddCustomTokenState.getSupportedTokensBlockchain().map {
it.toNetworkId()
}
val tangemTechServiceManager = AddCustomTokenService( val tangemTechServiceManager = AddCustomTokenService(
tangemTechService = globalState.networkServices.tangemTechService, tangemTechService = globalState.networkServices.tangemTechService,
supportedTokenNetworkIds = supportedTokenNetworkIds supportedTokenNetworkIds = supportedTokenNetworkIds

View file

@ -164,19 +164,17 @@ data class AddCustomTokenState(
/** /**
* Serves to determine the tokens that can be received from the TangemTech service * Serves to determine the tokens that can be received from the TangemTech service
*/ */
internal fun getSupportedTokens(): List<Blockchain> { internal fun getSupportedTokensBlockchain(): List<Blockchain> {
val supportedBlockchains = getNetworksList(CustomTokenType.Token).toMutableList() return Blockchain.values()
supportedBlockchains.remove(Blockchain.Unknown) .filter { !it.isTestnet() }
return supportedBlockchains .filter { it.canHandleTokens() }
} }
/** /**
* Serves to determine the networks (blockchains & tokens) that can be selected by Form.Networks. * Serves to determine the networks (blockchains & tokens) that can be selected by Form.Networks.
* Blockchain.Unknown - is the default selection * Blockchain.Unknown - is the default selection
*/ */
internal fun getNetworksList(type: CustomTokenType): List<Blockchain> { private fun getNetworksList(type: CustomTokenType): List<Blockchain> {
val default = Blockchain.Unknown
val evmBlockchains = Blockchain.values() val evmBlockchains = Blockchain.values()
.filter { it.isEvm() } .filter { it.isEvm() }
.filter { !it.isTestnet() } .filter { !it.isTestnet() }
@ -187,7 +185,6 @@ data class AddCustomTokenState(
) )
val networks = (evmBlockchains + additionalBlockchains).toMutableList() val networks = (evmBlockchains + additionalBlockchains).toMutableList()
networks.add(0, default)
//life hack //life hack
val fwCardVersion = domainStore.state.globalState.scanResponse?.card?.firmwareVersion val fwCardVersion = domainStore.state.globalState.scanResponse?.card?.firmwareVersion
@ -197,18 +194,22 @@ data class AddCustomTokenState(
val solanaTokensUnsupportedByCard = fwCardVersion < FirmwareVersion.SolanaTokensAvailable val solanaTokensUnsupportedByCard = fwCardVersion < FirmwareVersion.SolanaTokensAvailable
if (solanaUnsupportedByCard || solanaTokensUnsupportedByCard) networks.remove(Blockchain.Solana) if (solanaUnsupportedByCard || solanaTokensUnsupportedByCard) networks.remove(Blockchain.Solana)
networks.removeAll(getNetworksUnsupportedByApp(type)) if (type == CustomTokenType.Token) networks.removeAll(getUnsupportedTokensBlockchain())
val default = Blockchain.Unknown
networks.add(0, default)
return networks return networks
} }
private fun getNetworksUnsupportedByApp(type: CustomTokenType): List<Blockchain> { private fun getUnsupportedTokensBlockchain(): List<Blockchain> {
return when (type) { return Blockchain.values()
CustomTokenType.Token -> listOf(Blockchain.Solana) .filter { !it.isTestnet() }
CustomTokenType.Blockchain -> emptyList() .filter { !it.canHandleTokens() }
} .toMutableList()
} }
private fun createFormValidators(): Map<CustomTokenFieldId, CustomTokenValidator<out Any>> { private fun createFormValidators(): Map<CustomTokenFieldId, CustomTokenValidator<out Any>> {
return mapOf( return mapOf(
ContractAddress to TokenContractAddressValidator(), ContractAddress to TokenContractAddressValidator(),