diff --git a/src/components/app/index.js b/src/components/app/index.js index 085f7744e7..d67b8b6ce5 100644 --- a/src/components/app/index.js +++ b/src/components/app/index.js @@ -38,29 +38,29 @@ class App extends React.Component {
- ( + (
- - - - - + + + + +
)} /> - ( + (
- - - - + + + +
)} /> - - - + + +
diff --git a/src/components/app/index.test.js b/src/components/app/index.test.js index db8d2b6575..69b147123b 100644 --- a/src/components/app/index.test.js +++ b/src/components/app/index.test.js @@ -11,6 +11,7 @@ import Login from '../login'; import Transactions from '../transactionDashboard'; import Search from '../search'; import Voting from '../voting'; +import routes from '../../constants/routes'; const fakeStore = configureStore(); @@ -27,12 +28,12 @@ const addRouter = Component => (props, path) => const publicComponent = [ { route: '/', component: Login }, - { route: '/explorer/search', component: Search }, + { route: `${routes.explorer.path}${routes.search.path}`, component: Search }, ]; const privateComponent = [ - { route: '/main/transactions', component: Transactions }, - { route: '/main/voting', component: Voting }, + { route: `${routes.main.path}${routes.transaction.path}`, component: Transactions }, + { route: `${routes.main.path}${routes.voting.path}`, component: Voting }, ]; describe('App', () => { diff --git a/src/components/dashboard/index.js b/src/components/dashboard/index.js index 355ebc8a22..c7ddd4e6e7 100644 --- a/src/components/dashboard/index.js +++ b/src/components/dashboard/index.js @@ -8,6 +8,7 @@ import Box from '../box'; import TransactionList from './../transactions/transactionList'; import Send from '../send'; import CurrencyGraph from './currencyGraph'; +import routes from '../../constants/routes'; import styles from './dashboard.css'; class Dashboard extends React.Component { @@ -22,7 +23,7 @@ class Dashboard extends React.Component {

{t('Latest activity')} - + {t('See all transactions')} diff --git a/src/components/dialog/dialog.test.js b/src/components/dialog/dialog.test.js index 5b13250a4c..b12e925ab7 100644 --- a/src/components/dialog/dialog.test.js +++ b/src/components/dialog/dialog.test.js @@ -16,7 +16,7 @@ describe('Dialog', () => { beforeEach(() => { history = { location: { - pathname: `${routes.search.long}saved-accounts`, + pathname: `${routes.explorer.path}${routes.search.path}saved-accounts`, search: '', }, push: sinon.spy(), @@ -45,7 +45,7 @@ describe('Dialog', () => { }); it('allows to close the dialog on regexp path ', () => { - const basePath = '/explorer/transactions/1523498127498/'; + const basePath = `${routes.explorer.path}${routes.wallet.path}/1523498127498/`; history.location.pathname = `${basePath}saved-accounts`; wrapper.setProps({ history }); wrapper.find('.x-button').simulate('click'); @@ -53,7 +53,7 @@ describe('Dialog', () => { }); it('allows to close the dialog on non-regexp path ', () => { - history.location.pathname = `${routes.wallet.long}saved-accounts`; + history.location.pathname = `${routes.main.path}${routes.wallet.path}saved-accounts`; wrapper.setProps({ history }); wrapper.find('.x-button').simulate('click'); expect(history.push).to.have.been.calledWith(); diff --git a/src/components/header/header.js b/src/components/header/header.js index 267799aabd..72896dc61f 100644 --- a/src/components/header/header.js +++ b/src/components/header/header.js @@ -19,15 +19,15 @@ class Header extends React.Component { const { pathname } = this.props.location; return !this.props.isAuthenticated && !this.props.account.loading - && pathname !== routes.login.url - && ![routes.register.url, routes.addAccount.url] + && pathname !== routes.login.path + && ![routes.register.path, routes.addAccount.path] .some(el => pathname.includes(el)); } shouldShowSearchBar() { const { pathname } = this.props.location; - return ![routes.search.long, routes.register.url, routes.addAccount.url] - .some(el => pathname.includes(el)) && pathname !== routes.login.url; + return ![`${routes.explorer.path}${routes.search.path}`, routes.register.path, routes.addAccount.path] + .some(el => pathname.includes(el)) && pathname !== routes.login.path; } render() { diff --git a/src/components/header/header.test.js b/src/components/header/header.test.js index 48f92d183b..26f1e807ea 100644 --- a/src/components/header/header.test.js +++ b/src/components/header/header.test.js @@ -7,6 +7,7 @@ import PropTypes from 'prop-types'; import sinon from 'sinon'; import Header from './header'; import i18n from '../../i18n'; +import routes from '../../constants/routes'; describe('Header', () => { let wrapper; @@ -25,7 +26,7 @@ describe('Header', () => { setActiveDialog: () => { }, account: {}, t: key => key, - location: { pathname: '/explorer/search' }, + location: { pathname: `${routes.explorer.path}${routes.search}` }, isAuthenticated: false, }; propsMock = sinon.mock(mockInputProps); diff --git a/src/components/login/login.js b/src/components/login/login.js index f36c825a00..5a0178d494 100644 --- a/src/components/login/login.js +++ b/src/components/login/login.js @@ -12,6 +12,7 @@ import { extractAddress } from '../../utils/api/account'; import PassphraseInput from '../passphraseInput'; import styles from './login.css'; import networks from '../../constants/networks'; +import routes from '../../constants/routes'; import getNetwork from '../../utils/getNetwork'; import { parseSearchParams } from './../../utils/searchParams'; import Box from '../box'; @@ -99,7 +100,7 @@ class Login extends React.Component { getReferrerRoute() { const search = parseSearchParams(this.props.history.location.search); - const dashboardRoute = '/main/dashboard'; + const dashboardRoute = `${routes.main.path}${routes.dashboard.path}`; const referrerRoute = search.referrer ? search.referrer : dashboardRoute; return referrerRoute; } @@ -200,7 +201,7 @@ class Login extends React.Component {

- + {this.props.t('Create Lisk ID')} diff --git a/src/components/login/login.test.js b/src/components/login/login.test.js index 857d2ba046..debe332b52 100644 --- a/src/components/login/login.test.js +++ b/src/components/login/login.test.js @@ -7,6 +7,7 @@ import { MemoryRouter } from 'react-router-dom'; import PropTypes from 'prop-types'; import i18n from '../../i18n'; import Login from './login'; +import routes from '../../constants/routes'; describe('Login', () => { let wrapper; @@ -88,15 +89,15 @@ describe('Login', () => { it('calls this.props.history.replace(\'/main/dashboard\')', () => { wrapper = shallow(, options); wrapper.setProps({ account: { address: 'dummy' } }); - expect(props.history.replace).to.have.been.calledWith('/main/dashboard'); + expect(props.history.replace).to.have.been.calledWith(`${routes.main.path}${routes.dashboard.path}`); }); it('calls this.props.history.replace with referrer address', () => { wrapper = shallow(, options); props.history.replace.reset(); - history.location.search = '?referrer=/main/voting'; + history.location.search = `?referrer=${routes.main.path}${routes.voting.path}`; wrapper.setProps({ history, account: { address: 'dummy' } }); - expect(props.history.replace).to.have.been.calledWith('/main/voting'); + expect(props.history.replace).to.have.been.calledWith(`${routes.main.path}${routes.voting.path}`); }); it('hides network options by default', () => { diff --git a/src/components/mainMenu/mainMenu.js b/src/components/mainMenu/mainMenu.js index 96dbfbb030..d28ec4d753 100644 --- a/src/components/mainMenu/mainMenu.js +++ b/src/components/mainMenu/mainMenu.js @@ -7,6 +7,7 @@ import logo from '../../assets/images/logo-beta.svg'; import * as menuLogos from '../../assets/images/main-menu-icons/*.svg'; //eslint-disable-line import { FontIcon } from '../fontIcon'; import Setting from '../setting'; +import routes from '../../constants/routes'; const getIndex = (history, tabs) => { if (history.location.pathname.includes('explorer')) return 2; @@ -64,12 +65,12 @@ class MainMenu extends React.Component { const tabs = [ { label: t('Dashboard'), - route: '/main/dashboard', + route: `${routes.main.path}${routes.dashboard.path}`, id: 'dashboard', image: menuLogos.dashboard, }, { label: t('Wallet'), - route: '/main/transactions', + route: `${routes.main.path}${routes.wallet.path}`, id: 'transactions', image: menuLogos.wallet, }, { @@ -81,12 +82,12 @@ class MainMenu extends React.Component { }, { */ label: t('Explorer'), - route: '/explorer/search', + route: `${routes.explorer.path}${routes.search.path}`, id: 'explorer', image: menuLogos.search, }, { label: t('Sidechains'), - route: '/main/sidechains', + route: `${routes.main.path}${routes.sidechains.path}`, id: 'sidechains', image: menuLogos.sidechains, }, @@ -96,7 +97,7 @@ class MainMenu extends React.Component { tabs.splice(tabs.length - 1, 0, { label: t('Delegates'), id: 'voting', - route: '/main/voting', + route: `${routes.main.path}${routes.voting.path}`, image: menuLogos.delegates, }); } diff --git a/src/components/mainMenu/mainMenu.test.js b/src/components/mainMenu/mainMenu.test.js index fed29c150b..b18d533a7b 100644 --- a/src/components/mainMenu/mainMenu.test.js +++ b/src/components/mainMenu/mainMenu.test.js @@ -8,6 +8,7 @@ import sinon from 'sinon'; import PropTypes from 'prop-types'; import i18n from '../../i18n'; import MainMenu from './mainMenu'; +import routes from '../../constants/routes'; describe('MainMenu', () => { @@ -41,7 +42,7 @@ describe('MainMenu', () => { const history = { location: { - pathname: '/main/voting', + pathname: `${routes.main.path}${routes.voting.path}`, }, push: sinon.spy(), }; @@ -111,7 +112,7 @@ describe('MainMenu', () => { , options); wrapper.find(Tab).at(1).simulate('click'); - expect(history.push).to.have.been.calledWith('/main/transactions'); + expect(history.push).to.have.been.calledWith(`${routes.main.path}${routes.wallet.path}`); }); it('should click on more activate the drawer', () => { diff --git a/src/components/register/register.js b/src/components/register/register.js index f6345e6db7..2d7065ccd7 100644 --- a/src/components/register/register.js +++ b/src/components/register/register.js @@ -9,6 +9,7 @@ import networks from '../../constants/networks'; import getNetwork from '../../utils/getNetwork'; import Box from '../box'; import styles from './register.css'; +import routes from '../../constants/routes'; class Register extends React.Component { @@ -19,7 +20,7 @@ class Register extends React.Component { componentDidUpdate() { if (this.props.account.passphrase !== undefined) { - this.props.history.push('/main/dashboard'); + this.props.history.push(`${routes.main.path}${routes.dashboard.path}`); } } diff --git a/src/components/savedAccounts/savedAccounts.js b/src/components/savedAccounts/savedAccounts.js index 6790a3af29..f670e270c7 100644 --- a/src/components/savedAccounts/savedAccounts.js +++ b/src/components/savedAccounts/savedAccounts.js @@ -69,7 +69,7 @@ class SavedAccounts extends React.Component { const switchAccount = (account) => { if (!this.state.editing) { accountSwitched(account); - history.push('/main/dashboard/'); + history.push(`${routes.main.path}${routes.dashboard.path}`); } }; @@ -81,7 +81,7 @@ class SavedAccounts extends React.Component {

  • - +
    diff --git a/src/components/savedAccounts/savedAccounts.test.js b/src/components/savedAccounts/savedAccounts.test.js index 4617b0ca50..f265ff9b98 100644 --- a/src/components/savedAccounts/savedAccounts.test.js +++ b/src/components/savedAccounts/savedAccounts.test.js @@ -8,6 +8,7 @@ import PropTypes from 'prop-types'; import i18n from '../../i18n'; import networks from '../../constants/networks'; import SavedAccounts from './savedAccounts'; +import routes from '../../constants/routes'; const mountWithRouter = (node, options) => mount({node}, options); const fakeStore = configureStore(); @@ -89,7 +90,7 @@ describe('SavedAccounts', () => { it('should call props.accountSwitched on the "saved account card" click', () => { wrapper.find('.saved-account-card').at(1).simulate('click'); expect(props.accountSwitched).to.have.been.calledWith(savedAccounts[1]); - expect(props.history.push).to.have.been.calledWith('/main/dashboard/'); + expect(props.history.push).to.have.been.calledWith(`${routes.main.path}${routes.dashboard.path}`); }); it('should not call props.accountSwitched on the "saved account card" click if in "edit" mode', () => { diff --git a/src/components/search/keyAction.js b/src/components/search/keyAction.js index a3f0ea77ae..779a2c3f3f 100644 --- a/src/components/search/keyAction.js +++ b/src/components/search/keyAction.js @@ -13,17 +13,17 @@ const saveSearch = (search) => { export const visit = (value, history) => { if (value.match(regex.address)) { - history.push(`${routes.account.long}/${value}`); + history.push(`${routes.explorer.path}${routes.account.path}/${value}`); } else if (value.match(regex.transactionId)) { - history.push(`${routes.transaction.long}/${value}`); + history.push(`${routes.explorer.path}${routes.transaction.path}/${value}`); } else { - history.push(`${routes.searchResult.long}/${value}`); + history.push(`${routes.explorer.path}${routes.searchResult.path}/${value}`); } }; export const visitAndSaveSearch = (value, history) => { if (value.length === 0) { - history.push(routes.search.long); + history.push(`${routes.explorer.path}${routes.search.path}`); } else { value = value.trim(); saveSearch(value); diff --git a/src/components/search/keyAction.test.js b/src/components/search/keyAction.test.js index 116307c95d..93c318043a 100644 --- a/src/components/search/keyAction.test.js +++ b/src/components/search/keyAction.test.js @@ -43,9 +43,9 @@ describe('Search KeyAction', () => { ]; const expectedHistory = [ - `${routes.account.long}/${testValues[0]}`, - `${routes.transaction.long}/${testValues[1]}`, - `${routes.searchResult.long}/${testValues[2]}`, + `${routes.explorer.path}${routes.account.path}/${testValues[0]}`, + `${routes.explorer.path}${routes.transaction.path}/${testValues[1]}`, + `${routes.explorer.path}${routes.searchResult.path}/${testValues[2]}`, ]; testValues.forEach((value) => { diff --git a/src/components/searchBar/index.js b/src/components/searchBar/index.js index 23a1e98ae0..db10dc817c 100644 --- a/src/components/searchBar/index.js +++ b/src/components/searchBar/index.js @@ -28,7 +28,7 @@ class Search extends React.Component { shouldShowSearchBarOnMobile() { const { pathname } = this.props.location; - return pathname.includes('explorer') && !pathname.includes(routes.search.long); + return pathname.includes('explorer') && !pathname.includes(`${routes.explorer.path}${routes.search.path}`); } diff --git a/src/components/sendTo/index.js b/src/components/sendTo/index.js index 2370dec4ea..fe2947b790 100644 --- a/src/components/sendTo/index.js +++ b/src/components/sendTo/index.js @@ -58,7 +58,7 @@ class SendTo extends React.Component { ${grid['middle-sm']} ${styles.sendButton} `}> - + {this.props.t('Send to this address')} diff --git a/src/components/sendTo/sendTo.test.js b/src/components/sendTo/sendTo.test.js index b420a11407..88509f7886 100644 --- a/src/components/sendTo/sendTo.test.js +++ b/src/components/sendTo/sendTo.test.js @@ -18,11 +18,11 @@ describe('SendTo Component', () => { }); it('renders correct link', () => { - expect(wrapper.find('Link').prop('to')).to.equal(`${routes.wallet.long}?address=${props.address}`); + expect(wrapper.find('Link').prop('to')).to.equal(`${routes.main.path}${routes.wallet.path}?address=${props.address}`); }); it('updates when address changes', () => { wrapper.setProps({ address: '9876L' }); - expect(wrapper.find('Link').prop('to')).to.equal(`${routes.wallet.long}?address=9876L`); + expect(wrapper.find('Link').prop('to')).to.equal(`${routes.main.path}${routes.wallet.path}?address=9876L`); }); }); diff --git a/src/components/transactions/transactionDetailView.js b/src/components/transactions/transactionDetailView.js index d290a0fe0b..0eda4cdfa0 100644 --- a/src/components/transactions/transactionDetailView.js +++ b/src/components/transactions/transactionDetailView.js @@ -36,7 +36,7 @@ const TransactionsDetailView = props => ( }
    + to={`${routes.explorer.path}${routes.account.path}/${props.value.senderId}`}> {props.value.senderId}
    @@ -53,7 +53,7 @@ const TransactionsDetailView = props => ( { props.value.recipientId ? + to={`${routes.explorer.path}${routes.account.path}/${props.value.recipientId}`}> {props.value.recipientId} : '-' } diff --git a/src/constants/routes.js b/src/constants/routes.js index aeeb4f9dc0..78a3106a86 100644 --- a/src/constants/routes.js +++ b/src/constants/routes.js @@ -1,10 +1,16 @@ export default { - wallet: { long: '/main/transactions', short: '/transactions' }, - account: { long: '/explorer/accounts', short: '/accounts' }, - search: { long: '/explorer/search', short: '/search' }, - searchResult: { long: '/explorer/result', short: '/result' }, - transaction: { long: '/explorer/transactions', short: '/transactions' }, - login: { url: '/' }, - addAccount: { url: '/add-account' }, - register: { url: '/register' }, + wallet: { path: '/transactions' }, + account: { path: '/accounts' }, + accountVisualDemo: { path: '/account-visual-demo' }, + dashboard: { path: '/dashboard' }, + search: { path: '/search' }, + searchResult: { path: '/result' }, + transaction: { path: '/transactions' }, + login: { path: '/' }, + addAccount: { path: '/add-account' }, + register: { path: '/register' }, + sidechains: { path: '/sidechains' }, + voting: { path: '/voting' }, + main: { path: '/main' }, + explorer: { path: '/explorer' }, }; diff --git a/src/utils/externalLinks.test.js b/src/utils/externalLinks.test.js index 3a75aa4681..106d864148 100644 --- a/src/utils/externalLinks.test.js +++ b/src/utils/externalLinks.test.js @@ -2,6 +2,7 @@ import { expect } from 'chai'; import { spy } from 'sinon'; import externalLinks from './externalLinks'; import history from '../history'; +import routes from '../constants/routes'; describe('externalLinks', () => { const historyPush = spy(history, 'push'); @@ -28,6 +29,6 @@ describe('externalLinks', () => { }; externalLinks.init(); callbacks.openUrl({}, 'lisk://register'); - expect(historyPush).to.have.been.calledWith('/register'); + expect(historyPush).to.have.been.calledWith(routes.register.path); }); }); diff --git a/src/utils/routes.js b/src/utils/routes.js index 04eca951be..caaba26708 100644 --- a/src/utils/routes.js +++ b/src/utils/routes.js @@ -3,56 +3,56 @@ import routes from './../constants/routes'; export default [ { regex: /\/main\/account-visual-demo(?:\/[^/]*)?$/, - path: '/main/account-visual-demo/', + path: `${routes.main.path}${routes.accountVisualDemo.path}/`, params: 'dialog', name: 'account-visual-demo', }, { regex: /\/main\/dashboard(?:\/[^/]*)?$/, - path: '/main/dashboard/', + path: `${routes.main.path}${routes.dashboard.path}/`, params: 'dialog', name: 'dashboard', }, { regex: /\/main\/transactions(?:\/[^/]*)?$/, - path: `${routes.wallet.long}/`, + path: `${routes.main.path}${routes.wallet.path}/`, params: 'dialog', name: 'transactions', }, { regex: /\/main\/voting(?:\/[^/]*)?$/, - path: '/main/voting/', + path: `${routes.main.path}${routes.voting.path}/`, params: 'dialog', name: 'voting', }, { regex: /\/main\/sidechains(?:\/[^/]*)?$/, - path: '/main/sidechains/', + path: `${routes.main.path}${routes.sidechains.path}/`, params: 'dialog', name: 'sidechains', }, { regex: /\/add-account(?:\/[^/]*)?$/, - path: '/add-account/', + path: `${routes.addAccount.path}/`, params: 'dialog', name: 'add-account', }, { regex: /\/explorer\/accounts\/\d{1,21}[L|l](?:\/[^/]*)?$/, - path: new RegExp(`${routes.account.long}/\\d{1,21}[L|l]/`), + path: new RegExp(`${routes.explorer.path}${routes.account.path}/\\d{1,21}[L|l]/`), params: 'address', name: 'accounts', }, { regex: /\/explorer\/result\/([0-9]+|[a-z]+)(?:\/[^/]*)?$/, - path: new RegExp(`${routes.searchResult.long}/([0-9]+|[a-z]+)/`), + path: new RegExp(`${routes.explorer.path}${routes.searchResult.path}/([0-9]+|[a-z]+)/`), params: 'query', name: 'result', }, { regex: /\/explorer\/search(?:\/[^/]*)?$/, - path: `${routes.search.long}/`, + path: `${routes.explorer.path}${routes.search.path}/`, name: 'explorer', }, { regex: /\/explorer\/transactions\/\d+(?:\/[^/]*)?$/, - path: new RegExp(`${routes.transaction.long}/\\d+/`), + path: new RegExp(`${routes.explorer.path}${routes.transaction.path}/\\d+/`), params: 'id', name: 'explorer-transaction', }, { regex: /register(?:\/[^/]*)?$/, - path: '/register/', + path: `${routes.register.path}/`, params: 'dialog', name: 'register', }, {