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

feat(useWallet): add correctNetwork flag #74

Merged
merged 2 commits into from
Dec 7, 2021

Conversation

Dhaiwat10
Copy link
Member

Closes #72

Description

This PR adds the correctNetwork flag to the useWallet hook whose value changes between true -> false depending on whether the user is on the correct network supplied to the <Provider />.

Other changes

  • Added event listeners for network change, account change and account disconnect.
  • Cleaned up the useWallet hook a bit
  • The <Provider /> now accepts the network's chain ID (number) instead of the network's name as a string. This lets people pass in a custom chain ID.
  • To aid UX, I have added a constants file containing mappings between the network names and their respective chain IDs. Usage example: <Provider network={NETWORKS.mainnet} />

@Dhaiwat10
Copy link
Member Author

Sorry for introducing so many changes in one PR but they kinda depend on each other :(

const { connection, connectWallet, disconnectWallet, connected } = useWallet();
const { connection, connectWallet, disconnectWallet, connected, correctNetwork } = useWallet();

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason your using a named import here and we use the default React import everywhere else?

Just for my understanding, I personally find it confusing if both are used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to using useEffect instead of React.useEffect?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah that's just me being dumb. 😬 I'll fix that

@Dhaiwat10 Dhaiwat10 merged commit 5e89859 into main Dec 7, 2021
@Dhaiwat10 Dhaiwat10 deleted the feat/incorrect-network-usewallet branch December 24, 2021 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[useWallet] Add support for wrong network detection
2 participants