// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see .
import { observer } from 'mobx-react';
import React, { Component, PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import ParityLogo from '~/../assets/images/parity-logo-black-no-text.svg';
import { createIdentityImg } from '~/api/util/identity';
import { newError } from '~/redux/actions';
import { Button, Modal } from '~/ui';
import { CheckIcon, DoneIcon, NextIcon, PrintIcon } from '~/ui/Icons';
import { NewAccount, AccountDetails } from '../CreateAccount';
import print from '../CreateAccount/print';
import recoveryPage from '../CreateAccount/recoveryPage.ejs';
import CreateStore from '../CreateAccount/store';
import Completed from './Completed';
import TnC from './TnC';
import Welcome from './Welcome';
const STAGE_NAMES = [
,
,
,
,
];
const BUTTON_LABEL_NEXT = (
);
@observer
class FirstRun extends Component {
static contextTypes = {
api: PropTypes.object.isRequired
}
static propTypes = {
hasAccounts: PropTypes.bool.isRequired,
newError: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
visible: PropTypes.bool.isRequired
}
createStore = new CreateStore(this.context.api, {}, false);
state = {
stage: 0,
hasAcceptedTnc: false
}
render () {
const { visible } = this.props;
const { stage } = this.state;
if (!visible) {
return null;
}
return (
{ this.renderStage() }
);
}
renderStage () {
const { stage, hasAcceptedTnc } = this.state;
switch (stage) {
case 0:
return (
);
case 1:
return (
);
case 2:
return (
);
case 3:
return (
);
case 4:
return (
);
}
}
renderDialogActions () {
const { hasAccounts } = this.props;
const { stage, hasAcceptedTnc } = this.state;
const { canCreate } = this.createStore;
switch (stage) {
case 0:
return (
}
key='next'
label={ BUTTON_LABEL_NEXT }
onClick={ this.onNext }
/>
);
case 1:
return (
}
key='next'
label={ BUTTON_LABEL_NEXT }
onClick={ this.onNext }
/>
);
case 2:
const buttons = [
}
key='create'
label={
}
onClick={ this.onCreate }
/>
];
if (hasAccounts) {
buttons.unshift(
}
key='skip'
label={
}
onClick={ this.skipAccountCreation }
/>
);
}
return buttons;
case 3:
return [
}
key='print'
label={
}
onClick={ this.printPhrase }
/>,
}
key='next'
label={ BUTTON_LABEL_NEXT }
onClick={ this.onNext }
/>
];
case 4:
return (
}
key='close'
label={
}
onClick={ this.onClose }
/>
);
}
}
onClose = () => {
const { onClose } = this.props;
this.setState({
stage: 0
}, onClose);
}
onNext = () => {
const { stage } = this.state;
this.setState({
stage: stage + 1
});
}
onAcceptTnC = () => {
this.setState({
hasAcceptedTnc: !this.state.hasAcceptedTnc
});
}
onCreate = () => {
this.createStore.setBusy(true);
return this.createStore
.createAccount()
.then(() => {
this.onNext();
this.createStore.setBusy(false);
})
.catch((error) => {
this.createStore.setBusy(false);
this.props.newError(error);
});
}
skipAccountCreation = () => {
this.setState({ stage: this.state.stage + 2 });
}
printPhrase = () => {
const { address, phrase, name } = this.createStore;
const identity = createIdentityImg(address);
print(recoveryPage({
address,
identity,
logo: ParityLogo,
name,
phrase
}));
}
}
function mapStateToProps (state) {
const { hasAccounts } = state.personal;
return {
hasAccounts
};
}
function mapDispatchToProps (dispatch) {
return bindActionCreators({
newError
}, dispatch);
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(FirstRun);