@pearlphoenix your right u cant do that what cryptokid means is to save a referance to web3 session in local storage. Production apps lile uniswap and pancake swap do this by saving a referance to last session in local storage. If local storage has an ref they connect in page load. Its called eager connect. See this repo. Also lool at rhe uniswap v1 legacy interface fo a simpler implementation their old code is much easier to follow. Its well worth forking these repos to see how these guys do things in production you can learn a lot by taking a day or two.
As for walletconnect i find this finicky too. If you go to the likes of uniswap or pancakeswap and referesh the page when connect with any wallet the connector that it defaults back to is always injected. So if your connected with portis, fortmatic and even walletconnect and refresh youll always be loaded in with injected web3 when u refresh.
I had an idea of how to get around this but havent tested it yet so not sure if it will work. You could make two intances of the walletconnect connector. One with qrcode: true
and the other with qrcode: false
if you conect by clicking the connect button instiate web3 with the walletconnect provider that makes the qr modal pop up. Then save some refernace to the walletconnect session to local strage could simply be localStorage.setItem(provider, "walletconnect)". (this is what pancakeswap does)
. then on page load if local storage provider item === walletconnect then just activate walleconnectweb3 with the connector where qrcode: false
now ive only thought of this idea have never tried it myself so not sure if it will work. but just know that production apps like usinswap and packcake always default back to injected web3 on page refresh.