Open
Description
Hi there,
I've refrained from upgrading to v8 until there's some documentation, so still using v6.
I'm curious if there is a method to eagerly connect wallet connect after an initial activation. For whatever reason on subsequent page reloads it clears localStorage and makes me scan my QR code again.
I've tried adding an additional hook to the useEagerConnect example but it fails once localStorage is cleared, and the walletConnect connector does not have access to the isAuthorized() method the default injected connector does on v6.
Any ideas?
import { useWeb3React } from "@web3-react/core";
import { useEffect, useState } from "react";
import { injected } from "../connectors";
import { walletConnectInjected, rainbowWallectConnect } from "../connectors";
export default function useEagerConnect() {
const { activate, active, library } = useWeb3React();
const [tried, setTried] = useState(false);
console.log(rainbowWallectConnect)
useEffect(() => {
injected.isAuthorized().then((isAuthorized) => {
if (isAuthorized) {
activate(injected, undefined, true).catch(() => {
setTried(true);
});
} else {
setTried(true);
}
});
}, [activate]);
useEffect(() => {
const walletConnect = window.localStorage.getItem("walletconnect");
if (walletConnect) {
const parsedJson = JSON.parse(walletConnect)
if (parsedJson.connected) {
activate(rainbowWallectConnect, undefined, true).catch((error) => {
console.log(error)
setTried(true);
});
}
}
}, [activate]);
// if the connection worked, wait until we get confirmation of that to flip the flag
useEffect(() => {
if (!tried && active) {
setTried(true);
}
}, [tried, active]);
return tried;
}