2016-01-17 10:27:25 +01:00
|
|
|
const EventEmitter = require('events').EventEmitter
|
2016-01-15 11:03:42 +01:00
|
|
|
const Dnode = require('dnode')
|
2016-01-15 03:26:54 +01:00
|
|
|
const MetaMaskUi = require('metamask-ui')
|
|
|
|
const MetaMaskUiCss = require('metamask-ui/css')
|
|
|
|
const injectCss = require('inject-css')
|
2016-01-15 11:03:42 +01:00
|
|
|
const PortStream = require('./lib/port-stream.js')
|
2016-01-15 03:26:54 +01:00
|
|
|
|
|
|
|
|
2016-01-15 11:03:42 +01:00
|
|
|
// setup communication with background
|
|
|
|
var pluginPort = chrome.runtime.connect({name: 'popup'})
|
|
|
|
var duplex = new PortStream(pluginPort)
|
2016-01-17 10:27:25 +01:00
|
|
|
var eventEmitter = new EventEmitter()
|
2016-01-15 11:03:42 +01:00
|
|
|
var background = Dnode({
|
|
|
|
// setUnconfirmedTxs: setUnconfirmedTxs,
|
2016-01-17 10:27:25 +01:00
|
|
|
sendUpdate: function(state){
|
|
|
|
eventEmitter.emit('update', state)
|
|
|
|
},
|
2016-01-15 11:03:42 +01:00
|
|
|
})
|
|
|
|
duplex.pipe(background).pipe(duplex)
|
2016-01-17 10:27:25 +01:00
|
|
|
background.once('remote', function(accountManager){
|
|
|
|
accountManager.on = eventEmitter.on.bind(eventEmitter)
|
|
|
|
setupApp(accountManager)
|
|
|
|
})
|
2016-01-15 03:26:54 +01:00
|
|
|
|
2016-01-15 11:03:42 +01:00
|
|
|
// setup app
|
2016-01-15 03:26:54 +01:00
|
|
|
var css = MetaMaskUiCss()
|
|
|
|
injectCss(css)
|
|
|
|
|
2016-01-15 11:03:42 +01:00
|
|
|
function setupApp(accountManager){
|
|
|
|
|
|
|
|
var container = document.getElementById('app-content')
|
|
|
|
|
|
|
|
var app = MetaMaskUi({
|
|
|
|
container: container,
|
|
|
|
accountManager: accountManager,
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|