Add network from networkConfig

This commit is contained in:
Tornado Contrib 2024-05-09 20:19:00 +00:00
parent 57d3ba5ac5
commit add30d1939
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1

@ -505,82 +505,26 @@ const actions = {
throw new Error(err.message) throw new Error(err.message)
} }
}, },
async addNetwork(_, { netId }) { async addNetwork({ rootGetters }, { netId }) {
const METAMASK_LIST = { const config = networkConfig[`netId${netId}`]
56: { const { url } = rootGetters['settings/getRpc'](netId)
chainId: '0x38',
chainName: 'Binance Smart Chain Mainnet',
rpcUrls: ['https://bscrpc.com'],
nativeCurrency: {
name: 'Binance Chain Native Token',
symbol: 'BNB',
decimals: 18
},
blockExplorerUrls: ['https://bscscan.com']
},
10: {
chainId: '0xa',
chainName: 'Optimism',
rpcUrls: ['https://mainnet.optimism.io/'],
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18
},
blockExplorerUrls: ['https://optimistic.etherscan.io']
},
100: {
chainId: '0x64',
chainName: 'Gnosis',
rpcUrls: ['https://development.tornadocash.community/rpc/v1'],
nativeCurrency: {
name: 'xDAI',
symbol: 'xDAI',
decimals: 18
},
blockExplorerUrls: ['https://blockscout.com/xdai/mainnet']
},
137: {
chainId: '0x89',
chainName: 'Polygon Mainnet',
rpcUrls: ['https://polygon-rpc.com'],
nativeCurrency: {
name: 'MATIC',
symbol: 'MATIC',
decimals: 18
},
blockExplorerUrls: ['https://polygonscan.com']
},
42161: {
chainId: '0xA4B1',
chainName: 'Arbitrum One',
rpcUrls: ['https://arb1.arbitrum.io/rpc'],
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18
},
blockExplorerUrls: ['https://arbiscan.io']
},
43114: {
chainId: '0xA86A',
chainName: 'Avalanche C-Chain',
rpcUrls: ['https://api.avax.network/ext/bc/C/rpc'],
nativeCurrency: {
name: 'Avalanche',
symbol: 'AVAX',
decimals: 18
},
blockExplorerUrls: ['https://snowtrace.io']
}
}
if (METAMASK_LIST[netId]) {
await this.$provider.sendRequest({ await this.$provider.sendRequest({
method: 'wallet_addEthereumChain', method: 'wallet_addEthereumChain',
params: [METAMASK_LIST[netId]] params: [
}) {
chainId: `0x${Number(netId).toString(16)}`,
chainName: config.networkName,
rpcUrls: [url],
nativeCurrency: {
name: config.networkName,
symbol: config.currencyName,
decimals: 18
},
blockExplorerUrls: [config.explorerUrl.tx.replace('/tx', '')]
} }
]
})
}, },
async checkNetworkVersion() { async checkNetworkVersion() {
try { try {