Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

first run: skip account creation if they already have accounts #3827

Merged
merged 3 commits into from
Dec 15, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions js/src/modals/FirstRun/firstRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import ActionDone from 'material-ui/svg-icons/action/done';
import ActionDoneAll from 'material-ui/svg-icons/action/done-all';
import NavigationArrowForward from 'material-ui/svg-icons/navigation/arrow-forward';
Expand All @@ -35,14 +36,15 @@ import ParityLogo from '../../../assets/images/parity-logo-black-no-text.svg';

const STAGE_NAMES = ['welcome', 'terms', 'new account', 'recovery', 'completed'];

export default class FirstRun extends Component {
class FirstRun extends Component {
static contextTypes = {
api: PropTypes.object.isRequired,
store: PropTypes.object.isRequired
}

static propTypes = {
visible: PropTypes.bool,
hasAccounts: PropTypes.bool.isRequired,
visible: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired
}

Expand Down Expand Up @@ -109,6 +111,7 @@ export default class FirstRun extends Component {
}

renderDialogActions () {
const { hasAccounts } = this.props;
const { canCreate, stage, hasAcceptedTnc } = this.state;

switch (stage) {
Expand All @@ -130,13 +133,26 @@ export default class FirstRun extends Component {
);

case 2:
return (
const buttons = [
<Button
icon={ <ActionDone /> }
label='Create'
key='create'
disabled={ !canCreate }
onClick={ this.onCreate } />
);
onClick={ this.onCreate }
/>
];
if (hasAccounts) {
buttons.unshift(
<Button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have preferred the labels/hint/text changes into FormattedMessage while we are in the component. (Saves work later, especially when adding new features).

Not a crisis here though, so will just comment on it - small enough change overall.

icon={ <NavigationArrowForward /> }
label='Skip'
key='skip'
onClick={ this.skipAccountCreation }
/>
);
}
return buttons;

case 3:
return [
Expand Down Expand Up @@ -219,6 +235,10 @@ export default class FirstRun extends Component {
});
}

skipAccountCreation = () => {
this.setState({ stage: this.state.stage + 2 });
}

newError = (error) => {
const { store } = this.context;

Expand All @@ -232,3 +252,9 @@ export default class FirstRun extends Component {
print(recoveryPage({ phrase, name, identity, address, logo: ParityLogo }));
}
}

function mapStateToProps (state) {
return { hasAccounts: state.personal.hasAccounts };
}

export default connect(mapStateToProps, null)(FirstRun);
11 changes: 7 additions & 4 deletions js/src/views/Application/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

import { action, observable } from 'mobx';

const showFirstRun = window.localStorage.getItem('showFirstRun') !== '0';

export default class Store {
@observable firstrunVisible = showFirstRun;
@observable firstrunVisible = false;

constructor (api) {
this._api = api;

const value = window.localStorage.getItem('showFirstRun');
if (value) {
this.firstrunVisible = JSON.parse(value);
}

this._checkAccounts();
}

Expand All @@ -33,7 +36,7 @@ export default class Store {

@action toggleFirstrun = (visible = false) => {
this.firstrunVisible = visible;
window.localStorage.setItem('showFirstRun', visible ? '1' : '0');
window.localStorage.setItem('showFirstRun', JSON.stringify(!!visible));
}

_checkAccounts () {
Expand Down