ui - startPopup returns store after boot

feature/default_network_editable
kumavis 8 years ago
parent 0ef679388a
commit 49d8877fd7
  1. 27
      app/scripts/popup-core.js
  2. 34
      app/scripts/popup.js
  3. 1
      ui/app/reducers/app.js
  4. 23
      ui/index.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,
})
}

@ -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
}

@ -34,6 +34,7 @@ function reduceApp (state, action) {
seedWords,
}
// default state
var appState = extend({
menuOpen: false,
currentView: seedWords ? seedConfView : defaultView,

@ -4,27 +4,28 @@ const Root = require('./app/root')
const actions = require('./app/actions')
const configureStore = require('./app/store')
const txHelper = require('./lib/tx-helper')
module.exports = launchApp
global.log = require('loglevel')
let debugMode = window.METAMASK_DEBUG
const log = require('loglevel')
window.log = log
log.setLevel(debugMode ? 'debug' : 'warn')
module.exports = launchMetamaskUi
function launchApp (opts) {
log.setLevel(global.METAMASK_DEBUG ? 'debug' : 'warn')
function launchMetamaskUi (opts, cb) {
var accountManager = opts.accountManager
actions._setBackgroundConnection(accountManager)
// check if we are unlocked first
accountManager.getState(function (err, metamaskState) {
if (err) throw err
startApp(metamaskState, accountManager, opts)
if (err) return cb(err)
const store = startApp(metamaskState, accountManager, opts)
cb(null, store)
})
}
function startApp (metamaskState, accountManager, opts) {
// parse opts
var store = configureStore({
const store = configureStore({
// metamaskState represents the cross-tab state
metamask: metamaskState,
@ -37,7 +38,7 @@ function startApp (metamaskState, accountManager, opts) {
})
// if unconfirmed txs, start on txConf page
var unapprovedTxsAll = txHelper(metamaskState.unapprovedTxs, metamaskState.unapprovedMsgs, metamaskState.unapprovedPersonalMsgs, metamaskState.network)
const unapprovedTxsAll = txHelper(metamaskState.unapprovedTxs, metamaskState.unapprovedMsgs, metamaskState.unapprovedPersonalMsgs, metamaskState.network)
if (unapprovedTxsAll.length > 0) {
store.dispatch(actions.showConfTxPage())
}
@ -53,4 +54,6 @@ function startApp (metamaskState, accountManager, opts) {
store: store,
}
), opts.container)
return store
}

Loading…
Cancel
Save