From 5263395adda43c302223799ffd9480c99744cb2f Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Fri, 17 Apr 2020 09:53:46 -0700 Subject: [PATCH] Fix background console errors on pending transaction (#8351) * fix background console error on pending transaction --- .../transactions/pending-tx-tracker.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/scripts/controllers/transactions/pending-tx-tracker.js b/app/scripts/controllers/transactions/pending-tx-tracker.js index 233fef697..3843d6671 100644 --- a/app/scripts/controllers/transactions/pending-tx-tracker.js +++ b/app/scripts/controllers/transactions/pending-tx-tracker.js @@ -164,8 +164,8 @@ class PendingTransactionTracker extends EventEmitter { try { // check the network if the nonce is ahead the tx // and the tx has not been mined into a block - dropped = await this._checkIftxWasDropped(txMeta, transactionReceipt) + // the dropped buffer is in case we ask a node for the tx // that is behind the node we asked for tx count // IS A SECURITY FOR HITTING NODES IN INFURA THAT COULD GO OUT @@ -185,21 +185,19 @@ class PendingTransactionTracker extends EventEmitter { // clean up delete this.droppedBuffer[txHash] } - } catch (e) { log.error(e) } + if (taken || dropped) { return this.emit('tx:dropped', txId) } // get latest transaction status - try { - const { blockNumber } = transactionReceipt - if (blockNumber) { - this.emit('tx:confirmed', txId, transactionReceipt) - } - } catch (err) { + if (transactionReceipt?.blockNumber) { + this.emit('tx:confirmed', txId, transactionReceipt) + } else { + const err = new Error('Missing transaction receipt or block number.') txMeta.warning = { error: err.message, message: 'There was a problem loading this transaction.', @@ -215,10 +213,13 @@ class PendingTransactionTracker extends EventEmitter { @returns {boolean} */ - async _checkIftxWasDropped (txMeta, { blockNumber }) { + async _checkIftxWasDropped (txMeta, transactionReceipt) { const { txParams: { nonce, from } } = txMeta const nextNonce = await this.query.getTransactionCount(from) - if (!blockNumber && parseInt(nextNonce) > parseInt(nonce)) { + if ( + !transactionReceipt?.blockNumber && + parseInt(nextNonce) > parseInt(nonce) + ) { return true } return false