2017-07-04 03:28:56 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { Provider } from 'react-redux';
|
2017-10-29 08:24:28 +00:00
|
|
|
import { withRouter, Switch, Redirect, Router, Route } from 'react-router-dom';
|
2017-09-29 02:09:01 +00:00
|
|
|
// Components
|
2017-10-17 04:01:28 +00:00
|
|
|
import Contracts from 'containers/Tabs/Contracts';
|
2017-09-29 02:09:01 +00:00
|
|
|
import ENS from 'containers/Tabs/ENS';
|
|
|
|
import GenerateWallet from 'containers/Tabs/GenerateWallet';
|
|
|
|
import Help from 'containers/Tabs/Help';
|
|
|
|
import SendTransaction from 'containers/Tabs/SendTransaction';
|
|
|
|
import Swap from 'containers/Tabs/Swap';
|
|
|
|
import ViewWallet from 'containers/Tabs/ViewWallet';
|
2017-10-30 19:10:25 +00:00
|
|
|
import SignAndVerifyMessage from 'containers/Tabs/SignAndVerifyMessage';
|
2017-10-23 20:48:55 +00:00
|
|
|
import BroadcastTx from 'containers/Tabs/BroadcastTx';
|
2017-11-30 20:16:30 +00:00
|
|
|
import RestoreKeystore from 'containers/Tabs/RestoreKeystore';
|
2017-12-08 06:16:27 +00:00
|
|
|
import ErrorScreen from 'components/ErrorScreen';
|
2017-04-12 05:04:27 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
// TODO: fix this
|
|
|
|
interface Props {
|
|
|
|
store: any;
|
|
|
|
history: any;
|
|
|
|
}
|
2017-04-12 05:04:27 +00:00
|
|
|
|
2017-12-08 06:16:27 +00:00
|
|
|
interface State {
|
|
|
|
hasError: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class Root extends Component<Props, State> {
|
|
|
|
public state = {
|
|
|
|
hasError: false
|
|
|
|
};
|
|
|
|
|
|
|
|
public componentDidCatch() {
|
|
|
|
this.setState({ hasError: true });
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public render() {
|
2017-09-29 02:09:01 +00:00
|
|
|
const { store, history } = this.props;
|
2017-12-08 06:16:27 +00:00
|
|
|
const { hasError } = this.state;
|
2017-09-18 06:31:52 +00:00
|
|
|
// key={Math.random()} = hack for HMR from https://github.com/webpack/webpack-dev-server/issues/395
|
2017-12-08 06:16:27 +00:00
|
|
|
return hasError ? (
|
|
|
|
<ErrorScreen />
|
|
|
|
) : (
|
2017-09-18 06:31:52 +00:00
|
|
|
<Provider store={store} key={Math.random()}>
|
2017-07-04 03:28:56 +00:00
|
|
|
<Router history={history} key={Math.random()}>
|
2017-09-29 02:09:01 +00:00
|
|
|
<div>
|
|
|
|
<Route exact={true} path="/" component={GenerateWallet} />
|
|
|
|
<Route path="/view-wallet" component={ViewWallet} />
|
|
|
|
<Route path="/help" component={Help} />
|
|
|
|
<Route path="/swap" component={Swap} />
|
|
|
|
<Route path="/send-transaction" component={SendTransaction} />
|
2017-10-17 04:01:28 +00:00
|
|
|
<Route path="/contracts" component={Contracts} />
|
2017-09-29 02:09:01 +00:00
|
|
|
<Route path="/ens" component={ENS} />
|
2017-11-30 20:16:30 +00:00
|
|
|
<Route path="/utilities" component={RestoreKeystore} />
|
2017-12-08 06:16:27 +00:00
|
|
|
<Route path="/sign-and-verify-message" component={SignAndVerifyMessage} />
|
2017-10-23 20:48:55 +00:00
|
|
|
<Route path="/pushTx" component={BroadcastTx} />
|
2017-10-29 08:24:28 +00:00
|
|
|
<LegacyRoutes />
|
2017-09-29 02:09:01 +00:00
|
|
|
</div>
|
2017-07-04 03:28:56 +00:00
|
|
|
</Router>
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
}
|
2017-04-12 05:04:27 +00:00
|
|
|
}
|
2017-10-29 08:24:28 +00:00
|
|
|
|
|
|
|
const LegacyRoutes = withRouter(props => {
|
|
|
|
const { history } = props;
|
|
|
|
const { pathname, hash } = props.location;
|
|
|
|
|
|
|
|
if (pathname === '/') {
|
|
|
|
switch (hash) {
|
|
|
|
case '#send-transaction':
|
|
|
|
case '#offline-transaction':
|
|
|
|
history.push('/send-transaction');
|
|
|
|
break;
|
|
|
|
case '#generate-wallet':
|
|
|
|
history.push('/');
|
|
|
|
break;
|
|
|
|
case '#swap':
|
|
|
|
history.push('/swap');
|
|
|
|
break;
|
|
|
|
case '#contracts':
|
|
|
|
history.push('/contracts');
|
|
|
|
break;
|
|
|
|
case '#ens':
|
|
|
|
history.push('/ens');
|
|
|
|
break;
|
|
|
|
case '#view-wallet-info':
|
|
|
|
history.push('/view-wallet');
|
|
|
|
break;
|
|
|
|
case '#check-tx-status':
|
|
|
|
history.push('/check-tx-status');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Switch>
|
|
|
|
<Redirect from="/signmsg.html" to="/sign-and-verify-message" />
|
|
|
|
<Redirect from="/helpers.html" to="/helpers" />
|
|
|
|
</Switch>
|
|
|
|
);
|
|
|
|
});
|