Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useAccountEffect.onConnect not called after some page reloads #4221

Open
1 task done
lukaw3d opened this issue Aug 24, 2024 · 3 comments
Open
1 task done

useAccountEffect.onConnect not called after some page reloads #4221

lukaw3d opened this issue Aug 24, 2024 · 3 comments
Labels
Good First Issue Misc: Good First Issue

Comments

@lukaw3d
Copy link

lukaw3d commented Aug 24, 2024

Check existing issues

Describe the bug

I'm trying to consistently listen to onConnect

useAccountEffect({ onConnect: console.log });

but it isn't triggered when reloading the page by enabling metamask to run on the site

Link to Minimal Reproducible Example

https://stackblitz.com/edit/new-wagmi-tfvypz?file=src%2FApp.tsx

Steps To Reproduce

Added logging for useAccountEffect.onConnect conditions

onChange(data, prevData) {
if (
(prevData.status === 'reconnecting' ||
(prevData.status === 'connecting' &&
prevData.address === undefined)) &&
data.status === 'connected'
) {

https://stackblitz.com/edit/new-wagmi-tfvypz?file=src%2FApp.tsx
open preview in new tab

First time connecting, click Injected: 🟢

{"prevData":{"status":"connecting"},"data":{"status":"disconnected"}}
{"prevData":{"status":"disconnected"},"data":{"status":"connecting"}}
{"prevData":{"status":"connecting"},"data":{"status":"connected","address":"0xC3ecf872F643C6238Aa20673798eed6F7dA199e9"}}
useAccountEffect.onConnect was called

Reload page: 🟢

{"prevData":{"status":"reconnecting","address":"0xC3ecf872F643C6238Aa20673798eed6F7dA199e9"},"data":{"status":"reconnecting","address":"0xC3ecf872F643C6238Aa20673798eed6F7dA199e9"}}
{"prevData":{"status":"reconnecting","address":"0xC3ecf872F643C6238Aa20673798eed6F7dA199e9"},"data":{"status":"connected","address":"0xC3ecf872F643C6238Aa20673798eed6F7dA199e9"}}
useAccountEffect.onConnect was called

Reload by enabling metamask to run on this site: 🔴

  • configure metamask Site access: On specific sites (chrome://extensions/?id=nkbihfbeogaeaoehlefnkodbefgpgknn)
  • close preview and open preview in new tab again
  • metamask is disabled on this site
  • click metamask to allow it and reload the page
{"prevData":{"status":"connecting"},"data":{"status":"connecting","address":"0xC3ecf872F643C6238Aa20673798eed6F7dA199e9"}}
{"prevData":{"status":"connecting","address":"0xC3ecf872F643C6238Aa20673798eed6F7dA199e9"},"data":{"status":"connected","address":"0xC3ecf872F643C6238Aa20673798eed6F7dA199e9"}}
useAccountEffect.onConnect was not called

What Wagmi package(s) are you using?

wagmi

Wagmi Package(s) Version(s)

2.12.7

Viem Version

2.0.0

TypeScript Version

5.2.2

Anything else?

No response

@ahmetson
Copy link

ahmetson commented Sep 7, 2024

@nfts2me
Copy link

nfts2me commented Sep 10, 2024

We are also having this issue on https://nfts2me.com/app/

After some digging, we've seen that the issue comes from WalletConnect and wallets that use it, like walletConnectWallet, okxWallet, trustWallet, rainbowWallet, tokenPocketWallet.

Wagmi should be able to handle a delay from WalletConnect servers response and ignore its response until it responds, not affecting the rest of the connectors for wallets.

It seems that the WS requests to wss://relay.walletconnect.com/ keep pending, and after a time out, it continues and the wagmi account status is finally as expected.

image

No idea why it doesn't happen on the first connect, and only after a reconnection.

We've disabled temporarily those wallets to make it work.

@tmm tmm added the Good First Issue Misc: Good First Issue label Sep 10, 2024
@nfts2me
Copy link

nfts2me commented Sep 11, 2024

After latest viem and wagmi ("[email protected]") there are no petitions to relay.walletconnect.com ws, and thus, seems to be fixed.

Probably due to this fix by @tmm #4259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Misc: Good First Issue
Projects
None yet
Development

No branches or pull requests

4 participants