-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
Move stream functionality from BaseProvider to new StreamProvider #209
Conversation
88fcf08
to
cf3be4b
Compare
fae748d
to
f5889b7
Compare
f5889b7
to
a0f7ded
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.
This is something that we've obviously been thinking about for a while and have wanted to do, so thank you for doing this. I took another look at EIP-1193 to verify that BaseProvider satisfies the minimum requirements and didn't see anything that stands out. I also like how minimal BaseProvider is now. A few questions/suggestions below, but overall looks good to me.
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.
One more thing, then I'm good!
By the way one thing I've noticed is that you've changed all of the default exports to named exports. That isn't the first time I've seen that pattern, so I'm curious — what are your thoughts? What are the benefits you see using named exports vs. default exports? Are there any scenarios in which we would still want to use default exports?
71e8565
to
abd90a1
Compare
@mcmire, regarding named vs default exports, I think default exports make sense when you have a module that exports a single thing for which the name isn't that important. As soon as you are exporting multiple things from the same file, it's probably time for named exports. Mixing default and named exports isn't really that harmful in TypeScript IMO, but there's not really any benefit either. In JavaScript, I've found the practice to be actively harmful and confusing, because it's easy to mess up your imports and/or exports when your editor doesn't tell you about it. The reason I made the change in this PR is because I made a change that caused a file to export two things instead of one, and then I just went through and removed all default exports except one, which is an internal log / error message utility ( On second thought, default exports also have the weakness of being importable under different names, which can be very confusing in large code bases. For our single message utility it doesn't matter, but it's been a real pain in the ass to deal with in the extension historically. |
Okay, thanks for the explanation, makes sense! |
ed6873e
to
5bba4db
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.
Two more things!
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.
LGTM!
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.
LGTM!
I accidentally mangled the docstring in #209. This PR fixes it.
The constructor of the
BaseProvider
expected a duplex stream, and the class as a whole contained a considerable amount of logic specific to streams and stream handling. This PR extracts this and other dependent functionality into a new class,StreamProvider
, which is now extended byMetaMaskInpageProvider
, whileBaseProvider
is made abstract. This will be useful for replacing internal legacy providers (which do not always / ever use streams) with EIP-1193 equivalents throughout the MetaMask codebase.This PR should be completely non-breaking except for the changes made to the
BaseProvider
class. In addition,createExternalExtensionProvider
,MetaMaskInpageProvider
, andinitializeProvider
should have no behavior changes at all.In detail, this PR:
BaseProvider
to an abstract class, and moves all stream-specific functionality into a new class,StreamProvider
BaseProvider
tests to theStreamProvider
tests, adds an initialization test caserpcMiddleware
parameter toBaseProvider
BaseProvider
are now instead passed as constructor parameters toStreamProvider
andMetaMaskInpageProvider
as necessary.networkVersion
-related logic from theBaseProvider
toMetaMaskInpageProvider
, while continuing to rely on thenetworkVersion
having the value of'loading'
to detect when we are mid-network change in theStreamProvider
(and by extension its child classes).jest-it-up
and minimum coverage requirements