From 12065a10aab05690b45c83648ee26f85f403b864 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Mon, 3 Apr 2017 11:03:58 +0200 Subject: [PATCH] Make Popup close after approving a transaction --- library/src/popup.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/library/src/popup.js b/library/src/popup.js index 3dcc508bf..ef7759a81 100644 --- a/library/src/popup.js +++ b/library/src/popup.js @@ -1,28 +1,35 @@ const injectCss = require('inject-css') +const SWcontroller = require('client-sw-ready-event/lib/sw-client.js') +const SwStream = require('sw-stream/lib/sw-stream.js') const MetaMaskUiCss = require('../../ui/css') const setupIframe = require('./lib/setup-iframe.js') const MetamaskInpageProvider = require('../../app/scripts/lib/inpage-provider.js') -const SWcontroller = require('client-sw-ready-event/lib/sw-client.js') -const SwStream = require('sw-stream/lib/sw-stream.js') const startPopup = require('../../app/scripts/popup-core') - var css = MetaMaskUiCss() injectCss(css) +const container = document.getElementById('app-content') var name = 'popup' window.METAMASK_UI_TYPE = name -console.log('outside:open') - const background = new SWcontroller({ fileName: '/popup/sw-build.js', }) + +// Setup listener for when the service worker is read background.on('ready', (readSw) => { - let swStream = SwStream({ + let connectionStream = SwStream({ serviceWorker: background.controller, + context: name, + }) + startPopup({container, connectionStream}, (err, store) => { + if (err) return displayCriticalError(err) + store.subscribe(() => { + const state = store.getState() + if (state.appState.shouldClose) window.close() + }) }) - startPopup(swStream) }) background.startWorker()