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

Commit

Permalink
Merge pull request #700 from alepop/698-fix-referrer-link-for-differe…
Browse files Browse the repository at this point in the history
…nt-account

Reset focus in wallet while logging again with different account - Closes #698
  • Loading branch information
reyraa authored Sep 4, 2017
2 parents bae879f + 36a6267 commit 3c3ea00
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 3c3ea00

Please sign in to comment.