Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate and set custom node when creating new account - Closes #1326 #1396

Merged
merged 10 commits into from
Nov 13, 2018
1 change: 1 addition & 0 deletions src/components/account/account.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
text-align: left;
width: auto;
height: 56px;
margin-bottom: 20px;
}

@media (--medium-viewport) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { withRouter } from 'react-router';
import { setDefaults, translate } from 'react-i18next';
import { dialogDisplayed } from '../../actions/dialog';
import Login from './login';
import { errorToastDisplayed } from '../../actions/toaster';
import { activePeerSet } from '../../actions/peers';
import { settingsUpdated } from '../../actions/settings';
import { errorToastDisplayed } from '../../actions/toaster';
import { loadingStarted, loadingFinished } from '../../actions/loading';

setDefaults({
Expand Down
41 changes: 36 additions & 5 deletions src/components/login/login.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import grid from 'flexboxgrid/dist/flexboxgrid.css';
import i18next from 'i18next';
import Lisk from 'lisk-elements';

import Dropdown from '../toolbox/dropdown/dropdown';
import Input from '../toolbox/inputs/input';
import { PrimaryButton } from '../toolbox/buttons/button';
Expand Down Expand Up @@ -126,16 +128,16 @@ class Login extends React.Component {
this.props.peers.options.address === network.address;
}

getNetwork() {
const network = Object.assign({}, getNetwork(this.state.network));
if (this.state.network === networks.customNode.code) {
getNetwork(chosenNetwork) {
const network = Object.assign({}, getNetwork(chosenNetwork));
if (chosenNetwork === networks.customNode.code) {
network.address = addHttp(this.state.address);
}
return network;
}

onLoginSubmission(passphrase) {
const network = this.getNetwork();
const network = this.getNetwork(this.state.network);
this.secondIteration = true;
if (this.alreadyLoggedWithThisAddress(extractAddress(passphrase), network)) {
this.redirectToReferrer();
Expand Down Expand Up @@ -193,6 +195,32 @@ class Login extends React.Component {
return showNetworkParam === 'true' || (showNetwork && showNetworkParam !== 'false');
}

validateCorrectNode() {
const { address } = this.state;
const nodeURL = address !== '' ? addHttp(address) : address;

if (this.state.network === networks.customNode.code) {
const liskAPIClient = new Lisk.APIClient([nodeURL], {});
liskAPIClient.node.getConstants()
.then((res) => {
if (res.data) {
this.props.activePeerSet({
network: this.getNetwork(this.state.network),
});
this.props.history.push(routes.register.path);
} else {
throw new Error();
}
}).catch(() => {
this.props.errorToastDisplayed({ label: i18next.t('Unable to connect to the node') });
});
} else {
const network = this.getNetwork(this.state.network);
this.props.activePeerSet({ network });
this.props.history.push(routes.register.path);
}
}

cancelLedgerLogin() {
this.setState({ isLedgerLogin: false, isLedgerFirstLogin: false });
}
Expand Down Expand Up @@ -269,7 +297,10 @@ class Login extends React.Component {
</div>
</section>
</section>
<SignUp t={this.props.t} passInputState={this.state.passInputState} />
<SignUp
t={this.props.t}
passInputState={this.state.passInputState}
validateCorrectNode={this.validateCorrectNode.bind(this)}/>
</Box>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/login/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('Login', () => {
pathname: '',
search: '',
},
push: spy(),
replace: spy(),
};
props = {
Expand Down Expand Up @@ -135,6 +136,11 @@ describe('Login', () => {
spyFn.restore();
localStorage.removeItem('address');
});

it('calls this.props.history.push on signButton click', () => {
wrapper.find('.new-account-button').simulate('click');
expect(props.history.push).to.have.been.calledWith(`${routes.register.path}`);
});
});

describe('After submission', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/components/login/signUp.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
margin-top: 32vh; /* stylelint-disable-line */
margin-bottom: 24px;
white-space: nowrap;
display: flex;
cursor: pointer;
}

& .subTitle,
Expand Down Expand Up @@ -121,6 +123,7 @@

& h2 {
font-size: 50px;
display: flex;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/login/signUp.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React from 'react';
import { Link } from 'react-router-dom';
import Parallax from '../parallax';
import { FontIcon } from '../fontIcon';
// eslint-disable-next-line import/no-unresolved
import * as shapes from '../../assets/images/*.svg';
import styles from './signUp.css';
import routes from '../../constants/routes';

const SignUp = ({ t, passInputState }) =>
const SignUp = ({ t, passInputState, validateCorrectNode }) =>
(<section className={`${styles.signUp} ${styles[passInputState]}`}>
<section className={styles.table}>
<div className='text-left'>
<h2>
<Link className='new-account-button' to={routes.register.path}>
<div
className='new-account-button'
onClick={() => { validateCorrectNode(); }} >
{t('Create Lisk ID')}
</Link>
</div>
<FontIcon className={styles.singUpArrow} value='arrow-right' />
</h2>

Expand Down