sms verification: bugfixes 🐛

- fixed imports
- renamed `uiSteps` to `phases` to make the distinction between
  actual (tiny) steps and visible UI steps clear
- lookup `requestTx` if request has already been sent
- change code regex to match ethcore/sms-verification@59acb73
This commit is contained in:
Jannis R 2016-11-15 19:05:16 +01:00
parent 7a83fb8595
commit 8d4b1a332b
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5
7 changed files with 41 additions and 35 deletions

View File

@ -43,7 +43,7 @@ export default class SMSVerification extends Component {
onClose: PropTypes.func.isRequired onClose: PropTypes.func.isRequired
} }
static uiSteps = { // mapping (store steps -> steps) static phases = { // mapping (store steps -> steps)
[GATHERING_DATA]: 0, [GATHERED_DATA]: 0, [GATHERING_DATA]: 0, [GATHERED_DATA]: 0,
[POSTING_REQUEST]: 1, [POSTED_REQUEST]: 1, [REQUESTING_SMS]: 1, [POSTING_REQUEST]: 1, [POSTED_REQUEST]: 1, [REQUESTING_SMS]: 1,
[REQUESTED_SMS]: 2, [REQUESTED_SMS]: 2,
@ -56,24 +56,24 @@ export default class SMSVerification extends Component {
} }
render () { render () {
const step = SMSVerification.uiSteps[this.props.store.step]; const phase = SMSVerification.phases[this.props.store.step];
const { error, isStepValid } = this.props.store; const { error, isStepValid } = this.props.store;
return ( return (
<Modal <Modal
actions={ this.renderDialogActions(step, error, isStepValid) } actions={ this.renderDialogActions(phase, error, isStepValid) }
title='verify your account via SMS' title='verify your account via SMS'
visible scroll visible scroll
current={ step } current={ phase }
steps={ ['Enter Data', 'Request', 'Enter Code', 'Confirm', 'Done!'] } steps={ ['Enter Data', 'Request', 'Enter Code', 'Confirm', 'Done!'] }
waiting={ [ 1, 3 ] } waiting={ [ 1, 3 ] }
> >
{ this.renderStep(step, error) } { this.renderStep(phase, error) }
</Modal> </Modal>
); );
} }
renderDialogActions (step, error, isStepValid) { renderDialogActions (phase, error, isStepValid) {
const { store, account, onClose } = this.props; const { store, account, onClose } = this.props;
const cancel = ( const cancel = (
@ -85,7 +85,7 @@ export default class SMSVerification extends Component {
); );
if (error) return (<div>{ cancel }</div>); if (error) return (<div>{ cancel }</div>);
if (step === 4) { if (phase === 4) {
return ( return (
<div> <div>
{ cancel } { cancel }
@ -100,13 +100,13 @@ export default class SMSVerification extends Component {
} }
let action; let action;
if (step === 3) { if (phase === 3) {
action = store.done; action = store.done;
} else if (step === 2) { } else if (phase === 2) {
action = store.sendConfirmation; action = store.sendConfirmation;
} else if (step === 1) { } else if (phase === 1) {
action = store.queryCode; action = store.queryCode;
} else if (step === 0) { } else if (phase === 0) {
action = store.sendRequest; action = store.sendRequest;
} }
@ -123,28 +123,34 @@ export default class SMSVerification extends Component {
); );
} }
renderStep (step, error) { renderStep (phase, error) {
if (error) return (<p>{ error }</p>); if (error) return (<p>{ error }</p>);
const { const {
fee, isNumberValid, isVerified, hasRequested, step,
fee, number, isNumberValid, isVerified, hasRequested,
requestTx, isCodeValid, confirmationTx, requestTx, isCodeValid, confirmationTx,
setNumber, setConsentGiven, setCode setNumber, setConsentGiven, setCode
} = this.props.store; } = this.props.store;
if (step === 4) { if (phase === 4) {
return (<Done />); return (<Done />);
} }
if (step === 3) { if (phase === 3) {
return (<SendConfirmation step={ step } tx={ confirmationTx } />); return (<SendConfirmation step={ step } tx={ confirmationTx } />);
} }
if (step === 2) { if (phase === 2) {
return (<QueryCode fee={ fee } isCodeValid={ isCodeValid } setCode={ setCode } />); return (
<QueryCode
number={ number } fee={ fee } isCodeValid={ isCodeValid }
setCode={ setCode }
/>
);
} }
if (step === 1) { if (phase === 1) {
return (<SendRequest step={ step } tx={ requestTx } />); return (<SendRequest step={ step } tx={ requestTx } />);
} }
if (step === 0) { if (phase === 0) {
const { setNumber, setConsentGiven } = this.props.store; const { setNumber, setConsentGiven } = this.props.store;
return ( return (
<GatherData <GatherData

View File

@ -17,10 +17,9 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import TxHash from '../../../ui/TxHash'; import TxHash from '../../../ui/TxHash';
import VerificationStore from '../store'; import {
const {
POSTING_CONFIRMATION, POSTED_CONFIRMATION POSTING_CONFIRMATION, POSTED_CONFIRMATION
} = VerificationStore; } from '../store';
import styles from './sendConfirmation.css'; import styles from './sendConfirmation.css';

View File

@ -17,10 +17,9 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import TxHash from '../../../ui/TxHash'; import TxHash from '../../../ui/TxHash';
import VerificationStore from '../store'; import {
const {
POSTING_REQUEST, POSTED_REQUEST, REQUESTING_SMS POSTING_REQUEST, POSTED_REQUEST, REQUESTING_SMS
} = VerificationStore; } from '../store';
import styles from './sendRequest.css'; import styles from './sendRequest.css';

View File

@ -22,9 +22,10 @@ const checkIfRequested = (contract, account) => {
if (err) { if (err) {
return reject(err); return reject(err);
} }
resolve(logs.some((l) => { const e = logs.find((l) => {
return l.type === 'mined' && l.params.who && l.params.who.value === account; return l.type === 'mined' && l.params.who && l.params.who.value === account;
})); });
resolve(e ? e.transactionHash : false);
}); });
}); });
}; };

