Update popup-core script to use ES6 destructuring, const, let

feature/default_network_editable
Whymarrh Whitby 6 years ago
parent ade96fda41
commit 92cc60f425
  1. 12
      app/scripts/popup-core.js

@ -1,11 +1,11 @@
const EventEmitter = require('events').EventEmitter const {EventEmitter} = require('events')
const async = require('async') const async = require('async')
const Dnode = require('dnode') const Dnode = require('dnode')
const Eth = require('ethjs') const Eth = require('ethjs')
const EthQuery = require('eth-query') const EthQuery = require('eth-query')
const launchMetamaskUi = 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')
module.exports = initializePopup module.exports = initializePopup
@ -32,7 +32,7 @@ function initializePopup ({ container, connectionStream }, cb) {
function connectToAccountManager (connectionStream, cb) { function connectToAccountManager (connectionStream, cb) {
// setup communication with background // setup communication with background
// setup multiplexing // setup multiplexing
var mx = setupMultiplex(connectionStream) const mx = setupMultiplex(connectionStream)
// connect features // connect features
setupControllerConnection(mx.createStream('controller'), cb) setupControllerConnection(mx.createStream('controller'), cb)
setupWeb3Connection(mx.createStream('provider')) setupWeb3Connection(mx.createStream('provider'))
@ -44,7 +44,7 @@ function connectToAccountManager (connectionStream, cb) {
* @param {PortDuplexStream} connectionStream PortStream instance establishing a background connection * @param {PortDuplexStream} connectionStream PortStream instance establishing a background connection
*/ */
function setupWeb3Connection (connectionStream) { function setupWeb3Connection (connectionStream) {
var providerStream = new StreamProvider() const providerStream = new StreamProvider()
providerStream.pipe(connectionStream).pipe(providerStream) providerStream.pipe(connectionStream).pipe(providerStream)
connectionStream.on('error', console.error.bind(console)) connectionStream.on('error', console.error.bind(console))
providerStream.on('error', console.error.bind(console)) providerStream.on('error', console.error.bind(console))
@ -62,8 +62,8 @@ function setupWeb3Connection (connectionStream) {
function setupControllerConnection (connectionStream, 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() const eventEmitter = new EventEmitter()
var accountManagerDnode = Dnode({ const accountManagerDnode = Dnode({
sendUpdate: function (state) { sendUpdate: function (state) {
eventEmitter.emit('update', state) eventEmitter.emit('update', state)
}, },

Loading…
Cancel
Save