move verification store into modal (#3951)

* move verification store

* address style grumbles 
This commit is contained in:
Jannis Redmann 2016-12-23 15:40:04 +01:00 committed by Jaco Greeff
parent fc620d0d3e
commit db6964acc4
2 changed files with 46 additions and 46 deletions

View File

@ -15,13 +15,17 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { observable } from 'mobx';
import DoneIcon from 'material-ui/svg-icons/action/done-all'; import DoneIcon from 'material-ui/svg-icons/action/done-all';
import CancelIcon from 'material-ui/svg-icons/content/clear'; import CancelIcon from 'material-ui/svg-icons/content/clear';
import { Button, IdentityIcon, Modal } from '~/ui'; import { Button, IdentityIcon, Modal } from '~/ui';
import RadioButtons from '~/ui/Form/RadioButtons'; import RadioButtons from '~/ui/Form/RadioButtons';
import { nullableProptype } from '~/util/proptypes';
import SMSVerificationStore from './sms-store';
import EmailVerificationStore from './email-store';
import styles from './verification.css'; import styles from './verification.css';
@ -52,11 +56,14 @@ import SendConfirmation from './SendConfirmation';
import Done from './Done'; import Done from './Done';
@observer @observer
export default class Verification extends Component { class Verification extends Component {
static contextTypes = {
api: PropTypes.object.isRequired
}
static propTypes = { static propTypes = {
store: nullableProptype(PropTypes.object.isRequired),
account: PropTypes.string.isRequired, account: PropTypes.string.isRequired,
onSelectMethod: PropTypes.func.isRequired, isTest: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired onClose: PropTypes.func.isRequired
} }
@ -72,8 +79,10 @@ export default class Verification extends Component {
method: 'sms' method: 'sms'
}; };
@observable store = null;
render () { render () {
const { store } = this.props; const store = this.store;
let phase = 0; let error = false; let isStepValid = true; let phase = 0; let error = false; let isStepValid = true;
if (store) { if (store) {
@ -97,7 +106,8 @@ export default class Verification extends Component {
} }
renderDialogActions (phase, error, isStepValid) { renderDialogActions (phase, error, isStepValid) {
const { store, account, onClose } = this.props; const { account, onClose } = this.props;
const store = this.store;
const cancel = ( const cancel = (
<Button <Button
@ -128,9 +138,8 @@ export default class Verification extends Component {
switch (phase) { switch (phase) {
case 0: case 0:
action = () => { action = () => {
const { onSelectMethod } = this.props;
const { method } = this.state; const { method } = this.state;
onSelectMethod(method); this.onSelectMethod(method);
}; };
break; break;
case 1: case 1:
@ -183,7 +192,7 @@ export default class Verification extends Component {
fee, isVerified, hasRequested, fee, isVerified, hasRequested,
requestTx, isCodeValid, confirmationTx, requestTx, isCodeValid, confirmationTx,
setCode setCode
} = this.props.store; } = this.store;
switch (phase) { switch (phase) {
case 1: case 1:
@ -191,7 +200,7 @@ export default class Verification extends Component {
return (<p>Loading verification data.</p>); return (<p>Loading verification data.</p>);
} }
const { setConsentGiven } = this.props.store; const { setConsentGiven } = this.store;
const fields = []; const fields = [];
if (method === 'sms') { if (method === 'sms') {
@ -199,16 +208,16 @@ export default class Verification extends Component {
key: 'number', key: 'number',
label: 'phone number in international format', label: 'phone number in international format',
hint: 'the SMS will be sent to this number', hint: 'the SMS will be sent to this number',
error: this.props.store.isNumberValid ? null : 'invalid number', error: this.store.isNumberValid ? null : 'invalid number',
onChange: this.props.store.setNumber onChange: this.store.setNumber
}); });
} else if (method === 'email') { } else if (method === 'email') {
fields.push({ fields.push({
key: 'email', key: 'email',
label: 'email address', label: 'email address',
hint: 'the code will be sent to this address', hint: 'the code will be sent to this address',
error: this.props.store.isEmailValid ? null : 'invalid email', error: this.store.isEmailValid ? null : 'invalid email',
onChange: this.props.store.setEmail onChange: this.store.setEmail
}); });
} }
@ -228,10 +237,10 @@ export default class Verification extends Component {
case 3: case 3:
let receiver, hint; let receiver, hint;
if (method === 'sms') { if (method === 'sms') {
receiver = this.props.store.number; receiver = this.store.number;
hint = 'Enter the code you received via SMS.'; hint = 'Enter the code you received via SMS.';
} else if (method === 'email') { } else if (method === 'email') {
receiver = this.props.store.email; receiver = this.store.email;
hint = 'Enter the code you received via e-mail.'; hint = 'Enter the code you received via e-mail.';
} }
return ( return (
@ -258,7 +267,27 @@ export default class Verification extends Component {
} }
} }
onSelectMethod = (name) => {
const { api } = this.context;
const { account, isTest } = this.props;
if (name === 'sms') {
this.store = new SMSVerificationStore(api, account, isTest);
} else if (name === 'email') {
this.store = new EmailVerificationStore(api, account, isTest);
}
}
selectMethod = (choice, i) => { selectMethod = (choice, i) => {
this.setState({ method: choice.value }); this.setState({ method: choice.value });
} }
} }
const mapStateToProps = (state) => ({
isTest: state.nodeStatus.isTest
});
export default connect(
mapStateToProps,
null // mapDispatchToProps
)(Verification);

View File

@ -33,16 +33,9 @@ import Transactions from './Transactions';
import { setVisibleAccounts } from '~/redux/providers/personalActions'; import { setVisibleAccounts } from '~/redux/providers/personalActions';
import { fetchCertifiers, fetchCertifications } from '~/redux/providers/certifications/actions'; import { fetchCertifiers, fetchCertifications } from '~/redux/providers/certifications/actions';
import SMSVerificationStore from '~/modals/Verification/sms-store';
import EmailVerificationStore from '~/modals/Verification/email-store';
import styles from './account.css'; import styles from './account.css';
class Account extends Component { class Account extends Component {
static contextTypes = {
api: PropTypes.object.isRequired
}
static propTypes = { static propTypes = {
setVisibleAccounts: PropTypes.func.isRequired, setVisibleAccounts: PropTypes.func.isRequired,
fetchCertifiers: PropTypes.func.isRequired, fetchCertifiers: PropTypes.func.isRequired,
@ -51,7 +44,6 @@ class Account extends Component {
params: PropTypes.object, params: PropTypes.object,
accounts: PropTypes.object, accounts: PropTypes.object,
isTestnet: PropTypes.bool,
balances: PropTypes.object balances: PropTypes.object
} }
@ -60,7 +52,6 @@ class Account extends Component {
showEditDialog: false, showEditDialog: false,
showFundDialog: false, showFundDialog: false,
showVerificationDialog: false, showVerificationDialog: false,
verificationStore: null,
showTransferDialog: false, showTransferDialog: false,
showPasswordDialog: false showPasswordDialog: false
} }
@ -221,13 +212,11 @@ class Account extends Component {
return null; return null;
} }
const store = this.state.verificationStore;
const { address } = this.props.params; const { address } = this.props.params;
return ( return (
<Verification <Verification
store={ store } account={ address } account={ address }
onSelectMethod={ this.selectVerificationMethod }
onClose={ this.onVerificationClose } onClose={ this.onVerificationClose }
/> />
); );
@ -301,22 +290,6 @@ class Account extends Component {
this.setState({ showVerificationDialog: true }); this.setState({ showVerificationDialog: true });
} }
selectVerificationMethod = (name) => {
const { isTestnet } = this.props;
if (typeof isTestnet !== 'boolean' || this.state.verificationStore) return;
const { api } = this.context;
const { address } = this.props.params;
let verificationStore = null;
if (name === 'sms') {
verificationStore = new SMSVerificationStore(api, address, isTestnet);
} else if (name === 'email') {
verificationStore = new EmailVerificationStore(api, address, isTestnet);
}
this.setState({ verificationStore });
}
onVerificationClose = () => { onVerificationClose = () => {
this.setState({ showVerificationDialog: false }); this.setState({ showVerificationDialog: false });
} }
@ -344,13 +317,11 @@ class Account extends Component {
function mapStateToProps (state) { function mapStateToProps (state) {
const { accounts } = state.personal; const { accounts } = state.personal;
const { isTest } = state.nodeStatus;
const { balances } = state.balances; const { balances } = state.balances;
const { images } = state; const { images } = state;
return { return {
accounts, accounts,
isTestnet: isTest,
balances, balances,
images images
}; };