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.
*/
function updateBadge () {
var label = ''
var unapprovedTxCount = controller.txController.getUnapprovedTxCount()
var unapprovedMsgCount = controller.messageManager.unapprovedMsgCount
var unapprovedPersonalMsgs = controller.personalMessageManager.unapprovedPersonalMsgCount
var unapprovedTypedMsgs = controller.typedMessageManager.unapprovedTypedMessagesCount
let label = ''
const unapprovedTxCount = controller.txController.getUnapprovedTxCount()
const unapprovedMsgCount = controller.messageManager.unapprovedMsgCount
const unapprovedPersonalMsgs = controller.personalMessageManager.unapprovedPersonalMsgCount
const unapprovedTypedMsgs = controller.typedMessageManager.unapprovedTypedMessagesCount
const pendingProviderRequests = controller.providerApprovalController.store.getState().providerRequests.length
var count = unapprovedTxCount + unapprovedMsgCount + unapprovedPersonalMsgs + unapprovedTypedMsgs + pendingProviderRequests
const count = unapprovedTxCount + unapprovedMsgCount + unapprovedPersonalMsgs + unapprovedTypedMsgs + pendingProviderRequests
if (count) {
label = String(count)
}
@ -463,7 +463,7 @@ function openPopup () {
triggerUi()
return new Promise(
(resolve) => {
var interval = setInterval(() => {
const interval = setInterval(() => {
if (!notificationIsOpen) {
clearInterval(interval)
resolve()

@ -7,7 +7,7 @@ const PongStream = require('ping-pong-stream/pong')
const ObjectMultiplex = require('obj-multiplex')
const extension = require('extensionizer')
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 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
*/
function documentElementCheck () {
var documentElement = document.documentElement.nodeName
const documentElement = document.documentElement.nodeName
if (documentElement) {
return documentElement.toLowerCase() === 'html'
}
@ -260,7 +260,7 @@ function documentElementCheck () {
* @returns {boolean} {@code true} if the current domain is blacklisted
*/
function blacklistedDomainCheck () {
var blacklistedDomains = [
const blacklistedDomains = [
'uscourts.gov',
'dropbox.com',
'webbyawards.com',
@ -271,8 +271,8 @@ function blacklistedDomainCheck () {
'ani.gamer.com.tw',
'blueskybooking.com',
]
var currentUrl = window.location.href
var currentRegex
const currentUrl = window.location.href
let currentRegex
for (let i = 0; i < blacklistedDomains.length; i++) {
const blacklistedDomain = blacklistedDomains[i].replace('.', '\\.')
currentRegex = new RegExp(`(?:https?:\\/\\/)(?:(?!${blacklistedDomain}).)*$`)

@ -42,13 +42,13 @@ function onMessage (messageType, handler, remove) {
//
// setup background connection
var metamaskStream = new LocalMessageDuplexStream({
const metamaskStream = new LocalMessageDuplexStream({
name: 'inpage',
target: 'contentscript',
})
// compose the inpage provider
var inpageProvider = new MetamaskInpageProvider(metamaskStream)
const inpageProvider = new MetamaskInpageProvider(metamaskStream)
// set a high max listener count to avoid unnecesary warnings
inpageProvider.setMaxListeners(100)
@ -181,7 +181,7 @@ if (typeof window.web3 !== 'undefined') {
and try again.`)
}
var web3 = new Web3(proxiedInpageProvider)
const web3 = new Web3(proxiedInpageProvider)
web3.setProvider = function () {
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
// and that we dont affect the app with our namespace
// 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

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

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

@ -3,7 +3,7 @@ const dnode = require('dnode')
const { EventEmitter } = require('events')
const PortStream = require('extension-port-stream')
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 ExtensionPlatform = require('./platforms/extension')

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

@ -1,11 +1,11 @@
const EventEmitter = require('events').EventEmitter
const {EventEmitter} = require('events')
const async = require('async')
const Dnode = require('dnode')
const Eth = require('ethjs')
const EthQuery = require('eth-query')
const launchMetamaskUi = require('../../ui')
const StreamProvider = require('web3-stream-provider')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const {setupMultiplex} = require('./lib/stream-utils.js')
module.exports = initializePopup
@ -32,7 +32,7 @@ function initializePopup ({ container, connectionStream }, cb) {
function connectToAccountManager (connectionStream, cb) {
// setup communication with background
// setup multiplexing
var mx = setupMultiplex(connectionStream)
const mx = setupMultiplex(connectionStream)
// connect features
setupControllerConnection(mx.createStream('controller'), cb)
setupWeb3Connection(mx.createStream('provider'))
@ -44,7 +44,7 @@ function connectToAccountManager (connectionStream, cb) {
* @param {PortDuplexStream} connectionStream PortStream instance establishing a background connection
*/
function setupWeb3Connection (connectionStream) {
var providerStream = new StreamProvider()
const providerStream = new StreamProvider()
providerStream.pipe(connectionStream).pipe(providerStream)
connectionStream.on('error', console.error.bind(console))
providerStream.on('error', console.error.bind(console))
@ -62,8 +62,8 @@ function setupWeb3Connection (connectionStream) {
function setupControllerConnection (connectionStream, cb) {
// this is a really sneaky way of adding EventEmitter api
// to a bi-directional dnode instance
var eventEmitter = new EventEmitter()
var accountManagerDnode = Dnode({
const eventEmitter = new EventEmitter()
const accountManagerDnode = Dnode({
sendUpdate: function (state) {
eventEmitter.emit('update', state)
},

Loading…
Cancel
Save