mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
popup - further clean and comment
This commit is contained in:
parent
8a5007a396
commit
ed11ab6d18
@ -1,5 +1,4 @@
|
|||||||
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 MetaMaskUi = require('../../ui')
|
||||||
@ -16,9 +15,7 @@ const notification = require('./lib/notifications')
|
|||||||
var css = MetaMaskUiCss()
|
var css = MetaMaskUiCss()
|
||||||
injectCss(css)
|
injectCss(css)
|
||||||
|
|
||||||
async.parallel({
|
connectToAccountManager(setupApp)
|
||||||
accountManager: connectToAccountManager,
|
|
||||||
}, setupApp)
|
|
||||||
|
|
||||||
function connectToAccountManager (cb) {
|
function connectToAccountManager (cb) {
|
||||||
// setup communication with background
|
// setup communication with background
|
||||||
@ -35,32 +32,32 @@ function connectToAccountManager (cb) {
|
|||||||
setupWeb3Connection(mx.createStream('provider'))
|
setupWeb3Connection(mx.createStream('provider'))
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupWeb3Connection (stream) {
|
function setupWeb3Connection (connectionStream) {
|
||||||
var remoteProvider = new StreamProvider()
|
var providerStream = new StreamProvider()
|
||||||
remoteProvider.pipe(stream).pipe(remoteProvider)
|
providerStream.pipe(connectionStream).pipe(providerStream)
|
||||||
stream.on('error', console.error.bind(console))
|
connectionStream.on('error', console.error.bind(console))
|
||||||
remoteProvider.on('error', console.error.bind(console))
|
providerStream.on('error', console.error.bind(console))
|
||||||
global.web3 = new Web3(remoteProvider)
|
global.web3 = new Web3(providerStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupControllerConnection (stream, cb) {
|
function setupControllerConnection (connectionStream, cb) {
|
||||||
// this is a really sneaky way of adding EventEmitter api
|
// this is a really sneaky way of adding EventEmitter api
|
||||||
// to a bi-directional dnode instance
|
// to a bi-directional dnode instance
|
||||||
var eventEmitter = new EventEmitter()
|
var eventEmitter = new EventEmitter()
|
||||||
var background = Dnode({
|
var accountManagerDnode = Dnode({
|
||||||
sendUpdate: function (state) {
|
sendUpdate: function (state) {
|
||||||
eventEmitter.emit('update', state)
|
eventEmitter.emit('update', state)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
stream.pipe(background).pipe(stream)
|
connectionStream.pipe(accountManagerDnode).pipe(connectionStream)
|
||||||
background.once('remote', function (accountManager) {
|
accountManagerDnode.once('remote', function (accountManager) {
|
||||||
// setup push events
|
// setup push events
|
||||||
accountManager.on = eventEmitter.on.bind(eventEmitter)
|
accountManager.on = eventEmitter.on.bind(eventEmitter)
|
||||||
cb(null, accountManager)
|
cb(null, accountManager)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupApp (err, opts) {
|
function setupApp (err, accountManager) {
|
||||||
if (err) {
|
if (err) {
|
||||||
alert(err.stack)
|
alert(err.stack)
|
||||||
throw err
|
throw err
|
||||||
@ -70,8 +67,7 @@ function setupApp (err, opts) {
|
|||||||
|
|
||||||
MetaMaskUi({
|
MetaMaskUi({
|
||||||
container: container,
|
container: container,
|
||||||
accountManager: opts.accountManager,
|
accountManager: accountManager,
|
||||||
networkVersion: opts.networkVersion,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user