From 5b7641d16d6ef1cf55ad882d9738eb2e73338b79 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 29 Dec 2021 02:13:46 -0800 Subject: [PATCH] setup network switchers and checks --- suchwowx/static/js/main.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/suchwowx/static/js/main.js b/suchwowx/static/js/main.js index 4aef5d2..11a0cb1 100644 --- a/suchwowx/static/js/main.js +++ b/suchwowx/static/js/main.js @@ -8,10 +8,26 @@ async function getSignedData(publicAddress, jsonData) { } async function confirmAvalanche(){ + let debug = true; + let chainId; + let rpcUrl; + let explorerUrl; + let name; + if (debug) { + name = 'Avalance Testnet'; + chainId = '0xA869'; + rpcUrl = 'https://api.avax-test.network/ext/bc/C/rpc'; + explorerUrl = 'https://testnet.snowtrace.io'; + } else { + name = 'Avalanche Mainnet'; + chainId = '0xA86A'; + rpcUrl = 'https://api.avax.network/ext/bc/C/rpc'; + explorerUrl = 'https://snowtrace.io'; + } try { await ethereum.request({ method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xA86A' }], + params: [{ chainId: chainId }], }); } catch (switchError) { // This error code indicates that the chain has not been added to MetaMask. @@ -20,15 +36,15 @@ async function confirmAvalanche(){ await ethereum.request({ method: 'wallet_addEthereumChain', params: [{ - chainId: '0xA86A', - chainName: 'Avalanche', + chainId: chainId, + chainName: name, nativeCurrency: { name: 'Avalanche', symbol: 'AVAX', decimals: 18, }, - rpcUrls: ['https://api.avax.network/ext/bc/C/rpc'], - blockExplorerUrls: ['https://snowtrace.io'], + rpcUrls: [rpcUrl], + blockExplorerUrls: [explorerUrl], }], }); } catch (addError) {