mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
ui - startPopup returns store after boot
This commit is contained in:
parent
0ef679388a
commit
49d8877fd7
@ -1,7 +1,8 @@
|
|||||||
const EventEmitter = require('events').EventEmitter
|
const EventEmitter = require('events').EventEmitter
|
||||||
|
const async = require('async')
|
||||||
const Dnode = require('dnode')
|
const Dnode = require('dnode')
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const MetaMaskUi = require('../../ui')
|
const launchMetamaskUi = require('../../ui')
|
||||||
const StreamProvider = require('web3-stream-provider')
|
const StreamProvider = require('web3-stream-provider')
|
||||||
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
||||||
|
|
||||||
@ -9,9 +10,13 @@ const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
|||||||
module.exports = initializePopup
|
module.exports = initializePopup
|
||||||
|
|
||||||
|
|
||||||
function initializePopup (connectionStream) {
|
function initializePopup ({ container, connectionStream }, cb) {
|
||||||
// setup app
|
// setup app
|
||||||
connectToAccountManager(connectionStream, setupApp)
|
async.waterfall([
|
||||||
|
(cb) => connectToAccountManager(connectionStream, cb),
|
||||||
|
(accountManager, cb) => launchMetamaskUi({ container, accountManager }, cb),
|
||||||
|
], cb)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectToAccountManager (connectionStream, cb) {
|
function connectToAccountManager (connectionStream, cb) {
|
||||||
@ -47,19 +52,3 @@ function setupControllerConnection (connectionStream, cb) {
|
|||||||
cb(null, accountManager)
|
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 isPopupOrNotification = require('./lib/is-popup-or-notification')
|
||||||
const extension = require('extensionizer')
|
const extension = require('extensionizer')
|
||||||
const NotificationManager = require('./lib/notification-manager')
|
const NotificationManager = require('./lib/notification-manager')
|
||||||
|
|
||||||
const notificationManager = new NotificationManager()
|
const notificationManager = new NotificationManager()
|
||||||
|
|
||||||
var css = MetaMaskUiCss()
|
// inject css
|
||||||
|
const css = MetaMaskUiCss()
|
||||||
injectCss(css)
|
injectCss(css)
|
||||||
|
|
||||||
var name = isPopupOrNotification()
|
// identify window type (popup, notification)
|
||||||
closePopupIfOpen(name)
|
const windowType = isPopupOrNotification()
|
||||||
window.METAMASK_UI_TYPE = name
|
global.METAMASK_UI_TYPE = windowType
|
||||||
|
closePopupIfOpen(windowType)
|
||||||
|
|
||||||
var pluginPort = extension.runtime.connect({ name })
|
// setup stream to background
|
||||||
var portStream = new PortStream(pluginPort)
|
const extensionPort = extension.runtime.connect({ windowType })
|
||||||
|
const connectionStream = new PortStream(extensionPort)
|
||||||
|
|
||||||
startPopup(portStream)
|
// start ui
|
||||||
|
const container = document.getElementById('app-content')
|
||||||
|
startPopup({ container, connectionStream }, (err, store) => {
|
||||||
|
if (err) return displayCriticalError(err)
|
||||||
|
})
|
||||||
|
|
||||||
function closePopupIfOpen (name) {
|
|
||||||
if (name !== 'notification') {
|
function closePopupIfOpen (windowType) {
|
||||||
|
if (windowType !== 'notification') {
|
||||||
notificationManager.closePopup()
|
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,
|
seedWords,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// default state
|
||||||
var appState = extend({
|
var appState = extend({
|
||||||
menuOpen: false,
|
menuOpen: false,
|
||||||
currentView: seedWords ? seedConfView : defaultView,
|
currentView: seedWords ? seedConfView : defaultView,
|
||||||
|
23
ui/index.js
23
ui/index.js
@ -4,27 +4,28 @@ const Root = require('./app/root')
|
|||||||
const actions = require('./app/actions')
|
const actions = require('./app/actions')
|
||||||
const configureStore = require('./app/store')
|
const configureStore = require('./app/store')
|
||||||
const txHelper = require('./lib/tx-helper')
|
const txHelper = require('./lib/tx-helper')
|
||||||
module.exports = launchApp
|
global.log = require('loglevel')
|
||||||
|
|
||||||
let debugMode = window.METAMASK_DEBUG
|
module.exports = launchMetamaskUi
|
||||||
const log = require('loglevel')
|
|
||||||
window.log = log
|
|
||||||
log.setLevel(debugMode ? 'debug' : 'warn')
|
|
||||||
|
|
||||||
function launchApp (opts) {
|
|
||||||
|
log.setLevel(global.METAMASK_DEBUG ? 'debug' : 'warn')
|
||||||
|
|
||||||
|
function launchMetamaskUi (opts, cb) {
|
||||||
var accountManager = opts.accountManager
|
var accountManager = opts.accountManager
|
||||||
actions._setBackgroundConnection(accountManager)
|
actions._setBackgroundConnection(accountManager)
|
||||||
|
|
||||||
// check if we are unlocked first
|
// check if we are unlocked first
|
||||||
accountManager.getState(function (err, metamaskState) {
|
accountManager.getState(function (err, metamaskState) {
|
||||||
if (err) throw err
|
if (err) return cb(err)
|
||||||
startApp(metamaskState, accountManager, opts)
|
const store = startApp(metamaskState, accountManager, opts)
|
||||||
|
cb(null, store)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function startApp (metamaskState, accountManager, opts) {
|
function startApp (metamaskState, accountManager, opts) {
|
||||||
// parse opts
|
// parse opts
|
||||||
var store = configureStore({
|
const store = configureStore({
|
||||||
|
|
||||||
// metamaskState represents the cross-tab state
|
// metamaskState represents the cross-tab state
|
||||||
metamask: metamaskState,
|
metamask: metamaskState,
|
||||||
@ -37,7 +38,7 @@ function startApp (metamaskState, accountManager, opts) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// if unconfirmed txs, start on txConf page
|
// 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) {
|
if (unapprovedTxsAll.length > 0) {
|
||||||
store.dispatch(actions.showConfTxPage())
|
store.dispatch(actions.showConfTxPage())
|
||||||
}
|
}
|
||||||
@ -53,4 +54,6 @@ function startApp (metamaskState, accountManager, opts) {
|
|||||||
store: store,
|
store: store,
|
||||||
}
|
}
|
||||||
), opts.container)
|
), opts.container)
|
||||||
|
|
||||||
|
return store
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user