-
Notifications
You must be signed in to change notification settings - Fork 151
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
Add switchToCorrectNetwork
method
#125
Conversation
🦋 Changeset detectedLatest commit: 0fd8c23 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@Nazeeh21 can you check the failing test? |
add `any` type to error in catch handler add any type to error in catch handler
74290e7
to
6693167
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
import Authereum from 'authereum'; | ||
import React, { useEffect } from 'react'; | ||
import { NETWORKS, Provider, useWallet } from '..'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change the order of the imports? We should try to keep the changes to the minimum. Only introduce relevant changes so that it's easier for anyone to grasp the PR when re-visiting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is not any specific reason for that. I'll change it back. 😅
} else { | ||
// if no window.ethereum then MetaMask is not installed | ||
alert( | ||
'MetaMask is not installed. Please consider installing it: https://metamask.io/download.html' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'MetaMask is not installed. Please consider installing it: https://metamask.io/download.html' | |
'Switching networks automatically is only supported in MetaMask. https://metamask.io/download.html' |
Can you change the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll update it.
console.error(error); | ||
// This error code indicates that the chain has not been added to MetaMask. | ||
// If it is not, then install it into the user MetaMask | ||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of @ts-ignore
, did you try using something @ts-expect-error
? I think that would be more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I haven't tried it, I'll try using it.
} catch (error) { | ||
console.error(error); | ||
// This error code indicates that the chain has not been added to MetaMask. | ||
// If it is not, then install it into the user MetaMask |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If it is not, then install it into the user MetaMask | |
// If it is not, then install it into the user's MetaMask |
} | ||
} | ||
} else { | ||
// if no window.ethereum then MetaMask is not installed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// if no window.ethereum then MetaMask is not installed | |
// if window.ethereum is undefined then MetaMask is not installed |
You need to also run |
Closes #119
Description
This PR adds a method
switchToCorrectNetwork
to theuseWallet()
hook. This method allows the user to connect to the required network without manually heading over to the MetaMask and switching the network.Users can use this method by directly assigning this
switchToCorrectNetwork
function to theonClick
handler of any button and then the magic will happen and the MetaMask network will get changed to the required network.In case, any user doesn't have MetaMask installed then it will show an alert to the user and ask them to install MetaMask.