Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
fix: switch wallet from unsuported network
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paouvrard committed Apr 13, 2021
1 parent e02f90a commit 98b3b88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/html/incorrect-network-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<h1 class="modal__heading">Incorrect Wallet Network</h1>
<div data-behavior="modalMessage" class="modal__message"></div>
<p class="modal__cta">Change your active wallet network to proceed.</p>
<button
class="button-variant--secondary button-size--small"
data-behavior="switchEthWallet"
>
Switch wallet
</button>
</div>
</div>

Expand All @@ -23,7 +29,8 @@ <h1 class="modal__heading">Incorrect Wallet Network</h1>
// 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");
}
Expand Down
7 changes: 7 additions & 0 deletions src/js/authEthereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 98b3b88

Please sign in to comment.