|
|
@ -1,11 +1,22 @@ |
|
|
|
|
|
|
|
const url = require('url') |
|
|
|
const EventEmitter = require('events').EventEmitter |
|
|
|
const EventEmitter = require('events').EventEmitter |
|
|
|
|
|
|
|
const async = require('async') |
|
|
|
const Dnode = require('dnode') |
|
|
|
const Dnode = require('dnode') |
|
|
|
const MetaMaskUi = require('metamask-ui') |
|
|
|
const MetaMaskUi = require('metamask-ui') |
|
|
|
const MetaMaskUiCss = require('metamask-ui/css') |
|
|
|
const MetaMaskUiCss = require('metamask-ui/css') |
|
|
|
const injectCss = require('inject-css') |
|
|
|
const injectCss = require('inject-css') |
|
|
|
const PortStream = require('./lib/port-stream.js') |
|
|
|
const PortStream = require('./lib/port-stream.js') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// setup app
|
|
|
|
|
|
|
|
var css = MetaMaskUiCss() |
|
|
|
|
|
|
|
injectCss(css) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.parallel({ |
|
|
|
|
|
|
|
currentDomain: getCurrentDomain, |
|
|
|
|
|
|
|
accountManager: connectToAccountManager, |
|
|
|
|
|
|
|
}, setupApp) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function connectToAccountManager(cb){ |
|
|
|
// setup communication with background
|
|
|
|
// setup communication with background
|
|
|
|
var pluginPort = chrome.runtime.connect({name: 'popup'}) |
|
|
|
var pluginPort = chrome.runtime.connect({name: 'popup'}) |
|
|
|
var duplex = new PortStream(pluginPort) |
|
|
|
var duplex = new PortStream(pluginPort) |
|
|
@ -18,21 +29,37 @@ var background = Dnode({ |
|
|
|
}) |
|
|
|
}) |
|
|
|
duplex.pipe(background).pipe(duplex) |
|
|
|
duplex.pipe(background).pipe(duplex) |
|
|
|
background.once('remote', function(accountManager){ |
|
|
|
background.once('remote', function(accountManager){ |
|
|
|
|
|
|
|
// setup push events
|
|
|
|
accountManager.on = eventEmitter.on.bind(eventEmitter) |
|
|
|
accountManager.on = eventEmitter.on.bind(eventEmitter) |
|
|
|
setupApp(accountManager) |
|
|
|
cb(null, accountManager) |
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// setup app
|
|
|
|
function getCurrentDomain(cb){ |
|
|
|
var css = MetaMaskUiCss() |
|
|
|
chrome.tabs.query({active: true, currentWindow: true}, function(results){ |
|
|
|
injectCss(css) |
|
|
|
var activeTab = results[0] |
|
|
|
|
|
|
|
var currentUrl = activeTab && activeTab.url |
|
|
|
|
|
|
|
var currentDomain = url.parse(currentUrl).host |
|
|
|
|
|
|
|
if (!currentUrl) { |
|
|
|
|
|
|
|
return cb(null, '<unknown>') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cb(null, currentDomain) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function setupApp(accountManager){ |
|
|
|
function setupApp(err, opts){ |
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
|
|
alert(err.stack) |
|
|
|
|
|
|
|
throw err |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var container = document.getElementById('app-content') |
|
|
|
var container = document.getElementById('app-content') |
|
|
|
|
|
|
|
|
|
|
|
var app = MetaMaskUi({ |
|
|
|
var app = MetaMaskUi({ |
|
|
|
container: container, |
|
|
|
container: container, |
|
|
|
accountManager: accountManager, |
|
|
|
accountManager: opts.accountManager, |
|
|
|
|
|
|
|
currentDomain: opts.currentDomain, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |