-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add updateEthereumChain, switchEthereumChain, getOwnedAssets, watchAsset #4
Conversation
0e0fa84
to
338a5d4
Compare
3456746
to
2764ecf
Compare
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.
also changes required in readme and package.json like:
https://github.com/web3/web3-wallet-rpc-utils/blob/a342b7bc3fd16a85509369c2b30f5a984c1e663d/package.json#L2
Thanks
that is already covered in my very first PR https://github.com/web3/web3-wallet-rpc-utils/pull/2/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519 There are 3 PRs so far, each building on top of the other, as I try to move fast but also to keep the review scope small. |
src/utils.ts
Outdated
export function parseToGetOwnedAssetsResult( | ||
result: unknown[] | ||
): GetOwnedAssetsResult { | ||
return result as GetOwnedAssetsResult; |
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.
this is a reminder for now to parse data returned by wallet to the expected format, even if not returned by wallet in the expected format.
* @param param - See {@link AddEthereumChainRequest} | ||
* @returns a Promise that resolves if the request is successful | ||
*/ | ||
public async addEthereumChain(param: AddEthereumChainRequest): Promise<void> { |
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.
wdyt about removing Ethereum
from the function names?
The usage would look like:
web3.walletRpc.addChain();
web3.walletRpc.switchChain();
web3.walletRpc.updateChain();
etc.
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.
I can see arguments for both approaches, but I think it's best to maintain consistency with the RPC method names.
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.
Several comments/questions, but nothing blocking
README.md
Outdated
- [wallet_watchAsset (EIP-747)](https://eips.ethereum.org/EIPS/eip-747) | ||
- [wallet_requestPermissions (EIP-2255)](https://eips.ethereum.org/EIPS/eip-2255) | ||
- [wallet_getPermissions (EIP-2255)](https://eips.ethereum.org/EIPS/eip-2255) |
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.
Same comment as before. It would be nice to mention these aren't yet implemented.
}); | ||
``` | ||
|
||
#### watchAsset |
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.
Can you update the PR title to mention that this method is implemented?
* @param param - See {@link AddEthereumChainRequest} | ||
* @returns a Promise that resolves if the request is successful | ||
*/ | ||
public async addEthereumChain(param: AddEthereumChainRequest): Promise<void> { |
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.
I can see arguments for both approaches, but I think it's best to maintain consistency with the RPC method names.
src/WalletRpcPlugin.ts
Outdated
type WalletRpcApi = { | ||
wallet_addEthereumChain: (param: AddEthereumChainRequest) => void; | ||
wallet_updateEthereumChain: (param: UpdateEthereumChainRequest) => void; | ||
wallet_switchEthereumChain: (param: SwitchEthereumChainRequest) => void; | ||
wallet_getOwnedAssets: (param: GetOwnedAssetsRequest) => GetOwnedAssetsResult; | ||
wallet_watchAsset: (param: WatchAssetRequest) => boolean; | ||
}; |
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.
Some minimal doc comments on these functions would be nice.
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.
I actually still don't understand what is this for, I copied this approach from some rpc plugin example. It is used as Web3PluginBase<WalletRpcApi>
but if I remove it, or change the names/types it doesn't affect anything in my plugin code. maybe @avkos @luu-alex @jdevcs could share some more. Anyway, it's internal use only.
* @param param - See {@link UpdateEthereumChainRequest} | ||
* @returns a Promise that resolves if the request is successful | ||
*/ | ||
public async updateEthereumChain( |
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.
The EIP for this method is stagnant and the method is not implemented by MetaMask. Are we sure we want to add this?
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.
I will test all wallet rpc methods with a few different wallets and see what is actually implemented.
/** | ||
* Array of asset interface identifiers such as ['ERC20', 'ERC721']. | ||
*/ | ||
types?: string[]; |
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.
For some of these less straightforward optional parameters, it may be nice to document what the behavior is when the parameter is omitted.
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.
The thing is, right now I don't know what happens and it's up to each wallet to decide how they handle that. I want to test it with a few popular wallets and see if there is any patter there. We can also introduce our own error types.
src/types.ts
Outdated
chainId: Numbers; | ||
/** | ||
* Asset interface ERC identifier, e.g., ERC20. | ||
* Optional - EIP-1820 could be used. |
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 does this mean, exactly, that "EIP-1820 could be used"? If this property is omitted, how should the user interpret it?
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.
I think I copied it from the EIP spec, I have no idea what does it mean :) I will remove it.
it("should return correct result", async () => { | ||
const result = await web3.walletRpc.addEthereumChain({ chainId: 5000 }); | ||
|
||
expect(result).toBeUndefined(); | ||
}); |
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 is the purpose of this test?
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.
I don't know yet how to test actual wallet responses as each wallet can return whatever they want. I'm thinking to add some response parsers to always return the same type, despite wallet response, but I need to test it on real examples first (with real browser extension wallets). This test is not testing much yet, I agree.
338a5d4
to
244812b
Compare
5ae1665
to
b19b187
Compare
b19b187
to
93f518e
Compare
c617bb1
to
522e5b2
Compare
No description provided.