Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GITC-600: enforce ethereum chain for zksync checkout #9689

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions app/assets/v2/js/cart-ethereum-zksync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down