bridge_ui: detect metamask accountsChanged

Change-Id: I3ef224daf567313f70f6082c374cca7a7607f611
This commit is contained in:
Evan Gray 2021-09-08 15:43:15 -04:00
parent 8974fa999d
commit 020314d0f0
1 changed files with 17 additions and 1 deletions

View File

@ -88,6 +88,23 @@ export const EthereumProviderProvider = ({
setChainId(BigNumber.from(chainId).toNumber());
} catch (e) {}
});
// @ts-ignore
detectedProvider.on("accountsChanged", (accounts) => {
try {
const signer = provider.getSigner();
setSigner(signer);
signer
.getAddress()
.then((address) => {
setSignerAddress(address);
})
.catch(() => {
setProviderError(
"An error occurred while getting the signer address"
);
});
} catch (e) {}
});
}
})
.catch(() => {
@ -110,7 +127,6 @@ export const EthereumProviderProvider = ({
setSigner(undefined);
setSignerAddress(undefined);
}, []);
//TODO: detect account change
const contextValue = useMemo(
() => ({
connect,