| 1 | import 'package:cake_wallet/src/screens/wallet_connect/services/chain_service/eth/evm_chain_id.dart'; |
| 2 | import 'package:cake_wallet/src/screens/wallet_connect/services/chain_service/eth/evm_supported_methods.dart'; |
| 3 | import 'package:cake_wallet/src/screens/wallet_connect/services/chain_service/solana/solana_chain_id.dart'; |
| 4 | import 'package:cake_wallet/src/screens/wallet_connect/services/chain_service/solana/solana_supported_methods.dart'; |
| 5 | import 'package:cw_core/wallet_type.dart'; |
| 6 | import 'package:cake_wallet/evm/evm.dart'; |
| 7 | |
| 8 | const List<WalletType> walletConnectCompatibleChains = [ |
| 9 | WalletType.ethereum, |
| 10 | WalletType.polygon, |
| 11 | WalletType.base, |
| 12 | WalletType.arbitrum, |
| 13 | WalletType.bsc, |
| 14 | WalletType.solana, |
| 15 | ]; |
| 16 | |
| 17 | String walletConnectCompatibleChainsLabel() { |
| 18 | final names = walletConnectCompatibleChains.map(walletTypeToDisplayName).toList(); |
| 19 | if (names.length <= 1) return names.join(); |
| 20 | final head = names.sublist(0, names.length - 1).join(', '); |
| 21 | return '$head, and ${names.last}'; |
| 22 | } |
| 23 | |
| 24 | String networkDisplayName(WalletType type, int? chainId) { |
| 25 | if (evm != null && isEVMCompatibleChain(type)) { |
| 26 | final id = chainId ?? evm!.getChainIdByWalletType(type); |
| 27 | final info = evm!.getChainInfoByChainId(id); |
| 28 | if (info != null) { |
| 29 | return info.name; |
| 30 | } |
| 31 | } |
| 32 | return walletTypeToString(type); |
| 33 | } |
| 34 | |
| 35 | bool isEVMCompatibleChain(WalletType walletType) { |
| 36 | switch (walletType) { |
| 37 | case WalletType.polygon: |
| 38 | case WalletType.ethereum: |
| 39 | case WalletType.base: |
| 40 | case WalletType.arbitrum: |
| 41 | case WalletType.bsc: |
| 42 | return true; |
| 43 | default: |
| 44 | return false; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Blink Protection is supported on Ethereum and Base chains |
| 49 | bool canSupportBlinkProtection(int? chainId) { |
| 50 | if (chainId == null) return false; |
| 51 | |
| 52 | return chainId == 1 || chainId == 8453; |
| 53 | } |
| 54 | |
| 55 | bool isNFTACtivatedChain(WalletType walletType, {int? chainId}) { |
| 56 | if (chainId != null) { |
| 57 | switch (chainId) { |
| 58 | case 1: |
| 59 | case 8453: |
| 60 | case 137: |
| 61 | case 42161: |
| 62 | case 56: |
| 63 | return true; |
| 64 | default: |
| 65 | return false; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | switch (walletType) { |
| 70 | case WalletType.solana: |
| 71 | return true; |
| 72 | default: |
| 73 | return false; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | bool isWalletConnectCompatibleChain(WalletType walletType) => |
| 78 | walletConnectCompatibleChains.contains(walletType); |
| 79 | |
| 80 | String getChainNameSpaceAndIdBasedOnWalletType(WalletType walletType, {int? chainId}) { |
| 81 | if (chainId != null) { |
| 82 | return evm!.getCaip2ByChainId(chainId); |
| 83 | } |
| 84 | |
| 85 | switch (walletType) { |
| 86 | case WalletType.ethereum: |
| 87 | return EVMChainId.ethereum.chain(); |
| 88 | case WalletType.polygon: |
| 89 | return EVMChainId.polygon.chain(); |
| 90 | case WalletType.base: |
| 91 | return EVMChainId.base.chain(); |
| 92 | case WalletType.arbitrum: |
| 93 | return EVMChainId.arbitrum.chain(); |
| 94 | case WalletType.bsc: |
| 95 | return EVMChainId.bsc.chain(); |
| 96 | case WalletType.solana: |
| 97 | return SolanaChainId.mainnet.chain(); |
| 98 | default: |
| 99 | return ''; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | List<String> getChainSupportedMethodsOnWalletType(WalletType walletType) { |
| 104 | switch (walletType) { |
| 105 | case WalletType.ethereum: |
| 106 | case WalletType.polygon: |
| 107 | case WalletType.base: |
| 108 | case WalletType.arbitrum: |
| 109 | case WalletType.bsc: |
| 110 | return EVMSupportedMethods.values.map((e) => e.name).toList(); |
| 111 | case WalletType.solana: |
| 112 | return SolanaSupportedMethods.values.map((e) => e.name).toList(); |
| 113 | default: |
| 114 | return []; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | String getChainNameBasedOnWalletType(WalletType walletType, {int? chainId}) { |
| 119 | if (walletType == WalletType.solana) { |
| 120 | return 'mainnet'; |
| 121 | } |
| 122 | |
| 123 | if (chainId != null) { |
| 124 | return evm!.getChainNameByChainId(chainId); |
| 125 | } |
| 126 | |
| 127 | return evm!.getChainNameByWalletType(walletType); |
| 128 | } |
| 129 | |
| 130 | String getTokenNameBasedOnWalletType(WalletType walletType, {int? chainId}) { |
| 131 | if (walletType == WalletType.solana) { |
| 132 | return 'SOL'; |
| 133 | } |
| 134 | |
| 135 | if (chainId != null) { |
| 136 | return evm!.getTokenNameByChainId(chainId); |
| 137 | } |
| 138 | |
| 139 | return evm!.getTokenNameByWalletType(walletType); |
| 140 | } |