xmtp / example-chat-react

This repo has been archived. Replacement apps include the XMTP Quickstart React and XMTP Inbox chat apps. For more details and links, see the README in this repo.
MIT License
74 stars 52 forks source link

Bug: Excessive Errors in the Console #172

Closed jazzz closed 1 year ago

jazzz commented 1 year ago

Describe the bug

Excessive errors in the devtools console. First reported by @prashantpbagga

Steps to Reproduce

  1. Go to 'vercel.xmtp.com'
  2. Login in with your Blockchain account
  3. Inspect

Occurs after login, without any further user action.

Expected behavior

Not lots of errors.

Screenshots

image image Screenshot 2023-01-09 at 12 33 08 PM

Additional context

Add any other context about the problem here.

Desktop

Please complete the following information if you think it is relevant to the bug:

michaelx11 commented 1 year ago

Steps to repro addition: attempt to log in with WalletConnect to trigger the issue. Metamask login worked fine for me.

michaelx11 commented 1 year ago

@snormore - points out that we're likely not using the right InfuraID. He's looking into that work thread now.

I'm looking into why we're getting so many requests in the first place if there's a 800ms retry timeout. I believe we're invoking this effect https://github.com/xmtp/example-chat-react/blob/main/hooks/useWalletProvider.tsx#L106-L107 to initialize a walletConnect provider 12 times in quick succession when a user connects with WalletConnect.

See "invoking effect" log line in this screenshot. These 12 initializations match the spamming behavior which is 10-12 requests punctuated by a short 800ms delay

Screen Shot 2023-01-09 at 1 51 07 PM
michaelx11 commented 1 year ago

I'm tracing the hooks a bit, still not exactly sure of why we're getting multiple provider initializations but here are some clues:

In a release build (xmtp.chat) we see 6 duplicate web3Modal HTML tags. In a dev build we see 12 (React doubles some hooks in dev). It looks like multiple provider instances are created independently and all will separately retry their connections, or poll.

Screenshots from a local build:

Screen Shot 2023-01-09 at 2 10 07 PM Screen Shot 2023-01-09 at 2 10 51 PM
elisealix22 commented 1 year ago

I'm able to reproduce this! Looks like this is causing ENS resolution to fail as well. We'll prioritize.

neekolas commented 1 year ago

At least part of the problem is that we are giving our Infura API key away to the public in our code, who can then abuse it and eat up our rate limit.

We should use a separate key with a paid account for our deployed versions of our 1P apps. We can lock the key to our 1P domains to avoid people stealing that one.