aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers/network/createBlockTracker.js
blob: 6573b18a1e30b59bbcc5de7c2710a2a64c96037c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const BlockTracker = require('eth-block-tracker')

/**
 * Creates a block tracker that sends platform events on success and failure
 */
module.exports = function createBlockTracker (args, platform) {
  const blockTracker = new BlockTracker(args)
  blockTracker.on('latest', () => {
    if (platform && platform.sendMessage) {
      platform.sendMessage({ action: 'ethereum-ping-success' })
    }
  })
  blockTracker.on('error', () => {
    if (platform && platform.sendMessage) {
      platform.sendMessage({ action: 'ethereum-ping-error' })
    }
  })
  return blockTracker
}