From 042792dda281203b136dc3bdb3752e8dbdd17d92 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Fri, 9 Mar 2018 18:38:16 +0100 Subject: [PATCH 1/3] Refactor route definition --- src/components/app/index.js | 20 ++++++++--------- src/components/app/index.test.js | 7 +++--- src/components/dashboard/index.js | 3 ++- src/components/dialog/dialog.test.js | 6 ++--- src/components/header/header.js | 2 +- src/components/header/header.test.js | 3 ++- src/components/login/login.js | 5 +++-- src/components/login/login.test.js | 9 ++++---- src/components/mainMenu/mainMenu.js | 11 +++++----- src/components/mainMenu/mainMenu.test.js | 5 +++-- src/components/register/register.js | 3 ++- src/components/savedAccounts/savedAccounts.js | 4 ++-- .../savedAccounts/savedAccounts.test.js | 3 ++- src/components/search/keyAction.js | 8 +++---- src/components/search/keyAction.test.js | 6 ++--- src/components/searchBar/index.js | 2 +- src/components/sendTo/index.js | 2 +- src/components/sendTo/sendTo.test.js | 4 ++-- .../transactions/transactionDetailView.js | 4 ++-- src/constants/routes.js | 16 +++++++++----- src/utils/externalLinks.test.js | 3 ++- src/utils/routes.js | 22 +++++++++---------- 22 files changed, 82 insertions(+), 66 deletions(-) diff --git a/src/components/app/index.js b/src/components/app/index.js index 085f7744e7..ce07f0a3d2 100644 --- a/src/components/app/index.js +++ b/src/components/app/index.js @@ -38,24 +38,24 @@ class App extends React.Component {
- ( + (
- - + + - - + +
)} /> - ( + (
- - - - + + + +
)} /> diff --git a/src/components/app/index.test.js b/src/components/app/index.test.js index db8d2b6575..871aecf305 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}${routes.search.url}`, component: Search }, ]; const privateComponent = [ - { route: '/main/transactions', component: Transactions }, - { route: '/main/voting', component: Voting }, + { route: `${routes.main}${routes.transaction.url}`, component: Transactions }, + { route: `${routes.main}${routes.voting.url}`, component: Voting }, ]; describe('App', () => { diff --git a/src/components/dashboard/index.js b/src/components/dashboard/index.js index 75c8acb5be..05325ca644 100644 --- a/src/components/dashboard/index.js +++ b/src/components/dashboard/index.js @@ -9,6 +9,7 @@ import TransactionList from './../transactions/transactionList'; import Send from '../send'; import CurrencyGraph from './currencyGraph'; import styles from './styles.css'; +import routes from '../../constants/routes'; class Dashboard extends React.Component { render() { @@ -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..efc0e27771 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}${routes.search.url}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}${routes.wallet.url}/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}${routes.wallet.url}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..7c73d541e8 100644 --- a/src/components/header/header.js +++ b/src/components/header/header.js @@ -26,7 +26,7 @@ class Header extends React.Component { shouldShowSearchBar() { const { pathname } = this.props.location; - return ![routes.search.long, routes.register.url, routes.addAccount.url] + return ![`${routes.explorer}${routes.search.url}`, routes.register.url, routes.addAccount.url] .some(el => pathname.includes(el)) && pathname !== routes.login.url; } diff --git a/src/components/header/header.test.js b/src/components/header/header.test.js index 48f92d183b..6986021a31 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}${routes.search}` }, isAuthenticated: false, }; propsMock = sinon.mock(mockInputProps); diff --git a/src/components/login/login.js b/src/components/login/login.js index f36c825a00..a530a9f910 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}${routes.dashboard.url}`; 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..a382210255 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; @@ -85,18 +86,18 @@ describe('Login', () => { }); describe('History management', () => { - it('calls this.props.history.replace(\'/main/dashboard\')', () => { + it(`calls this.props.history.replace('${routes.main}${routes.dashboard.url}')`, () => { 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}${routes.dashboard.url}`); }); 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}${routes.voting.url}`; 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}${routes.voting.url}`); }); it('hides network options by default', () => { diff --git a/src/components/mainMenu/mainMenu.js b/src/components/mainMenu/mainMenu.js index 96dbfbb030..cf412b268b 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}${routes.dashboard.url}`, id: 'dashboard', image: menuLogos.dashboard, }, { label: t('Wallet'), - route: '/main/transactions', + route: `${routes.main}${routes.wallet.url}`, id: 'transactions', image: menuLogos.wallet, }, { @@ -81,12 +82,12 @@ class MainMenu extends React.Component { }, { */ label: t('Explorer'), - route: '/explorer/search', + route: `${routes.explorer}${routes.search.url}`, id: 'explorer', image: menuLogos.search, }, { label: t('Sidechains'), - route: '/main/sidechains', + route: `${routes.main}${routes.sidechains.url}`, 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}${routes.voting.url}`, image: menuLogos.delegates, }); } diff --git a/src/components/mainMenu/mainMenu.test.js b/src/components/mainMenu/mainMenu.test.js index fed29c150b..9b34bbff19 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}${routes.voting.url}`, }, 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}${routes.wallet.url}`); }); it('should click on more activate the drawer', () => { diff --git a/src/components/register/register.js b/src/components/register/register.js index f6345e6db7..44b0bca937 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}${routes.dashboard.url}`); } } diff --git a/src/components/savedAccounts/savedAccounts.js b/src/components/savedAccounts/savedAccounts.js index 6790a3af29..04489bda1e 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}${routes.dashboard.url}`); } }; @@ -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..7b28c4343e 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}${routes.dashboard.url}`); }); 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..dc3c47ec94 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}${routes.account.url}/${value}`); } else if (value.match(regex.transactionId)) { - history.push(`${routes.transaction.long}/${value}`); + history.push(`${routes.explorer}${routes.transaction.url}/${value}`); } else { - history.push(`${routes.searchResult.long}/${value}`); + history.push(`${routes.explorer}${routes.searchResult.url}/${value}`); } }; export const visitAndSaveSearch = (value, history) => { if (value.length === 0) { - history.push(routes.search.long); + history.push(`${routes.explorer}${routes.search.url}`); } else { value = value.trim(); saveSearch(value); diff --git a/src/components/search/keyAction.test.js b/src/components/search/keyAction.test.js index 116307c95d..c97d44dbcd 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}${routes.account.url}/${testValues[0]}`, + `${routes.explorer}${routes.transaction.url}/${testValues[1]}`, + `${routes.explorer}${routes.searchResult.url}/${testValues[2]}`, ]; testValues.forEach((value) => { diff --git a/src/components/searchBar/index.js b/src/components/searchBar/index.js index 23a1e98ae0..70029ff7c5 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}${routes.search.url}`); } diff --git a/src/components/sendTo/index.js b/src/components/sendTo/index.js index 2370dec4ea..f9e84a9449 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..70e71a3dbe 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}${routes.wallet.url}?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}${routes.wallet.url}?address=9876L`); }); }); diff --git a/src/components/transactions/transactionDetailView.js b/src/components/transactions/transactionDetailView.js index d290a0fe0b..822964bf6a 100644 --- a/src/components/transactions/transactionDetailView.js +++ b/src/components/transactions/transactionDetailView.js @@ -36,7 +36,7 @@ const TransactionsDetailView = props => ( }
    + to={`${routes.explorer}${routes.account.url}/${props.value.senderId}`}> {props.value.senderId}
    @@ -53,7 +53,7 @@ const TransactionsDetailView = props => ( { props.value.recipientId ? + to={`${routes.explorer}${routes.account.url}/${props.value.recipientId}`}> {props.value.recipientId} : '-' } diff --git a/src/constants/routes.js b/src/constants/routes.js index aeeb4f9dc0..2afe0bb2a8 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' }, + wallet: { url: '/transactions' }, + account: { url: '/accounts' }, + accountVisualDemo: { url: '/account-visual-demo' }, + dashboard: { url: '/dashboard' }, + search: { url: '/search' }, + searchResult: { url: '/result' }, + transaction: { url: '/transactions' }, login: { url: '/' }, addAccount: { url: '/add-account' }, register: { url: '/register' }, + sidechains: { url: '/sidechains' }, + voting: { url: '/voting' }, + main: '/main', + explorer: '/explorer', }; diff --git a/src/utils/externalLinks.test.js b/src/utils/externalLinks.test.js index 3a75aa4681..abcb762fe3 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.url); }); }); diff --git a/src/utils/routes.js b/src/utils/routes.js index 04eca951be..45d5d24173 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}${routes.accountVisualDemo.url}/`, params: 'dialog', name: 'account-visual-demo', }, { regex: /\/main\/dashboard(?:\/[^/]*)?$/, - path: '/main/dashboard/', + path: `/main${routes.dashboard.url}/`, params: 'dialog', name: 'dashboard', }, { regex: /\/main\/transactions(?:\/[^/]*)?$/, - path: `${routes.wallet.long}/`, + path: `${routes.main}${routes.wallet.url}/`, params: 'dialog', name: 'transactions', }, { regex: /\/main\/voting(?:\/[^/]*)?$/, - path: '/main/voting/', + path: `/main${routes.voting.url}/`, params: 'dialog', name: 'voting', }, { regex: /\/main\/sidechains(?:\/[^/]*)?$/, - path: '/main/sidechains/', + path: `/main${routes.sidechains.url}/`, params: 'dialog', name: 'sidechains', }, { regex: /\/add-account(?:\/[^/]*)?$/, - path: '/add-account/', + path: `${routes.addAccount.url}/`, 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(`/explorer${routes.account.url}/\\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(`/explorer${routes.searchResult.url}/([0-9]+|[a-z]+)/`), params: 'query', name: 'result', }, { regex: /\/explorer\/search(?:\/[^/]*)?$/, - path: `${routes.search.long}/`, + path: `/explorer${routes.search.url}/`, name: 'explorer', }, { regex: /\/explorer\/transactions\/\d+(?:\/[^/]*)?$/, - path: new RegExp(`${routes.transaction.long}/\\d+/`), + path: new RegExp(`/explorer${routes.transaction.url}/\\d+/`), params: 'id', name: 'explorer-transaction', }, { regex: /register(?:\/[^/]*)?$/, - path: '/register/', + path: `${routes.register.url}/`, params: 'dialog', name: 'register', }, { From abb5f114097d9a329683f7d886b240e8c2e76e47 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Tue, 13 Mar 2018 14:38:06 +0100 Subject: [PATCH 2/3] Apply code review suggestions --- src/components/app/index.js | 24 +++++++++---------- src/components/app/index.test.js | 6 ++--- src/components/dashboard/index.js | 2 +- src/components/dialog/dialog.test.js | 6 ++--- src/components/header/header.js | 8 +++---- src/components/login/login.js | 4 ++-- src/components/login/login.test.js | 8 +++---- src/components/mainMenu/mainMenu.js | 10 ++++---- src/components/mainMenu/mainMenu.test.js | 4 ++-- src/components/register/register.js | 2 +- src/components/savedAccounts/savedAccounts.js | 4 ++-- .../savedAccounts/savedAccounts.test.js | 2 +- src/components/search/keyAction.js | 8 +++---- src/components/search/keyAction.test.js | 6 ++--- src/components/searchBar/index.js | 2 +- src/components/sendTo/index.js | 2 +- src/components/sendTo/sendTo.test.js | 4 ++-- .../transactions/transactionDetailView.js | 4 ++-- src/constants/routes.js | 24 +++++++++---------- src/utils/externalLinks.test.js | 2 +- src/utils/routes.js | 22 ++++++++--------- 21 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/components/app/index.js b/src/components/app/index.js index ce07f0a3d2..e6679c4405 100644 --- a/src/components/app/index.js +++ b/src/components/app/index.js @@ -41,26 +41,26 @@ class App extends React.Component { (
    - - - - - + + + + +
    )} /> (
    - - - - + + + +
    )} /> - - - + + +
    diff --git a/src/components/app/index.test.js b/src/components/app/index.test.js index 871aecf305..228908fcee 100644 --- a/src/components/app/index.test.js +++ b/src/components/app/index.test.js @@ -28,12 +28,12 @@ const addRouter = Component => (props, path) => const publicComponent = [ { route: '/', component: Login }, - { route: `${routes.explorer}${routes.search.url}`, component: Search }, + { route: `${routes.explorer}${routes.search.path}`, component: Search }, ]; const privateComponent = [ - { route: `${routes.main}${routes.transaction.url}`, component: Transactions }, - { route: `${routes.main}${routes.voting.url}`, component: Voting }, + { route: `${routes.main}${routes.transaction.path}`, component: Transactions }, + { route: `${routes.main}${routes.voting.path}`, component: Voting }, ]; describe('App', () => { diff --git a/src/components/dashboard/index.js b/src/components/dashboard/index.js index 05325ca644..387e874bae 100644 --- a/src/components/dashboard/index.js +++ b/src/components/dashboard/index.js @@ -23,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 efc0e27771..e0e9190cc2 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.explorer}${routes.search.url}saved-accounts`, + pathname: `${routes.explorer}${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 = `${routes.explorer}${routes.wallet.url}/1523498127498/`; + const basePath = `${routes.explorer}${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.main}${routes.wallet.url}saved-accounts`; + history.location.pathname = `${routes.main}${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 7c73d541e8..94c2ca9a30 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.explorer}${routes.search.url}`, routes.register.url, routes.addAccount.url] - .some(el => pathname.includes(el)) && pathname !== routes.login.url; + return ![`${routes.explorer}${routes.search.path}`, routes.register.path, routes.addAccount.path] + .some(el => pathname.includes(el)) && pathname !== routes.login.path; } render() { diff --git a/src/components/login/login.js b/src/components/login/login.js index a530a9f910..59ba91ae6d 100644 --- a/src/components/login/login.js +++ b/src/components/login/login.js @@ -100,7 +100,7 @@ class Login extends React.Component { getReferrerRoute() { const search = parseSearchParams(this.props.history.location.search); - const dashboardRoute = `${routes.main}${routes.dashboard.url}`; + const dashboardRoute = `${routes.main}${routes.dashboard.path}`; const referrerRoute = search.referrer ? search.referrer : dashboardRoute; return referrerRoute; } @@ -201,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 a382210255..0c0cdde854 100644 --- a/src/components/login/login.test.js +++ b/src/components/login/login.test.js @@ -86,18 +86,18 @@ describe('Login', () => { }); describe('History management', () => { - it(`calls this.props.history.replace('${routes.main}${routes.dashboard.url}')`, () => { + it('calls this.props.history.replace(\'/main/dashboard\')', () => { wrapper = shallow(, options); wrapper.setProps({ account: { address: 'dummy' } }); - expect(props.history.replace).to.have.been.calledWith(`${routes.main}${routes.dashboard.url}`); + expect(props.history.replace).to.have.been.calledWith(`${routes.main}${routes.dashboard.path}`); }); it('calls this.props.history.replace with referrer address', () => { wrapper = shallow(, options); props.history.replace.reset(); - history.location.search = `?referrer=${routes.main}${routes.voting.url}`; + history.location.search = `?referrer=${routes.main}${routes.voting.path}`; wrapper.setProps({ history, account: { address: 'dummy' } }); - expect(props.history.replace).to.have.been.calledWith(`${routes.main}${routes.voting.url}`); + expect(props.history.replace).to.have.been.calledWith(`${routes.main}${routes.voting.path}`); }); it('hides network options by default', () => { diff --git a/src/components/mainMenu/mainMenu.js b/src/components/mainMenu/mainMenu.js index cf412b268b..a1eb47ba47 100644 --- a/src/components/mainMenu/mainMenu.js +++ b/src/components/mainMenu/mainMenu.js @@ -65,12 +65,12 @@ class MainMenu extends React.Component { const tabs = [ { label: t('Dashboard'), - route: `${routes.main}${routes.dashboard.url}`, + route: `${routes.main}${routes.dashboard.path}`, id: 'dashboard', image: menuLogos.dashboard, }, { label: t('Wallet'), - route: `${routes.main}${routes.wallet.url}`, + route: `${routes.main}${routes.wallet.path}`, id: 'transactions', image: menuLogos.wallet, }, { @@ -82,12 +82,12 @@ class MainMenu extends React.Component { }, { */ label: t('Explorer'), - route: `${routes.explorer}${routes.search.url}`, + route: `${routes.explorer}${routes.search.path}`, id: 'explorer', image: menuLogos.search, }, { label: t('Sidechains'), - route: `${routes.main}${routes.sidechains.url}`, + route: `${routes.main}${routes.sidechains.path}`, id: 'sidechains', image: menuLogos.sidechains, }, @@ -97,7 +97,7 @@ class MainMenu extends React.Component { tabs.splice(tabs.length - 1, 0, { label: t('Delegates'), id: 'voting', - route: `${routes.main}${routes.voting.url}`, + route: `${routes.main}${routes.voting.path}`, image: menuLogos.delegates, }); } diff --git a/src/components/mainMenu/mainMenu.test.js b/src/components/mainMenu/mainMenu.test.js index 9b34bbff19..51ae53be09 100644 --- a/src/components/mainMenu/mainMenu.test.js +++ b/src/components/mainMenu/mainMenu.test.js @@ -42,7 +42,7 @@ describe('MainMenu', () => { const history = { location: { - pathname: `${routes.main}${routes.voting.url}`, + pathname: `${routes.main}${routes.voting.path}`, }, push: sinon.spy(), }; @@ -112,7 +112,7 @@ describe('MainMenu', () => { , options); wrapper.find(Tab).at(1).simulate('click'); - expect(history.push).to.have.been.calledWith(`${routes.main}${routes.wallet.url}`); + expect(history.push).to.have.been.calledWith(`${routes.main}${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 44b0bca937..5ad56cbca0 100644 --- a/src/components/register/register.js +++ b/src/components/register/register.js @@ -20,7 +20,7 @@ class Register extends React.Component { componentDidUpdate() { if (this.props.account.passphrase !== undefined) { - this.props.history.push(`${routes.main}${routes.dashboard.url}`); + this.props.history.push(`${routes.main}${routes.dashboard.path}`); } } diff --git a/src/components/savedAccounts/savedAccounts.js b/src/components/savedAccounts/savedAccounts.js index 04489bda1e..6ba34bae74 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(`${routes.main}${routes.dashboard.url}`); + history.push(`${routes.main}${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 7b28c4343e..3badaec733 100644 --- a/src/components/savedAccounts/savedAccounts.test.js +++ b/src/components/savedAccounts/savedAccounts.test.js @@ -90,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(`${routes.main}${routes.dashboard.url}`); + expect(props.history.push).to.have.been.calledWith(`${routes.main}${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 dc3c47ec94..502c55d0d8 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.explorer}${routes.account.url}/${value}`); + history.push(`${routes.explorer}${routes.account.path}/${value}`); } else if (value.match(regex.transactionId)) { - history.push(`${routes.explorer}${routes.transaction.url}/${value}`); + history.push(`${routes.explorer}${routes.transaction.path}/${value}`); } else { - history.push(`${routes.explorer}${routes.searchResult.url}/${value}`); + history.push(`${routes.explorer}${routes.searchResult.path}/${value}`); } }; export const visitAndSaveSearch = (value, history) => { if (value.length === 0) { - history.push(`${routes.explorer}${routes.search.url}`); + history.push(`${routes.explorer}${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 c97d44dbcd..059c7e6810 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.explorer}${routes.account.url}/${testValues[0]}`, - `${routes.explorer}${routes.transaction.url}/${testValues[1]}`, - `${routes.explorer}${routes.searchResult.url}/${testValues[2]}`, + `${routes.explorer}${routes.account.path}/${testValues[0]}`, + `${routes.explorer}${routes.transaction.path}/${testValues[1]}`, + `${routes.explorer}${routes.searchResult.path}/${testValues[2]}`, ]; testValues.forEach((value) => { diff --git a/src/components/searchBar/index.js b/src/components/searchBar/index.js index 70029ff7c5..77a05a628f 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.explorer}${routes.search.url}`); + return pathname.includes('explorer') && !pathname.includes(`${routes.explorer}${routes.search.path}`); } diff --git a/src/components/sendTo/index.js b/src/components/sendTo/index.js index f9e84a9449..c30387380c 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 70e71a3dbe..c47b10ffd1 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.main}${routes.wallet.url}?address=${props.address}`); + expect(wrapper.find('Link').prop('to')).to.equal(`${routes.main}${routes.wallet.path}?address=${props.address}`); }); it('updates when address changes', () => { wrapper.setProps({ address: '9876L' }); - expect(wrapper.find('Link').prop('to')).to.equal(`${routes.main}${routes.wallet.url}?address=9876L`); + expect(wrapper.find('Link').prop('to')).to.equal(`${routes.main}${routes.wallet.path}?address=9876L`); }); }); diff --git a/src/components/transactions/transactionDetailView.js b/src/components/transactions/transactionDetailView.js index 822964bf6a..28c01aef48 100644 --- a/src/components/transactions/transactionDetailView.js +++ b/src/components/transactions/transactionDetailView.js @@ -36,7 +36,7 @@ const TransactionsDetailView = props => ( }
      + to={`${routes.explorer}${routes.account.path}/${props.value.senderId}`}> {props.value.senderId}
      @@ -53,7 +53,7 @@ const TransactionsDetailView = props => ( { props.value.recipientId ? + to={`${routes.explorer}${routes.account.path}/${props.value.recipientId}`}> {props.value.recipientId} : '-' } diff --git a/src/constants/routes.js b/src/constants/routes.js index 2afe0bb2a8..906d7e9cfa 100644 --- a/src/constants/routes.js +++ b/src/constants/routes.js @@ -1,16 +1,16 @@ export default { - wallet: { url: '/transactions' }, - account: { url: '/accounts' }, - accountVisualDemo: { url: '/account-visual-demo' }, - dashboard: { url: '/dashboard' }, - search: { url: '/search' }, - searchResult: { url: '/result' }, - transaction: { url: '/transactions' }, - login: { url: '/' }, - addAccount: { url: '/add-account' }, - register: { url: '/register' }, - sidechains: { url: '/sidechains' }, - voting: { url: '/voting' }, + 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: '/main', explorer: '/explorer', }; diff --git a/src/utils/externalLinks.test.js b/src/utils/externalLinks.test.js index abcb762fe3..106d864148 100644 --- a/src/utils/externalLinks.test.js +++ b/src/utils/externalLinks.test.js @@ -29,6 +29,6 @@ describe('externalLinks', () => { }; externalLinks.init(); callbacks.openUrl({}, 'lisk://register'); - expect(historyPush).to.have.been.calledWith(routes.register.url); + expect(historyPush).to.have.been.calledWith(routes.register.path); }); }); diff --git a/src/utils/routes.js b/src/utils/routes.js index 45d5d24173..c9dd4cfee0 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: `${routes.main}${routes.accountVisualDemo.url}/`, + path: `${routes.main}${routes.accountVisualDemo.path}/`, params: 'dialog', name: 'account-visual-demo', }, { regex: /\/main\/dashboard(?:\/[^/]*)?$/, - path: `/main${routes.dashboard.url}/`, + path: `${routes.main}${routes.dashboard.path}/`, params: 'dialog', name: 'dashboard', }, { regex: /\/main\/transactions(?:\/[^/]*)?$/, - path: `${routes.main}${routes.wallet.url}/`, + path: `${routes.main}${routes.wallet.path}/`, params: 'dialog', name: 'transactions', }, { regex: /\/main\/voting(?:\/[^/]*)?$/, - path: `/main${routes.voting.url}/`, + path: `${routes.main}${routes.voting.path}/`, params: 'dialog', name: 'voting', }, { regex: /\/main\/sidechains(?:\/[^/]*)?$/, - path: `/main${routes.sidechains.url}/`, + path: `${routes.main}${routes.sidechains.path}/`, params: 'dialog', name: 'sidechains', }, { regex: /\/add-account(?:\/[^/]*)?$/, - path: `${routes.addAccount.url}/`, + path: `${routes.addAccount.path}/`, params: 'dialog', name: 'add-account', }, { regex: /\/explorer\/accounts\/\d{1,21}[L|l](?:\/[^/]*)?$/, - path: new RegExp(`/explorer${routes.account.url}/\\d{1,21}[L|l]/`), + path: new RegExp(`${routes.explorer}${routes.account.path}/\\d{1,21}[L|l]/`), params: 'address', name: 'accounts', }, { regex: /\/explorer\/result\/([0-9]+|[a-z]+)(?:\/[^/]*)?$/, - path: new RegExp(`/explorer${routes.searchResult.url}/([0-9]+|[a-z]+)/`), + path: new RegExp(`${routes.explorer}${routes.searchResult.path}/([0-9]+|[a-z]+)/`), params: 'query', name: 'result', }, { regex: /\/explorer\/search(?:\/[^/]*)?$/, - path: `/explorer${routes.search.url}/`, + path: `${routes.explorer}${routes.search.path}/`, name: 'explorer', }, { regex: /\/explorer\/transactions\/\d+(?:\/[^/]*)?$/, - path: new RegExp(`/explorer${routes.transaction.url}/\\d+/`), + path: new RegExp(`${routes.explorer}${routes.transaction.path}/\\d+/`), params: 'id', name: 'explorer-transaction', }, { regex: /register(?:\/[^/]*)?$/, - path: `${routes.register.url}/`, + path: `${routes.register.path}/`, params: 'dialog', name: 'register', }, { From ddddb61ccf85fdcefba5a885de8f2b6807f7ba0a Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Tue, 13 Mar 2018 16:25:47 +0100 Subject: [PATCH 3/3] Change explorer and main constants to objects --- src/components/app/index.js | 4 ++-- src/components/app/index.test.js | 6 +++--- src/components/dashboard/index.js | 2 +- src/components/dialog/dialog.test.js | 6 +++--- src/components/header/header.js | 2 +- src/components/header/header.test.js | 2 +- src/components/login/login.js | 2 +- src/components/login/login.test.js | 6 +++--- src/components/mainMenu/mainMenu.js | 10 +++++----- src/components/mainMenu/mainMenu.test.js | 4 ++-- src/components/register/register.js | 2 +- src/components/savedAccounts/savedAccounts.js | 4 ++-- .../savedAccounts/savedAccounts.test.js | 2 +- src/components/search/keyAction.js | 8 ++++---- src/components/search/keyAction.test.js | 6 +++--- src/components/searchBar/index.js | 2 +- src/components/sendTo/index.js | 2 +- src/components/sendTo/sendTo.test.js | 4 ++-- .../transactions/transactionDetailView.js | 4 ++-- src/constants/routes.js | 4 ++-- src/utils/routes.js | 18 +++++++++--------- 21 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/components/app/index.js b/src/components/app/index.js index e6679c4405..d67b8b6ce5 100644 --- a/src/components/app/index.js +++ b/src/components/app/index.js @@ -38,7 +38,7 @@ class App extends React.Component {
      - ( + (
      @@ -50,7 +50,7 @@ class App extends React.Component {
      )} /> - ( + (
      diff --git a/src/components/app/index.test.js b/src/components/app/index.test.js index 228908fcee..69b147123b 100644 --- a/src/components/app/index.test.js +++ b/src/components/app/index.test.js @@ -28,12 +28,12 @@ const addRouter = Component => (props, path) => const publicComponent = [ { route: '/', component: Login }, - { route: `${routes.explorer}${routes.search.path}`, component: Search }, + { route: `${routes.explorer.path}${routes.search.path}`, component: Search }, ]; const privateComponent = [ - { route: `${routes.main}${routes.transaction.path}`, component: Transactions }, - { route: `${routes.main}${routes.voting.path}`, 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 387e874bae..f9664347df 100644 --- a/src/components/dashboard/index.js +++ b/src/components/dashboard/index.js @@ -23,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 e0e9190cc2..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.explorer}${routes.search.path}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 = `${routes.explorer}${routes.wallet.path}/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.main}${routes.wallet.path}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 94c2ca9a30..72896dc61f 100644 --- a/src/components/header/header.js +++ b/src/components/header/header.js @@ -26,7 +26,7 @@ class Header extends React.Component { shouldShowSearchBar() { const { pathname } = this.props.location; - return ![`${routes.explorer}${routes.search.path}`, routes.register.path, routes.addAccount.path] + return ![`${routes.explorer.path}${routes.search.path}`, routes.register.path, routes.addAccount.path] .some(el => pathname.includes(el)) && pathname !== routes.login.path; } diff --git a/src/components/header/header.test.js b/src/components/header/header.test.js index 6986021a31..26f1e807ea 100644 --- a/src/components/header/header.test.js +++ b/src/components/header/header.test.js @@ -26,7 +26,7 @@ describe('Header', () => { setActiveDialog: () => { }, account: {}, t: key => key, - location: { pathname: `${routes.explorer}${routes.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 59ba91ae6d..5a0178d494 100644 --- a/src/components/login/login.js +++ b/src/components/login/login.js @@ -100,7 +100,7 @@ class Login extends React.Component { getReferrerRoute() { const search = parseSearchParams(this.props.history.location.search); - const dashboardRoute = `${routes.main}${routes.dashboard.path}`; + const dashboardRoute = `${routes.main.path}${routes.dashboard.path}`; const referrerRoute = search.referrer ? search.referrer : dashboardRoute; return referrerRoute; } diff --git a/src/components/login/login.test.js b/src/components/login/login.test.js index 0c0cdde854..debe332b52 100644 --- a/src/components/login/login.test.js +++ b/src/components/login/login.test.js @@ -89,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(`${routes.main}${routes.dashboard.path}`); + 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=${routes.main}${routes.voting.path}`; + history.location.search = `?referrer=${routes.main.path}${routes.voting.path}`; wrapper.setProps({ history, account: { address: 'dummy' } }); - expect(props.history.replace).to.have.been.calledWith(`${routes.main}${routes.voting.path}`); + 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 a1eb47ba47..d28ec4d753 100644 --- a/src/components/mainMenu/mainMenu.js +++ b/src/components/mainMenu/mainMenu.js @@ -65,12 +65,12 @@ class MainMenu extends React.Component { const tabs = [ { label: t('Dashboard'), - route: `${routes.main}${routes.dashboard.path}`, + route: `${routes.main.path}${routes.dashboard.path}`, id: 'dashboard', image: menuLogos.dashboard, }, { label: t('Wallet'), - route: `${routes.main}${routes.wallet.path}`, + route: `${routes.main.path}${routes.wallet.path}`, id: 'transactions', image: menuLogos.wallet, }, { @@ -82,12 +82,12 @@ class MainMenu extends React.Component { }, { */ label: t('Explorer'), - route: `${routes.explorer}${routes.search.path}`, + route: `${routes.explorer.path}${routes.search.path}`, id: 'explorer', image: menuLogos.search, }, { label: t('Sidechains'), - route: `${routes.main}${routes.sidechains.path}`, + route: `${routes.main.path}${routes.sidechains.path}`, id: 'sidechains', image: menuLogos.sidechains, }, @@ -97,7 +97,7 @@ class MainMenu extends React.Component { tabs.splice(tabs.length - 1, 0, { label: t('Delegates'), id: 'voting', - route: `${routes.main}${routes.voting.path}`, + 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 51ae53be09..b18d533a7b 100644 --- a/src/components/mainMenu/mainMenu.test.js +++ b/src/components/mainMenu/mainMenu.test.js @@ -42,7 +42,7 @@ describe('MainMenu', () => { const history = { location: { - pathname: `${routes.main}${routes.voting.path}`, + pathname: `${routes.main.path}${routes.voting.path}`, }, push: sinon.spy(), }; @@ -112,7 +112,7 @@ describe('MainMenu', () => { , options); wrapper.find(Tab).at(1).simulate('click'); - expect(history.push).to.have.been.calledWith(`${routes.main}${routes.wallet.path}`); + 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 5ad56cbca0..2d7065ccd7 100644 --- a/src/components/register/register.js +++ b/src/components/register/register.js @@ -20,7 +20,7 @@ class Register extends React.Component { componentDidUpdate() { if (this.props.account.passphrase !== undefined) { - this.props.history.push(`${routes.main}${routes.dashboard.path}`); + 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 6ba34bae74..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(`${routes.main}${routes.dashboard.path}`); + 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 3badaec733..f265ff9b98 100644 --- a/src/components/savedAccounts/savedAccounts.test.js +++ b/src/components/savedAccounts/savedAccounts.test.js @@ -90,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(`${routes.main}${routes.dashboard.path}`); + 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 502c55d0d8..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.explorer}${routes.account.path}/${value}`); + history.push(`${routes.explorer.path}${routes.account.path}/${value}`); } else if (value.match(regex.transactionId)) { - history.push(`${routes.explorer}${routes.transaction.path}/${value}`); + history.push(`${routes.explorer.path}${routes.transaction.path}/${value}`); } else { - history.push(`${routes.explorer}${routes.searchResult.path}/${value}`); + history.push(`${routes.explorer.path}${routes.searchResult.path}/${value}`); } }; export const visitAndSaveSearch = (value, history) => { if (value.length === 0) { - history.push(`${routes.explorer}${routes.search.path}`); + 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 059c7e6810..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.explorer}${routes.account.path}/${testValues[0]}`, - `${routes.explorer}${routes.transaction.path}/${testValues[1]}`, - `${routes.explorer}${routes.searchResult.path}/${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 77a05a628f..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.explorer}${routes.search.path}`); + 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 c30387380c..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 c47b10ffd1..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.main}${routes.wallet.path}?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.main}${routes.wallet.path}?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 28c01aef48..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 906d7e9cfa..78a3106a86 100644 --- a/src/constants/routes.js +++ b/src/constants/routes.js @@ -11,6 +11,6 @@ export default { register: { path: '/register' }, sidechains: { path: '/sidechains' }, voting: { path: '/voting' }, - main: '/main', - explorer: '/explorer', + main: { path: '/main' }, + explorer: { path: '/explorer' }, }; diff --git a/src/utils/routes.js b/src/utils/routes.js index c9dd4cfee0..caaba26708 100644 --- a/src/utils/routes.js +++ b/src/utils/routes.js @@ -3,27 +3,27 @@ import routes from './../constants/routes'; export default [ { regex: /\/main\/account-visual-demo(?:\/[^/]*)?$/, - path: `${routes.main}${routes.accountVisualDemo.path}/`, + path: `${routes.main.path}${routes.accountVisualDemo.path}/`, params: 'dialog', name: 'account-visual-demo', }, { regex: /\/main\/dashboard(?:\/[^/]*)?$/, - path: `${routes.main}${routes.dashboard.path}/`, + path: `${routes.main.path}${routes.dashboard.path}/`, params: 'dialog', name: 'dashboard', }, { regex: /\/main\/transactions(?:\/[^/]*)?$/, - path: `${routes.main}${routes.wallet.path}/`, + path: `${routes.main.path}${routes.wallet.path}/`, params: 'dialog', name: 'transactions', }, { regex: /\/main\/voting(?:\/[^/]*)?$/, - path: `${routes.main}${routes.voting.path}/`, + path: `${routes.main.path}${routes.voting.path}/`, params: 'dialog', name: 'voting', }, { regex: /\/main\/sidechains(?:\/[^/]*)?$/, - path: `${routes.main}${routes.sidechains.path}/`, + path: `${routes.main.path}${routes.sidechains.path}/`, params: 'dialog', name: 'sidechains', }, { @@ -33,21 +33,21 @@ export default [ name: 'add-account', }, { regex: /\/explorer\/accounts\/\d{1,21}[L|l](?:\/[^/]*)?$/, - path: new RegExp(`${routes.explorer}${routes.account.path}/\\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.explorer}${routes.searchResult.path}/([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.explorer}${routes.search.path}/`, + path: `${routes.explorer.path}${routes.search.path}/`, name: 'explorer', }, { regex: /\/explorer\/transactions\/\d+(?:\/[^/]*)?$/, - path: new RegExp(`${routes.explorer}${routes.transaction.path}/\\d+/`), + path: new RegExp(`${routes.explorer.path}${routes.transaction.path}/\\d+/`), params: 'id', name: 'explorer-transaction', }, {