From 9f8d5f05470d68a7a9a5474a5b1f4587398e94a3 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 25 May 2018 13:30:26 -0700 Subject: [PATCH] controllers - transactions - pending-tx-tracker - _getBlock - poll until block is truthy --- .../controllers/transactions/pending-tx-tracker.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/scripts/controllers/transactions/pending-tx-tracker.js b/app/scripts/controllers/transactions/pending-tx-tracker.js index bd26a72d9..e1bb67c90 100644 --- a/app/scripts/controllers/transactions/pending-tx-tracker.js +++ b/app/scripts/controllers/transactions/pending-tx-tracker.js @@ -1,6 +1,7 @@ const EventEmitter = require('events') const log = require('loglevel') const EthQuery = require('ethjs-query') +const timeout = (duration) => new Promise(resolve => setTimeout(resolve, duration)) /** Event emitter utility class for tracking the transactions as they
@@ -212,7 +213,15 @@ class PendingTransactionTracker extends EventEmitter { } async _getBlock (blockNumber) { - return await this.query.getBlockByNumber(blockNumber, false) + let block + while (!block) { + // block requests will sometimes return null due do the infura api + // being backed by multiple out-of-sync clients + block = await this.query.getBlockByNumber(blockNumber, false) + // if block is null, wait 1 sec then try again + if (!block) await timeout(1000) + } + return block } /**