Init history in dapp module

This commit is contained in:
Jaco Greeff 2017-08-30 11:29:15 +02:00
parent b1428c2b56
commit d7de40ab4c
2 changed files with 22 additions and 24 deletions

View File

@ -19,10 +19,24 @@ import { observer } from 'mobx-react';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Api from '@parity/api';
import builtinDapps from '@parity/shared/config/dappsBuiltin.json';
import viewsDapps from '@parity/shared/config/dappsViews.json';
import DappsStore from '@parity/shared/mobx/dappsStore'; import DappsStore from '@parity/shared/mobx/dappsStore';
import HistoryStore from '@parity/shared/mobx/historyStore';
import styles from './dapp.css'; import styles from './dapp.css';
const internalDapps = []
.concat(viewsDapps, builtinDapps)
.map((app) => {
if (app.id && app.id.substr(0, 2) !== '0x') {
app.id = Api.util.sha3(app.id);
}
return app;
});
@observer @observer
export default class Dapp extends Component { export default class Dapp extends Component {
static contextTypes = { static contextTypes = {
@ -39,10 +53,15 @@ export default class Dapp extends Component {
}; };
store = DappsStore.get(this.context.api); store = DappsStore.get(this.context.api);
historyStore = HistoryStore.get('dapps');
componentWillMount () { componentWillMount () {
const { id } = this.props.params; const { id } = this.props.params;
if (!internalDapps[id] || !internalDapps[id].skipHistory) {
this.historyStore.add(id);
}
this.loadApp(id); this.loadApp(id);
} }

View File

@ -23,11 +23,7 @@ import injectTapEventPlugin from 'react-tap-event-plugin';
import { IndexRoute, Redirect, Route, Router, hashHistory } from 'react-router'; import { IndexRoute, Redirect, Route, Router, hashHistory } from 'react-router';
import qs from 'querystring'; import qs from 'querystring';
import Api from '@parity/api';
import builtinDapps from '@parity/shared/config/dappsBuiltin.json';
import viewsDapps from '@parity/shared/config/dappsViews.json';
import ContractInstances from '@parity/shared/contracts'; import ContractInstances from '@parity/shared/contracts';
import HistoryStore from '@parity/shared/mobx/historyStore';
import { initStore } from '@parity/shared/redux'; import { initStore } from '@parity/shared/redux';
import ContextProvider from '@parity/ui/ContextProvider'; import ContextProvider from '@parity/ui/ContextProvider';
@ -35,8 +31,8 @@ import '@parity/shared/environment';
import Application from './Application'; import Application from './Application';
import Dapp from './Dapp'; import Dapp from './Dapp';
import { setupProviderFilters } from './DappRequests';
import Dapps from './Dapps'; import Dapps from './Dapps';
import { setupProviderFilters } from './DappRequests';
import SecureApi from './secureApi'; import SecureApi from './secureApi';
injectTapEventPlugin(); injectTapEventPlugin();
@ -65,32 +61,15 @@ setupProviderFilters(api.provider);
const store = initStore(api, hashHistory); const store = initStore(api, hashHistory);
const dapps = [].concat(viewsDapps, builtinDapps).map((app) => {
if (app.id && app.id.substr(0, 2) !== '0x') {
app.id = Api.util.sha3(app.id);
}
return app;
});
const dappsHistory = HistoryStore.get('dapps');
function onEnterDapp ({ params: { id } }) {
if (!dapps[id] || !dapps[id].skipHistory) {
dappsHistory.add(id);
}
}
console.log('UI version', process.env.UI_VERSION); console.log('UI version', process.env.UI_VERSION);
console.log('Loaded dapps', dapps);
ReactDOM.render( ReactDOM.render(
<ContextProvider api={ api } store={ store }> <ContextProvider api={ api } store={ store }>
<Router history={ hashHistory }> <Router history={ hashHistory }>
<Route path='/' component={ Application }> <Route path='/' component={ Application }>
<Redirect from='/auth' to='/' /> <Redirect from='/auth' to='/' />
<Route path='/:id' component={ Dapp } onEnter={ onEnterDapp } /> <Route path='/:id' component={ Dapp } />
<Route path='/:id/:details' component={ Dapp } onEnter={ onEnterDapp } /> <Route path='/:id/:details' component={ Dapp } />
<IndexRoute component={ Dapps } /> <IndexRoute component={ Dapps } />
</Route> </Route>
</Router> </Router>