-
Notifications
You must be signed in to change notification settings - Fork 435
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
Provider injection #88
Conversation
I imagine we also want to add a screen inside the extension where the user can choose the RPC endpoint, if it's different from |
Still have to work out the handling of WsProvider connection/disconnection/reconnection and how it should affect the PostMessageProvider (right now it assumes the extension provider is always on) ; and have to actually test this PR against apps (next step in this PR), but overall I think the gist of it is here. so open for reviewing/comments! |
@@ -0,0 +1,126 @@ | |||
// Copyright 2019 @polkadot/extension authors & contributors |
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 have just been scrolling through, so no in-depth comments yet - however, it would be good if we can actually move the provider (as to be injected) to extension-provider
so it is actually easily re-usable by others as well.
(I can see that this file, as-is, can be shared - just the endpoint can be custom for a "quick start")
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.
And yes... need to do exactly the same with the injected signer. (In thinking about these 2, it may end up being in extension-inject
then as sub-folders.) So extensions do the following -
- include the package
- use the top-level interface to inject into the page
- create an instance of the signer for signing (or do their own)
- create an instance of the provider (or ignore, or do their own)
One self-contained bundle.
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.
it would be good if we can actually move the provider (as to be injected) to extension-provider so it is actually easily re-usable by others as well.
PostMessageProvider only sends messages to the window, it heavily relies on the logic (and message format) of page.js/content.js so that the messages are sent to the extension and received from the extension; as such I don't think it's very reusable by itself. Same for the injected signer, which basically only does sendRequest('extrinsic.sign', payload);
. What do you think?
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 would suggest looking at how other extensions are using this - as it is, it is being used as-is. You do have a good suggestion buried in there though to make the message names slightly less generic for these case, i.e so it is explicit where it comes from and what it is for.
Prior to the previous commit, the extension was using a single WsProvider, shared by all pages. Since we need active subscriptions made by the page to be closed when the page closes, and since there is no maintainable way of deriving the unsubscription method name from the subscription method name, I resorted to using one WsProvider per page. When the page closes, the associated underlying WsProvider disconnects. Right now the WsProvider connects when the page makes an RPC request. Connecting or disconnecting the WsProvider from the Page (from the PostMessageProvider) isn't supported as it seems to me like a lot of overhead for little benefit. |
Can we start pulling parts in? i.e. the typing changes - that we can pull in via another PR. (Actually unrelated and will clean this one . up some more). Would like to start getting this ready so it doesn't hang about. |
Sure sounds good, will do this now. I'll go about figuring out a strategy for reusability straight after |
Perfect. Don't need to solve all the world's problems at once - happy to get improvements in as they come in. (Not a massive fan . of large PRs hanging about) |
Closing, needed at some point, but not being worked on here or merge-able. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Close #58
Preparing the groundwork. Next up in this PR: integrating this in
extension