sms verification: refactor checks & confirmation
This commit is contained in:
@@ -18,35 +18,10 @@ import React, { Component, PropTypes } from 'react';
|
||||
import TxHash from '../../../ui/TxHash';
|
||||
|
||||
import { sha3 } from '../../../api/util/sha3';
|
||||
import waitForConfirmations from '../wait-for-confirmations';
|
||||
|
||||
import styles from './sendConfirmation.css';
|
||||
|
||||
const isValidReceipt = (receipt) => {
|
||||
return receipt && receipt.blockNumber && receipt.blockNumber.gt(0);
|
||||
};
|
||||
|
||||
// TODO: DRY up with ../SendRequest
|
||||
const waitForConfirmations = (api, tx, confirmations) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
api.pollMethod('eth_getTransactionReceipt', tx, isValidReceipt)
|
||||
.then((receipt) => {
|
||||
let subscription;
|
||||
api.subscribe('eth_blockNumber', (err, block) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else if (block.minus(confirmations - 1).gte(receipt.blockNumber)) {
|
||||
api.unsubscribe(subscription);
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
.then((_subscription) => {
|
||||
subscription = _subscription;
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default class SendConfirmation extends Component {
|
||||
static contextTypes = {
|
||||
api: PropTypes.object.isRequired
|
||||
|
||||
Reference in New Issue
Block a user