Add Vaults logic to First Run (#4894) (#4914)

This commit is contained in:
Nicolas Gotchac 2017-03-15 13:40:18 +01:00 committed by Gav Wood
parent b27138e93f
commit e4c61a5fab
3 changed files with 47 additions and 9 deletions

View File

@ -49,7 +49,7 @@ export default class FirstRun extends Component {
defaultMessage='As part of a new installation, the next few steps will guide you through the process of setting up you Parity instance and your associated accounts. Our aim is to make it as simple as possible and to get you up and running in record-time, so please bear with us. Once completed you will have -' defaultMessage='As part of a new installation, the next few steps will guide you through the process of setting up you Parity instance and your associated accounts. Our aim is to make it as simple as possible and to get you up and running in record-time, so please bear with us. Once completed you will have -'
/> />
</p> </p>
<p> <div>
<ul> <ul>
<li> <li>
<FormattedMessage <FormattedMessage
@ -70,7 +70,7 @@ export default class FirstRun extends Component {
/> />
</li> </li>
</ul> </ul>
</p> </div>
<p> <p>
<FormattedMessage <FormattedMessage
id='firstRun.welcome.next' id='firstRun.welcome.next'

View File

@ -18,6 +18,7 @@ import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import ReactPortal from 'react-portal'; import ReactPortal from 'react-portal';
import keycode from 'keycode'; import keycode from 'keycode';
import { noop } from 'lodash';
import { nodeOrStringProptype } from '~/util/proptypes'; import { nodeOrStringProptype } from '~/util/proptypes';
import { CloseIcon } from '~/ui/Icons'; import { CloseIcon } from '~/ui/Icons';
@ -29,7 +30,6 @@ import styles from './portal.css';
export default class Portal extends Component { export default class Portal extends Component {
static propTypes = { static propTypes = {
onClose: PropTypes.func.isRequired,
open: PropTypes.bool.isRequired, open: PropTypes.bool.isRequired,
activeStep: PropTypes.number, activeStep: PropTypes.number,
busy: PropTypes.bool, busy: PropTypes.bool,
@ -45,11 +45,16 @@ export default class Portal extends Component {
isChildModal: PropTypes.bool, isChildModal: PropTypes.bool,
isSmallModal: PropTypes.bool, isSmallModal: PropTypes.bool,
onClick: PropTypes.func, onClick: PropTypes.func,
onClose: PropTypes.func,
onKeyDown: PropTypes.func, onKeyDown: PropTypes.func,
steps: PropTypes.array, steps: PropTypes.array,
title: nodeOrStringProptype() title: nodeOrStringProptype()
}; };
static defaultProps = {
onClose: noop
};
componentDidMount () { componentDidMount () {
this.setBodyOverflow(this.props.open); this.setBodyOverflow(this.props.open);
} }

View File

@ -17,12 +17,20 @@
import { action, observable } from 'mobx'; import { action, observable } from 'mobx';
import store from 'store'; import store from 'store';
const OLD_LS_FIRST_RUN_KEY = 'showFirstRun';
const LS_FIRST_RUN_KEY = '_parity::showFirstRun';
export default class Store { export default class Store {
@observable firstrunVisible = false; @observable firstrunVisible = false;
constructor (api) { constructor (api) {
// Migrate the old key to the new one
this._migrateStore();
this._api = api; this._api = api;
this.firstrunVisible = store.get('showFirstRun'); // Show the first run if it hasn't been shown before
// (thus an undefined value)
this.firstrunVisible = store.get(LS_FIRST_RUN_KEY) === undefined;
this._checkAccounts(); this._checkAccounts();
} }
@ -33,16 +41,41 @@ export default class Store {
@action toggleFirstrun = (visible = false) => { @action toggleFirstrun = (visible = false) => {
this.firstrunVisible = visible; this.firstrunVisible = visible;
store.set('showFirstRun', !!visible);
// There's no need to write to storage that the
// First Run should be visible
if (!visible) {
store.set(LS_FIRST_RUN_KEY, !!visible);
}
}
/**
* Migrate the old LocalStorage ket format
* to the new one
*/
_migrateStore () {
const oldValue = store.get(OLD_LS_FIRST_RUN_KEY);
const newValue = store.get(LS_FIRST_RUN_KEY);
if (newValue === undefined && oldValue !== undefined) {
store.set(LS_FIRST_RUN_KEY, oldValue);
store.remove(OLD_LS_FIRST_RUN_KEY);
}
} }
_checkAccounts () { _checkAccounts () {
this._api.parity return Promise
.allAccountsInfo() .all([
.then((info) => { this._api.parity.listVaults(),
this._api.parity.allAccountsInfo()
])
.then(([ vaults, info ]) => {
const accounts = Object.keys(info).filter((address) => info[address].uuid); const accounts = Object.keys(info).filter((address) => info[address].uuid);
// Has accounts if any vaults or accounts
const hasAccounts = (accounts && accounts.length > 0) || (vaults && vaults.length > 0);
this.toggleFirstrun(this.firstrunVisible || !accounts || !accounts.length); // Show First Run if no accounts and no vaults
this.toggleFirstrun(this.firstrunVisible || !hasAccounts);
}) })
.catch((error) => { .catch((error) => {
console.error('checkAccounts', error); console.error('checkAccounts', error);