aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-04-01 04:20:16 +0800
committerkumavis <aaron@kumavis.me>2017-04-01 04:20:16 +0800
commit49d8877fd78b8251b6856292ca71a55773a74b0e (patch)
tree7f67d5c2f9048c12db05ad6f4485494f3d7fd45e /app
parent0ef679388a9604c39a432408826c080d2d17c221 (diff)
downloadtangerine-wallet-browser-49d8877fd78b8251b6856292ca71a55773a74b0e.tar
tangerine-wallet-browser-49d8877fd78b8251b6856292ca71a55773a74b0e.tar.gz
tangerine-wallet-browser-49d8877fd78b8251b6856292ca71a55773a74b0e.tar.bz2
tangerine-wallet-browser-49d8877fd78b8251b6856292ca71a55773a74b0e.tar.lz
tangerine-wallet-browser-49d8877fd78b8251b6856292ca71a55773a74b0e.tar.xz
tangerine-wallet-browser-49d8877fd78b8251b6856292ca71a55773a74b0e.tar.zst
tangerine-wallet-browser-49d8877fd78b8251b6856292ca71a55773a74b0e.zip
ui - startPopup returns store after boot
Diffstat (limited to 'app')
-rw-r--r--app/scripts/popup-core.js27
-rw-r--r--app/scripts/popup.js34
2 files changed, 32 insertions, 29 deletions
diff --git a/app/scripts/popup-core.js b/app/scripts/popup-core.js
index b1e521a7a..1e5d70e8b 100644
--- a/app/scripts/popup-core.js
+++ b/app/scripts/popup-core.js
@@ -1,7 +1,8 @@
const EventEmitter = require('events').EventEmitter
+const async = require('async')
const Dnode = require('dnode')
const Web3 = require('web3')
-const MetaMaskUi = require('../../ui')
+const launchMetamaskUi = require('../../ui')
const StreamProvider = require('web3-stream-provider')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
@@ -9,9 +10,13 @@ const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
module.exports = initializePopup
-function initializePopup (connectionStream) {
+function initializePopup ({ container, connectionStream }, cb) {
// setup app
- connectToAccountManager(connectionStream, setupApp)
+ async.waterfall([
+ (cb) => connectToAccountManager(connectionStream, cb),
+ (accountManager, cb) => launchMetamaskUi({ container, accountManager }, cb),
+ ], cb)
+
}
function connectToAccountManager (connectionStream, cb) {
@@ -47,19 +52,3 @@ function setupControllerConnection (connectionStream, cb) {
cb(null, accountManager)
})
}
-
-function setupApp (err, accountManager) {
- var container = document.getElementById('app-content')
- if (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
- }
-
-
- MetaMaskUi({
- container: container,
- accountManager: accountManager,
- })
-}
diff --git a/app/scripts/popup.js b/app/scripts/popup.js
index 6606c9584..f6dcb829b 100644
--- a/app/scripts/popup.js
+++ b/app/scripts/popup.js
@@ -5,23 +5,37 @@ const PortStream = require('./lib/port-stream.js')
const isPopupOrNotification = require('./lib/is-popup-or-notification')
const extension = require('extensionizer')
const NotificationManager = require('./lib/notification-manager')
-
const notificationManager = new NotificationManager()
-var css = MetaMaskUiCss()
+// 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({ 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)
+})
-startPopup(portStream)
-function closePopupIfOpen (name) {
- if (name !== 'notification') {
+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
+}