pass fields to query into GatherData

This commit is contained in:
Jannis R 2016-12-07 11:53:48 +01:00
parent d3fd71d953
commit 052f9258a5
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5
3 changed files with 33 additions and 31 deletions

View File

@ -15,10 +15,6 @@
/* along with Parity. If not, see <http://www.gnu.org/licenses/>. /* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/ */
.list li {
padding: .1em 0;
}
.spacing { .spacing {
margin-top: 1.5em; margin-top: 1.5em;
} }

View File

@ -25,41 +25,31 @@ import { fromWei } from '~/api/util/wei';
import { Form, Input } from '~/ui'; import { Form, Input } from '~/ui';
import { nullableProptype } from '~/util/proptypes'; import { nullableProptype } from '~/util/proptypes';
import { termsOfService } from '../../../3rdparty/sms-verification'; import * as sms from '../../../3rdparty/sms-verification';
import * as email from '../../../3rdparty/email-verification';
import styles from './gatherData.css'; import styles from './gatherData.css';
export default class GatherData extends Component { export default class GatherData extends Component {
static propTypes = { static propTypes = {
fee: React.PropTypes.instanceOf(BigNumber), fee: React.PropTypes.instanceOf(BigNumber),
isNumberValid: PropTypes.bool.isRequired, method: PropTypes.string.isRequired,
fields: PropTypes.array.isRequired,
isVerified: nullableProptype(PropTypes.bool.isRequired), isVerified: nullableProptype(PropTypes.bool.isRequired),
hasRequested: nullableProptype(PropTypes.bool.isRequired), hasRequested: nullableProptype(PropTypes.bool.isRequired),
setNumber: PropTypes.func.isRequired,
setConsentGiven: PropTypes.func.isRequired setConsentGiven: PropTypes.func.isRequired
} }
render () { render () {
const { isNumberValid, isVerified } = this.props; const { method, isVerified } = this.props;
const { howItWorks, termsOfService } = method === 'email' ? email : sms;
return ( return (
<Form> <Form>
<p>The following steps will let you prove that you control both an account and a phone number.</p> { howItWorks }
<ol className={ styles.list }>
<li>You send a verification request to a specific contract.</li>
<li>Our server puts a puzzle into this contract.</li>
<li>The code you receive via SMS is the solution to this puzzle.</li>
</ol>
{ this.renderFee() } { this.renderFee() }
{ this.renderCertified() } { this.renderCertified() }
{ this.renderRequested() } { this.renderRequested() }
<Input { this.renderFields() }
label={ 'phone number in international format' }
hint={ 'the SMS will be sent to this number' }
error={ isNumberValid ? null : 'invalid number' }
disabled={ isVerified }
onChange={ this.numberOnChange }
onSubmit={ this.numberOnSubmit }
/>
<Checkbox <Checkbox
className={ styles.spacing } className={ styles.spacing }
label={ 'I agree to the terms and conditions below.' } label={ 'I agree to the terms and conditions below.' }
@ -136,12 +126,28 @@ export default class GatherData extends Component {
); );
} }
numberOnSubmit = (value) => { renderFields () {
this.props.setNumber(value); const { isVerified, fields } = this.props;
}
numberOnChange = (_, value) => { const rendered = fields.map((field) => {
this.props.setNumber(value); const onChange = (_, v) => {
field.onChange(v);
};
const onSubmit = field.onChange;
return (
<Input
key={ field.key }
label={ field.label }
hint={ field.hint }
error={ field.error }
disabled={ isVerified }
onChange={ onChange }
onSubmit={ onSubmit }
/>
);
});
return (<div>{rendered}</div>);
} }
consentOnChange = (_, consentGiven) => { consentOnChange = (_, consentGiven) => {

View File

@ -46,7 +46,7 @@ import Done from './Done';
@observer @observer
export default class Verification extends Component { export default class Verification extends Component {
static propTypes = { static propTypes = {
store: nullableProptype(PropTypes.object).isRequired, store: nullableProptype(PropTypes.object.isRequired),
account: PropTypes.string.isRequired, account: PropTypes.string.isRequired,
onSelectMethod: PropTypes.func.isRequired, onSelectMethod: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired onClose: PropTypes.func.isRequired
@ -209,9 +209,9 @@ export default class Verification extends Component {
return ( return (
<GatherData <GatherData
fee={ fee } isNumberValid={ isNumberValid } method={ method } fields={ fields }
isVerified={ isVerified } hasRequested={ hasRequested } fee={ fee } isVerified={ isVerified } hasRequested={ hasRequested }
setNumber={ setNumber } setConsentGiven={ setConsentGiven } setConsentGiven={ setConsentGiven }
/> />
); );