web3-react
web3-react copied to clipboard
How to catch the error from activate
When calling the connector.activate(...) method, if the user cancels the network switch in MetaMask I can see the RPC error in the console, but the error isn't propogated to the caller because it is caught and supplied to reportError().
What is the best approach to determining whether the activate succeeds?
Also looking at this. You can catch the error by using the Web3ReactProvider and the useWeb3React() hook. So it would look something like this:
const { error } = useWeb3React();
useEffect(() => {
if (error) {
handleError();
}
}, [error]);
It would be very nice to allow onConnected or onRejected callbacks to be passed to the activate method. That or just return the error in the promise of activate instead of returning a void
Yes, I think having the activate method return/throw the error would be highly benefical.
At the moment I have restored to this which seems to work but isn't ideal imo.
await connector.activate(chainId);
const { error } = store.getState();
if (error === undefined) {
connect(type);
}
@cosullivan where are you imprting the store?