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: memoize createClient in Remix example #392

Merged
merged 2 commits into from May 1, 2022
Merged

Conversation

jxom
Copy link
Member

@jxom jxom commented May 1, 2022

Description

Memoizing the wagmi client creation so we don't clear out the wagmi state on every render.

@changeset-bot
Copy link

changeset-bot bot commented May 1, 2022

⚠️ No Changeset found

Latest commit: 9e1e969

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link

vercel bot commented May 1, 2022

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

Name Status Preview Updated
wagmi ✅ Ready (Inspect) Visit Preview May 1, 2022 at 4:50AM (UTC)

Comment on lines +69 to +73
provider({ chainId }) {
return new providers.AlchemyProvider(
isChainSupported(chainId) ? chainId : defaultChain.id,
alchemyId,
)
Copy link
Sponsor

Choose a reason for hiding this comment

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

Do you think it's a good idea to fallback to Web3 provider? Otherwise if Infura/Alchemy does not support the chain it'll just fail with an exception.

Just as PoC (pretty bad error handling 😄 ). This can help with smoothly supporting custom chains (e.g. Moonbeam):

try {
  return new providers.InfuraProvider(config.chainId, infuraId);
} catch (e) {
  try {
    return providers.getDefaultProvider(config.chainId);
  } catch (e) {
    try {
      return new providers.Web3Provider(
        window.ethereum as any,
        Number(config.chainId)
      );
    } catch (e) {
      return providers.getDefaultProvider();
    }
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it is a good idea! We are actually planning to add a first class RPC Provider API very shortly (which will have fallback support for: if a provider goes down, or if a chain is unsupported by a provider).

We will update the examples accordingly once we add this.

@jxom jxom merged commit 299c77f into main May 1, 2022
@jxom jxom deleted the jxom/fix-remix-example branch May 1, 2022 21:20
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.

None yet

2 participants