mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
transaction - promisify _checkPendingTxs
This commit is contained in:
parent
d249da77d7
commit
67fdba5e42
@ -3,6 +3,7 @@ const async = require('async')
|
|||||||
const extend = require('xtend')
|
const extend = require('xtend')
|
||||||
const ObservableStore = require('obs-store')
|
const ObservableStore = require('obs-store')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
const pify = require('pify')
|
||||||
const TxProviderUtil = require('../lib/tx-utils')
|
const TxProviderUtil = require('../lib/tx-utils')
|
||||||
const createId = require('../lib/random-id')
|
const createId = require('../lib/random-id')
|
||||||
const NonceTracker = require('../lib/nonce-tracker')
|
const NonceTracker = require('../lib/nonce-tracker')
|
||||||
@ -481,35 +482,48 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
// checks the network for signed txs and
|
// checks the network for signed txs and
|
||||||
// if confirmed sets the tx status as 'confirmed'
|
// if confirmed sets the tx status as 'confirmed'
|
||||||
_checkPendingTxs () {
|
async _checkPendingTxs () {
|
||||||
var signedTxList = this.getFilteredTxList({status: 'submitted'})
|
const signedTxList = this.getFilteredTxList({status: 'submitted'})
|
||||||
if (!signedTxList.length) return
|
try {
|
||||||
signedTxList.forEach((txMeta) => {
|
await Promise.all(signedTxList.map((txMeta) => this._checkPendingTx(txMeta)))
|
||||||
var txHash = txMeta.hash
|
} catch (err) {
|
||||||
var txId = txMeta.id
|
console.error('TransactionController - Error updating pending transactions')
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async _checkPendingTx (txMeta) {
|
||||||
|
const txHash = txMeta.hash
|
||||||
|
const txId = txMeta.id
|
||||||
|
// extra check in case there was an uncaught error during the
|
||||||
|
// signature and submission process
|
||||||
if (!txHash) {
|
if (!txHash) {
|
||||||
const errReason = {
|
const errReason = {
|
||||||
errCode: 'No hash was provided',
|
errCode: 'No hash was provided',
|
||||||
message: 'We had an error while submitting this transaction, please try again.',
|
message: 'We had an error while submitting this transaction, please try again.',
|
||||||
}
|
}
|
||||||
return this.setTxStatusFailed(txId, errReason)
|
this.setTxStatusFailed(txId, errReason)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
this.query.getTransactionByHash(txHash, (err, txParams) => {
|
// get latest transaction status
|
||||||
if (err || !txParams) {
|
let txParams
|
||||||
|
try {
|
||||||
|
txParams = await pify((cb) => this.query.getTransactionByHash(txHash, cb))()
|
||||||
if (!txParams) return
|
if (!txParams) return
|
||||||
|
if (txParams.blockNumber) {
|
||||||
|
this.setTxStatusConfirmed(txId)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (err || !txParams) {
|
||||||
txMeta.err = {
|
txMeta.err = {
|
||||||
isWarning: true,
|
isWarning: true,
|
||||||
errorCode: err,
|
errorCode: err,
|
||||||
message: 'There was a problem loading this transaction.',
|
message: 'There was a problem loading this transaction.',
|
||||||
}
|
}
|
||||||
this.updateTx(txMeta)
|
this.updateTx(txMeta)
|
||||||
return log.error(err)
|
log.error(err)
|
||||||
}
|
}
|
||||||
if (txParams.blockNumber) {
|
|
||||||
this.setTxStatusConfirmed(txId)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user