diff --git a/app/assets/v2/js/cart-ethereum-zksync.js b/app/assets/v2/js/cart-ethereum-zksync.js index a5631209dd8..3efee328b63 100644 --- a/app/assets/v2/js/cart-ethereum-zksync.js +++ b/app/assets/v2/js/cart-ethereum-zksync.js @@ -180,8 +180,7 @@ Vue.component('grantsCartEthereumZksync', { this.zksync.showModal = false; // hide checkout modal if visible this.resetZkSyncModal(); // reset modal settings - _alert('There is an insufficient balance to complete checkout. Please load funds and try again.', 'danger'); - this.handleError(new Error('Insufficient balance to complete checkout')); // throw error and show to user + this.handleError(new Error('There is an insufficient balance to complete checkout. Please load funds and try again.')); // throw error and show to user }, // Reset zkSync modal status after a checkout failure @@ -217,6 +216,26 @@ Vue.component('grantsCartEthereumZksync', { throw new Error('Please connect a wallet'); } + let networkId = String(Number(web3.eth.currentProvider.chainId)); + + if (networkId !== '1' && networkId !== '4') { + // User MetaMask must be connected to Ethereum mainnet + 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); + } + } + } + // Make sure setup is completed properly const isCorrectNetwork = this.zksync.checkoutManager && this.zksync.checkoutManager.network === this.network; diff --git a/app/assets/v2/js/cart.js b/app/assets/v2/js/cart.js index 3fe6dfe67fb..d747ca61af5 100644 --- a/app/assets/v2/js/cart.js +++ b/app/assets/v2/js/cart.js @@ -898,7 +898,7 @@ Vue.component('grants-cart', { let networkName = getDataChains(networkId, 'chainId')[0] && getDataChains(networkId, 'chainId')[0].network; if (networkName == 'mainnet' && networkId !== '1') { - // User MetaMask must be connected to Ethereum mainnet or a supported testnet + // User MetaMask must be connected to Ethereum mainnet try { await ethereum.request({ method: 'wallet_switchEthereumChain',