Merge pull request #6137 from whymarrh/es6-background

Sprinkle ES6 onto background files
feature/default_network_editable
Whymarrh Whitby 6 years ago committed by GitHub
commit ce543f059e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/scripts/background.js
  2. 10
      app/scripts/contentscript.js
  3. 8
      app/scripts/inpage.js
  4. 10
      app/scripts/metamask-controller.js
  5. 6
      app/scripts/notice-controller.js
  6. 2
      app/scripts/phishing-detect.js
  7. 2
      app/scripts/platforms/extension.js
  8. 12
      app/scripts/popup-core.js

@ -421,13 +421,13 @@ function setupController (initState, initLangCode) {
* The number reflects the current number of pending transactions or message signatures needing user approval. * The number reflects the current number of pending transactions or message signatures needing user approval.
*/ */
function updateBadge () { function updateBadge () {
var label = '' let label = ''
var unapprovedTxCount = controller.txController.getUnapprovedTxCount() const unapprovedTxCount = controller.txController.getUnapprovedTxCount()
var unapprovedMsgCount = controller.messageManager.unapprovedMsgCount const unapprovedMsgCount = controller.messageManager.unapprovedMsgCount
var unapprovedPersonalMsgs = controller.personalMessageManager.unapprovedPersonalMsgCount const unapprovedPersonalMsgs = controller.personalMessageManager.unapprovedPersonalMsgCount
var unapprovedTypedMsgs = controller.typedMessageManager.unapprovedTypedMessagesCount const unapprovedTypedMsgs = controller.typedMessageManager.unapprovedTypedMessagesCount
const pendingProviderRequests = controller.providerApprovalController.store.getState().providerRequests.length const pendingProviderRequests = controller.providerApprovalController.store.getState().providerRequests.length
var count = unapprovedTxCount + unapprovedMsgCount + unapprovedPersonalMsgs + unapprovedTypedMsgs + pendingProviderRequests const count = unapprovedTxCount + unapprovedMsgCount + unapprovedPersonalMsgs + unapprovedTypedMsgs + pendingProviderRequests
if (count) { if (count) {
label = String(count) label = String(count)
} }
@ -463,7 +463,7 @@ function openPopup () {
triggerUi() triggerUi()
return new Promise( return new Promise(
(resolve) => { (resolve) => {
var interval = setInterval(() => { const interval = setInterval(() => {
if (!notificationIsOpen) { if (!notificationIsOpen) {
clearInterval(interval) clearInterval(interval)
resolve() resolve()

@ -7,7 +7,7 @@ const PongStream = require('ping-pong-stream/pong')
const ObjectMultiplex = require('obj-multiplex') const ObjectMultiplex = require('obj-multiplex')
const extension = require('extensionizer') const extension = require('extensionizer')
const PortStream = require('extension-port-stream') const PortStream = require('extension-port-stream')
const TransformStream = require('stream').Transform const {Transform: TransformStream} = require('stream')
const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js')).toString() const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js')).toString()
const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('inpage.js') + '\n' const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('inpage.js') + '\n'
@ -247,7 +247,7 @@ function suffixCheck () {
* @returns {boolean} {@code true} if the documentElement is an html node or if none exists * @returns {boolean} {@code true} if the documentElement is an html node or if none exists
*/ */
function documentElementCheck () { function documentElementCheck () {
var documentElement = document.documentElement.nodeName const documentElement = document.documentElement.nodeName
if (documentElement) { if (documentElement) {
return documentElement.toLowerCase() === 'html' return documentElement.toLowerCase() === 'html'
} }
@ -260,7 +260,7 @@ function documentElementCheck () {
* @returns {boolean} {@code true} if the current domain is blacklisted * @returns {boolean} {@code true} if the current domain is blacklisted
*/ */
function blacklistedDomainCheck () { function blacklistedDomainCheck () {
var blacklistedDomains = [ const blacklistedDomains = [
'uscourts.gov', 'uscourts.gov',
'dropbox.com', 'dropbox.com',
'webbyawards.com', 'webbyawards.com',
@ -271,8 +271,8 @@ function blacklistedDomainCheck () {
'ani.gamer.com.tw', 'ani.gamer.com.tw',
'blueskybooking.com', 'blueskybooking.com',
] ]
var currentUrl = window.location.href const currentUrl = window.location.href
var currentRegex let currentRegex
for (let i = 0; i < blacklistedDomains.length; i++) { for (let i = 0; i < blacklistedDomains.length; i++) {
const blacklistedDomain = blacklistedDomains[i].replace('.', '\\.') const blacklistedDomain = blacklistedDomains[i].replace('.', '\\.')
currentRegex = new RegExp(`(?:https?:\\/\\/)(?:(?!${blacklistedDomain}).)*$`) currentRegex = new RegExp(`(?:https?:\\/\\/)(?:(?!${blacklistedDomain}).)*$`)

@ -42,13 +42,13 @@ function onMessage (messageType, handler, remove) {
// //
// setup background connection // setup background connection
var metamaskStream = new LocalMessageDuplexStream({ const metamaskStream = new LocalMessageDuplexStream({
name: 'inpage', name: 'inpage',
target: 'contentscript', target: 'contentscript',
}) })
// compose the inpage provider // compose the inpage provider
var inpageProvider = new MetamaskInpageProvider(metamaskStream) const inpageProvider = new MetamaskInpageProvider(metamaskStream)
// set a high max listener count to avoid unnecesary warnings // set a high max listener count to avoid unnecesary warnings
inpageProvider.setMaxListeners(100) inpageProvider.setMaxListeners(100)
@ -181,7 +181,7 @@ if (typeof window.web3 !== 'undefined') {
and try again.`) and try again.`)
} }
var web3 = new Web3(proxiedInpageProvider) const web3 = new Web3(proxiedInpageProvider)
web3.setProvider = function () { web3.setProvider = function () {
log.debug('MetaMask - overrode web3.setProvider') log.debug('MetaMask - overrode web3.setProvider')
} }
@ -218,7 +218,7 @@ inpageProvider.publicConfigStore.subscribe(function (state) {
// need to make sure we aren't affected by overlapping namespaces // need to make sure we aren't affected by overlapping namespaces
// and that we dont affect the app with our namespace // and that we dont affect the app with our namespace
// mostly a fix for web3's BigNumber if AMD's "define" is defined... // mostly a fix for web3's BigNumber if AMD's "define" is defined...
var __define let __define
/** /**
* Caches reference to global define object and deletes it to * Caches reference to global define object and deletes it to

@ -19,7 +19,7 @@ const createSubscriptionManager = require('eth-json-rpc-filters/subscriptionMana
const createOriginMiddleware = require('./lib/createOriginMiddleware') const createOriginMiddleware = require('./lib/createOriginMiddleware')
const createLoggerMiddleware = require('./lib/createLoggerMiddleware') const createLoggerMiddleware = require('./lib/createLoggerMiddleware')
const createProviderMiddleware = require('./lib/createProviderMiddleware') const createProviderMiddleware = require('./lib/createProviderMiddleware')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex const {setupMultiplex} = require('./lib/stream-utils.js')
const KeyringController = require('eth-keyring-controller') const KeyringController = require('eth-keyring-controller')
const NetworkController = require('./controllers/network') const NetworkController = require('./controllers/network')
const PreferencesController = require('./controllers/preferences') const PreferencesController = require('./controllers/preferences')
@ -42,9 +42,9 @@ const ProviderApprovalController = require('./controllers/provider-approval')
const nodeify = require('./lib/nodeify') const nodeify = require('./lib/nodeify')
const accountImporter = require('./account-import-strategies') const accountImporter = require('./account-import-strategies')
const getBuyEthUrl = require('./lib/buy-eth-url') const getBuyEthUrl = require('./lib/buy-eth-url')
const Mutex = require('await-semaphore').Mutex const {Mutex} = require('await-semaphore')
const version = require('../manifest.json').version const {version} = require('../manifest.json')
const BN = require('ethereumjs-util').BN const {BN} = require('ethereumjs-util')
const GWEI_BN = new BN('1000000000') const GWEI_BN = new BN('1000000000')
const percentile = require('percentile') const percentile = require('percentile')
const seedPhraseVerifier = require('./lib/seed-phrase-verifier') const seedPhraseVerifier = require('./lib/seed-phrase-verifier')
@ -208,7 +208,7 @@ module.exports = class MetamaskController extends EventEmitter {
}) })
this.networkController.on('networkDidChange', () => { this.networkController.on('networkDidChange', () => {
this.balancesController.updateAllBalances() this.balancesController.updateAllBalances()
var currentCurrency = this.currencyController.getCurrentCurrency() const currentCurrency = this.currencyController.getCurrentCurrency()
this.setCurrentCurrency(currentCurrency, function () {}) this.setCurrentCurrency(currentCurrency, function () {})
}) })
this.balancesController.updateAllBalances() this.balancesController.updateAllBalances()

@ -1,4 +1,4 @@
const EventEmitter = require('events').EventEmitter const {EventEmitter} = require('events')
const semver = require('semver') const semver = require('semver')
const extend = require('xtend') const extend = require('xtend')
const ObservableStore = require('obs-store') const ObservableStore = require('obs-store')
@ -46,8 +46,8 @@ module.exports = class NoticeController extends EventEmitter {
markNoticeRead (noticeToMark, cb) { markNoticeRead (noticeToMark, cb) {
cb = cb || function (err) { if (err) throw err } cb = cb || function (err) { if (err) throw err }
try { try {
var notices = this.getNoticesList() const notices = this.getNoticesList()
var index = notices.findIndex((currentNotice) => currentNotice.id === noticeToMark.id) const index = notices.findIndex((currentNotice) => currentNotice.id === noticeToMark.id)
notices[index].read = true notices[index].read = true
notices[index].body = '' notices[index].body = ''
this.setNoticesList(notices) this.setNoticesList(notices)

@ -3,7 +3,7 @@ const dnode = require('dnode')
const { EventEmitter } = require('events') const { EventEmitter } = require('events')
const PortStream = require('extension-port-stream') const PortStream = require('extension-port-stream')
const extension = require('extensionizer') const extension = require('extensionizer')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex const {setupMultiplex} = require('./lib/stream-utils.js')
const { getEnvironmentType } = require('./lib/util') const { getEnvironmentType } = require('./lib/util')
const ExtensionPlatform = require('./platforms/extension') const ExtensionPlatform = require('./platforms/extension')

@ -1,5 +1,5 @@
const extension = require('extensionizer') const extension = require('extensionizer')
const explorerLink = require('etherscan-link').createExplorerLink const {createExplorerLink: explorerLink} = require('etherscan-link')
class ExtensionPlatform { class ExtensionPlatform {

@ -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