From f9ecea8f4de9d27eb3e3f19e82f95bba4be17746 Mon Sep 17 00:00:00 2001 From: Jannis Redmann Date: Mon, 21 Nov 2016 20:45:47 +0100 Subject: [PATCH] sms verification code style (#3564) * sms verification: fix code style * sms verification: move server-related code to 3rdparty * sms verification: adapt to ropsten --- .../sms-verification/index.js} | 18 ++++- js/src/contracts/sms-verification.js | 17 ---- .../SMSVerification/GatherData/gatherData.js | 7 +- .../modals/SMSVerification/SMSVerification.js | 80 +++++++++++-------- js/src/modals/SMSVerification/store.js | 5 +- 5 files changed, 68 insertions(+), 59 deletions(-) rename js/src/{modals/SMSVerification/terms-of-service.js => 3rdparty/sms-verification/index.js} (81%) diff --git a/js/src/modals/SMSVerification/terms-of-service.js b/js/src/3rdparty/sms-verification/index.js similarity index 81% rename from js/src/modals/SMSVerification/terms-of-service.js rename to js/src/3rdparty/sms-verification/index.js index f61b3c97d..9b113f364 100644 --- a/js/src/modals/SMSVerification/terms-of-service.js +++ b/js/src/3rdparty/sms-verification/index.js @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +import { stringify } from 'querystring'; import React from 'react'; -export default ( +export const termsOfService = ( ); + +export const postToServer = (query) => { + query = stringify(query); + return fetch('https://sms-verification.parity.io/?' + query, { + method: 'POST', mode: 'cors', cache: 'no-store' + }) + .then((res) => { + return res.json().then((data) => { + if (res.ok) { + return data.message; + } + throw new Error(data.message || 'unknown error'); + }); + }); +}; diff --git a/js/src/contracts/sms-verification.js b/js/src/contracts/sms-verification.js index e93d57ffc..c6893e639 100644 --- a/js/src/contracts/sms-verification.js +++ b/js/src/contracts/sms-verification.js @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -import { stringify } from 'querystring'; - export const checkIfVerified = (contract, account) => { return contract.instance.certified.call({}, [account]); }; @@ -35,18 +33,3 @@ export const checkIfRequested = (contract, account) => { }); }); }; - -export const postToServer = (query) => { - query = stringify(query); - return fetch('https://sms-verification.parity.io/?' + query, { - method: 'POST', mode: 'cors', cache: 'no-store' - }) - .then((res) => { - return res.json().then((data) => { - if (res.ok) { - return data.message; - } - throw new Error(data.message || 'unknown error'); - }); - }); -}; diff --git a/js/src/modals/SMSVerification/GatherData/gatherData.js b/js/src/modals/SMSVerification/GatherData/gatherData.js index f4036a3bc..3620de904 100644 --- a/js/src/modals/SMSVerification/GatherData/gatherData.js +++ b/js/src/modals/SMSVerification/GatherData/gatherData.js @@ -25,7 +25,7 @@ import ErrorIcon from 'material-ui/svg-icons/navigation/close'; import { fromWei } from '../../../api/util/wei'; import { Form, Input } from '../../../ui'; -import terms from '../terms-of-service'; +import { termsOfService } from '../../../3rdparty/sms-verification'; import styles from './gatherData.css'; export default class GatherData extends Component { @@ -66,7 +66,7 @@ export default class GatherData extends Component { disabled={ isVerified } onCheck={ this.consentOnChange } /> -
{ terms }
+
{ termsOfService }
); } @@ -123,8 +123,7 @@ export default class GatherData extends Component {

You already requested verification.

); - } - if (hasRequested === false) { + } else if (hasRequested === false) { return (
diff --git a/js/src/modals/SMSVerification/SMSVerification.js b/js/src/modals/SMSVerification/SMSVerification.js index 4ec0b608d..b7c8a901a 100644 --- a/js/src/modals/SMSVerification/SMSVerification.js +++ b/js/src/modals/SMSVerification/SMSVerification.js @@ -16,8 +16,8 @@ import React, { Component, PropTypes } from 'react'; import { observer } from 'mobx-react'; -import ActionDoneAll from 'material-ui/svg-icons/action/done-all'; -import ContentClear from 'material-ui/svg-icons/content/clear'; +import DoneIcon from 'material-ui/svg-icons/action/done-all'; +import CancelIcon from 'material-ui/svg-icons/content/clear'; import { Button, IdentityIcon, Modal } from '../../ui'; @@ -77,7 +77,7 @@ export default class SMSVerification extends Component { const cancel = (
@@ -140,37 +140,47 @@ export default class SMSVerification extends Component { setNumber, setConsentGiven, setCode } = this.props.store; - if (phase === 5) { - return (); - } - if (phase === 4) { - return (); - } - if (phase === 3) { - return ( - - ); - } - if (phase === 2) { - return (); - } - if (phase === 1) { - const { setNumber, setConsentGiven } = this.props.store; - return ( - - ); - } - if (phase === 0) { - return (

Preparing awesomeness!

); - } + switch (phase) { + case 0: + return ( +

Loading SMS Verification.

+ ); - return null; + case 1: + const { setNumber, setConsentGiven } = this.props.store; + return ( + + ); + + case 2: + return ( + + ); + + case 3: + return ( + + ); + + case 4: + return ( + + ); + + case 5: + return ( + + ); + + default: + return null; + } } } diff --git a/js/src/modals/SMSVerification/store.js b/js/src/modals/SMSVerification/store.js index 7337f4eac..8c4db373a 100644 --- a/js/src/modals/SMSVerification/store.js +++ b/js/src/modals/SMSVerification/store.js @@ -20,7 +20,8 @@ import { sha3 } from '../../api/util/sha3'; import Contracts from '../../contracts'; -import { checkIfVerified, checkIfRequested, postToServer } from '../../contracts/sms-verification'; +import { checkIfVerified, checkIfRequested } from '../../contracts/sms-verification'; +import { postToServer } from '../../3rdparty/sms-verification'; import checkIfTxFailed from '../../util/check-if-tx-failed'; import waitForConfirmations from '../../util/wait-for-block-confirmations'; @@ -87,7 +88,7 @@ export default class VerificationStore { this.account = account; this.step = LOADING; - Contracts.create(api).registry.getContract('smsVerification') + Contracts.create(api).registry.getContract('smsverification') .then((contract) => { this.contract = contract; this.load();