From fff8743ee6d5a1e779793206246263a63d45cfdb Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 17 Nov 2016 14:21:05 +0100 Subject: [PATCH] sms verification: fetch contract address from Registry --- js/src/contracts/abi/index.js | 4 +- js/src/modals/SMSVerification/store.js | 56 +++++++++++++++----------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/js/src/contracts/abi/index.js b/js/src/contracts/abi/index.js index dda43775e..a6a7f0783 100644 --- a/js/src/contracts/abi/index.js +++ b/js/src/contracts/abi/index.js @@ -23,7 +23,7 @@ import githubhint from './githubhint.json'; import owned from './owned.json'; import registry from './registry.json'; import signaturereg from './signaturereg.json'; -import smsVerification from './sms-verification.json'; +import smsverification from './sms-verification.json'; import tokenreg from './tokenreg.json'; import wallet from './wallet.json'; @@ -37,7 +37,7 @@ export { owned, registry, signaturereg, - smsVerification, + smsverification, tokenreg, wallet }; diff --git a/js/src/modals/SMSVerification/store.js b/js/src/modals/SMSVerification/store.js index 0682369c1..7337f4eac 100644 --- a/js/src/modals/SMSVerification/store.js +++ b/js/src/modals/SMSVerification/store.js @@ -18,9 +18,7 @@ import { observable, computed, autorun, action } from 'mobx'; import phone from 'phoneformat.js'; import { sha3 } from '../../api/util/sha3'; -import ABI from '../../contracts/abi/sms-verification.json'; -// TODO: move this to a better place -const contract = '0xcE381B876A85A72303f7cA7b3a012f58F4CEEEeB'; +import Contracts from '../../contracts'; import { checkIfVerified, checkIfRequested, postToServer } from '../../contracts/sms-verification'; import checkIfTxFailed from '../../util/check-if-tx-failed'; @@ -28,8 +26,8 @@ import waitForConfirmations from '../../util/wait-for-block-confirmations'; const validCode = /^[A-Z\s]+$/i; -export const GATHERING_DATA = 'gathering-data'; -export const GATHERED_DATA = 'gathered-data'; +export const LOADING = 'fetching-contract'; +export const QUERY_DATA = 'query-data'; export const POSTING_REQUEST = 'posting-request'; export const POSTED_REQUEST = 'posted-request'; export const REQUESTING_SMS = 'requesting-sms'; @@ -43,6 +41,7 @@ export default class VerificationStore { @observable step = null; @observable error = null; + @observable contract = null; @observable fee = null; @observable isVerified = null; @observable hasRequested = null; @@ -68,8 +67,10 @@ export default class VerificationStore { } switch (this.step) { - case GATHERED_DATA: - return this.fee && this.isVerified === false && this.isNumberValid && this.consentGiven; + case LOADING: + return this.contract && this.fee && this.isVerified !== null && this.hasRequested !== null; + case QUERY_DATA: + return this.isNumberValid && this.consentGiven; case REQUESTED_SMS: return this.requestTx; case QUERY_CODE: @@ -84,7 +85,16 @@ export default class VerificationStore { constructor (api, account) { this.api = api; this.account = account; - this.contract = api.newContract(ABI, contract); + + this.step = LOADING; + Contracts.create(api).registry.getContract('smsVerification') + .then((contract) => { + this.contract = contract; + this.load(); + }) + .catch((err) => { + this.error = 'Failed to fetch the contract: ' + err.message; + }); autorun(() => { if (this.error) { @@ -93,21 +103,9 @@ export default class VerificationStore { }); } - @action setNumber = (number) => { - this.number = number; - } - - @action setConsentGiven = (consentGiven) => { - this.consentGiven = consentGiven; - } - - @action setCode = (code) => { - this.code = code; - } - - @action gatherData = () => { + @action load = () => { const { contract, account } = this; - this.step = GATHERING_DATA; + this.step = LOADING; const fee = contract.instance.fee.call() .then((fee) => { @@ -139,10 +137,22 @@ export default class VerificationStore { Promise .all([ fee, isVerified, hasRequested ]) .then(() => { - this.step = GATHERED_DATA; + this.step = QUERY_DATA; }); } + @action setNumber = (number) => { + this.number = number; + } + + @action setConsentGiven = (consentGiven) => { + this.consentGiven = consentGiven; + } + + @action setCode = (code) => { + this.code = code; + } + @action sendRequest = () => { const { api, account, contract, fee, number, hasRequested } = this;