Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Work around WS in UI #3587

Merged
merged 6 commits into from
Nov 23, 2016
Merged

Work around WS in UI #3587

merged 6 commits into from
Nov 23, 2016

Conversation

ngotchac
Copy link
Contributor

@ngotchac ngotchac commented Nov 23, 2016

This might help with #3544

This UI gets smarter about connection and the use of Signer Token.
There shouldn't be anymore the Enter Signer Token modal if a correct one is available.
Connection status should work better.
Close to no calls should be stacked up in the queue if Parity is disconnected.

In dev mode, one can do window._parityWS._debug = true to have some debug information about WS messages. It will print the number of requests made per second (on average) every 5 seconds, as well as the total number of calls made from the start of the application.

Closes https://github.com/ethcore/parity/issues/3494

@ngotchac ngotchac added A0-pleasereview 🤓 Pull request needs code review. M7-ui labels Nov 23, 2016
@@ -389,7 +389,7 @@ export default class Contract {
const subscriptions = Object.values(this._subscriptions)
.filter((s) => s.options.toBlock && s.options.toBlock === 'pending');

const timeout = () => setTimeout(() => this._subscribeFromPendings(), 1000);
const timeout = () => setTimeout(() => this._subscribeToPendings(), 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't this fixed/merged? (Update with master?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes sorry, will update

@@ -102,7 +102,7 @@ export default class Status {
}, timeout);
};

fetch('/', { method: 'HEAD' })
fetch('/api/ping', { method: 'HEAD' })
Copy link
Contributor

@jacogr jacogr Nov 23, 2016

Choose a reason for hiding this comment

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

Anything under //api/* is not available on :8180, needs to be /. You cannot connect to :8080 either since to get the port you first need the API up via dappsUrl/dappsPort.


console.log('SecureApi:constructor', sysuiToken);
// Try tokens from hash, then from localstorage
this._tokensToTry = [ nextToken, sysuiToken ].filter((t) => t && t.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to be localStorage first, otherwise we end up with a bunch of single-use tokens. (Parity needs to clean this up, so we want to re-use as much as possible.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix

const url = process.env.PARITY_URL || window.location.host;

return fetch(
`http://${url}/api/ping`,
Copy link
Contributor

Choose a reason for hiding this comment

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

:8180 doesn't have /api/ping


console.log('SecureApi:constructor', sysuiToken);
// Try tokens from hash, then from localstorage
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment doesn't quite match the code anymore ;)

}
}

_checkNodeUp () {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't really belong in the WS transport layer, the purpose it to manage the connection, not rely on how the rest is stitched together. Here we are now assuming that there is always a capable /api/ping available.

Copy link
Contributor

Choose a reason for hiding this comment

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

Better now with the HEAD /, however we are assuming that the content is served from the same location as the WS now in the WS interface. Very specific...

// Event code 1006 for WS means there is an error
// (not just closed by server)
if (up && event.code === 1006) {
event.status = 403;
Copy link
Contributor

Choose a reason for hiding this comment

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

Dangerous, but better than what we have atm. (Apart from the up check that doesn't belong)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the thing is that there is no way to know why a WS connection has been closed. It's like this in the specs. I will just remove this and put the checkNodeUp method in the secureApi

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeap. That is the issue - if we had a 403 like gets displayed in the console, it would be so much easier.

'/api/*': {
proxy: [
{
context: (pathname, req) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I learn something new every day.

@ngotchac
Copy link
Contributor Author

Fixed comments


console.log('SecureApi:constructor', sysuiToken);
// Try tokens from localstorage, then from hash
this._tokensToTry = [ sysuiToken, nextToken ].filter((t) => t && t.length);
Copy link
Contributor

@jacogr jacogr Nov 23, 2016

Choose a reason for hiding this comment

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

Ok, one last comment - as soon as we change anything here we need a full test of all the iterations -

  1. localStorage token cleared, none specified
  2. token set to initial in localStorage`
  3. localeStorage token, none specified
  4. invalid localStorage token
  5. 1, 2, 3 & 4 with parity ui (calling /#/auth)
  6. doing everything wrong and having to supply a token (both correct & incorrect)
  7. ...

e.g. also see we have autoConnect swapped in WS, could be fine with logic, but need to thoroughly re-test all scenarios we can think of 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.

I've already tested them all

@jacogr
Copy link
Contributor

jacogr commented Nov 23, 2016

Ok, last comment made on the re-testing (really critical, since I have burned once or twice on this by not testing each and every scenario). Apart from that, looks good.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0c3d87f on ng-ws-improved into ** on master**.

@jacogr jacogr added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 23, 2016
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0c3d87f on ng-ws-improved into ** on master**.

@gavofyork gavofyork merged commit 7e800b7 into master Nov 23, 2016
@gavofyork gavofyork deleted the ng-ws-improved branch November 23, 2016 18:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants