From 3ef54f9172ec7c371d6fe1149fd790b0fe1660bb Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 8 Nov 2016 16:54:25 +0100 Subject: [PATCH] sms verification: wait for tx confirmations --- .../SendRequest/sendRequest.css | 19 ++++++++++ .../SendRequest/sendRequest.js | 37 +++++++++++++++---- 2 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 js/src/modals/SMSVerification/SendRequest/sendRequest.css diff --git a/js/src/modals/SMSVerification/SendRequest/sendRequest.css b/js/src/modals/SMSVerification/SendRequest/sendRequest.css new file mode 100644 index 000000000..563bf01ad --- /dev/null +++ b/js/src/modals/SMSVerification/SendRequest/sendRequest.css @@ -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 . +*/ +.centered { + text-align: center; +} diff --git a/js/src/modals/SMSVerification/SendRequest/sendRequest.js b/js/src/modals/SMSVerification/SendRequest/sendRequest.js index 1cfb757af..9e3a1ffe8 100644 --- a/js/src/modals/SMSVerification/SendRequest/sendRequest.js +++ b/js/src/modals/SMSVerification/SendRequest/sendRequest.js @@ -23,7 +23,7 @@ import TxHash from '../../../ui/TxHash'; import { toWei } from '../../../api/util/wei'; import { sha3 } from '../../../api/util/sha3'; -// import styles from './sendRequest.css'; +import styles from './sendRequest.css'; export default class SendRequest extends Component { static contextTypes = { @@ -65,11 +65,13 @@ export default class SendRequest extends Component { if (step === 'posted') { return ( -
-

The transaction has been sent to the network.

- -
- ); +
+ +
); + } + + if (step === 'mined') { + return (

mined

); } return null; @@ -101,7 +103,28 @@ export default class SendRequest extends Component { .then((txHash) => { onData({ txHash: txHash }); 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) => { console.error('failed to request sms verification', err);