sms verification: check if already requested
This commit is contained in:
parent
01cf88d71a
commit
8028c0fd65
@ -17,7 +17,7 @@
|
|||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
import { Checkbox } from 'material-ui';
|
import { Checkbox } from 'material-ui';
|
||||||
import SuccessIcon from 'material-ui/svg-icons/navigation/check';
|
import SuccessIcon from 'material-ui/svg-icons/navigation/check';
|
||||||
import ErrorIcon from 'material-ui/svg-icons/alert/error-outline';
|
import ErrorIcon from 'material-ui/svg-icons/navigation/close';
|
||||||
|
|
||||||
import phone from 'phoneformat.js';
|
import phone from 'phoneformat.js';
|
||||||
|
|
||||||
@ -43,6 +43,7 @@ export default class GatherData extends Component {
|
|||||||
state = {
|
state = {
|
||||||
init: true,
|
init: true,
|
||||||
isCertified: null,
|
isCertified: null,
|
||||||
|
hasRequested: null,
|
||||||
numberIsValid: null,
|
numberIsValid: null,
|
||||||
consentGiven: false
|
consentGiven: false
|
||||||
};
|
};
|
||||||
@ -53,6 +54,7 @@ export default class GatherData extends Component {
|
|||||||
this.setState({ init: false });
|
this.setState({ init: false });
|
||||||
this.queryFee();
|
this.queryFee();
|
||||||
this.checkIfCertified();
|
this.checkIfCertified();
|
||||||
|
this.checkIfRequested();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +66,7 @@ export default class GatherData extends Component {
|
|||||||
<Form>
|
<Form>
|
||||||
<p>{ fee ? `The fee is ${fromWei(fee).toFixed(3)} ETH.` : 'Fetching the fee…' }</p>
|
<p>{ fee ? `The fee is ${fromWei(fee).toFixed(3)} ETH.` : 'Fetching the fee…' }</p>
|
||||||
{ this.renderCertified() }
|
{ this.renderCertified() }
|
||||||
|
{ this.renderRequested() }
|
||||||
<Input
|
<Input
|
||||||
label={ 'phone number' }
|
label={ 'phone number' }
|
||||||
hint={ 'the sms will be sent to this number' }
|
hint={ 'the sms will be sent to this number' }
|
||||||
@ -102,6 +105,28 @@ export default class GatherData extends Component {
|
|||||||
return (<p className={ styles.message }>Checking if your account is verified…</p>);
|
return (<p className={ styles.message }>Checking if your account is verified…</p>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderRequested () {
|
||||||
|
const { hasRequested } = this.props.data;
|
||||||
|
|
||||||
|
if (hasRequested) {
|
||||||
|
return (
|
||||||
|
<div className={ styles.container }>
|
||||||
|
<ErrorIcon />
|
||||||
|
<p className={ styles.message }>You already requested verification.</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (hasRequested === false) {
|
||||||
|
return (
|
||||||
|
<div className={ styles.container }>
|
||||||
|
<SuccessIcon />
|
||||||
|
<p className={ styles.message }>You did not request verification yet.</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (<p className={ styles.message }>Checking if you requested verification…</p>);
|
||||||
|
}
|
||||||
|
|
||||||
queryFee = () => {
|
queryFee = () => {
|
||||||
const { contract, onData } = this.props;
|
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) => {
|
numberOnSubmit = (value) => {
|
||||||
this.numberOnChange(null, value);
|
this.numberOnChange(null, value);
|
||||||
this.props.onData({ number: value });
|
this.props.onData({ number: value });
|
||||||
@ -148,7 +191,7 @@ export default class GatherData extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onChange = () => {
|
onChange = () => {
|
||||||
const { fee, isCertified } = this.props.data;
|
const { fee, isCertified, hasRequested } = this.props.data;
|
||||||
const { numberIsValid, consentGiven } = this.state;
|
const { numberIsValid, consentGiven } = this.state;
|
||||||
|
|
||||||
if (fee && numberIsValid && consentGiven && isCertified === false) {
|
if (fee && numberIsValid && consentGiven && isCertified === false) {
|
||||||
|
@ -122,28 +122,33 @@ export default class SendRequest extends Component {
|
|||||||
send = () => {
|
send = () => {
|
||||||
const { api } = this.context;
|
const { api } = this.context;
|
||||||
const { account, contract, onData, onError, onSuccess } = this.props;
|
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 request = contract.functions.find((fn) => fn.name === 'request');
|
||||||
const options = { from: account, value: fee.toString() };
|
const options = { from: account, value: fee.toString() };
|
||||||
|
|
||||||
request.estimateGas(options, [])
|
let chain = Promise.resolve();
|
||||||
.then((gas) => {
|
if (!hasRequested) {
|
||||||
options.gas = gas.mul(1.2).toFixed(0);
|
chain = request.estimateGas(options, [])
|
||||||
// TODO: show message
|
.then((gas) => {
|
||||||
this.setState({ step: 'pending' });
|
options.gas = gas.mul(1.2).toFixed(0);
|
||||||
return request.postTransaction(options, []);
|
// TODO: show message
|
||||||
})
|
this.setState({ step: 'pending' });
|
||||||
.then((handle) => {
|
return request.postTransaction(options, []);
|
||||||
// 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.
|
.then((handle) => {
|
||||||
return api.pollMethod('parity_checkRequest', 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.
|
||||||
.then((txHash) => {
|
return api.pollMethod('parity_checkRequest', handle);
|
||||||
onData({ txHash: txHash });
|
})
|
||||||
this.setState({ step: 'posted' });
|
.then((txHash) => {
|
||||||
return waitForConfirmations(api, txHash, 3);
|
onData({ txHash: txHash });
|
||||||
})
|
this.setState({ step: 'posted' });
|
||||||
|
return waitForConfirmations(api, txHash, 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
chain
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.setState({ step: 'mined' });
|
this.setState({ step: 'mined' });
|
||||||
return postToVerificationServer({ number, address: account });
|
return postToVerificationServer({ number, address: account });
|
||||||
|
Loading…
Reference in New Issue
Block a user