// 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
{ this.state.error }
); } if (step === 'pending') { return (Waiting for authorization by the Parity Signer.
); } if (step === 'posted') { return (Please keep this window open.
Requesting an SMS from the Parity server.
); } if (step === 'sms-sent') { return (The verification code has been sent to { this.props.data.number }.
); } return null; } send = () => { const { api } = this.context; const { account, contract, onData, onError, onSuccess } = this.props; const { fee, number, hasRequested } = this.props.data; const request = contract.functions.find((fn) => fn.name === 'request'); const options = { from: account, value: fee.toString() }; 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 }); }) .then(() => { this.setState({ step: 'sms-sent' }); onSuccess(); }) .catch((err) => { console.error('failed to request sms verification', err); onError(err); this.setState({ step: 'error', error: 'Failed to request a confirmation SMS: ' + err.message }); // TODO: show message in SnackBar }); } }