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._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 = <passed via constructor>
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 = <personal_generateAuthorizationToken>
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 () {

View File

@ -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 (