-
Notifications
You must be signed in to change notification settings - Fork 494
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
[common, core] Update: allow instantiation with only chain id #1589
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Looks good to me! Although, not sure demo app changes are intended...
Just noting a good accompanying feature is to allow RPC URL to be passed explicitly in the appropriate places: i.e. when adding the chain to an injected wallet the RPC URL is required - but it's only then, and if it's needed. I don't actually see the changes in this PR that would handle the chain addition without the URL. Will the wallet just return an error here? @sesh92, could please provide a review here? |
I'd expect some changes around here: web3-onboard/packages/core/src/chain.ts Line 76 in 5dcf0c9
To either allow passing the whole |
@MOZGIII Sounds like you're looking for allowing for the passing of a rpcUrl (and token and label) as optional parameters in setChain i.e.: |
No goal in particular except for the better alignment of the internally available APIs and what they allow/offer with the potential use cases. Currently, the Ultimately, the way things would be set up after this PR, it would be possible to omit the parameters that are only required for I'd even put the newly optional values into a subobject to be more explicit about their nature and separate them from the rest (i.e. I.e. like: type ChainId = number | biting | ...;
type Chain = {
chainId: ChainId;
addChainParams?: AddChainParams;
}
type AddChainParams = {
rpcUrl: string;
label: string;
token: string;
// ...
} This way the API users know what the parameters are for, and the implementors know for what purpose the RPC URL is supposed to be used (i.e. don't accidentally start calling it directly instead of passing it to the wallet). |
packages/core/src/provider.ts
Outdated
): Promise<unknown> { | ||
return provider.request({ | ||
method: 'wallet_addEthereumChain', | ||
params: [ | ||
{ | ||
chainId: chain.id, | ||
chainName: chain.label, | ||
chainName: chain.label || label, |
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.
What happens if label, token or rpcUrl aren't defined on init and one or any subset are missing when this is called?
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.
In theory, the call should fail, and the provider should throw an implementation-dependent error. Not sure what will happen in practice, and how it's handled here...
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.
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.
Yep. This modal is good enough for the case where the app doesn't care - if it does care, I think the whole addChain
invocation logic can be implemented on the app side - to then follow with the onboard switch chain call. This is not the most straightforward way around the use of the available API for the users, but a good one for those who know what they're doing. We might want to note it in the docs though.
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.
Nice!! Good work!!
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.
Nice work, looks good!
Description
Issue: #1520
Allows a new web-3-onboard instance to be instantiated with only an id required in the Chain object.
Updates
setChain
function to accept optional arguments of rpcUrl, label, and token to add if needed to add a chain and chain was only instantiated with an id.Test Notes:
To run this demo use the command
yarn && yarn dev
to get the project running athttp://localhost:8080/
In the Onboard object, set a chain or two (I used Goerli and Optimism) to only their Ids:
{ id: '0x5' },
{ id: 10 },
Test switching chains.
after testing that initial behavior- add optional arguments to Optimism button and retest switch chains:
<button on:click={() => onboard.setChain({ chainId: 10, rpcUrl: 'https://mainnet.optimism.io', label: 'Optimism', token: 'OETH'})} >Set Chain to Optimism</button >
PLEASE NOTE- Checklist must be complete prior to review.
Checklist
package.json
of the package you have made changes in following semantic versioning and using alpha release taggingyarn check-all
to confirm there are not any associated errorsDocs Checklist
docs/package.json
file (if applicable)If this PR includes changes to add an injected wallet or SDK wallet module:
Please complete the following using the internal demo package.
Tests with demo app (injected)
Tests with demo app (SDK)
Docs Changes:
To test changes: start the svelte project demo (yarn && yarn dev from root directory). Goerli and Optimism Chains have been instantiated with just a chainId.
Video of Testing Changes:
LOOM VIDEO