From 969cf73fae4073f48a6491d3768d68ce64caeff9 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 12 Feb 2019 10:27:03 -0330 Subject: [PATCH 1/8] Fix all "var used instead of let or const" problems in background.js --- app/scripts/background.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/scripts/background.js b/app/scripts/background.js index 6056962dd..8cc60be80 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.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() From 3c915b0d7ff7241c0b3f1b58aadda6da7bcb712d Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 12 Feb 2019 10:31:09 -0330 Subject: [PATCH 2/8] Update contentscript to use ES6 destructuring, const, let --- app/scripts/contentscript.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 92e382ea5..65e2ec523 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -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}).)*$`) From f5eb1512d4dd2c521034d121f3de3e7957cfd53e Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 12 Feb 2019 10:32:24 -0330 Subject: [PATCH 3/8] Fix all "var used instead of let or const" problems in inpage.js --- app/scripts/inpage.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index f8c6cf573..fb2a84d1a 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -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 From ae084cef6c5cf7240e5fd1b3ff762e35dab5cf2b Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 12 Feb 2019 10:33:06 -0330 Subject: [PATCH 4/8] Update MetaMaskController to use ES6 destructuring, const, let --- app/scripts/metamask-controller.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 16ab34c7d..8de17d7f0 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -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') @@ -207,7 +207,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() From d735439de9f4f0bcbaab59afa7dab51e24788289 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 12 Feb 2019 10:33:37 -0330 Subject: [PATCH 5/8] Update NoticesController to use ES6 destructuring, const, let --- app/scripts/notice-controller.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js index ce686d9d1..6fe8b8cf0 100644 --- a/app/scripts/notice-controller.js +++ b/app/scripts/notice-controller.js @@ -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) From 5d3aea785730dab8903718df3fc1d0a9d7ebace4 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 12 Feb 2019 10:34:12 -0330 Subject: [PATCH 6/8] Update phishing-detect script to use ES6 destructuring requires --- app/scripts/phishing-detect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/phishing-detect.js b/app/scripts/phishing-detect.js index ff95d1f6f..b30c76b72 100644 --- a/app/scripts/phishing-detect.js +++ b/app/scripts/phishing-detect.js @@ -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') From ade96fda413b265d9c5eb5329c7c644908514f6e Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 12 Feb 2019 10:34:48 -0330 Subject: [PATCH 7/8] Update platforms/extension to use ES6 destructuring requires --- app/scripts/platforms/extension.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index 3dadd5d34..099b0d7ea 100644 --- a/app/scripts/platforms/extension.js +++ b/app/scripts/platforms/extension.js @@ -1,5 +1,5 @@ const extension = require('extensionizer') -const explorerLink = require('etherscan-link').createExplorerLink +const {createExplorerLink: explorerLink} = require('etherscan-link') class ExtensionPlatform { From 92cc60f425e33fd3de31efd004e5144cb270b924 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 12 Feb 2019 10:35:30 -0330 Subject: [PATCH 8/8] Update popup-core script to use ES6 destructuring, const, let --- app/scripts/popup-core.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/scripts/popup-core.js b/app/scripts/popup-core.js index db885ec93..e964d001d 100644 --- a/app/scripts/popup-core.js +++ b/app/scripts/popup-core.js @@ -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) },