Skip to content
This repository has been archived by the owner on Mar 25, 2019. It is now read-only.

Rough version of web3 support and embeddable ParityBar #16

Merged
merged 21 commits into from
Jan 24, 2017
Merged

Conversation

tomusdrw
Copy link
Contributor

@tomusdrw tomusdrw commented Jan 19, 2017

Embeds ParityBar from running node.

Things left to do (as a separate issues)

  • Indicate that the node is not running (extension icon?)
  • Customizable port and interface (currently hardcoded to 127.0.0.1:8180)
  • Support for web3.site?
  • Go through all todos in code to fix those minor issues.

@tomusdrw
Copy link
Contributor Author

tomusdrw commented Jan 23, 2017

@ngotchac Ready to review and test (requires Parity build with cargo build --release --no-default-features --features ui from this branch: https://github.com/ethcore/parity/pull/4222)

}

if (openedTabId) {
chrome.tabs.remove(openedTabId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it looks a bit sketchy to randomly open and close the tab when the Extension installs ? The user won't have the time to understand what happens ; I know I would be surprised. Might be better to have a settings/options/status window where it says that it needs the auth token, and on a button click it could open the right tab and gather the right data. However this might be included in a future issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That tab is opened in the background (and it always opens only once), we also check if the node is up before opening it.

I think it might be better to just display a welcome page (that's actually quite a common thing for extensions) loaded from http://127.0.0.1:8180/#/welcome - it could list extension features, and the token would be extracted automatically :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with the welcome message, as per other extensions. Would log it in another issue though.
Because even if the tab is open in background, you can still see it open and close, right?

styles: /styles\/embed\.([a-z0-9]{10})\.css/.exec(page),
scripts: /embed\.([a-z0-9]{10})\.js/.exec(page)
}))
.then(res => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to use a ServiceWorker here. It's its job to fetch and cache requests, and it's work pretty good. Also it might be good to have a way to export which files are required by the embed.html file, instead of using some RegExp. There might be a Webpack plugin/option for that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT you cannot use ServiceWorker in background script of chrome extension (cause actually background scripts are more powerful then service workers). Also we cannot use service worker in the iframe, because of Mixed Content limitations.

So the way it works is:
Load an iframe with chrome-extension://<hash>/web3/embed.html and that page asks a background thread to fetch and provide correct files. (As I said ServiceWorker is not an option, cause the browser would detect that https had iframe that fetched non-https content and would block it as violating non-secure source.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, didn't know... So the API is not available either ?

})
.catch(err => {
console.error('Node seems down, will re-try', err);
setTimeout(() => extractToken(), 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might not want a background script making a request every second if I don't have my node up and running on installation. Cf. comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right we should use exponential backoff here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use exponential backoff everywhere.

@@ -24,7 +24,7 @@ export default class Socials {
const { all } = Socials;

let match = null;
const social = Object.values(all).find((social) => {
const social = Object.keys(all).map(key => all[key]).find((social) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use Object.values ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not supported in my Chrome and we don't include polyfill.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought Babel was taking care of this... Should have a proper Webpack config I guess

@ngotchac
Copy link
Contributor

Great start ! Some comments/remarks/questions. Seems to have some strange behaviors sometimes (eg. showing "Connecting to Parity..."), and tries to load some font file without success, or a service worker (that's from the UI code).

Copy link
Contributor

@ngotchac ngotchac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good !

@tomusdrw tomusdrw merged commit eb90753 into master Jan 24, 2017
@tomusdrw tomusdrw deleted the web3-ext branch January 24, 2017 10:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants