diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/MarketKitExtensions.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/MarketKitExtensions.kt index e59c60fee31..3025dd39a4a 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/MarketKitExtensions.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/MarketKitExtensions.kt @@ -312,7 +312,11 @@ fun BlockchainType.supports(accountType: AccountType): Boolean { else -> false } } - is AccountType.BitcoinAddress -> this === accountType.blockchainType + + is AccountType.BitcoinAddress -> { + this === accountType.blockchainType + } + is AccountType.EvmAddress -> this == BlockchainType.Ethereum || this == BlockchainType.BinanceSmartChain @@ -380,8 +384,47 @@ val FullCoin.iconPlaceholder: Int R.drawable.coin_placeholder } +fun Token.supports(accountType: AccountType): Boolean { + return when (accountType) { + is AccountType.BitcoinAddress -> { + tokenQuery.tokenType == accountType.tokenType + } + + is AccountType.HdExtendedKey -> { + when (blockchainType) { + BlockchainType.Bitcoin, + BlockchainType.Litecoin -> { + val type = type + if (type is TokenType.Derived) { + if (!accountType.hdExtendedKey.purposes.contains(type.derivation.purpose)) { + false + } else if (blockchainType == BlockchainType.Bitcoin) { + accountType.hdExtendedKey.coinTypes.contains(ExtendedKeyCoinType.Bitcoin) + } else { + accountType.hdExtendedKey.coinTypes.contains(ExtendedKeyCoinType.Litecoin) + } + } else { + false + } + } + + BlockchainType.BitcoinCash, + BlockchainType.ECash, + BlockchainType.Dash -> { + accountType.hdExtendedKey.purposes.contains(HDWallet.Purpose.BIP44) + } + + else -> false + } + } + + else -> true + } +} + fun FullCoin.eligibleTokens(accountType: AccountType): List { - return supportedTokens.filter { it.blockchainType.supports(accountType) } + return supportedTokens + .filter { it.supports(accountType) && it.blockchainType.supports(accountType) } } val HsPointTimePeriod.title: Int diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/managewallets/ManageWalletsService.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/managewallets/ManageWalletsService.kt index 3e21b723b03..5ca0038bf31 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/managewallets/ManageWalletsService.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/managewallets/ManageWalletsService.kt @@ -106,8 +106,8 @@ class ManageWalletsService( val tokens = if (filter.isNotBlank()) { eligibleTokens } else if ( - eligibleTokens.all { it.type is TokenType.Derived } || - eligibleTokens.all { it.type is TokenType.AddressTyped } + accountType !is AccountType.HdExtendedKey && + (eligibleTokens.all { it.type is TokenType.Derived } || eligibleTokens.all { it.type is TokenType.AddressTyped }) ) { eligibleTokens.filter { isEnabled(it) || it.type.isDefault } } else { diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/restoreaccount/restoreblockchains/RestoreBlockchainsService.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/restoreaccount/restoreblockchains/RestoreBlockchainsService.kt index 43533a7a368..25662eb6a79 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/restoreaccount/restoreblockchains/RestoreBlockchainsService.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/restoreaccount/restoreblockchains/RestoreBlockchainsService.kt @@ -92,7 +92,7 @@ class RestoreBlockchainsService( .map { it.nativeTokenQueries } .flatten() - tokens = marketKit.tokens(tokenQueries) + tokens = marketKit.tokens(tokenQueries).filter { it.supports(accountType) } } private fun handleApproveTokens(blockchain: Blockchain, tokens: List) {