Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
redirect non-delegete account to transaction page
Browse files Browse the repository at this point in the history
  • Loading branch information
alepop committed Sep 4, 2017
1 parent bae879f commit 36a6267
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,25 @@ class Login extends React.Component {

componentDidUpdate() {
if (this.props.account && this.props.account.address) {
const search = this.props.history.location.search;
this.props.history.replace(
search.indexOf('?referrer') === 0 ? search.replace('?referrer=', '') : '/main/transactions');
this.props.history.replace(this.getReferrerRoute());
if (this.state.address) {
localStorage.setItem('address', this.state.address);
}
localStorage.setItem('network', this.state.network);
}
}

getReferrerRoute() {
const { isDelegate } = this.props.account;
const { search } = this.props.history.location;
const transactionRoute = '/main/transactions';
const referrerRoute = search.indexOf('?referrer') === 0 ? search.replace('?referrer=', '') : transactionRoute;
if (!isDelegate && referrerRoute === '/main/forging') {
return transactionRoute;
}
return referrerRoute;
}

// eslint-disable-next-line class-methods-use-this
validateUrl(value) {
const addHttp = (url) => {
Expand Down
13 changes: 13 additions & 0 deletions src/components/login/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ describe('Login', () => {
expect(props.history.replace).to.have.been.calledWith('/main/transactions');
});

it('calls this.props.history.replace with referrer address', () => {
props.history.location.search = '?referrer=/main/voting';
wrapper = mount(<Login {...props}/>);
expect(props.history.replace).to.have.been.calledWith('/main/voting');
});

it('call this.props.history.replace with "/main/transaction" if referrer address is "/main/forging" and account.isDelegate === false', () => {
props.history.location.search = '?referrer=/main/forging';
props.account.isDelegate = false;
wrapper = mount(<Login {...props} />);
expect(props.history.replace).to.have.been.calledWith('/main/transactions');
});

it('calls localStorage.setItem(\'address\', address) if this.state.address', () => {
const spyFn = spy(localStorage, 'setItem');
wrapper = mount(<Login {...props} />);
Expand Down

0 comments on commit 36a6267

Please sign in to comment.