diff --git a/js/src/modals/SMSVerification/SMSVerification.js b/js/src/modals/SMSVerification/SMSVerification.js index c3d02c95d..dbdb7625f 100644 --- a/js/src/modals/SMSVerification/SMSVerification.js +++ b/js/src/modals/SMSVerification/SMSVerification.js @@ -43,7 +43,7 @@ export default class SMSVerification extends Component { onClose: PropTypes.func.isRequired } - static uiSteps = { // mapping (store steps -> steps) + static phases = { // mapping (store steps -> steps) [GATHERING_DATA]: 0, [GATHERED_DATA]: 0, [POSTING_REQUEST]: 1, [POSTED_REQUEST]: 1, [REQUESTING_SMS]: 1, [REQUESTED_SMS]: 2, @@ -56,24 +56,24 @@ export default class SMSVerification extends Component { } render () { - const step = SMSVerification.uiSteps[this.props.store.step]; + const phase = SMSVerification.phases[this.props.store.step]; const { error, isStepValid } = this.props.store; return ( - { this.renderStep(step, error) } + { this.renderStep(phase, error) } ); } - renderDialogActions (step, error, isStepValid) { + renderDialogActions (phase, error, isStepValid) { const { store, account, onClose } = this.props; const cancel = ( @@ -85,7 +85,7 @@ export default class SMSVerification extends Component { ); if (error) return (
{ cancel }
); - if (step === 4) { + if (phase === 4) { return (
{ cancel } @@ -100,13 +100,13 @@ export default class SMSVerification extends Component { } let action; - if (step === 3) { + if (phase === 3) { action = store.done; - } else if (step === 2) { + } else if (phase === 2) { action = store.sendConfirmation; - } else if (step === 1) { + } else if (phase === 1) { action = store.queryCode; - } else if (step === 0) { + } else if (phase === 0) { action = store.sendRequest; } @@ -123,28 +123,34 @@ export default class SMSVerification extends Component { ); } - renderStep (step, error) { + renderStep (phase, error) { if (error) return (

{ error }

); const { - fee, isNumberValid, isVerified, hasRequested, + step, + fee, number, isNumberValid, isVerified, hasRequested, requestTx, isCodeValid, confirmationTx, setNumber, setConsentGiven, setCode } = this.props.store; - if (step === 4) { + if (phase === 4) { return (); } - if (step === 3) { + if (phase === 3) { return (); } - if (step === 2) { - return (); + if (phase === 2) { + return ( + + ); } - if (step === 1) { + if (phase === 1) { return (); } - if (step === 0) { + if (phase === 0) { const { setNumber, setConsentGiven } = this.props.store; return ( { if (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; - })); + }); + resolve(e ? e.transactionHash : false); }); }); }; diff --git a/js/src/modals/SMSVerification/post-to-verification-server.js b/js/src/modals/SMSVerification/post-to-verification-server.js index 649bd4fc7..b7889f3e0 100644 --- a/js/src/modals/SMSVerification/post-to-verification-server.js +++ b/js/src/modals/SMSVerification/post-to-verification-server.js @@ -28,10 +28,6 @@ const postToVerificationServer = (query) => { } throw new Error(data.message || 'unknown error'); }); - }) - .catch((err) => { - console.error('foooo', err.stack); - throw err; }); }; diff --git a/js/src/modals/SMSVerification/store.js b/js/src/modals/SMSVerification/store.js index 01c775c3a..2d4aa099b 100644 --- a/js/src/modals/SMSVerification/store.js +++ b/js/src/modals/SMSVerification/store.js @@ -27,7 +27,7 @@ import checkIfRequested from './check-if-requested'; import waitForConfirmations from './wait-for-confirmations'; 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 GATHERED_DATA = 'gathered-data'; @@ -126,8 +126,11 @@ export default class VerificationStore { }); const hasRequested = checkIfRequested(contract, account) - .then((hasRequested) => { - this.hasRequested = hasRequested; + .then((txHash) => { + this.hasRequested = !!txHash; + if (txHash) { + this.requestTx = txHash; + } }) .catch((err) => { this.error = 'Failed to check if requested: ' + err.message; diff --git a/js/src/modals/SMSVerification/wait-for-confirmations.js b/js/src/modals/SMSVerification/wait-for-confirmations.js index e99d3d173..79ba2be25 100644 --- a/js/src/modals/SMSVerification/wait-for-confirmations.js +++ b/js/src/modals/SMSVerification/wait-for-confirmations.js @@ -27,7 +27,9 @@ const waitForConfirmations = (api, tx, confirmations) => { if (err) { reject(err); } else if (block.minus(confirmations - 1).gte(receipt.blockNumber)) { - api.unsubscribe(subscription); + if (subscription) { + api.unsubscribe(subscription); + } resolve(); } })