From 2f079dfdd158b787659e3f87d5c5c442b2f05e7a Mon Sep 17 00:00:00 2001 From: kumavis Date: Sun, 17 Jan 2016 01:27:25 -0800 Subject: refactor - push data to popup --- app/scripts/popup.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'app/scripts/popup.js') diff --git a/app/scripts/popup.js b/app/scripts/popup.js index a7e33e7ff..ca88f4fa7 100644 --- a/app/scripts/popup.js +++ b/app/scripts/popup.js @@ -1,3 +1,4 @@ +const EventEmitter = require('events').EventEmitter const Dnode = require('dnode') const MetaMaskUi = require('metamask-ui') const MetaMaskUiCss = require('metamask-ui/css') @@ -8,11 +9,18 @@ const PortStream = require('./lib/port-stream.js') // setup communication with background var pluginPort = chrome.runtime.connect({name: 'popup'}) var duplex = new PortStream(pluginPort) +var eventEmitter = new EventEmitter() var background = Dnode({ // setUnconfirmedTxs: setUnconfirmedTxs, + sendUpdate: function(state){ + eventEmitter.emit('update', state) + }, }) duplex.pipe(background).pipe(duplex) -background.once('remote', setupApp) +background.once('remote', function(accountManager){ + accountManager.on = eventEmitter.on.bind(eventEmitter) + setupApp(accountManager) +}) // setup app var css = MetaMaskUiCss() -- cgit v1.2.3