aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-05-23 07:22:10 +0800
committerkumavis <aaron@kumavis.me>2018-05-23 07:22:10 +0800
commit145016be4c681b725d3450f59cb2892f0ec6d993 (patch)
tree732b5a63fbd6ee1cbf7b9bc472330c163ae49936
parent9e7a9e47bd36feb1ea2179dca6c2740ba6eb2ab1 (diff)
parented01c6c8264a860cdc4248991839954bdf22e2ef (diff)
downloadtangerine-wallet-browser-145016be4c681b725d3450f59cb2892f0ec6d993.tar
tangerine-wallet-browser-145016be4c681b725d3450f59cb2892f0ec6d993.tar.gz
tangerine-wallet-browser-145016be4c681b725d3450f59cb2892f0ec6d993.tar.bz2
tangerine-wallet-browser-145016be4c681b725d3450f59cb2892f0ec6d993.tar.lz
tangerine-wallet-browser-145016be4c681b725d3450f59cb2892f0ec6d993.tar.xz
tangerine-wallet-browser-145016be4c681b725d3450f59cb2892f0ec6d993.tar.zst
tangerine-wallet-browser-145016be4c681b725d3450f59cb2892f0ec6d993.zip
Merge branch 'develop' of github.com:MetaMask/metamask-extension into network-remove-provider-engine
-rw-r--r--app/scripts/controllers/recent-blocks.js22
1 files changed, 7 insertions, 15 deletions
diff --git a/app/scripts/controllers/recent-blocks.js b/app/scripts/controllers/recent-blocks.js
index 9a215d0e5..a6208b89c 100644
--- a/app/scripts/controllers/recent-blocks.js
+++ b/app/scripts/controllers/recent-blocks.js
@@ -3,7 +3,6 @@ const extend = require('xtend')
const EthQuery = require('eth-query')
const log = require('loglevel')
const pify = require('pify')
-const timeout = (duration) => new Promise(resolve => setTimeout(resolve, duration))
class RecentBlocksController {
@@ -123,28 +122,21 @@ class RecentBlocksController {
*/
async backfill() {
this.blockTracker.once('latest', async (blockNumberHex) => {
- let recentBlocks
- let blockNumber = Number.parseInt(blockNumberHex, 16)
- let state = this.store.getState()
- recentBlocks = state.recentBlocks
-
- while (recentBlocks.length < this.historyLength) {
+ const currentBlockNumber = Number.parseInt(blockNumberHex, 16)
+ const blocksToFetch = Math.min(currentBlockNumber, this.historyLength)
+ const prevBlockNumber = currentBlockNumber - 1
+ const targetBlockNumbers = Array(blocksToFetch).fill().map((_, index) => prevBlockNumber - index)
+ await Promise.all(targetBlockNumbers.map(async (targetBlockNumber) => {
try {
- const prevBlockNumber = blockNumber - 1
- const newBlock = await this.getBlockByNumber(prevBlockNumber)
+ const newBlock = await this.getBlockByNumber(targetBlockNumber)
if (newBlock) {
this.backfillBlock(newBlock)
- blockNumber = Number.parseInt(newBlock.number, 16)
}
-
- state = this.store.getState()
- recentBlocks = state.recentBlocks
} catch (e) {
log.error(e)
}
- await timeout(100)
- }
+ }))
})
}