sms verification: check if certified

This commit is contained in:
Jannis R 2016-11-07 13:18:36 +01:00
parent 435d3c24db
commit 14da2d2805
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5
4 changed files with 147 additions and 2 deletions

View File

@ -0,0 +1,27 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.container {
display: flex;
align-items: center;
}
.message {
margin-top: 0;
margin-bottom: 0;
margin-left: .5em;
}

View File

@ -0,0 +1,88 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import { Checkbox } from 'material-ui';
import SuccessIcon from 'material-ui/svg-icons/navigation/check';
import ErrorIcon from 'material-ui/svg-icons/alert/error-outline';
import { Form, Input } from '../../../ui';
import styles from './checkIfCertified.css';
export default class CheckIfCertified extends Component {
static contextTypes = {
api: PropTypes.object.isRequired
}
static propTypes = {
account: PropTypes.string.isRequired,
contract: PropTypes.object.isRequired,
onIsCertified: PropTypes.func.isRequired,
onIsNotCertified: PropTypes.func.isRequired
}
state = {
pending: false,
isCertified: null
};
componentWillMount () {
const { pending } = this.state;
if (pending) {
return;
}
this.setState({ pending: true });
const { account, contract, onIsCertified, onIsNotCertified } = this.props;
contract.instance.certified.call({}, [account])
.then((isCertified) => {
this.setState({ isCertified, pending: false });
if (isCertified) {
onIsCertified();
} else {
onIsNotCertified();
}
})
.catch((err) => {
console.error('error checking if certified', err);
});
}
render () {
const { pending, isCertified } = this.state;
if (pending) {
return (<p className={ styles.message }>Checking if your account is verified</p>);
}
if (isCertified) {
return (
<div className={ styles.container }>
<ErrorIcon />
<p className={ styles.message }>Your account is already verified.</p>
</div>
);
}
return (
<div className={ styles.container }>
<SuccessIcon />
<p className={ styles.message }>Your account is not verified yet.</p>
</div>
);
}
}

View File

@ -0,0 +1,17 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './checkIfCertified';

View File

@ -24,6 +24,7 @@ import { validateAddress, validateUint } from '../../util/validation';
import ABI from '../../contracts/abi/sms-verification.json'; import ABI from '../../contracts/abi/sms-verification.json';
const contract = '0x7B3F58965439b22ef1dA4BB78f16191d11ab80B0'; const contract = '0x7B3F58965439b22ef1dA4BB78f16191d11ab80B0';
import CheckIfCertified from './CheckIfCertified';
import GatherData from './GatherData'; import GatherData from './GatherData';
export default class SMSVerification extends Component { export default class SMSVerification extends Component {
@ -119,16 +120,28 @@ export default class SMSVerification extends Component {
onDataIsValid = () => { onDataIsValid = () => {
this.setState({ stepIsValid: true }); this.setState({ stepIsValid: true });
} }
onDataIsInvalid = () => { onDataIsInvalid = () => {
this.setState({ stepIsValid: false }); this.setState({ stepIsValid: false });
} }
next = () => { next = () => {
this.setState({ step: this.state.step + 1 }); this.setState({ step: this.state.step + 1, stepIsValid: false });
} }
renderFirstStep () { renderFirstStep () {
const { account } = this.props;
const { contract } = this.state;
return (
<CheckIfCertified
account={ account } contract={ contract }
onIsCertified={ this.onDataIsInvalid }
onIsNotCertified={ this.onDataIsValid }
/>
);
}
renderSecondStep () {
return ( return (
<GatherData <GatherData
onDataIsValid={ this.onDataIsValid } onDataIsValid={ this.onDataIsValid }