From 5969b0d0067e4f1b4f3610e7447487313c1cee72 Mon Sep 17 00:00:00 2001 From: Chibuotu Amadi Date: Sun, 19 Sep 2021 19:35:21 +0100 Subject: [PATCH] enforce eth chain for standard checkout --- app/assets/v2/js/cart.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/assets/v2/js/cart.js b/app/assets/v2/js/cart.js index 9301ca98a88..e9c02b41f48 100644 --- a/app/assets/v2/js/cart.js +++ b/app/assets/v2/js/cart.js @@ -876,6 +876,26 @@ Vue.component('grants-cart', { return await onConnect(); } + let supportedTestnets = [ 'rinkeby', 'goerli', 'kovan', 'ropsten' ]; + + if (!supportedTestnets.includes(networkName) || this.networkId !== '1') { + // User MetaMask must be connected to Ethereum mainnet or a supported testnet + try { + await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0x1' }] + }); + } catch (switchError) { + if (switchError.code === 4001) { + throw new Error('Please connect MetaMask to Ethereum network.'); + } else if (switchError.code === -32002) { + throw new Error('Please respond to a pending MetaMask request.'); + } else { + console.error(switchError); + } + } + } + if (typeof ga !== 'undefined') { ga('send', 'event', 'Grant Checkout', 'click', 'Person'); }