sms verification: show fee in consent form
This commit is contained in:
		
							parent
							
								
									e84531f31c
								
							
						
					
					
						commit
						e7113e7eb4
					
				@ -18,27 +18,41 @@ import React, { Component, PropTypes } from 'react';
 | 
				
			|||||||
import { Checkbox } from 'material-ui';
 | 
					import { Checkbox } from 'material-ui';
 | 
				
			||||||
import phone from 'phoneformat.js';
 | 
					import phone from 'phoneformat.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { fromWei } from '../../../api/util/wei';
 | 
				
			||||||
import { Form, Input } from '../../../ui';
 | 
					import { Form, Input } from '../../../ui';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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 = {
 | 
				
			||||||
 | 
					    contract: PropTypes.object.isRequired,
 | 
				
			||||||
 | 
					    data: PropTypes.object.isRequired,
 | 
				
			||||||
 | 
					    onData: PropTypes.func.isRequired,
 | 
				
			||||||
    onDataIsValid: PropTypes.func.isRequired,
 | 
					    onDataIsValid: PropTypes.func.isRequired,
 | 
				
			||||||
    onDataIsInvalid: PropTypes.func.isRequired,
 | 
					    onDataIsInvalid: PropTypes.func.isRequired
 | 
				
			||||||
    onData: PropTypes.func.isRequired
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  state = {
 | 
					  state = {
 | 
				
			||||||
 | 
					    init: true,
 | 
				
			||||||
    numberIsValid: null,
 | 
					    numberIsValid: null,
 | 
				
			||||||
    consentGiven: false
 | 
					    consentGiven: false
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  componentWillMount () {
 | 
				
			||||||
 | 
					    const { init } = this.state;
 | 
				
			||||||
 | 
					    if (init) {
 | 
				
			||||||
 | 
					      this.queryFee();
 | 
				
			||||||
 | 
					      this.setState({ init: false });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  render () {
 | 
					  render () {
 | 
				
			||||||
 | 
					    const { fee } = this.props.data;
 | 
				
			||||||
    const { numberIsValid } = this.state;
 | 
					    const { numberIsValid } = this.state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <Form>
 | 
					      <Form>
 | 
				
			||||||
 | 
					        <p>{ fee ? `The fee is ${fromWei(fee).toFixed(3)} ETH.` : 'Fetching the fee…' }</p>
 | 
				
			||||||
        <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' }
 | 
				
			||||||
@ -55,6 +69,20 @@ export default class GatherData extends Component {
 | 
				
			|||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  queryFee = () => {
 | 
				
			||||||
 | 
					    const { contract, onData } = this.props;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    contract.instance.fee.call()
 | 
				
			||||||
 | 
					    .then((fee) => {
 | 
				
			||||||
 | 
					      onData({ fee });
 | 
				
			||||||
 | 
					      this.onChange();
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .catch((err) => {
 | 
				
			||||||
 | 
					      console.error('error fetching fee', err);
 | 
				
			||||||
 | 
					      this.onChange();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  numberOnSubmit = (value) => {
 | 
					  numberOnSubmit = (value) => {
 | 
				
			||||||
    this.numberOnChange(null, value);
 | 
					    this.numberOnChange(null, value);
 | 
				
			||||||
    this.props.onData({ number: value });
 | 
					    this.props.onData({ number: value });
 | 
				
			||||||
@ -74,9 +102,10 @@ export default class GatherData extends Component {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  onChange = () => {
 | 
					  onChange = () => {
 | 
				
			||||||
 | 
					    const { fee } = this.props.data;
 | 
				
			||||||
    const { numberIsValid, consentGiven } = this.state;
 | 
					    const { numberIsValid, consentGiven } = this.state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (numberIsValid && consentGiven) {
 | 
					    if (fee && numberIsValid && consentGiven) {
 | 
				
			||||||
      this.props.onDataIsValid();
 | 
					      this.props.onDataIsValid();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      this.props.onDataIsInvalid();
 | 
					      this.props.onDataIsInvalid();
 | 
				
			||||||
 | 
				
			|||||||
@ -154,8 +154,11 @@ export default class SMSVerification extends Component {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  renderSecondStep () {
 | 
					  renderSecondStep () {
 | 
				
			||||||
 | 
					    const { contract, data } = this.state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <GatherData
 | 
					      <GatherData
 | 
				
			||||||
 | 
					        contract={ contract } data={ data }
 | 
				
			||||||
        onData={ this.onData }
 | 
					        onData={ this.onData }
 | 
				
			||||||
        onDataIsValid={ this.onDataIsValid }
 | 
					        onDataIsValid={ this.onDataIsValid }
 | 
				
			||||||
        onDataIsInvalid={ this.onDataIsInvalid }
 | 
					        onDataIsInvalid={ this.onDataIsInvalid }
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,6 @@ import React, { Component, PropTypes } from 'react';
 | 
				
			|||||||
import qs from 'querystring';
 | 
					import qs from 'querystring';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import TxHash from '../../../ui/TxHash';
 | 
					import TxHash from '../../../ui/TxHash';
 | 
				
			||||||
import { toWei } from '../../../api/util/wei';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import styles from './sendRequest.css';
 | 
					import styles from './sendRequest.css';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -121,10 +120,7 @@ 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 { number } = this.props.data;
 | 
					    const { fee, number } = this.props.data;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // TODO: redeploy SMSVerification.sol, it has a public fee prop now
 | 
					 | 
				
			||||||
    const fee = toWei(0.01); // 0.01 Eth
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    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() };
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user