web3-react
web3-react copied to clipboard
Eagerly connect walletconnect on v6
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;
}
hey did you ever solve this? I am having the exact same issue
bump - any feedback on this? thanks!
upgrade web3-react/core from v6 to v8 https://github.com/Uniswap/web3-react/tree/main#upgrading-from-v6 use latest WalletConnect -v2 (v1 depreciated) @web3-react/walletconnect-v2 https://docs.walletconnect.com/2.0/advanced/migration-from-v1.x/dapps/#web3-react
https://github.com/SmartDev-0205/web3-react-walletconnectv2-dex It is working on my side. Try to check and follow me.