Merge pull request #3379 from ethcore/new-token
Signer new-token generates a link and opens browser
This commit is contained in:
@@ -25,6 +25,7 @@ import ReactDOM from 'react-dom';
|
||||
import injectTapEventPlugin from 'react-tap-event-plugin';
|
||||
import { createHashHistory } from 'history';
|
||||
import { Redirect, Router, Route, useRouterHistory } from 'react-router';
|
||||
import qs from 'querystring';
|
||||
|
||||
import SecureApi from './secureApi';
|
||||
import ContractInstances from './contracts';
|
||||
@@ -45,6 +46,7 @@ import './index.html';
|
||||
|
||||
injectTapEventPlugin();
|
||||
|
||||
const AUTH_HASH = '#/auth?';
|
||||
const parityUrl = process.env.PARITY_URL ||
|
||||
(
|
||||
process.env.NODE_ENV === 'production'
|
||||
@@ -52,7 +54,12 @@ const parityUrl = process.env.PARITY_URL ||
|
||||
: '127.0.0.1:8180'
|
||||
);
|
||||
|
||||
const api = new SecureApi(`ws://${parityUrl}`);
|
||||
let token = null;
|
||||
if (window.location.hash && window.location.hash.indexOf(AUTH_HASH) === 0) {
|
||||
token = qs.parse(window.location.hash.substr(AUTH_HASH.length)).token;
|
||||
}
|
||||
|
||||
const api = new SecureApi(`ws://${parityUrl}`, token);
|
||||
ContractInstances.create(api);
|
||||
|
||||
const store = initStore(api);
|
||||
@@ -67,6 +74,7 @@ ReactDOM.render(
|
||||
<ContextProvider api={ api } muiTheme={ muiTheme } store={ store }>
|
||||
<Router className={ styles.reset } history={ routerHistory }>
|
||||
<Redirect from='/' to='/accounts' />
|
||||
<Redirect from='/auth' to='/accounts' query={ {} } />
|
||||
<Redirect from='/settings' to='/settings/views' />
|
||||
<Route path='/' component={ Application }>
|
||||
<Route path='accounts' component={ Accounts } />
|
||||
|
||||
@@ -19,12 +19,13 @@ import Api from './api';
|
||||
const sysuiToken = window.localStorage.getItem('sysuiToken');
|
||||
|
||||
export default class SecureApi extends Api {
|
||||
constructor (url) {
|
||||
constructor (url, nextToken) {
|
||||
super(new Api.Transport.Ws(url, sysuiToken));
|
||||
|
||||
this._isConnecting = true;
|
||||
this._connectState = sysuiToken === 'initial' ? 1 : 0;
|
||||
this._needsToken = false;
|
||||
this._nextToken = nextToken;
|
||||
this._dappsPort = 8080;
|
||||
this._dappsInterface = null;
|
||||
this._signerPort = 8180;
|
||||
@@ -57,7 +58,11 @@ export default class SecureApi extends Api {
|
||||
if (isConnected) {
|
||||
return this.connectSuccess();
|
||||
} else if (lastError) {
|
||||
this.updateToken('initial', 1);
|
||||
const nextToken = this._nextToken || 'initial';
|
||||
const nextState = this._nextToken ? 0 : 1;
|
||||
|
||||
this._nextToken = null;
|
||||
this.updateToken(nextToken, nextState);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user