WalletConnect Connection after Refresh

Hi,
i give up … after like 8 hours of trying i really need to ask someone. I think the solution is easy but idk …

So Connecting Metamask is working perfectly… i can switch sites, refresh site everything no problem… web3 connections is still alive …

but if i am connected with walletconnect and trrustwallet for example, the login works perfectly… i even can call functions and stuff… but as soon as i refresh the website the web3 connection is lost, and the walletconnect - QR Code stuff appears …

How can i solve that?

here some of my code xD (the function init is called if website is loaded / refreshed)

async function login()

{

  if (window.ethereum) {

    loginmeta();

  } else {

    walletlogin();

  }

}

async function loginmeta() {

  let user = Moralis.User.current();

  if (!user) {

    user = await Moralis.authenticate();

  }

  callthewallet(user.get("ethAddress"));

  document.querySelector("#prepare").style.display = "none";

  document.querySelector("#connected").style.display = "block";

}

async function logOut() {

  await Moralis.User.logOut();

  document.querySelector("#prepare").style.display = "block";

  document.querySelector("#connected").style.display = "none";

}

async function walletlogin() {

  let user = Moralis.User.current();

  if (!user) {

    user = await Moralis.authenticate({

      provider: "walletconnect",

      mobileLinks: [

      "1inch",

      "metamask",

      "trust",

      ],

      chainId: 56,

      })  

  }

  callthewallet(user.get("ethAddress"));

  window.localStorage.walletconnect = "walletconnect";

  document.querySelector("#prepare").style.display = "none";

  document.querySelector("#connected").style.display = "block";

}

async function init()

{

 const user = await Moralis.User.current();

 if(user)

  {

    if (window.localStorage.walletconnect) {

     

      Moralis.enableWeb3({ provider: "walletconnect",chainId:56});

     

    }

    else

    {

     

      Moralis.enableWeb3();

    }

   

    callthewallet(user.get("ethAddress"));

    document.querySelector("#prepare").style.display = "none";

    document.querySelector("#connected").style.display = "block";

  }

  else

  {

   

  }

 

}

i really hope someone can help me … the dapp is almost done … cant belive i am to stupid for this rofl

ah to let you know i am using these scripts 

 <script src="https://github.com/WalletConnect/walletconnect-monorepo/releases/download/1.7.1/web3-provider.min.js"></script>
  
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/moralis.js"></script>

<script src="https://cdn.ethers.io/scripts/ethers-v3.min.js" charset="utf-8" type="text/javascript"></script>

if anyone could help me out here, would be awesome <3

I face this problem too…

thanks sent to the team for review

1 Like

Welcome :slight_smile: any news for this problem?

We are currently working on it. It has been implemented by design that the user requires to scan a new code on each session.
I understand that this is not ideal in all cases, so we will make adjustments to make this optional.

2 Likes

Thank you very much ! Awesome support as always :slight_smile:

hey, have you found a way to mitigate this while the team make a fix?

We are thinking about creating our custom provider and connector instead…

This has been fixed in the latest version. We will re-use the same walletconnect session.

It only gets cleared when

  • User authenticates again
  • User logs out
  • You call enableWeb3 with the param: newSession
4 Likes

works perfectly!!! thank you so much

2 Likes