starknet-react icon indicating copy to clipboard operation
starknet-react copied to clipboard

getInstalledInjectedConnectors() may be empty on page load but not empty a bit later

Open nmalzieu opened this issue 3 years ago • 3 comments

On pxls.wtf we had the following issue: sometimes the users couldn't log because there were no connectors. I found that it happened when the user was reloading the page (command R on chrome). At that point, the getInstalledInjectedConnectors() that gets called at the very beginning of my Next.js app was empty!

Right now, I fixed it the hacky way: https://github.com/nmalzieu/pxls-frontend/blob/main/pages/_app.tsx#L111-L129

However, I wonder:

  • could we detect that the installed connectors available on the page have changed?
  • should we really check this just once, at the very beginning of a Next.js app as done in the example or should we have a way to reload this before trying to connect
  • is there a reason why this happened to me only when doing a "reload" of the page and not when I was opening the same page in a new tab?

nmalzieu avatar Sep 19 '22 14:09 nmalzieu

This is a long standing issue and as you say there is no clear way forward. The wallets inject themselves at any point after the page loads and so it's impossible to detect them reliably. My guess is that users that experience issues have many extensions installed or slower computers. In your case, when you reload the page maybe chrome uses the cached version of the application and so the code is executed before the wallets finished injecting themselves.

The solutions are two:

  • manually create a list of supported wallets
  • use a hook similar to yours to refresh the installed wallets periodically

I wish we had a way to listen for changes to the window object to detect the wallets better.

fracek avatar Sep 19 '22 14:09 fracek

Thanks for your quick answer! I wonder if we shouldn't see connectors in 2 groups:

  • connectors that we manually pass to the provider
  • injected installed connectors that we find in the window object

When we use injected connectors, maybe we should just make the connectors and available properties of useStarknet methods that actually refresh them?

Do you know how wagmi handles this on Ethereum? They should have the exact same issue?

nmalzieu avatar Sep 19 '22 16:09 nmalzieu

In wagmi you need to specify the connectors manually so there is no issue. I agree connectors and available should be functions not values, probably a good idea to do that in the next breaking release.

fracek avatar Sep 19 '22 17:09 fracek

This issue has been automatically marked as stale because it has not had activity in the six months. It will be closed in 2 weeks if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant.

github-actions[bot] avatar Feb 26 '24 02:02 github-actions[bot]

This issue has been automatically closed because it has not had any further activity in the last 14 days.

github-actions[bot] avatar Mar 12 '24 02:03 github-actions[bot]