Fix initial token generation (#3289)

* Fix initial token generation

* Remove extra debug info
This commit is contained in:
Jaco Greeff 2016-11-08 23:17:33 +01:00 committed by Arkadiy Paronyan
parent 7b5824d4a2
commit f9dc766ae2
2 changed files with 16 additions and 11 deletions

View File

@ -28,19 +28,22 @@ export default class SecureApi extends Api {
this._dappsPort = 8080; this._dappsPort = 8080;
this._signerPort = 8180; this._signerPort = 8180;
console.log('SecureApi:constructor', sysuiToken);
this._followConnection(); this._followConnection();
} }
setToken = () => { setToken = () => {
window.localStorage.setItem('sysuiToken', this._transport.token); window.localStorage.setItem('sysuiToken', this._transport.token);
console.log('SecureApi:setToken', this._transport.token);
} }
_followConnection = () => { _followConnection = () => {
const nextTick = () => { const nextTick = () => {
setTimeout(this._followConnection, 250); setTimeout(() => this._followConnection(), 250);
}; };
const setManual = () => { const setManual = () => {
this._connectedState = 100; this._connectState = 100;
this._needsToken = true; this._needsToken = true;
this._isConnecting = false; this._isConnecting = false;
}; };
@ -51,7 +54,6 @@ export default class SecureApi extends Api {
// token = <passed via constructor> // token = <passed via constructor>
case 0: case 0:
if (isConnected) { if (isConnected) {
this._isConnecting = false;
return this.connectSuccess(); return this.connectSuccess();
} else if (lastError) { } else if (lastError) {
this.updateToken('initial', 1); this.updateToken('initial', 1);
@ -61,14 +63,13 @@ export default class SecureApi extends Api {
// token = 'initial' // token = 'initial'
case 1: case 1:
if (isConnected) { if (isConnected) {
this._connectState = 2; this.signer
this.parity
.generateAuthorizationToken() .generateAuthorizationToken()
.then((token) => { .then((token) => {
this.updateToken(token, 2); this.updateToken(token, 2);
}) })
.catch((error) => { .catch((error) => {
console.error('_followConnection', error); console.error('SecureApi:generateAuthorizationToken', error);
setManual(); setManual();
}); });
return; return;
@ -80,7 +81,6 @@ export default class SecureApi extends Api {
// token = <personal_generateAuthorizationToken> // token = <personal_generateAuthorizationToken>
case 2: case 2:
if (isConnected) { if (isConnected) {
this._isConnecting = false;
return this.connectSuccess(); return this.connectSuccess();
} else if (lastError) { } else if (lastError) {
return setManual(); return setManual();
@ -92,6 +92,9 @@ export default class SecureApi extends Api {
} }
connectSuccess () { connectSuccess () {
this._isConnecting = false;
this._needsToken = false;
this.setToken(); this.setToken();
Promise Promise
@ -103,12 +106,15 @@ export default class SecureApi extends Api {
this._dappsPort = dappsPort.toNumber(); this._dappsPort = dappsPort.toNumber();
this._signerPort = signerPort.toNumber(); this._signerPort = signerPort.toNumber();
}); });
console.log('SecureApi:connectSuccess', this._transport.token);
} }
updateToken (token, connectedState = 0) { updateToken (token, connectState) {
this._connectState = connectedState; this._connectState = connectState;
this._transport.updateToken(token.replace(/[^a-zA-Z0-9]/g, '')); this._transport.updateToken(token.replace(/[^a-zA-Z0-9]/g, ''));
this._followConnection(); this._followConnection();
console.log('SecureApi:updateToken', this._transport.token, connectState);
} }
get dappsPort () { get dappsPort () {

View File

@ -83,9 +83,8 @@ class Connection extends Component {
} }
renderSigner () { renderSigner () {
const { api } = this.context;
const { token, validToken } = this.state; const { token, validToken } = this.state;
const { needsToken, isConnecting } = api; const { isConnecting, needsToken } = this.props;
if (needsToken && !isConnecting) { if (needsToken && !isConnecting) {
return ( return (