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

fix: ethers/ethers5 infinite requests #3086

Merged
merged 3 commits into from
Oct 15, 2024
Merged

Conversation

magiziz
Copy link
Contributor

@magiziz magiziz commented Oct 15, 2024

Description

There's a bug where if you switch to any network other than ethereum you'll get a lot of network requests sometimes up to 50k.

This happens because the ethers/ethers5 adapters switches caip address every second. It goes back and forth between the ethereum caip address and polygon caip address if you're connected to polygon. This results into hitting the rpc endpoint loads of times.

image

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Associated Issues

For Linear issues: Closes APKT-1283
For GH issues: closes #...

Checklist

  • Code in this PR is covered by automated tests (Unit tests, E2E tests)
  • My changes generate no new warnings
  • I have reviewed my own code
  • I have filled out all required sections
  • I have tested my changes on the preview link
  • Approver of this PR confirms that the changes are tested on the preview link

Copy link

changeset-bot bot commented Oct 15, 2024

🦋 Changeset detected

Latest commit: 4e9fb31

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@reown/appkit-adapter-ethers5 Patch
@reown/appkit-adapter-ethers Patch
@apps/demo Patch
@apps/gallery Patch
@apps/laboratory Patch
@reown/appkit-adapter-polkadot Patch
@reown/appkit-adapter-solana Patch
@reown/appkit-adapter-wagmi Patch
@reown/appkit Patch
@reown/appkit-utils Patch
@reown/appkit-cdn Patch
@reown/appkit-common Patch
@reown/appkit-core Patch
@reown/appkit-experimental Patch
@reown/appkit-polyfills Patch
@reown/appkit-scaffold-ui Patch
@reown/appkit-siwe Patch
@reown/appkit-ui Patch
@reown/appkit-wallet Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Oct 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
appkit-laboratory ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 15, 2024 5:17pm
appkit-wagmi-cdn-example ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 15, 2024 5:17pm
web3modal-gallery ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 15, 2024 5:17pm

Copy link
Contributor

github-actions bot commented Oct 15, 2024

Coverage Report for Coverage

Status Category Percentage Covered / Total
🔵 Lines 320.71000000000004% 4447 / 19306
🔵 Statements 320.71000000000004% 4447 / 19306
🔵 Functions 343.5% 347 / 1031
🔵 Branches 380.2% 637 / 1328
File CoverageNo changed files found.
Generated in workflow #6843 for commit 4e9fb31 by the Vitest Coverage Report Action

const caipAddress = `${this.chainNamespace}:${chainId}:${firstAddress}` as CaipAddress
const caipNetwork = this.caipNetworks.find(c => c.id === chainId) ?? this.caipNetworks[0]
const caipAddress =
`${this.chainNamespace}:${caipNetwork?.id}:${firstAddress}` as CaipAddress
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the caipNetwork id directly?

Copy link
Contributor Author

@magiziz magiziz Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like adding chainId directly into caipAddress ? I tried doing that, but when switching to a unsupported network it'd throw an error, instead i checked if the network is supported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I meant ${caipNetwork.namespace}:${caipNetwork?.id}:${firstAddress} or ${caipNetwork.caipNetworkId}:${firstAddress}

(unsure about proper names but you get what I mean)

@@ -631,9 +631,12 @@ export class EthersAdapter {
if (provider) {
const { addresses, chainId } = await EthersHelpersUtil.getUserInfo(provider)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why source the infor from here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's because during the construct of the adapter we'd need to get the address and chain id directly from the provider so users are still connected even if they refresh the page. The logic happens here.

@magiziz magiziz merged commit d27bd6d into main Oct 15, 2024
18 checks passed
@magiziz magiziz deleted the fix/ethers5-infinite-requests branch October 15, 2024 18:21
Copy link

linear bot commented Oct 15, 2024

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

Successfully merging this pull request may close these issues.

3 participants