View File

@ -28,10 +28,6 @@ const postToVerificationServer = (query) => {
} }
throw new Error(data.message || 'unknown error'); throw new Error(data.message || 'unknown error');
}); });
})
.catch((err) => {
console.error('foooo', err.stack);
throw err;
}); });
}; };

View File

@ -27,7 +27,7 @@ import checkIfRequested from './check-if-requested';
import waitForConfirmations from './wait-for-confirmations'; import waitForConfirmations from './wait-for-confirmations';
import postToVerificationServer from './post-to-verification-server'; import postToVerificationServer from './post-to-verification-server';
const validCode = /^[A-Z0-9_-]{7,14}$/i; const validCode = /^[A-Z\s]+$/i;
export const GATHERING_DATA = 'gathering-data'; export const GATHERING_DATA = 'gathering-data';
export const GATHERED_DATA = 'gathered-data'; export const GATHERED_DATA = 'gathered-data';
@ -126,8 +126,11 @@ export default class VerificationStore {
}); });
const hasRequested = checkIfRequested(contract, account) const hasRequested = checkIfRequested(contract, account)
.then((hasRequested) => { .then((txHash) => {
this.hasRequested = hasRequested; this.hasRequested = !!txHash;
if (txHash) {
this.requestTx = txHash;
}
}) })
.catch((err) => { .catch((err) => {
this.error = 'Failed to check if requested: ' + err.message; this.error = 'Failed to check if requested: ' + err.message;

View File

@ -27,7 +27,9 @@ const waitForConfirmations = (api, tx, confirmations) => {
if (err) { if (err) {
reject(err); reject(err);
} else if (block.minus(confirmations - 1).gte(receipt.blockNumber)) { } else if (block.minus(confirmations - 1).gte(receipt.blockNumber)) {
if (subscription) {
api.unsubscribe(subscription); api.unsubscribe(subscription);
}
resolve(); resolve();
} }
}) })