-
Notifications
You must be signed in to change notification settings - Fork 64
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 select network and add token requests #11
base: multi
Are you sure you want to change the base?
Conversation
If ethereum provider is a class, spreading it onto a new object won't copy methods to the new object
I've tested this fix locally and switching networks via the AnySwap UI works as expected with the injected provider from our wallet, and still works as expected with MetaMask. |
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.
No need of setting request
method to the same method or an empty string.
src/config/tools/methods.ts
Outdated
const ethereumFN: any = ethereum; | ||
ethereumFN.request = (ethereum as any).request ?? ''; |
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.
calling ethereumFN.request
will throw an error if ethereum
obj is undefined. You dont need to set the request
method as it should be part of the ethereum
object you are referencing
const ethereumFN: any = ethereum; | |
ethereumFN.request = (ethereum as any).request ?? ''; | |
const ethereumFN: any = ethereum |
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, this is definitely better. I originally raised an issue (#10) about this, I'm not sure why the code is de-structuring ethereumFN
from window.ethereum
at all, but I tried to keep my PR as close to the original code as possible. But I should have made lines 9 & 10 like this to properly maintain consistency:
const ethereumFN: any = ethereum ?? {};
ethereumFN.request = (ethereum as any).request ?? '';
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 simplified the code in my PR slightly which should also fix the concern with window.ethereum
being undefined.
src/config/tools/methods.ts
Outdated
const ethereumFN: any = ethereum; | ||
ethereumFN.request = (ethereum as any).request ?? ''; |
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.
ditto
const ethereumFN: any = ethereum; | |
ethereumFN.request = (ethereum as any).request ?? ''; | |
const ethereumFN: any = ethereum |
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.
utACK
If Ethereum provider is a class, spreading it onto a new object won't copy methods to the new object
Fixes #10