1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/app/scripts/popup.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-01-15 03:26:54 +01:00
const injectCss = require('inject-css')
2016-09-13 08:28:07 +02:00
const MetaMaskUiCss = require('../../ui/css')
const startPopup = require('./popup-core')
const PortStream = require('./lib/port-stream.js')
2016-08-17 01:46:44 +02:00
const isPopupOrNotification = require('./lib/is-popup-or-notification')
const extension = require('extensionizer')
const ExtensionPlatform = require('./platforms/extension')
const NotificationManager = require('./lib/notification-manager')
const notificationManager = new NotificationManager()
2016-01-15 03:26:54 +01:00
// create platform global
global.platform = new ExtensionPlatform()
// inject css
const css = MetaMaskUiCss()
2016-01-15 03:26:54 +01:00
injectCss(css)
// 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)
2016-02-13 05:01:48 +01:00
// 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()
})
})
2016-01-15 11:03:42 +01:00
2016-08-17 01:46:44 +02:00
function closePopupIfOpen (windowType) {
if (windowType !== 'notification') {
notificationManager.closePopup()
2016-08-24 00:44:50 +02:00
}
}
2017-04-27 06:05:45 +02:00
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
}