2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-12-11 21:03:48 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import {
|
|
|
|
Accounts, Account, Addresses, Address, Application,
|
2017-02-14 08:29:32 +01:00
|
|
|
Contract, Contracts, Dapp, Dapps, HistoryStore, Home,
|
2016-12-11 21:03:48 +01:00
|
|
|
Settings, SettingsBackground, SettingsParity, SettingsProxy,
|
2016-12-27 11:15:02 +01:00
|
|
|
SettingsViews, Signer, Status,
|
|
|
|
Wallet, Web, WriteContract
|
2016-12-11 21:03:48 +01:00
|
|
|
} from '~/views';
|
2017-01-26 17:37:52 +01:00
|
|
|
import builtinDapps from '~/views/Dapps/builtin.json';
|
|
|
|
|
|
|
|
const accountsHistory = HistoryStore.get('accounts');
|
|
|
|
const dappsHistory = HistoryStore.get('dapps');
|
2016-12-11 21:03:48 +01:00
|
|
|
|
|
|
|
function handleDeprecatedRoute (nextState, replace) {
|
|
|
|
const { address } = nextState.params;
|
|
|
|
const redirectMap = {
|
|
|
|
account: 'accounts',
|
|
|
|
address: 'addresses',
|
|
|
|
contract: 'contracts'
|
|
|
|
};
|
|
|
|
|
|
|
|
const oldRoute = nextState.routes[0].path;
|
|
|
|
const newRoute = Object.keys(redirectMap).reduce((newRoute, key) => {
|
|
|
|
return newRoute.replace(new RegExp(`^/${key}`), '/' + redirectMap[key]);
|
|
|
|
}, oldRoute);
|
|
|
|
|
|
|
|
console.warn(`Route "${oldRoute}" is deprecated. Please use "${newRoute}"`);
|
|
|
|
replace(newRoute.replace(':address', address));
|
|
|
|
}
|
|
|
|
|
|
|
|
function redirectTo (path) {
|
|
|
|
return (nextState, replace) => {
|
|
|
|
replace(path);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const accountsRoutes = [
|
2017-01-26 17:37:52 +01:00
|
|
|
{
|
|
|
|
path: ':address',
|
|
|
|
component: Account,
|
|
|
|
onEnter: ({ params }) => {
|
2017-02-14 08:29:32 +01:00
|
|
|
accountsHistory.add(params.address, 'account');
|
2017-01-26 17:37:52 +01:00
|
|
|
}
|
|
|
|
},
|
2017-02-14 08:29:32 +01:00
|
|
|
{
|
|
|
|
path: '/wallet/:address',
|
|
|
|
component: Wallet,
|
|
|
|
onEnter: ({ params }) => {
|
|
|
|
accountsHistory.add(params.address, 'wallet');
|
|
|
|
}
|
|
|
|
}
|
2016-12-11 21:03:48 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
const addressesRoutes = [
|
|
|
|
{ path: ':address', component: Address }
|
|
|
|
];
|
|
|
|
|
|
|
|
const contractsRoutes = [
|
|
|
|
{ path: 'develop', component: WriteContract },
|
|
|
|
{ path: ':address', component: Contract }
|
|
|
|
];
|
|
|
|
|
|
|
|
const settingsRoutes = [
|
|
|
|
{ path: 'background', component: SettingsBackground },
|
|
|
|
{ path: 'proxy', component: SettingsProxy },
|
|
|
|
{ path: 'views', component: SettingsViews },
|
|
|
|
{ path: 'parity', component: SettingsParity }
|
|
|
|
];
|
|
|
|
|
|
|
|
const statusRoutes = [
|
|
|
|
{ path: ':subpage', component: Status }
|
|
|
|
];
|
|
|
|
|
|
|
|
const routes = [
|
|
|
|
// Backward Compatible routes
|
|
|
|
{ path: '/account/:address', onEnter: handleDeprecatedRoute },
|
|
|
|
{ path: '/address/:address', onEnter: handleDeprecatedRoute },
|
|
|
|
{ path: '/contract/:address', onEnter: handleDeprecatedRoute },
|
|
|
|
|
2017-02-14 08:29:32 +01:00
|
|
|
{ path: '/', onEnter: redirectTo('/home') },
|
|
|
|
{ path: '/auth', onEnter: redirectTo('/home') },
|
2017-01-26 16:15:49 +01:00
|
|
|
{ path: '/settings', onEnter: redirectTo('/settings/views') }
|
|
|
|
];
|
2016-12-11 21:03:48 +01:00
|
|
|
|
2017-01-26 17:37:52 +01:00
|
|
|
const childRoutes = [
|
2017-01-26 16:15:49 +01:00
|
|
|
{
|
|
|
|
path: 'accounts',
|
|
|
|
indexRoute: { component: Accounts },
|
|
|
|
childRoutes: accountsRoutes
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'addresses',
|
|
|
|
indexRoute: { component: Addresses },
|
|
|
|
childRoutes: addressesRoutes
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'contracts',
|
|
|
|
indexRoute: { component: Contracts },
|
|
|
|
childRoutes: contractsRoutes
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'status',
|
|
|
|
indexRoute: { component: Status },
|
|
|
|
childRoutes: statusRoutes
|
|
|
|
},
|
2016-12-11 21:03:48 +01:00
|
|
|
{
|
2017-01-26 16:15:49 +01:00
|
|
|
path: 'settings',
|
|
|
|
component: Settings,
|
|
|
|
childRoutes: settingsRoutes
|
|
|
|
},
|
2017-01-26 17:37:52 +01:00
|
|
|
{
|
|
|
|
path: 'app/:id',
|
|
|
|
component: Dapp,
|
|
|
|
onEnter: ({ params }) => {
|
|
|
|
if (!builtinDapps[params.id] || !builtinDapps[params.id].skipHistory) {
|
|
|
|
dappsHistory.add(params.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-01-26 16:15:49 +01:00
|
|
|
{ path: 'apps', component: Dapps },
|
2017-02-14 08:29:32 +01:00
|
|
|
{ path: 'home', component: Home },
|
2017-01-26 16:15:49 +01:00
|
|
|
{ path: 'web', component: Web },
|
|
|
|
{ path: 'web/:url', component: Web },
|
|
|
|
{ path: 'signer', component: Signer }
|
2016-12-11 21:03:48 +01:00
|
|
|
];
|
|
|
|
|
2017-01-26 16:15:49 +01:00
|
|
|
// TODO : use ES6 imports when supported
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
const Playground = require('./playground').default;
|
|
|
|
|
2017-01-26 17:37:52 +01:00
|
|
|
childRoutes.push({
|
2017-01-26 16:15:49 +01:00
|
|
|
path: 'playground',
|
|
|
|
component: Playground
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
routes.push({
|
|
|
|
path: '/',
|
|
|
|
component: Application,
|
2017-01-26 17:37:52 +01:00
|
|
|
childRoutes
|
2017-01-26 16:15:49 +01:00
|
|
|
});
|
|
|
|
|
2016-12-11 21:03:48 +01:00
|
|
|
export default routes;
|