aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-07-19 05:00:43 +0800
committerkumavis <aaron@kumavis.me>2017-07-19 05:00:43 +0800
commit67fdba5e42d8deac1dcbb4a82fd3d22b944e639a (patch)
treed52228a192183ce8d47629cde8d6bb50fb3efeff
parentd249da77d7f9602507f708b4778c2128737d4dc5 (diff)
downloadtangerine-wallet-browser-67fdba5e42d8deac1dcbb4a82fd3d22b944e639a.tar
tangerine-wallet-browser-67fdba5e42d8deac1dcbb4a82fd3d22b944e639a.tar.gz
tangerine-wallet-browser-67fdba5e42d8deac1dcbb4a82fd3d22b944e639a.tar.bz2
tangerine-wallet-browser-67fdba5e42d8deac1dcbb4a82fd3d22b944e639a.tar.lz
tangerine-wallet-browser-67fdba5e42d8deac1dcbb4a82fd3d22b944e639a.tar.xz
tangerine-wallet-browser-67fdba5e42d8deac1dcbb4a82fd3d22b944e639a.tar.zst
tangerine-wallet-browser-67fdba5e42d8deac1dcbb4a82fd3d22b944e639a.zip
transaction - promisify _checkPendingTxs
-rw-r--r--app/scripts/controllers/transactions.js68
1 files changed, 41 insertions, 27 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 61e96ca13..1fc48aadd 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -3,6 +3,7 @@ const async = require('async')
const extend = require('xtend')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
+const pify = require('pify')
const TxProviderUtil = require('../lib/tx-utils')
const createId = require('../lib/random-id')
const NonceTracker = require('../lib/nonce-tracker')
@@ -481,35 +482,48 @@ module.exports = class TransactionController extends EventEmitter {
// checks the network for signed txs and
// if confirmed sets the tx status as 'confirmed'
- _checkPendingTxs () {
- var signedTxList = this.getFilteredTxList({status: 'submitted'})
- if (!signedTxList.length) return
- signedTxList.forEach((txMeta) => {
- var txHash = txMeta.hash
- var txId = txMeta.id
- if (!txHash) {
- const errReason = {
- errCode: 'No hash was provided',
- message: 'We had an error while submitting this transaction, please try again.',
- }
- return this.setTxStatusFailed(txId, errReason)
+ async _checkPendingTxs () {
+ const signedTxList = this.getFilteredTxList({status: 'submitted'})
+ try {
+ await Promise.all(signedTxList.map((txMeta) => this._checkPendingTx(txMeta)))
+ } catch (err) {
+ 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) {
+ const errReason = {
+ errCode: 'No hash was provided',
+ message: 'We had an error while submitting this transaction, please try again.',
}
- this.query.getTransactionByHash(txHash, (err, txParams) => {
- if (err || !txParams) {
- if (!txParams) return
- txMeta.err = {
- isWarning: true,
- errorCode: err,
- message: 'There was a problem loading this transaction.',
- }
- this.updateTx(txMeta)
- return log.error(err)
- }
- if (txParams.blockNumber) {
- this.setTxStatusConfirmed(txId)
+ this.setTxStatusFailed(txId, errReason)
+ return
+ }
+ // get latest transaction status
+ let txParams
+ try {
+ txParams = await pify((cb) => this.query.getTransactionByHash(txHash, cb))()
+ if (!txParams) return
+ if (txParams.blockNumber) {
+ this.setTxStatusConfirmed(txId)
+ }
+ } catch (err) {
+ if (err || !txParams) {
+ txMeta.err = {
+ isWarning: true,
+ errorCode: err,
+ message: 'There was a problem loading this transaction.',
}
- })
- })
+ this.updateTx(txMeta)
+ log.error(err)
+ }
+ }
}
}