2016-01-15 03:26:54 +01:00
|
|
|
const injectCss = require('inject-css')
|
2017-11-15 18:39:54 +01:00
|
|
|
const OldMetaMaskUiCss = require('../../old-ui/css')
|
|
|
|
const NewMetaMaskUiCss = require('../../ui/css')
|
2016-09-13 08:28:07 +02:00
|
|
|
const startPopup = require('./popup-core')
|
2016-09-13 09:31:04 +02:00
|
|
|
const PortStream = require('./lib/port-stream.js')
|
2016-08-17 01:46:44 +02:00
|
|
|
const isPopupOrNotification = require('./lib/is-popup-or-notification')
|
2017-03-31 03:33:19 +02:00
|
|
|
const extension = require('extensionizer')
|
2017-04-01 03:04:13 +02:00
|
|
|
const ExtensionPlatform = require('./platforms/extension')
|
2017-03-31 03:33:19 +02:00
|
|
|
const NotificationManager = require('./lib/notification-manager')
|
|
|
|
const notificationManager = new NotificationManager()
|
2018-02-28 19:37:53 +01:00
|
|
|
const setupRaven = require('./lib/setupRaven')
|
2016-01-15 03:26:54 +01:00
|
|
|
|
2017-04-01 03:04:13 +02:00
|
|
|
// create platform global
|
|
|
|
global.platform = new ExtensionPlatform()
|
|
|
|
|
2018-01-17 23:59:15 +01:00
|
|
|
// setup sentry error reporting
|
|
|
|
const release = global.platform.getVersion()
|
|
|
|
setupRaven({ release })
|
|
|
|
|
2017-03-31 22:20:16 +02:00
|
|
|
// inject css
|
2018-01-20 00:29:36 +01:00
|
|
|
// const css = MetaMaskUiCss()
|
|
|
|
// injectCss(css)
|
2016-01-15 03:26:54 +01:00
|
|
|
|
2017-03-31 22:20:16 +02:00
|
|
|
// identify window type (popup, notification)
|
|
|
|
const windowType = isPopupOrNotification()
|
|
|
|
global.METAMASK_UI_TYPE = windowType
|
|
|
|
closePopupIfOpen(windowType)
|
|
|
|
|
|
|
|
// setup stream to background
|
2017-03-31 22:32:47 +02:00
|
|
|
const extensionPort = extension.runtime.connect({ name: windowType })
|
2017-03-31 22:20:16 +02:00
|
|
|
const connectionStream = new PortStream(extensionPort)
|
2016-02-13 05:01:48 +01:00
|
|
|
|
2017-03-31 22:20:16 +02:00
|
|
|
// start ui
|
|
|
|
const container = document.getElementById('app-content')
|
|
|
|
startPopup({ container, connectionStream }, (err, store) => {
|
|
|
|
if (err) return displayCriticalError(err)
|
2017-11-15 18:39:54 +01:00
|
|
|
|
2018-01-15 22:23:44 +01:00
|
|
|
// Code commented out until we begin auto adding users to NewUI
|
|
|
|
// const { isMascara, identities = {}, featureFlags = {} } = store.getState().metamask
|
|
|
|
// const firstTime = Object.keys(identities).length === 0
|
|
|
|
const { isMascara, featureFlags = {} } = store.getState().metamask
|
2018-01-10 01:45:39 +01:00
|
|
|
let betaUIState = featureFlags.betaUI
|
|
|
|
|
2018-01-15 22:23:44 +01:00
|
|
|
// Code commented out until we begin auto adding users to NewUI
|
|
|
|
// const useBetaCss = isMascara || firstTime || betaUIState
|
|
|
|
const useBetaCss = isMascara || betaUIState
|
2018-01-10 01:45:39 +01:00
|
|
|
|
|
|
|
let css = useBetaCss ? NewMetaMaskUiCss() : OldMetaMaskUiCss()
|
2017-11-15 18:39:54 +01:00
|
|
|
let deleteInjectedCss = injectCss(css)
|
|
|
|
let newBetaUIState
|
|
|
|
|
2017-03-31 22:32:47 +02:00
|
|
|
store.subscribe(() => {
|
|
|
|
const state = store.getState()
|
2017-11-15 18:39:54 +01:00
|
|
|
newBetaUIState = state.metamask.featureFlags.betaUI
|
|
|
|
if (newBetaUIState !== betaUIState) {
|
|
|
|
deleteInjectedCss()
|
|
|
|
betaUIState = newBetaUIState
|
|
|
|
css = betaUIState ? NewMetaMaskUiCss() : OldMetaMaskUiCss()
|
|
|
|
deleteInjectedCss = injectCss(css)
|
|
|
|
}
|
2017-03-31 22:32:47 +02:00
|
|
|
if (state.appState.shouldClose) notificationManager.closePopup()
|
|
|
|
})
|
2017-03-31 22:20:16 +02:00
|
|
|
})
|
2016-01-15 11:03:42 +01:00
|
|
|
|
2016-08-17 01:46:44 +02:00
|
|
|
|
2017-03-31 22:20:16 +02:00
|
|
|
function closePopupIfOpen (windowType) {
|
|
|
|
if (windowType !== 'notification') {
|
2018-03-11 18:17:08 +01:00
|
|
|
// should close only chrome popup
|
2017-03-31 03:33:19 +02:00
|
|
|
notificationManager.closePopup()
|
2016-08-24 00:44:50 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 22:20:16 +02:00
|
|
|
|
2017-04-27 06:05:45 +02:00
|
|
|
function displayCriticalError (err) {
|
2017-03-31 22:20:16 +02:00
|
|
|
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
|
|
|
|
}
|