diff --git a/js/src/secureApi.js b/js/src/secureApi.js index 2f03d62e9..abc893d78 100644 --- a/js/src/secureApi.js +++ b/js/src/secureApi.js @@ -28,19 +28,22 @@ export default class SecureApi extends Api { this._dappsPort = 8080; this._signerPort = 8180; + console.log('SecureApi:constructor', sysuiToken); + this._followConnection(); } setToken = () => { window.localStorage.setItem('sysuiToken', this._transport.token); + console.log('SecureApi:setToken', this._transport.token); } _followConnection = () => { const nextTick = () => { - setTimeout(this._followConnection, 250); + setTimeout(() => this._followConnection(), 250); }; const setManual = () => { - this._connectedState = 100; + this._connectState = 100; this._needsToken = true; this._isConnecting = false; }; @@ -51,7 +54,6 @@ export default class SecureApi extends Api { // token = case 0: if (isConnected) { - this._isConnecting = false; return this.connectSuccess(); } else if (lastError) { this.updateToken('initial', 1); @@ -61,14 +63,13 @@ export default class SecureApi extends Api { // token = 'initial' case 1: if (isConnected) { - this._connectState = 2; - this.parity + this.signer .generateAuthorizationToken() .then((token) => { this.updateToken(token, 2); }) .catch((error) => { - console.error('_followConnection', error); + console.error('SecureApi:generateAuthorizationToken', error); setManual(); }); return; @@ -80,7 +81,6 @@ export default class SecureApi extends Api { // token = case 2: if (isConnected) { - this._isConnecting = false; return this.connectSuccess(); } else if (lastError) { return setManual(); @@ -92,6 +92,9 @@ export default class SecureApi extends Api { } connectSuccess () { + this._isConnecting = false; + this._needsToken = false; + this.setToken(); Promise @@ -103,12 +106,15 @@ export default class SecureApi extends Api { this._dappsPort = dappsPort.toNumber(); this._signerPort = signerPort.toNumber(); }); + + console.log('SecureApi:connectSuccess', this._transport.token); } - updateToken (token, connectedState = 0) { - this._connectState = connectedState; + updateToken (token, connectState) { + this._connectState = connectState; this._transport.updateToken(token.replace(/[^a-zA-Z0-9]/g, '')); this._followConnection(); + console.log('SecureApi:updateToken', this._transport.token, connectState); } get dappsPort () { diff --git a/js/src/views/Connection/connection.js b/js/src/views/Connection/connection.js index 2217bb13c..07fc8f18a 100644 --- a/js/src/views/Connection/connection.js +++ b/js/src/views/Connection/connection.js @@ -83,9 +83,8 @@ class Connection extends Component { } renderSigner () { - const { api } = this.context; const { token, validToken } = this.state; - const { needsToken, isConnecting } = api; + const { isConnecting, needsToken } = this.props; if (needsToken && !isConnecting) { return (