diff --git a/modules/dbSync.js b/modules/dbSync.js index eda6e81f8..b21f9b22d 100644 --- a/modules/dbSync.js +++ b/modules/dbSync.js @@ -14,13 +14,13 @@ exports.backendSyncInit = function () { ipc.on('dbSync-add', (event, args) => { let collName = args.collName, - coll = db.getCollection('UI_'+ collName); + coll = db.getCollection(`UI_${collName}`); log.trace('dbSync-add', collName, args._id); const _id = args._id; - if (!coll.by("_id", _id)) { + if (!coll.by('_id', _id)) { args.fields._id = _id; coll.insert(args.fields); } @@ -28,12 +28,12 @@ exports.backendSyncInit = function () { ipc.on('dbSync-changed', (event, args) => { let collName = args.collName, - coll = db.getCollection('UI_'+ collName); + coll = db.getCollection(`UI_${collName}`); log.trace('dbSync-changed', collName, args._id); const _id = args._id; - const item = coll.by("_id", _id); + const item = coll.by('_id', _id); if (item) { for (const k in args.fields) { @@ -50,12 +50,12 @@ exports.backendSyncInit = function () { ipc.on('dbSync-removed', (event, args) => { let collName = args.collName, - coll = db.getCollection('UI_'+ collName); + coll = db.getCollection(`UI_${collName}`); log.trace('dbSync-removed', collName, args._id); const _id = args._id; - const item = coll.by("_id", _id); + const item = coll.by('_id', _id); if (item) { coll.remove(item); @@ -67,7 +67,7 @@ exports.backendSyncInit = function () { // Get all data (synchronous) ipc.on('dbSync-reloadSync', (event, args) => { let collName = args.collName, - coll = db.getCollection('UI_'+ collName), + coll = db.getCollection(`UI_${collName}`), docs = coll.find(); log.debug('dbSync-reloadSync, no. of docs:', collName, docs.length); @@ -88,15 +88,15 @@ exports.backendSyncInit = function () { }); }; -var syncDataFromBackend = function(coll){ - let ipc = ipcRenderer; +const syncDataFromBackend = function (coll) { + const ipc = ipcRenderer; - let collName = coll._name; + const collName = coll._name; console.debug('Load collection data from backend: ', collName); return new Promise((resolve, reject) => { - let dataJson = ipc.sendSync('dbSync-reloadSync', { + const dataJson = ipc.sendSync('dbSync-reloadSync', { collName, }); @@ -105,8 +105,9 @@ var syncDataFromBackend = function(coll){ coll.remove({}); - if(!dataJson.length) + if (!dataJson.length) { resolve(); + } // we do inserts slowly, to avoid race conditions when it comes // to updating the UI @@ -120,10 +121,11 @@ var syncDataFromBackend = function(coll){ record.redirect = null; } - if(record._id) + if (record._id) { coll.upsert(record._id, record); - else + } else { coll.insert(record); + } } catch (err) { console.error(err.toString()); } @@ -138,7 +140,7 @@ var syncDataFromBackend = function(coll){ } catch (err) { reject(err); } - }) + }); }; exports.syncDataFromBackend = syncDataFromBackend; @@ -146,8 +148,8 @@ exports.frontendSyncInit = function (coll) { let ipc = ipcRenderer, syncDoneResolver; - let collName = coll._name; - + const collName = coll._name; + coll.onceSynced = new Promise((resolve, reject) => { syncDoneResolver = resolve; }); diff --git a/modules/ethereumNode.js b/modules/ethereumNode.js index 2932dac0a..b37c67e8e 100644 --- a/modules/ethereumNode.js +++ b/modules/ethereumNode.js @@ -315,13 +315,14 @@ class EthereumNode extends EventEmitter { this._network = network; this._type = nodeType; - let client = ClientBinaryManager.getClient(nodeType); + const client = ClientBinaryManager.getClient(nodeType); let binPath; - if(client) + if (client) { binPath = client.binPath; - else + } else { throw new Error(`Node "${nodeType}" binPath is not available.`); + } log.info(`Start node using ${binPath}`); @@ -358,7 +359,7 @@ class EthereumNode extends EventEmitter { // START MAINNET else { args = (nodeType === 'geth') - ? ['--fast', '--cache', '1024'] + ? ['--fast', '--cache', '1024'] : ['--unsafe-transactions']; } diff --git a/modules/ipc/dechunker.js b/modules/ipc/dechunker.js index a77e54866..3bf74b22c 100644 --- a/modules/ipc/dechunker.js +++ b/modules/ipc/dechunker.js @@ -39,8 +39,9 @@ module.exports = class Dechunker { return _.each(dechunkedData, (data) => { // prepend the last chunk - if (this.lastChunk) - { data = this.lastChunk + data; } + if (this.lastChunk) { + data = this.lastChunk + data; + } let result = data; diff --git a/modules/ipc/ipcProviderBackend.js b/modules/ipc/ipcProviderBackend.js index 8ce1b4040..794fc500e 100644 --- a/modules/ipc/ipcProviderBackend.js +++ b/modules/ipc/ipcProviderBackend.js @@ -100,8 +100,7 @@ class IpcProviderBackend { socket.destroy().finally(() => { - if(!owner.isDestroyed()) - owner.send(`ipcProvider-${ev}`, JSON.stringify(data)); + if (!owner.isDestroyed()) { owner.send(`ipcProvider-${ev}`, JSON.stringify(data)); } }); delete this._connections[ownerId]; @@ -110,8 +109,9 @@ class IpcProviderBackend { }); socket.on('connect', (data) => { - if(!owner.isDestroyed()) + if (!owner.isDestroyed()) { owner.send('ipcProvider-connect', JSON.stringify(data)); + } }); // pass notifications back up the chain @@ -124,8 +124,9 @@ class IpcProviderBackend { data = this._makeResponsePayload(data, data); } - if(!owner.isDestroyed()) + if (!owner.isDestroyed()) { owner.send('ipcProvider-data', JSON.stringify(data)); + } }); } }) @@ -172,8 +173,9 @@ class IpcProviderBackend { } }) .then(() => { - if(!owner.isDestroyed()) + if (!owner.isDestroyed()) { owner.send('ipcProvider-setWritable', true); + } return this._connections[ownerId]; }); @@ -356,7 +358,7 @@ class IpcProviderBackend { if (isSync) { event.returnValue = returnValue; - } else if(!event.sender.isDestroyed()) { + } else if (!event.sender.isDestroyed()) { event.sender.send('ipcProvider-data', returnValue); } }); diff --git a/modules/ipc/methods/eth_sendTransaction.js b/modules/ipc/methods/eth_sendTransaction.js index fc90f073f..8f37ddc10 100644 --- a/modules/ipc/methods/eth_sendTransaction.js +++ b/modules/ipc/methods/eth_sendTransaction.js @@ -70,8 +70,7 @@ module.exports = class extends BaseProcessor { ipc.once('backendAction_unlockedAccountAndSentTransaction', (ev, err, result) => { if (Windows.getById(ev.sender.id) === modalWindow - && !modalWindow.isClosed) - { + && !modalWindow.isClosed) { if (err || !result) { this._log.debug('Confirmation error', err); diff --git a/modules/ipcCommunicator.js b/modules/ipcCommunicator.js index a833daea5..0c527e56e 100644 --- a/modules/ipcCommunicator.js +++ b/modules/ipcCommunicator.js @@ -62,7 +62,7 @@ ipc.on('backendAction_windowCallback', (e, value1, value2, value3) => { const windowId = e.sender.id; const senderWindow = Windows.getById(windowId); - if(senderWindow.callback) { + if (senderWindow.callback) { senderWindow.callback(value1, value2, value3); } }); @@ -100,10 +100,11 @@ ipc.on('backendAction_setLanguage', (e, lang) => { ipc.on('backendAction_stopWebviewNavigation', (e, id) => { console.log('webcontent ID', id); - var webContent = webContents.fromId(id); + const webContent = webContents.fromId(id); - if(webContent && !webContent.isDestroyed()) + if (webContent && !webContent.isDestroyed()) { webContent.stop(); + } e.returnValue = true; }); @@ -126,8 +127,9 @@ ipc.on('backendAction_importPresaleFile', (e, path, pw) => { }); nodeProcess.stdout.on('data', (data) => { var data = data.toString(); - if (data) - { log.info('Imported presale: ', data); } + if (data) { + log.info('Imported presale: ', data); + } if (/Decryption failed|not equal to expected addr|could not decrypt/.test(data)) { e.sender.send('uiAction_importedPresaleFile', 'Decryption Failed'); diff --git a/modules/menuItems.js b/modules/menuItems.js index 39b26a8c2..812ebf349 100644 --- a/modules/menuItems.js +++ b/modules/menuItems.js @@ -13,8 +13,7 @@ const ClientBinaryManager = require('./clientBinaryManager'); const switchForSystem = function (options) { if (process.platform in options) { return options[process.platform]; - } - else if ('default' in options) { + } else if ('default' in options) { return options.default; } }; diff --git a/modules/preloader/browser.js b/modules/preloader/browser.js index 92b1241e5..1ba237466 100644 --- a/modules/preloader/browser.js +++ b/modules/preloader/browser.js @@ -18,7 +18,7 @@ ipcRenderer.sendToHost('setWebviewId'); ipcRenderer.send('ipcProvider-destroy'); // Security -process.on('loaded',function () { +process.on('loaded', function () { Object.freeze(window.JSON); // Object.freeze(window.Function); // Object.freeze(window.Function.prototype); diff --git a/modules/preloader/include/getFavicon.js b/modules/preloader/include/getFavicon.js index 6e67db48f..be7e26f2d 100644 --- a/modules/preloader/include/getFavicon.js +++ b/modules/preloader/include/getFavicon.js @@ -12,10 +12,11 @@ const { ipcRenderer } = require('electron'); function DOMContentLoaded(event) { const icon = document.querySelector('link[rel="apple-touch-icon"]') || document.querySelector('link[type="image/x-icon"]') || document.querySelector('link[rel="shortcut"]') || document.querySelector('link[rel="shortcut icon"]') || document.querySelector('link[rel="icon"]'); - if (icon) - { ipcRenderer.sendToHost('favicon', icon.href); } - else - { ipcRenderer.sendToHost('favicon', null); } + if (icon) { + ipcRenderer.sendToHost('favicon', icon.href); + } else { + ipcRenderer.sendToHost('favicon', null); + } document.removeEventListener('DOMContentLoaded', DOMContentLoaded, false); } diff --git a/modules/preloader/include/getMetaTags.js b/modules/preloader/include/getMetaTags.js index 233a1260b..6186ddade 100644 --- a/modules/preloader/include/getMetaTags.js +++ b/modules/preloader/include/getMetaTags.js @@ -4,7 +4,7 @@ Gest the meta[name="ethereum-dapp-url-bar-style"] meta tag @module getMetaTags */ -const { ipcRenderer } = require('electron'); +const { ipcRenderer } = require('electron'); module.export = (function () { document.addEventListener('DOMContentLoaded', DOMContentLoaded, false); @@ -12,10 +12,11 @@ module.export = (function () { function DOMContentLoaded(event) { const appBar = document.querySelector('meta[name="ethereum-dapp-url-bar-style"]'); - if (appBar) - { ipcRenderer.sendToHost('appBar', appBar.content); } - else - { ipcRenderer.sendToHost('appBar', null); } + if (appBar) { + ipcRenderer.sendToHost('appBar', appBar.content); + } else { + ipcRenderer.sendToHost('appBar', null); + } document.removeEventListener('DOMContentLoaded', DOMContentLoaded, false); } diff --git a/modules/preloader/include/mistAPI.js b/modules/preloader/include/mistAPI.js index bd2389128..996dcbf57 100644 --- a/modules/preloader/include/mistAPI.js +++ b/modules/preloader/include/mistAPI.js @@ -102,7 +102,7 @@ module.exports = () => { @param {Function} callback Change the callback to be called when the menu is pressed. */ add(id, options, callback) { - var args = Array.prototype.slice.call(arguments); + const args = Array.prototype.slice.call(arguments); callback = _.isFunction(args[args.length - 1]) ? args.pop() : null; options = _.isObject(args[args.length - 1]) ? args.pop() : null; id = _.isString(args[args.length - 1]) || _.isFinite(args[args.length - 1]) ? args.pop() : null; diff --git a/modules/preloader/include/openExternal.js b/modules/preloader/include/openExternal.js index 962eebb19..b4f484d64 100644 --- a/modules/preloader/include/openExternal.js +++ b/modules/preloader/include/openExternal.js @@ -12,10 +12,11 @@ document.addEventListener('click', (e) => { let node = false; - if (e.target.nodeName === 'A') - { node = e.target; } - else if (e.target.parentNode && e.target.parentNode.nodeName === 'A') - { node = e.target.parentNode; } + if (e.target.nodeName === 'A') { + node = e.target; + } else if (e.target.parentNode && e.target.parentNode.nodeName === 'A') { + node = e.target.parentNode; + } // open in browser if (node && node.attributes.target && node.attributes.target.value === '_blank') { diff --git a/modules/preloader/include/openPopup.js b/modules/preloader/include/openPopup.js index 54a1e1278..9f53b4ec5 100644 --- a/modules/preloader/include/openPopup.js +++ b/modules/preloader/include/openPopup.js @@ -10,10 +10,11 @@ const { remote } = require('electron'); document.addEventListener('click', (e) => { let node = false; - if (e.target.nodeName === 'A') - { node = e.target; } - else if (e.target.parentNode && e.target.parentNode.nodeName === 'A') - { node = e.target.parentNode; } + if (e.target.nodeName === 'A') { + node = e.target; + } else if (e.target.parentNode && e.target.parentNode.nodeName === 'A') { + node = e.target.parentNode; + } // open popup if (node && node.attributes.target && node.attributes.target.value === '_popup') { diff --git a/modules/preloader/mistUI.js b/modules/preloader/mistUI.js index b1dd85be2..6f401ab6f 100644 --- a/modules/preloader/mistUI.js +++ b/modules/preloader/mistUI.js @@ -56,11 +56,12 @@ ipcRenderer.on('uiAction_windowMessage', (e, type, id, error, value) => { } // forward to the webview (TODO: remove and manage in the ipcCommunicator?) - var tab = Tabs.findOne({ webviewId: id }); - if(tab) { - webview = $('webview[data-id='+ tab._id +']')[0]; - if(webview) + const tab = Tabs.findOne({ webviewId: id }); + if (tab) { + webview = $(`webview[data-id=${tab._id}]`)[0]; + if (webview) { webview.send('uiAction_windowMessage', type, error, value); + } } }); @@ -73,20 +74,22 @@ ipcRenderer.on('uiAction_enableBlurOverlay', (e, value) => { ipcRenderer.on('uiAction_toggleWebviewDevTool', (e, id) => { const webview = Helpers.getWebview(id); - if (!webview) - { return; } + if (!webview) { + return; + } - if (webview.isDevToolsOpened()) - { webview.closeDevTools(); } - else - { webview.openDevTools(); } + if (webview.isDevToolsOpened()) { + webview.closeDevTools(); + } else { + webview.openDevTools(); + } }); // randomize accounts and drop half // also certainly remove the web3.ethbase one -var randomizeAccounts = (acc, coinbase) => { - var accounts = _.shuffle(acc); +const randomizeAccounts = (acc, coinbase) => { + let accounts = _.shuffle(acc); accounts = _.rest(accounts, (accounts.length / 2).toFixed(0)); accounts = _.without(accounts, coinbase); return accounts; @@ -117,7 +120,7 @@ ipcRenderer.on('uiAction_runTests', (e, type) => { // update the permissions, when accounts change Tracker.autorun(() => { - var accountList = _.pluck(EthAccounts.find({}, { fields: { address: 1 } }).fetch(), 'address'); + const accountList = _.pluck(EthAccounts.find({}, { fields: { address: 1 } }).fetch(), 'address'); Tabs.update('tests', { $set: { 'permissions.accounts': randomizeAccounts(accountList, coinbase), @@ -136,18 +139,21 @@ const menu = new Menu(); // menu.append(new MenuItem({ type: 'separator' })); menu.append(new MenuItem({ label: i18n.t('mist.rightClick.reload'), accelerator: 'Command+R', click() { const webview = Helpers.getWebview(LocalStore.get('selectedTab')); - if (webview) - { webview.reloadIgnoringCache(); } + if (webview) { + webview.reloadIgnoringCache(); + } } })); menu.append(new MenuItem({ label: i18n.t('mist.rightClick.openDevTools'), click() { const webview = Helpers.getWebview(LocalStore.get('selectedTab')); - if (webview) - { webview.openDevTools(); } + if (webview) { + webview.openDevTools(); + } } })); menu.append(new MenuItem({ label: i18n.t('mist.rightClick.inspectElements'), click() { const webview = Helpers.getWebview(LocalStore.get('selectedTab')); - if (webview) - { webview.inspectElement(currentMousePosition.x, currentMousePosition.y); } + if (webview) { + webview.inspectElement(currentMousePosition.x, currentMousePosition.y); + } } })); @@ -167,7 +173,8 @@ document.addEventListener('keydown', (e) => { // RELOAD current webview if (e.metaKey && e.keyCode === 82) { const webview = Helpers.getWebview(LocalStore.get('selectedTab')); - if (webview) - { webview.reloadIgnoringCache(); } + if (webview) { + webview.reloadIgnoringCache(); + } } }, false); diff --git a/modules/preloader/walletMain.js b/modules/preloader/walletMain.js index 9b4909579..7bb9115f8 100644 --- a/modules/preloader/walletMain.js +++ b/modules/preloader/walletMain.js @@ -17,6 +17,7 @@ setTimeout(() => { }, 1000); setTimeout(() => { - if (document.getElementsByTagName('html')[0]) - { document.getElementsByTagName('html')[0].className = window.platform; } + if (document.getElementsByTagName('html')[0]) { + document.getElementsByTagName('html')[0].className = window.platform; + } }, 500);