diff --git a/src/components/login/login.js b/src/components/login/login.js
index 02ddb0a8a..4bd0f207c 100644
--- a/src/components/login/login.js
+++ b/src/components/login/login.js
@@ -42,9 +42,7 @@ 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);
}
@@ -52,6 +50,17 @@ class Login extends React.Component {
}
}
+ 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) => {
diff --git a/src/components/login/login.test.js b/src/components/login/login.test.js
index f94d8bf43..6449da74f 100644
--- a/src/components/login/login.test.js
+++ b/src/components/login/login.test.js
@@ -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();
+ 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();
+ 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();