aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers/network/createBlockTracker.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/controllers/network/createBlockTracker.js')
-rw-r--r--app/scripts/controllers/network/createBlockTracker.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/scripts/controllers/network/createBlockTracker.js b/app/scripts/controllers/network/createBlockTracker.js
new file mode 100644
index 000000000..6573b18a1
--- /dev/null
+++ b/app/scripts/controllers/network/createBlockTracker.js
@@ -0,0 +1,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
+}