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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
provider({ chainId }) { | ||
return new providers.AlchemyProvider( | ||
isChainSupported(chainId) ? chainId : defaultChain.id, | ||
alchemyId, | ||
) |
There was a problem hiding this comment.
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();
}
}
}
There was a problem hiding this comment.
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.
Description
Memoizing the wagmi client creation so we don't clear out the wagmi state on every render.