From 98b3b888b299ca8932aef20083fedc758694651b Mon Sep 17 00:00:00 2001 From: Pierre-Alain Date: Mon, 12 Apr 2021 21:26:10 +0900 Subject: [PATCH] fix: switch wallet from unsuported network Prevents the user from being stuck if the walletconnect connection is lost and the network cannot be changed from mobile wallet, or if mobile wallet doesn't support network change functionality. --- src/html/incorrect-network-modal.html | 9 ++++++++- src/js/authEthereum.js | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/html/incorrect-network-modal.html b/src/html/incorrect-network-modal.html index 67fe7971..e93539c9 100644 --- a/src/html/incorrect-network-modal.html +++ b/src/html/incorrect-network-modal.html @@ -10,6 +10,12 @@

Incorrect Wallet Network

+ @@ -23,7 +29,8 @@

Incorrect Wallet Network

// Disable scroll until correct eth network selected document.body.style.overflow = "hidden"; window.dom.fill("modalMessage").with({ - innerHTML: `The NEAR Testnet ↔︎ ${process.env.ethNetworkId} bridge requires an Ethereum wallet connected to ${process.env.ethNetworkId}.`, + innerHTML: `The ${window.bridgeName} bridge requires an Ethereum wallet connected to + ${process.env.ethNetworkId === 'main' ? 'mainnet' : process.env.ethNetworkId}.`, }); window.dom.show("unsupportedNetworkModal"); } diff --git a/src/js/authEthereum.js b/src/js/authEthereum.js index 854dc76f..42d090b7 100644 --- a/src/js/authEthereum.js +++ b/src/js/authEthereum.js @@ -69,6 +69,13 @@ async function login () { } onClick('authEthereum', login) +onClick('switchEthWallet', async () => { + window.ethInitialized = false + window.dom.hide('unsupportedNetworkModal') + await window.web3Modal.clearCachedProvider() + localStorage.removeItem('walletconnect') + login() +}) // on page load, check if user has already signed in via MetaMask if (window.web3Modal.cachedProvider) {