diff --git a/js/src/modals/SMSVerification/SMSVerification.js b/js/src/modals/SMSVerification/SMSVerification.js index ce2549ebc..7c31e00de 100644 --- a/js/src/modals/SMSVerification/SMSVerification.js +++ b/js/src/modals/SMSVerification/SMSVerification.js @@ -15,14 +15,20 @@ // along with Parity. If not, see . 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 { Button, IdentityIcon, Modal } from '../../ui'; -import ABI from '../../contracts/abi/sms-verification.json'; -// TODO: move this to a better place -const contract = '0xcE381B876A85A72303f7cA7b3a012f58F4CEEEeB'; +import VerificationStore from './store'; +const { + GATHERING_DATA, GATHERED_DATA, + POSTING_REQUEST, POSTED_REQUEST, + REQUESTING_SMS, REQUESTED_SMS, + POSTING_CONFIRMATION, POSTED_CONFIRMATION, + DONE +} = VerificationStore; import GatherData from './GatherData'; import SendRequest from './SendRequest'; @@ -30,6 +36,7 @@ import QueryCode from './QueryCode'; import SendConfirmation from './SendConfirmation'; import Done from './Done'; +@observer export default class SMSVerification extends Component { static contextTypes = { api: PropTypes.object.isRequired @@ -40,41 +47,51 @@ export default class SMSVerification extends Component { onClose: PropTypes.func.isRequired } + static uiSteps = { // mapping (store steps -> steps) + [GATHERING_DATA]: 0, [GATHERED_DATA]: 0, + [POSTING_REQUEST]: 1, [POSTED_REQUEST]: 1, [REQUESTING_SMS]: 1, + [REQUESTED_SMS]: 2, + [POSTING_CONFIRMATION]: 3, [POSTED_CONFIRMATION]: 3, + [DONE]: 4 + } + state = { - contract: null, - step: 0, - stepIsValid: false, - data: {} + store: null } componentDidMount () { const { api } = this.context; + const { account } = this.props; - this.setState({ - contract: api.newContract(ABI, contract) + const store = new VerificationStore(api, account); + this.setState({ store }, () => { + store.gatherData(); }); } render () { - const { step } = this.state; + const { store } = this.state; + if (!store) return null; + const step = SMSVerification.uiSteps[store.step]; + const { error, isStepValid } = store; return ( - { this.renderStep() } + { this.renderStep(step, error) } ); } - renderDialogActions () { + renderDialogActions (step, error, isStepValid) { const { onClose, account } = this.props; - const { step, stepIsValid } = this.state; + const { store } = this.state; const cancel = (