From 8028c0fd652b2cd74269594a1487b657f8d0960e Mon Sep 17 00:00:00 2001
From: Jannis R
You already requested verification.
+You did not request verification yet.
+Checking if you requested verification…
); + } + queryFee = () => { const { contract, onData } = this.props; @@ -129,6 +154,24 @@ export default class GatherData extends Component { }); } + checkIfRequested = () => { + const { account, contract, onData } = this.props; + + contract.subscribe('Requested', { + fromBlock: 0, toBlock: 'pending', + // limit: 1 + }, (err, logs) => { + if (err) { + return console.error('error checking if requested', err); + } + const hasRequested = logs.some((l) => { + return l.type === 'mined' && l.params.who && l.params.who.value === account; + }); + onData({ hasRequested }); + this.onChange(); + }); + } + numberOnSubmit = (value) => { this.numberOnChange(null, value); this.props.onData({ number: value }); @@ -148,7 +191,7 @@ export default class GatherData extends Component { } onChange = () => { - const { fee, isCertified } = this.props.data; + const { fee, isCertified, hasRequested } = this.props.data; const { numberIsValid, consentGiven } = this.state; if (fee && numberIsValid && consentGiven && isCertified === false) { diff --git a/js/src/modals/SMSVerification/SendRequest/sendRequest.js b/js/src/modals/SMSVerification/SendRequest/sendRequest.js index 7ca0c2410..e43464949 100644 --- a/js/src/modals/SMSVerification/SendRequest/sendRequest.js +++ b/js/src/modals/SMSVerification/SendRequest/sendRequest.js @@ -122,28 +122,33 @@ export default class SendRequest extends Component { send = () => { const { api } = this.context; const { account, contract, onData, onError, onSuccess } = this.props; - const { fee, number } = this.props.data; + const { fee, number, hasRequested } = this.props.data; const request = contract.functions.find((fn) => fn.name === 'request'); const options = { from: account, value: fee.toString() }; - request.estimateGas(options, []) - .then((gas) => { - options.gas = gas.mul(1.2).toFixed(0); - // TODO: show message - this.setState({ step: 'pending' }); - return request.postTransaction(options, []); - }) - .then((handle) => { - // TODO: The "request rejected" error doesn't have any property to - // distinguish it from other errors, so we can't give a meaningful error here. - return api.pollMethod('parity_checkRequest', handle); - }) - .then((txHash) => { - onData({ txHash: txHash }); - this.setState({ step: 'posted' }); - return waitForConfirmations(api, txHash, 3); - }) + let chain = Promise.resolve(); + if (!hasRequested) { + chain = request.estimateGas(options, []) + .then((gas) => { + options.gas = gas.mul(1.2).toFixed(0); + // TODO: show message + this.setState({ step: 'pending' }); + return request.postTransaction(options, []); + }) + .then((handle) => { + // TODO: The "request rejected" error doesn't have any property to + // distinguish it from other errors, so we can't give a meaningful error here. + return api.pollMethod('parity_checkRequest', handle); + }) + .then((txHash) => { + onData({ txHash: txHash }); + this.setState({ step: 'posted' }); + return waitForConfirmations(api, txHash, 3); + }); + } + + chain .then(() => { this.setState({ step: 'mined' }); return postToVerificationServer({ number, address: account });