on master help sign in
bridge: reload when selected chain changes

We can't guarantee connections/state still being valid, so a full reload is the right thing to do. Metamask used to do this for us, but no longer does.

commit23994744153f8254c5799ab7f0ae0e44d24356b4 authorfang <git@fang.io> dateFri 19 Mar 2021, 14:40 (6 years ago) parent29f4a14
1 file changed+9
src/Bridge.js+9
src/Bridge.js+9
@@ -1,4 +1,5 @@
11import React from 'react';
2+import { useEffect } from 'react';
23import { hot } from 'react-hot-loader/root';
34import { Just, Nothing } from 'folktale/maybe';
45import { IndigoApp } from 'indigo-react';
@@ -66,6 +67,14 @@ function useInitialRoutes() {
6667function Bridge() {
6768 const initialRoutes = useInitialRoutes();
6869
70+ // full reload if the user changes their selected network in Metamask
71+ //
72+ useEffect(() => {
73+ window.ethereum.on('chainChanged', () => {
74+ document.location.reload();
75+ });
76+ }, []);
77+
6978 return (
7079 <WithErrorBoundary render={error => <GlobalErrorBoundary error={error} />}>
7180 <Provider