How to make it possible to switch Network in metamask when it was not added yet in this wallet #92
-
Prerequisites: use wagmi with connectkit, metamask wallet used In codebase: There is used WagmiConfig HOC with passed wagmiClient along with ConnectKitProvider Hoc and these both wrap our page component. Flow: User click on buttons that call setOpen method (returned by invoked useModal hook) then when you click on metamask (only wallet allowed) Metamask detect that you are on unsupported network and shows "switch network" popup to the user. User clicks on switch network button to shown above network and then it fails due to user (not having network added yet in metamask wallet). Errors show up in browser console output these I would like to catch in frontend app.(ddapp). How can I do it ? I would like to call add network request to metamask when switch network fails so later user can switch to that network when it is added in metamask wallet. Main point: how to catch metamask errors on frontend app without calling separately first switch network request in code(once again), and trying only then to add this network to this metamask wallet. Let me know if you need me to provide more details or screen shots. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @pwiniarski1991! I think I get what you're getting at, basically if you have a custom network set up in your dApp but the user hasn't set that up there are errors in the console but no UI resolution for this. |
Beta Was this translation helpful? Give feedback.
-
@lochie Thank you so much for responding my question. Can you elaborate on second part on "detect with wagmi" ?. I think it is still good to use either way as may issue would be more related to wrong config delivered for Arbitrum Goerli Testnet network that is taken from wagmi/config package, but anyway it would be great to add such feature in this module as well (to catch/manage with switch/add network errors to be able to handle it if needed). |
Beta Was this translation helpful? Give feedback.
Hey @pwiniarski1991! I think I get what you're getting at, basically if you have a custom network set up in your dApp but the user hasn't set that up there are errors in the console but no UI resolution for this.
This is a great suggestion, I'll add this to our tasks.
But worth noting that you can detect this sort of thing with wagmi and implement your own solution, but I do agree that this is something that we should do built-in to our module.