aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/popup.js
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-04-03 14:04:55 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-04-03 14:04:55 +0800
commitf81fdbc34ff037ab64a9f4c98100304e7b1132e4 (patch)
tree20f2a75068af1b4b13ecb9a9b6276e07af94de93 /app/scripts/popup.js
parent89c924101e3ff52849c5a82ced7e058e1fa39dfd (diff)
parent235a70b9392d8b87eae4fc141e7f0be1d7788ee2 (diff)
downloadtangerine-wallet-browser-f81fdbc34ff037ab64a9f4c98100304e7b1132e4.tar
tangerine-wallet-browser-f81fdbc34ff037ab64a9f4c98100304e7b1132e4.tar.gz
tangerine-wallet-browser-f81fdbc34ff037ab64a9f4c98100304e7b1132e4.tar.bz2
tangerine-wallet-browser-f81fdbc34ff037ab64a9f4c98100304e7b1132e4.tar.lz
tangerine-wallet-browser-f81fdbc34ff037ab64a9f4c98100304e7b1132e4.tar.xz
tangerine-wallet-browser-f81fdbc34ff037ab64a9f4c98100304e7b1132e4.tar.zst
tangerine-wallet-browser-f81fdbc34ff037ab64a9f4c98100304e7b1132e4.zip
Merge branch 'master' into mascara
Diffstat (limited to 'app/scripts/popup.js')
-rw-r--r--app/scripts/popup.js48
1 files changed, 36 insertions, 12 deletions
diff --git a/app/scripts/popup.js b/app/scripts/popup.js
index 62db68c10..0fbde54b3 100644
--- a/app/scripts/popup.js
+++ b/app/scripts/popup.js
@@ -3,23 +3,47 @@ const MetaMaskUiCss = require('../../ui/css')
const startPopup = require('./popup-core')
const PortStream = require('./lib/port-stream.js')
const isPopupOrNotification = require('./lib/is-popup-or-notification')
-const extension = require('./lib/extension')
-const notification = require('./lib/notifications')
+const extension = require('extensionizer')
+const ExtensionPlatform = require('./platforms/extension')
+const NotificationManager = require('./lib/notification-manager')
+const notificationManager = new NotificationManager()
-var css = MetaMaskUiCss()
+// create platform global
+global.platform = new ExtensionPlatform()
+
+// inject css
+const css = MetaMaskUiCss()
injectCss(css)
-var name = isPopupOrNotification()
-closePopupIfOpen(name)
-window.METAMASK_UI_TYPE = name
+// identify window type (popup, notification)
+const windowType = isPopupOrNotification()
+global.METAMASK_UI_TYPE = windowType
+closePopupIfOpen(windowType)
+
+// setup stream to background
+const extensionPort = extension.runtime.connect({ name: windowType })
+const connectionStream = new PortStream(extensionPort)
-var pluginPort = extension.runtime.connect({ name })
-var portStream = new PortStream(pluginPort)
+// start ui
+const container = document.getElementById('app-content')
+startPopup({ container, connectionStream }, (err, store) => {
+ if (err) return displayCriticalError(err)
+ store.subscribe(() => {
+ const state = store.getState()
+ if (state.appState.shouldClose) notificationManager.closePopup()
+ })
+})
-startPopup(portStream)
-function closePopupIfOpen (name) {
- if (name !== 'notification') {
- notification.closePopup()
+function closePopupIfOpen (windowType) {
+ if (windowType !== 'notification') {
+ notificationManager.closePopup()
}
}
+
+function displayCriticalError(err) {
+ container.innerHTML = '<div class="critical-error">The MetaMask app failed to load: please open and close MetaMask again to restart.</div>'
+ container.style.height = '80px'
+ log.error(err.stack)
+ throw err
+}