sms verification: wait for tx confirmations

This commit is contained in:
Jannis R 2016-11-08 16:54:25 +01:00
parent d0d737d1e3
commit 3ef54f9172
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5
2 changed files with 49 additions and 7 deletions

View File

@ -0,0 +1,19 @@
/* 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/>.
*/
.centered {
text-align: center;
}

View File

@ -23,7 +23,7 @@ import TxHash from '../../../ui/TxHash';
import { toWei } from '../../../api/util/wei'; import { toWei } from '../../../api/util/wei';
import { sha3 } from '../../../api/util/sha3'; import { sha3 } from '../../../api/util/sha3';
// import styles from './sendRequest.css'; import styles from './sendRequest.css';
export default class SendRequest extends Component { export default class SendRequest extends Component {
static contextTypes = { static contextTypes = {
@ -65,11 +65,13 @@ export default class SendRequest extends Component {
if (step === 'posted') { if (step === 'posted') {
return ( return (
<div> <div className={ styles.centered }>
<p>The transaction has been sent to the network.</p> <TxHash hash={ this.props.data.txHash } maxConfirmations={ 3 } />
<TxHash hash={ this.props.data.txHash } /> </div>);
</div> }
);
if (step === 'mined') {
return (<p>mined</p>);
} }
return null; return null;
@ -101,7 +103,28 @@ export default class SendRequest extends Component {
.then((txHash) => { .then((txHash) => {
onData({ txHash: txHash }); onData({ txHash: txHash });
this.setState({ step: 'posted' }); this.setState({ step: 'posted' });
// TODO: subscribe to `Requested`
return api.pollMethod('eth_getTransactionReceipt', txHash, (receipt) => {
return receipt && receipt.blockNumber && receipt.blockNumber.gt(0);
});
})
.then((receipt) => new Promise((resolve, reject) => {
let subscription;
api.subscribe('eth_blockNumber', (err, block) => {
if (err) {
reject(err);
} else if (block.minus(2).gte(receipt.blockNumber)) {
api.unsubscribe(subscription);
resolve();
}
})
.then((_subscription) => {
subscription = _subscription;
})
.catch(reject);
}))
.then(() => {
this.setState({ step: 'mined' });
}) })
.catch((err) => { .catch((err) => {
console.error('failed to request sms verification', err); console.error('failed to request sms verification', err);