From 68a6a335fb4a2f10dd2909959bd78ac578a45695 Mon Sep 17 00:00:00 2001 From: Luca Zeug Date: Mon, 20 Mar 2017 17:27:38 +0100 Subject: [PATCH] [ESLint] fix simple rule violations in 'interface' (#1751) * fix rule "intend" * fix rule "no-trailing-spaces" * fix rule "eol-last" (new line at end of file) * fix rule "keyword-spacing" * fix rule "space-before-blocks" * fix rule "space-infix-ops" (space before and after operators) * fix rule "space-before-function-paren" * fix rule "object-curly-spacing" * fix rule "no-multi-spaces" * fix rule "curly" * fix rule "no-multiple-empty-lines" * fix rule "quotes" * fix rule "semi-spacing" * fix rule "semi" * fix rule "key-spacing" * fix rule "space-in-parens" * fix rule "spaced-comment" * fix rule "comma-spacing" * fix rule "no-lonely-if" * fix rule "eqeqeq" --- interface/client/collections.js | 6 +- .../client/lib/ethereum/1_web3js_init.js | 6 +- .../client/lib/helpers/helperFunctions.js | 43 +++-- .../client/lib/helpers/templateHelpers.js | 47 +++-- interface/client/lib/signatures.js | 2 +- interface/client/lib/thirdParty.js | 2 +- interface/client/mistAPIBackend.js | 2 +- interface/client/templates/elements/img.js | 4 +- .../templates/elements/networkIndicator.js | 32 ++-- interface/client/templates/index.js | 11 +- .../client/templates/layout/browserBar.js | 51 ++--- interface/client/templates/layout/sidebar.js | 69 ++++--- interface/client/templates/layout/webviews.js | 6 +- .../client/templates/popupWindows/about.js | 2 +- .../popupWindows/clientUpdateAvailable.js | 4 +- .../templates/popupWindows/connectAccount.js | 66 +++---- .../popupWindows/onboardingScreen.js | 167 ++++++++-------- .../templates/popupWindows/requestAccount.js | 33 ++-- .../sendTransactionConfirmation.js | 178 +++++++++--------- .../templates/popupWindows/splashScreen.js | 112 +++++------ .../popupWindows/unlockMasterPassword.js | 16 +- .../templates/popupWindows/updateAvailable.js | 11 +- interface/client/templates/views/webview.js | 68 +++---- interface/client/templates/webviewEvents.js | 92 ++++----- interface/client/windowEvents.js | 10 +- 25 files changed, 534 insertions(+), 506 deletions(-) diff --git a/interface/client/collections.js b/interface/client/collections.js index b8545051f..a58ed19e9 100644 --- a/interface/client/collections.js +++ b/interface/client/collections.js @@ -6,9 +6,9 @@ // BROWSER RELATED // Contains the accounts -Tabs = new Mongo.Collection('tabs', {connection: null}); -LastVisitedPages = new Mongo.Collection('last-visted-pages', {connection: null}); -History = new Mongo.Collection('history', {connection: null}); +Tabs = new Mongo.Collection('tabs', { connection: null }); +LastVisitedPages = new Mongo.Collection('last-visted-pages', { connection: null }); +History = new Mongo.Collection('history', { connection: null }); // Sync collection from and to the backend loki.js if (typeof window.dbSync !== 'undefined') { diff --git a/interface/client/lib/ethereum/1_web3js_init.js b/interface/client/lib/ethereum/1_web3js_init.js index 3be307bfd..270935e4b 100644 --- a/interface/client/lib/ethereum/1_web3js_init.js +++ b/interface/client/lib/ethereum/1_web3js_init.js @@ -1,10 +1,10 @@ // set providor -if(typeof web3 !== 'undefined') { - console.info('Web3 already initialized, re-using provider.'); +if (typeof web3 !== 'undefined') { + console.info('Web3 already initialized, re-using provider.'); web3 = new Web3(web3.currentProvider); } else { console.info('Web3 not yet initialized, doing so now with HttpProvider.'); - web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); + web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); } diff --git a/interface/client/lib/helpers/helperFunctions.js b/interface/client/lib/helpers/helperFunctions.js index bb6dbb32e..aa9e66226 100644 --- a/interface/client/lib/helpers/helperFunctions.js +++ b/interface/client/lib/helpers/helperFunctions.js @@ -39,8 +39,8 @@ Get the webview from either and ID, or the string "browser" @method getWebview @param {String} id The Id of a tab or the string "browser" */ -Helpers.getWebview = function(id){ - return $('webview[data-id="'+ id +'"]')[0]; +Helpers.getWebview = function (id) { + return $('webview[data-id="' + id + '"]')[0]; }; /** @@ -50,22 +50,24 @@ Get tab by url and return the id @param {String} url @return {String} id */ -Helpers.getTabIdByUrl= function(url, returnEmpty){ +Helpers.getTabIdByUrl = function (url, returnEmpty) { var tabs = Tabs.find().fetch(); url = Helpers.sanitizeUrl(url); - var foundTab = _.find(tabs, function(tab){ - if(tab._id === 'browser' || !tab.url) - return false; - var tabOrigin = new URL(tab.url).origin; - return (url && new URL(url).origin.indexOf(tabOrigin) === 0); - }); + var foundTab = _.find(tabs, function (tab) { + if (tab._id === 'browser' || !tab.url) { + return false; + } + var tabOrigin = new URL(tab.url).origin; + return (url && new URL(url).origin.indexOf(tabOrigin) === 0); + }); // switch tab to browser - if(foundTab) + if (foundTab) { foundTab = foundTab._id; - else + } else { foundTab = 'browser'; + } return foundTab; }; @@ -76,10 +78,11 @@ Format Urls, e.g add a default protocol if on is missing. @method formatUrl @param {String} url **/ -Helpers.formatUrl = function(url){ +Helpers.formatUrl = function (url) { // add http:// if no protocol is present - if(url && url.indexOf('://') === -1) - url = 'http://'+ url; + if (url && url.indexOf('://') === -1) { + url = 'http://' + url; + } return url; }; @@ -90,13 +93,13 @@ Sanatizes URLs to prevent phishing and XSS attacks @method sanitizeUrl @param {String} url **/ -Helpers.sanitizeUrl = function(url, returnEmptyURL){ +Helpers.sanitizeUrl = function (url, returnEmptyURL) { url = String(url); url = url.replace(/[\t\n\r\s]+/g, ''); url = url.replace(/^[:\/]{1,3}/i, 'http://'); - if(returnEmptyURL && /^(?:file|javascript|data):/i.test(url)) { + if (returnEmptyURL && /^(?:file|javascript|data):/i.test(url)) { url = false; } @@ -128,7 +131,7 @@ Helpers.generateBreadcrumb = function (url) { return el === ''; }); - return new Spacebars.SafeString(filteredUrl.protocol +'//'+ _.flatten(['' + filteredUrl.host + ' ', pathname]).join(' ▸ ')); + return new Spacebars.SafeString(filteredUrl.protocol + '//' + _.flatten(['' + filteredUrl.host + ' ', pathname]).join(' ▸ ')); }; /** @@ -139,7 +142,7 @@ Clear localStorage Helpers.getLocalStorageSize = function () { var size = 0; - if(localStorage) { + if (localStorage) { _.each(Object.keys(localStorage), function (key) { size += localStorage[key].length * 2 / 1024 / 1024; }); @@ -188,7 +191,9 @@ Helpers.selectTabWithOffset = function (offset) { currentTabIndex = tabList.indexOf(LocalStore.get('selectedTab')); newTabIndex = (currentTabIndex + offset) % tabList.length; - if (newTabIndex < 0) newTabIndex = tabList.length - 1; + if (newTabIndex < 0) { + newTabIndex = tabList.length - 1; + } LocalStore.set('selectedTab', tabList[newTabIndex]); }; diff --git a/interface/client/lib/helpers/templateHelpers.js b/interface/client/lib/helpers/templateHelpers.js index ac8137c13..98d7ae713 100644 --- a/interface/client/lib/helpers/templateHelpers.js +++ b/interface/client/lib/helpers/templateHelpers.js @@ -16,7 +16,7 @@ A simple template helper to log objects in the console. @method (debug) **/ -Template.registerHelper('debug', function(object){ +Template.registerHelper('debug', function (object) { console.log(object); }); @@ -25,7 +25,7 @@ Returns the current block @method (CurrentBlock) **/ -Template.registerHelper('CurrentBlock', function(){ +Template.registerHelper('CurrentBlock', function () { return EthBlocks.latest; }); @@ -35,7 +35,7 @@ Return the dirname. @method (dirname) **/ -Template.registerHelper('dirname', function(){ +Template.registerHelper('dirname', function () { return window.dirname; }); @@ -44,7 +44,7 @@ Return the Mist API. @method (mist) **/ -Template.registerHelper('mist', function(){ +Template.registerHelper('mist', function () { return window.mist; }); @@ -54,7 +54,7 @@ Return the app mode. @method (mode) **/ -Template.registerHelper('mode', function(){ +Template.registerHelper('mode', function () { return window.mistMode; }); @@ -63,7 +63,7 @@ Return the friendly app name. @method (appName) **/ -Template.registerHelper('appName', function(){ +Template.registerHelper('appName', function () { return window.mistMode === 'mist' ? 'Mist' : 'Ethereum Wallet'; }); @@ -72,8 +72,8 @@ Return the app icon path. @method (iconPath) **/ -Template.registerHelper('appIconPath', function(){ - return 'file://'+ window.dirname +'/icons/'+ window.mistMode +'/icon2x.png'; +Template.registerHelper('appIconPath', function () { + return 'file://' + window.dirname + '/icons/' + window.mistMode + '/icon2x.png'; }); /** @@ -81,7 +81,7 @@ Get the current user agent @method (useragent) **/ -Template.registerHelper('useragent', function(){ +Template.registerHelper('useragent', function () { return navigator.userAgent + ' Ethereum ' + (window.mistMode === 'mist' ? 'Mist' : 'Wallet'); }); @@ -90,8 +90,8 @@ Get all accounts @method (accounts) **/ -Template.registerHelper('accounts', function(identity){ - return EthAccounts.find({}, {sort: {name: 1}}); +Template.registerHelper('accounts', function (identity) { + return EthAccounts.find({}, { sort: { name: 1 } }); }); /** @@ -107,16 +107,18 @@ Return the right wallet icon @method (walletIcon) **/ -Template.registerHelper('walletIcon', function(){ +Template.registerHelper('walletIcon', function () { var icon = ''; - if(this.type === 'wallet') { - if(Helpers.isWatchOnly(this._id)) + if (this.type === 'wallet') { + if (Helpers.isWatchOnly(this._id)) { icon = ''; - else + } else { icon = ''; - } else if(this.type === 'account') + } + } else if (this.type === 'account') { icon = ''; + } return new Spacebars.SafeString(icon); }); @@ -128,12 +130,13 @@ Get the account name or display the address @method (accountNameOrAddress) @param {String} address */ -Template.registerHelper('accountNameOrAddress', function(address){ - var account = EthAccounts.findOne({address: address}); - if(account) +Template.registerHelper('accountNameOrAddress', function (address) { + var account = EthAccounts.findOne({ address: address }); + if (account) { return account.name; - else + } else { return address; + } }); /** @@ -176,7 +179,3 @@ Formats a number. Template.registerHelper('formatBalance', Helpers.formatBalance); - - - - diff --git a/interface/client/lib/signatures.js b/interface/client/lib/signatures.js index 30234c664..df02e99e7 100644 --- a/interface/client/lib/signatures.js +++ b/interface/client/lib/signatures.js @@ -10187,4 +10187,4 @@ window.SIGNATURES = { "0x4e077f2a": [ "addGasEther()" ] -}; \ No newline at end of file +}; diff --git a/interface/client/lib/thirdParty.js b/interface/client/lib/thirdParty.js index 225b81883..f35a8d93d 100644 --- a/interface/client/lib/thirdParty.js +++ b/interface/client/lib/thirdParty.js @@ -16,4 +16,4 @@ Meteor.Spinner.options = { zIndex: 2e9, // The z-index (defaults to 2000000000) top: '50%', // Top position relative to parent left: '50%' // Left position relative to parent -}; \ No newline at end of file +}; diff --git a/interface/client/mistAPIBackend.js b/interface/client/mistAPIBackend.js index d40f76b7d..7a0f057e7 100644 --- a/interface/client/mistAPIBackend.js +++ b/interface/client/mistAPIBackend.js @@ -38,7 +38,7 @@ mistAPIBackend = function (event) { // console.trace('mistAPIBackend event', event); if (event.channel === 'setWebviewId') { - Tabs.update(template.data._id, { $set: { webviewId: webview.getWebContents().id }}); + Tabs.update(template.data._id, { $set: { webviewId: webview.getWebContents().id } }); } // Send TEST DATA diff --git a/interface/client/templates/elements/img.js b/interface/client/templates/elements/img.js index 6e7e33502..060bef3bb 100644 --- a/interface/client/templates/elements/img.js +++ b/interface/client/templates/elements/img.js @@ -17,7 +17,7 @@ Template['elements_img'].helpers({ @method (preload) */ - 'preload': function(){ + 'preload': function () { var template = Template.instance(), data = this, img = new Image(); @@ -30,4 +30,4 @@ Template['elements_img'].helpers({ }; img.src = data.src; } -}); \ No newline at end of file +}); diff --git a/interface/client/templates/elements/networkIndicator.js b/interface/client/templates/elements/networkIndicator.js index 9b8a92bf1..f1f66fce2 100644 --- a/interface/client/templates/elements/networkIndicator.js +++ b/interface/client/templates/elements/networkIndicator.js @@ -12,61 +12,59 @@ The networkIndicator template */ - /** Check network type. @method checkNetworkType */ -var checkNetworkType = function(template) { +var checkNetworkType = function (template) { console.trace('Check network type...'); try { - web3.eth.getBlock(0, function(e, res) { + web3.eth.getBlock(0, function (e, res) { console.trace('Get block 0', e, res); - + if (e) { console.error('Got error fetching block 0', e); } else { - TemplateVar.set(template, 'network', Helpers.detectNetwork(res.hash).type); + TemplateVar.set(template, 'network', Helpers.detectNetwork(res.hash).type); } - }); + }); } catch (err) { console.error('Unable to get block 0', err); } }; - -Template['elements_networkIndicator'].onRendered(function(){ +Template['elements_networkIndicator'].onRendered(function () { var template = this; TemplateVar.set(template, 'network', 'unknown'); checkNetworkType(template); - ipc.on('uiAction_nodeStatus', function(e, status) { + ipc.on('uiAction_nodeStatus', function (e, status) { console.trace('Node status', status); switch (status) { - case 'starting': - case 'stopping': - case 'connected': - console.debug('Node status changing, reset network type indicator'); + case 'starting': + case 'stopping': + case 'connected': + console.debug('Node status changing, reset network type indicator'); + + TemplateVar.set(template, 'network', 'unknown'); - TemplateVar.set(template, 'network', 'unknown'); - break; } }); - ipc.on('uiAction_nodeSyncStatus', function(e, status, data) { + ipc.on('uiAction_nodeSyncStatus', function (e, status, data) { console.trace('Node sync status', status); if ('inProgress' === status && TemplateVar.get(template, 'network') === 'unknown') { console.debug('Node syncing, re-check network type.'); - checkNetworkType(template); + checkNetworkType(template); } }); }); diff --git a/interface/client/templates/index.js b/interface/client/templates/index.js index 6982956b6..1c92d6c21 100644 --- a/interface/client/templates/index.js +++ b/interface/client/templates/index.js @@ -17,17 +17,18 @@ Template.body.helpers({ @method renderApp */ - 'renderApp': function(){ - if(_.isEmpty(location.hash)) { + 'renderApp': function () { + if (_.isEmpty(location.hash)) { $('title').text('Mist'); return 'layout_main'; } else { var renderWindow = location.hash.match(/#([a-zA-Z]*)_?/); - if (renderWindow.length>0) + if (renderWindow.length > 0) { return 'popupWindows_' + renderWindow[1]; - else + } else { return false; + } } } }); @@ -42,4 +43,4 @@ Template.body.events({ 'dragover body > *, drop body > *': function(e){ e.preventDefault(); }, -});*/ \ No newline at end of file +});*/ diff --git a/interface/client/templates/layout/browserBar.js b/interface/client/templates/layout/browserBar.js index b5846210f..335d0f672 100644 --- a/interface/client/templates/layout/browserBar.js +++ b/interface/client/templates/layout/browserBar.js @@ -12,7 +12,7 @@ The browserBar template */ -Template['layout_browserBar'].onRendered(function(){ +Template['layout_browserBar'].onRendered(function () { var template = this; }); @@ -39,7 +39,7 @@ Template['layout_browserBar'].helpers({ @method (dapp) */ - 'dapp': function(){ + 'dapp': function () { return Tabs.findOne(LocalStore.get('selectedTab')); }, /** @@ -47,16 +47,17 @@ Template['layout_browserBar'].helpers({ @method (dappAccounts) */ - 'dappAccounts': function(){ - if(this.permissions) - return EthAccounts.find({address: {$in: this.permissions.accounts || []}}); + 'dappAccounts': function () { + if (this.permissions) { + return EthAccounts.find({ address: { $in: this.permissions.accounts || [] } }); + } }, /** Show the add button, when on a dapp and in doogle @method (isBrowser) */ - 'isBrowser': function(){ + 'isBrowser': function () { return (LocalStore.get('selectedTab') === 'browser'); }, /** @@ -64,8 +65,8 @@ Template['layout_browserBar'].helpers({ @method (currentWebView) */ - 'currentWebView': function(){ - return '.webview webview[data-id="'+ LocalStore.get('selectedTab') +'"]'; + 'currentWebView': function () { + return '.webview webview[data-id="' + LocalStore.get('selectedTab') + '"]'; } }); @@ -75,22 +76,24 @@ Template['layout_browserBar'].events({ @event click button.back */ - 'click button.back': function(){ + 'click button.back': function () { var webview = Helpers.getWebview(LocalStore.get('selectedTab')); - if(webview && webview.canGoBack()) + if (webview && webview.canGoBack()) { webview.goBack(); + } }, /* Reload the current webview @event click button.reload */ - 'click button.reload': function(){ + 'click button.reload': function () { var webview = Helpers.getWebview(LocalStore.get('selectedTab')); - if(webview) + if (webview) { webview.reload(); + } }, /* Remove the current selected tab @@ -99,7 +102,7 @@ Template['layout_browserBar'].events({ @event click button.remove-tab */ - 'click button.remove-tab': function(){ + 'click button.remove-tab': function () { var tabId = LocalStore.get('selectedTab'); Tabs.remove(tabId); @@ -110,15 +113,15 @@ Template['layout_browserBar'].events({ @event click .app-bar > button.accounts' */ - 'click .app-bar > button.accounts': function(e, template) { - mist.requestAccount(function(e, addresses){ + 'click .app-bar > button.accounts': function (e, template) { + mist.requestAccount(function (e, addresses) { var tabId = LocalStore.get('selectedTab'); dbSync.syncDataFromBackend(LastVisitedPages); - dbSync.syncDataFromBackend(Tabs).then(function(){ - Tabs.update(tabId, {$set: { + dbSync.syncDataFromBackend(Tabs).then(function () { + Tabs.update(tabId, { $set: { 'permissions.accounts': addresses - }}); + } }); }); }); @@ -128,7 +131,7 @@ Template['layout_browserBar'].events({ @event blur */ - 'blur .app-bar > form.url .url-input': function(e, template) { + 'blur .app-bar > form.url .url-input': function (e, template) { template.$('.app-bar').removeClass('show-bar'); }, /* @@ -136,7 +139,7 @@ Template['layout_browserBar'].events({ @event mouseenter .app-bar */ - 'mouseenter .app-bar': function(e, template){ + 'mouseenter .app-bar': function (e, template) { clearTimeout(TemplateVar.get('timeoutId')); }, /* @@ -144,7 +147,7 @@ Template['layout_browserBar'].events({ @event submit */ - 'submit': function(e, template){ + 'submit': function (e, template) { var url = Helpers.formatUrl(template.$('.url-input')[0].value); // remove focus from url input @@ -154,13 +157,13 @@ Template['layout_browserBar'].events({ var url = Helpers.sanitizeUrl(url); var tabId = Helpers.getTabIdByUrl(url); - console.log('Submitted new URL:'+ url); + console.log('Submitted new URL:' + url); // update current tab url - Tabs.update(tabId, {$set: { + Tabs.update(tabId, { $set: { url: url, redirect: url - }}); + } }); LocalStore.set('selectedTab', tabId); } }); diff --git a/interface/client/templates/layout/sidebar.js b/interface/client/templates/layout/sidebar.js index 381909d04..21e232d00 100644 --- a/interface/client/templates/layout/sidebar.js +++ b/interface/client/templates/layout/sidebar.js @@ -11,7 +11,7 @@ The sidebar template @constructor */ -Template['layout_sidebar'].onRendered(function(){ +Template['layout_sidebar'].onRendered(function () { var template = this, $ul = template.$('nav > ul'); @@ -25,16 +25,17 @@ Template['layout_sidebar'].onRendered(function(){ cursor: 'move', delay: 150, revert: 200, - start: function(e){ + start: function (e) { $ul.sortable('refreshPositions'); }, - update: function(e){ + update: function (e) { console.log('UPDATED'); // iterate over the lis and reposition the items - $ul.find('> li').each(function(index, test){ + $ul.find('> li').each(function (index, test) { var id = $(this).data('tab-id'); - if(id) - Tabs.update(id, {$set: {position: index+1}}); + if (id) { + Tabs.update(id, { $set: { position: index + 1 } }); + } }); } }); @@ -47,15 +48,15 @@ Template['layout_sidebar'].helpers({ @method (tabs) */ - 'tabs': function() { - return Tabs.find({}, {sort: {position: 1}}).fetch(); + 'tabs': function () { + return Tabs.find({}, { sort: { position: 1 } }).fetch(); }, /** Return the correct name @method (name) */ - 'name': function() { + 'name': function () { return (this._id === 'browser') ? TAPi18n.__('mist.sidebar.buttons.browser') : this.name; }, /** @@ -63,7 +64,7 @@ Template['layout_sidebar'].helpers({ @method (icon) */ - 'icon': function() { + 'icon': function () { return (this._id === 'browser') ? 'icons/browse-icon@2x.png' : this.icon; }, /** @@ -71,19 +72,23 @@ Template['layout_sidebar'].helpers({ @method (subMenu) */ - 'subMenu': function(){ + 'subMenu': function () { var template = Template.instance(); - if(this._id === 'browser') { - return LastVisitedPages.find({},{sort: {timestamp: -1}, limit: 25}); + if (this._id === 'browser') { + return LastVisitedPages.find({}, { sort: { timestamp: -1 }, limit: 25 }); - } else if(this.menu) { + } else if (this.menu) { var menu = _.toArray(this.menu); // sort by position - menu.sort(function(a, b){ - if(a.position < b.position) return -1; - if(a.position > b.position) return 1; + menu.sort(function (a, b) { + if (a.position < b.position) { + return -1; + } + if (a.position > b.position) { + return 1; + } return 0; }); @@ -95,11 +100,12 @@ Template['layout_sidebar'].helpers({ @method (isSelected) */ - 'isSelected': function(){ + 'isSelected': function () { var selected = (LocalStore.get('selectedTab') === (this._id || 'browser')) ? 'selected' : ''; - if(this.menuVisible) + if (this.menuVisible) { selected += ' slided-out'; + } return selected; }, @@ -108,7 +114,7 @@ Template['layout_sidebar'].helpers({ @method (fullTabs) */ - 'fullTabs': function(){ + 'fullTabs': function () { return (LocalStore.get('fullTabs')) ? 'full-tabs' : ''; } }); @@ -120,7 +126,7 @@ Template['layout_sidebar'].events({ @event click button.main */ - 'click nav button.main': function(e, template){ + 'click nav button.main': function (e, template) { LocalStore.set('selectedTab', this._id || 'browser'); }, /** @@ -128,16 +134,16 @@ Template['layout_sidebar'].events({ @event click ul.sub-menu button */ - 'click nav ul.sub-menu button': function(e, template){ + 'click nav ul.sub-menu button': function (e, template) { var tabId = $(e.currentTarget).parent().parents('li').data('tab-id'); - var webview = $('webview[data-id="'+ tabId +'"]')[0]; + var webview = $('webview[data-id="' + tabId + '"]')[0]; // browser - if(tabId === 'browser') { - webviewLoadStart.call(webview, tabId, {newURL: this.url, type: 'side-bar-click', preventDefault: function(){}}); + if (tabId === 'browser') { + webviewLoadStart.call(webview, tabId, { newURL: this.url, type: 'side-bar-click', preventDefault: function () {} }); // dapp tab - } else if(webview) { + } else if (webview) { webview.send('mistAPI_callMenuFunction', this.id); LocalStore.set('selectedTab', tabId); } @@ -147,7 +153,7 @@ Template['layout_sidebar'].events({ @event button.slide-out */ - 'click button.slide-out': function(e, template){ + 'click button.slide-out': function (e, template) { var isSelected = (LocalStore.get('selectedTab') === (this._id || 'browser')); if (isSelected && LocalStore.get('fullTabs')) { @@ -155,7 +161,7 @@ Template['layout_sidebar'].events({ } else if (isSelected) { LocalStore.set('fullTabs', true); } else { - Tabs.update(this._id, {$set: {menuVisible: !this.menuVisible}}); + Tabs.update(this._id, { $set: { menuVisible: !this.menuVisible } }); } }, /** @@ -163,7 +169,7 @@ Template['layout_sidebar'].events({ @event .see-all button */ - 'click li.see-all > button': function(e, template){ + 'click li.see-all > button': function (e, template) { var isSelected = (LocalStore.get('selectedTab') === (this._id || 'browser')); if (isSelected && LocalStore.get('fullTabs')) { @@ -179,9 +185,10 @@ Template['layout_sidebar'].events({ @event click button.remove-tab */ - 'click button.remove-tab': function(){ - if (LocalStore.get('selectedTab') === this._id) + 'click button.remove-tab': function () { + if (LocalStore.get('selectedTab') === this._id) { LocalStore.set('selectedTab', 'browser'); + } Tabs.remove(this._id); }, diff --git a/interface/client/templates/layout/webviews.js b/interface/client/templates/layout/webviews.js index 2ed22b65f..baefbfa0c 100644 --- a/interface/client/templates/layout/webviews.js +++ b/interface/client/templates/layout/webviews.js @@ -17,7 +17,7 @@ Template['layout_webviews'].helpers({ @method (tabs) */ - 'tabs': function() { - return Tabs.find({}, {field: {position: 1}}); + 'tabs': function () { + return Tabs.find({}, { field: { position: 1 } }); } -}); \ No newline at end of file +}); diff --git a/interface/client/templates/popupWindows/about.js b/interface/client/templates/popupWindows/about.js index 18035af5b..3be06a553 100644 --- a/interface/client/templates/popupWindows/about.js +++ b/interface/client/templates/popupWindows/about.js @@ -11,7 +11,7 @@ The about template @class [template] popupWindows_about @constructor */ -Template['popupWindows_about'].onCreated(function(){ +Template['popupWindows_about'].onCreated(function () { }); diff --git a/interface/client/templates/popupWindows/clientUpdateAvailable.js b/interface/client/templates/popupWindows/clientUpdateAvailable.js index 8f55f2d5e..34c48f3fd 100644 --- a/interface/client/templates/popupWindows/clientUpdateAvailable.js +++ b/interface/client/templates/popupWindows/clientUpdateAvailable.js @@ -6,10 +6,10 @@ Template Controllers Template['popupWindows_clientUpdateAvailable'].events({ - 'click .ok': function(e){ + 'click .ok': function (e) { ipc.send('backendAction_windowCallback', 'update'); }, - 'click .cancel': function(e){ + 'click .cancel': function (e) { ipc.send('backendAction_windowCallback', 'skip'); }, }); diff --git a/interface/client/templates/popupWindows/connectAccount.js b/interface/client/templates/popupWindows/connectAccount.js index 4926030f9..90314a7e1 100644 --- a/interface/client/templates/popupWindows/connectAccount.js +++ b/interface/client/templates/popupWindows/connectAccount.js @@ -1,15 +1,15 @@ -var pinToSidebar = function() { +var pinToSidebar = function () { var selectedTab = Tabs.findOne(LocalStore.get('selectedTab')); - if(selectedTab) { + if (selectedTab) { var existingUserTab = Helpers.getTabIdByUrl(selectedTab.url); console.log(existingUserTab); console.log(selectedTab); - if(existingUserTab === 'browser') { + if (existingUserTab === 'browser') { var newTabId = Tabs.insert({ url: selectedTab.url, redirect: selectedTab.url, @@ -20,7 +20,7 @@ var pinToSidebar = function() { }); LocalStore.set('selectedTab', newTabId); - } else if(existingUserTab) { + } else if (existingUserTab) { LocalStore.set('selectedTab', existingUserTab); } @@ -28,7 +28,7 @@ var pinToSidebar = function() { var sameLastPage; // move the current browser tab to the last visited page - var lastPageItems = LastVisitedPages.find({}, {limit: 2, sort: {timestamp: -1}}).fetch(); + var lastPageItems = LastVisitedPages.find({}, { limit: 2, sort: { timestamp: -1 } }).fetch(); var lastPage = lastPageItems.pop(); var lastPageURL = lastPage ? lastPage.url : 'http://about:blank'; Tabs.update('browser', { @@ -37,23 +37,24 @@ var pinToSidebar = function() { }); // remove last page form last pages - if(sameLastPage = LastVisitedPages.findOne({url: selectedTab.url})) + if (sameLastPage = LastVisitedPages.findOne({ url: selectedTab.url })) { LastVisitedPages.remove(sameLastPage._id); + } } } }; -var updateSelectedTabAccounts = function(accounts){ +var updateSelectedTabAccounts = function (accounts) { var tabId = LocalStore.get('selectedTab'); - Tabs.update(tabId, {$set: { + Tabs.update(tabId, { $set: { 'permissions.accounts': accounts - }}); + } }); }; -Template['popupWindows_connectAccount'].onCreated(function() { - this.autorun(function(){ - var tab = Tabs.findOne(LocalStore.get('selectedTab'), {fields: {'permissions.accounts': 1}}); - var accounts = (tab && tab.permissions && tab.permissions.accounts) ? tab.permissions.accounts : []; +Template['popupWindows_connectAccount'].onCreated(function () { + this.autorun(function () { + var tab = Tabs.findOne(LocalStore.get('selectedTab'), { fields: { 'permissions.accounts': 1 } }); + var accounts = (tab && tab.permissions && tab.permissions.accounts) ? tab.permissions.accounts : []; TemplateVar.set('accounts', accounts); }); }); @@ -65,7 +66,7 @@ Template['popupWindows_connectAccount'].helpers({ @method (dapp) */ - dapp: function(){ + dapp: function () { return Tabs.findOne(LocalStore.get('selectedTab')); }, /** @@ -73,9 +74,9 @@ Template['popupWindows_connectAccount'].helpers({ @method (dappFriendlyURL) */ - dappFriendlyURL: function(){ - var currentTab = Tabs.findOne(LocalStore.get('selectedTab')) - if (currentTab && currentTab.url){ + dappFriendlyURL: function () { + var currentTab = Tabs.findOne(LocalStore.get('selectedTab')); + if (currentTab && currentTab.url) { return currentTab.url.replace(/^https?:\/\/(www\.)?/, '').replace(/\/$/, ''); } }, @@ -85,7 +86,7 @@ Template['popupWindows_connectAccount'].helpers({ @method accountNumber @return {Number} */ - 'accountNumber': function(){ + 'accountNumber': function () { var accounts = _.pluck(EthAccounts.find().fetch(), 'address'); return _.intersection(accounts, TemplateVar.get('accounts')).length; @@ -96,7 +97,7 @@ Template['popupWindows_connectAccount'].helpers({ @method selectedAccounts @return {Array} */ - 'selectedAccounts': function() { + 'selectedAccounts': function () { var accounts = _.pluck(EthAccounts.find().fetch(), 'address'); return _.intersection(accounts, TemplateVar.get('accounts')); }, @@ -106,7 +107,7 @@ Template['popupWindows_connectAccount'].helpers({ @method selected @return {String} "selected" */ - 'selected': function(){ + 'selected': function () { return (_.contains(TemplateVar.get('accounts'), this.address)) ? 'selected' : ''; } }); @@ -117,45 +118,46 @@ Template['popupWindows_connectAccount'].events({ @event click .dapp-account-list button */ - 'click .dapp-account-list button': function(e, template) { + 'click .dapp-account-list button': function (e, template) { e.preventDefault(); var accounts = TemplateVar.get('accounts'); - if(!_.contains(accounts, this.address)) + if (!_.contains(accounts, this.address)) { accounts.push(this.address); - else + } else { accounts = _.without(accounts, this.address); + } TemplateVar.set(template, 'accounts', accounts); }, - /** + /** Closes the popup @event click .cancel */ - 'click .cancel': function(e) { - ipc.send('backendAction_closePopupWindow'); - }, + 'click .cancel': function (e) { + ipc.send('backendAction_closePopupWindow'); + }, /** - Confirm or cancel the accounts available for this dapp and reload the dapp. @event click button.confirm, click button.cancel */ - 'click .ok, click .stay-anonymous': function(e) { + 'click .ok, click .stay-anonymous': function (e) { e.preventDefault(); var accounts = TemplateVar.get('accounts'); - + // Pin to sidebar, if needed if ($('#pin-to-sidebar')[0].checked) { pinToSidebar(); } - accounts = _.unique(_.flatten(accounts)); + accounts = _.unique(_.flatten(accounts)); // reload the webview ipc.send('backendAction_windowMessageToOwner', null, accounts); - setTimeout(function(){ + setTimeout(function () { ipc.send('backendAction_closePopupWindow'); }, 600); }, @@ -164,7 +166,7 @@ Template['popupWindows_connectAccount'].events({ @event click button.create-account */ - 'click button.create-account': function(e, template){ + 'click button.create-account': function (e, template) { ipc.send('mistAPI_createAccount'); } }); diff --git a/interface/client/templates/popupWindows/onboardingScreen.js b/interface/client/templates/popupWindows/onboardingScreen.js index 35ba0b732..106c735c3 100644 --- a/interface/client/templates/popupWindows/onboardingScreen.js +++ b/interface/client/templates/popupWindows/onboardingScreen.js @@ -12,37 +12,36 @@ The onboardingScreen template */ - /** Update the peercount @method getPeerCount */ -var getPeerCount = function(template) { - web3.net.getPeerCount(function(e, res) { - if(!e) +var getPeerCount = function (template) { + web3.net.getPeerCount(function (e, res) { + if (!e) { TemplateVar.set(template, 'peerCount', res); + } }); }; - -Template['popupWindows_onboardingScreen'].onCreated(function(){ +Template['popupWindows_onboardingScreen'].onCreated(function () { var template = this; TemplateVar.set('readyToLaunch', false); TemplateVar.set('newAccount', false); // check for block status - this.syncFilter = web3.eth.isSyncing(function(error, syncing) { - if(!error) { + this.syncFilter = web3.eth.isSyncing(function (error, syncing) { + if (!error) { - if(syncing === true) { + if (syncing === true) { web3.reset(true); - } else if(_.isObject(syncing)) { + } else if (_.isObject(syncing)) { // loads syncing data and adds it to old by using 'extend' var oldData = TemplateVar.get(template, 'syncing'); - TemplateVar.set(template, 'syncing', _.extend(oldData||{}, syncing||{})); + TemplateVar.set(template, 'syncing', _.extend(oldData || {}, syncing || {})); } else { TemplateVar.set(template, 'syncing', false); @@ -58,7 +57,7 @@ Template['popupWindows_onboardingScreen'].onCreated(function(){ getPeerCount(template); Meteor.clearInterval(this.peerCountIntervalId); - this.peerCountIntervalId = setInterval(function() { + this.peerCountIntervalId = setInterval(function () { getPeerCount(template); }, 1000); @@ -66,14 +65,14 @@ Template['popupWindows_onboardingScreen'].onCreated(function(){ TemplateVar.set('currentActive', 'start'); // store the last class - this.autorun(function(){ + this.autorun(function () { TemplateVar.set('lastActive', TemplateVar.get('currentActive')); }); -}) +}); Template['popupWindows_onboardingScreen'].helpers({ - 'newAccountLowerCase': function(){ + 'newAccountLowerCase': function () { var account = TemplateVar.get('newAccount'); return (account) ? account.toLowerCase() : ''; }, @@ -82,7 +81,7 @@ Template['popupWindows_onboardingScreen'].helpers({ @method syncStatus */ - 'syncStatus' : function() { + 'syncStatus': function () { // This functions loops trhough numbers while waiting for the node to respond var template = Template.instance(); @@ -90,7 +89,7 @@ Template['popupWindows_onboardingScreen'].helpers({ Meteor.clearInterval(template._intervalId); // Create an interval to quickly iterate trough the numbers - template._intervalId = Meteor.setInterval(function(){ + template._intervalId = Meteor.setInterval(function () { // load the sync information var syncing = TemplateVar.get(template, 'syncing'); @@ -99,9 +98,9 @@ Template['popupWindows_onboardingScreen'].helpers({ TemplateVar.set(template, 'readyToLaunch', false); // Calculates a block t display that is always getting a few % closer to target - syncing._displayBlock = (syncing._displayBlock + 2*(syncing.currentBlock - syncing._displayBlock) / 100 ) || Number(syncing.startingBlock); + syncing._displayBlock = (syncing._displayBlock + 2 * (syncing.currentBlock - syncing._displayBlock) / 100) || Number(syncing.startingBlock); - syncing._displayStatesDownload = Number(syncing._displayStatesDownload + (syncing.pulledStates/(1 +syncing.knownStates) - syncing._displayStatesDownload) / 100 ) || Number(syncing.pulledStates)/Number(syncing.knownStates + 1); + syncing._displayStatesDownload = Number(syncing._displayStatesDownload + (syncing.pulledStates / (1 + syncing.knownStates) - syncing._displayStatesDownload) / 100) || Number(syncing.pulledStates) / Number(syncing.knownStates + 1); // Calculates progress syncing.progress = 100 * (syncing._displayBlock - syncing.startingBlock) / (1 + Number(syncing.highestBlock) - syncing.startingBlock); @@ -110,7 +109,7 @@ Template['popupWindows_onboardingScreen'].helpers({ syncing.blockDiff = numeral(syncing.highestBlock - syncing.currentBlock).format('0,0'); syncing.highestBlockString = numeral(syncing.highestBlock).format('0,0'); syncing.displayBlock = numeral(Math.round(syncing._displayBlock)).format('0,0'); - syncing.statesPercent = numeral(Math.round(syncing._displayStatesDownload*10000)/100).format('0.00'); + syncing.statesPercent = numeral(Math.round(syncing._displayStatesDownload * 10000) / 100).format('0.00'); // Saves the data back to the object TemplateVar.set(template, 'syncing', syncing); @@ -118,17 +117,17 @@ Template['popupWindows_onboardingScreen'].helpers({ // If it's close enough, show the synced button - if (Number(syncing.highestBlock) - syncing.currentBlock < 100 ) { + if (Number(syncing.highestBlock) - syncing.currentBlock < 100) { TemplateVar.set(template, 'readyToLaunch', true); } // Only show states if they are changing - if (Math.round(1000*Number(syncing._displayStatesDownload)) !== Math.round(1000*Number(syncing.pulledStates/(syncing.knownStates+1)))) { - TemplateVar.set(template, "syncStatusMessageLive", TAPi18n.__('mist.popupWindows.onboarding.syncMessageWithStates', syncing)); - } else if (syncing.displayBlock == '0') { - TemplateVar.set(template, "syncStatusMessageLive", ''); + if (Math.round(1000 * Number(syncing._displayStatesDownload)) !== Math.round(1000 * Number(syncing.pulledStates / (syncing.knownStates + 1)))) { + TemplateVar.set(template, 'syncStatusMessageLive', TAPi18n.__('mist.popupWindows.onboarding.syncMessageWithStates', syncing)); + } else if (syncing.displayBlock === '0') { + TemplateVar.set(template, 'syncStatusMessageLive', ''); } else { - TemplateVar.set(template, "syncStatusMessageLive", TAPi18n.__('mist.popupWindows.onboarding.syncMessage', syncing)); + TemplateVar.set(template, 'syncStatusMessageLive', TAPi18n.__('mist.popupWindows.onboarding.syncMessage', syncing)); } } @@ -139,63 +138,66 @@ Template['popupWindows_onboardingScreen'].helpers({ @method syncStatusMessage */ - 'syncStatusMessage' : function() { - return TemplateVar.get("syncStatusMessageLive"); + 'syncStatusMessage': function () { + return TemplateVar.get('syncStatusMessageLive'); } }); Template['popupWindows_onboardingScreen'].events({ - 'click .goto-start': function(e){ - TemplateVar.set('currentActive','start'); + 'click .goto-start': function (e) { + TemplateVar.set('currentActive', 'start'); }, - 'click .goto-import-account': function(){ - TemplateVar.set('currentActive','import-account'); + 'click .goto-import-account': function () { + TemplateVar.set('currentActive', 'import-account'); // if testnet, make sure to switch to the mainnet - if(TemplateVar.get('testnet')) { + if (TemplateVar.get('testnet')) { ipc.send('onBoarding_changeNet', false); TemplateVar.set('testnet', false); TemplateVar.set('syncing', null); } }, - 'click .start-testnet': function(e, template){ - if(!TemplateVar.get('testnet')) { + 'click .start-testnet': function (e, template) { + if (!TemplateVar.get('testnet')) { ipc.send('onBoarding_changeNet', true); TemplateVar.set('testnet', true); TemplateVar.set('syncing', null); } - TemplateVar.set('currentActive','testnet'); + TemplateVar.set('currentActive', 'testnet'); template.$('.onboarding-testnet input.password').focus(); }, - 'click .goto-password': function(e, template){ - TemplateVar.set('currentActive','password'); + 'click .goto-password': function (e, template) { + TemplateVar.set('currentActive', 'password'); template.$('.onboarding-password input.password').focus(); }, - 'click .goto-account': function(){ - TemplateVar.set('currentActive','account'); + 'click .goto-account': function () { + TemplateVar.set('currentActive', 'account'); }, - 'click .goto-tutorial-1': function(){ - TemplateVar.set('currentActive','tutorial-1'); - if (!TemplateVar.get('syncing')) + 'click .goto-tutorial-1': function () { + TemplateVar.set('currentActive', 'tutorial-1'); + if (!TemplateVar.get('syncing')) { TemplateVar.set('readyToLaunch', true); + } }, - 'click .goto-tutorial-2': function(){ - TemplateVar.set('currentActive','tutorial-2'); - if (!TemplateVar.get('syncing')) + 'click .goto-tutorial-2': function () { + TemplateVar.set('currentActive', 'tutorial-2'); + if (!TemplateVar.get('syncing')) { TemplateVar.set('readyToLaunch', true); + } }, - 'click .goto-tutorial-3': function(){ - TemplateVar.set('currentActive','tutorial-3'); - if (!TemplateVar.get('syncing')) + 'click .goto-tutorial-3': function () { + TemplateVar.set('currentActive', 'tutorial-3'); + if (!TemplateVar.get('syncing')) { TemplateVar.set('readyToLaunch', true); + } }, /** Start the application @event click .launch-app */ - 'click .launch-app': function(){ + 'click .launch-app': function () { ipc.send('onBoarding_launchApp'); }, /** @@ -203,7 +205,7 @@ Template['popupWindows_onboardingScreen'].events({ @event dragover .onboarding-screen, drop .onboarding-screen */ - 'dragover .onboarding-screen, drop .onboarding-screen': function(e){ + 'dragover .onboarding-screen, drop .onboarding-screen': function (e) { e.preventDefault(); } }); @@ -222,10 +224,10 @@ Template['popupWindows_onboardingScreen_importAccount'].helpers({ @method showPassword */ - 'showPassword': function() { - return TemplateVar.get('showPassword')? 'text' : 'password' ; + 'showPassword': function () { + return TemplateVar.get('showPassword') ? 'text' : 'password'; } -}) +}); Template['popupWindows_onboardingScreen_importAccount'].events({ @@ -234,7 +236,7 @@ Template['popupWindows_onboardingScreen_importAccount'].events({ @event dragenter .dropable */ - 'dragenter .dropable': function(e){ + 'dragenter .dropable': function (e) { $(e.currentTarget).addClass('active'); }, /** @@ -242,7 +244,7 @@ Template['popupWindows_onboardingScreen_importAccount'].events({ @event dragleave .dropable */ - 'dragleave .dropable': function(e){ + 'dragleave .dropable': function (e) { $(e.currentTarget).removeClass('active'); }, /** @@ -250,26 +252,28 @@ Template['popupWindows_onboardingScreen_importAccount'].events({ @event drop .dropable */ - 'drop .dropable': function(e, template) { + 'drop .dropable': function (e, template) { e.preventDefault(); - if (e.originalEvent.dataTransfer) files = e.originalEvent.dataTransfer.files; + if (e.originalEvent.dataTransfer) { + files = e.originalEvent.dataTransfer.files; + } if (files.length) { ipc.send('backendAction_checkWalletFile', files[0].path); - ipc.on('uiAction_checkedWalletFile', function(e, error, type) { + ipc.on('uiAction_checkedWalletFile', function (e, error, type) { switch (type) { case 'presale': TemplateVar.set(template, 'filePath', files[0].path); - Tracker.afterFlush(function() { + Tracker.afterFlush(function () { template.$('.password').focus(); }); break; case 'web3': TemplateVar.set(template, 'filePath', files[0].path); TemplateVar.set(template, 'importing', true); - setTimeout(function() { + setTimeout(function () { ipc.send('backendAction_closePopupWindow'); }, 750); break; @@ -289,7 +293,7 @@ Template['popupWindows_onboardingScreen_importAccount'].events({ @event dragover .dropable */ - 'dragover .dropable': function(e){ + 'dragover .dropable': function (e) { e.preventDefault(); }, /** @@ -297,31 +301,31 @@ Template['popupWindows_onboardingScreen_importAccount'].events({ @event click .show-password */ - 'click .show-password': function(e){ - TemplateVar.set('showPassword', e.currentTarget.checked) + 'click .show-password': function (e) { + TemplateVar.set('showPassword', e.currentTarget.checked); }, /** Checks the password match sends the file path and password to the mist backend to import @event submit form */ - 'submit form': function(e, template){ + 'submit form': function (e, template) { var pw = template.find('input.password').value; ipc.send('backendAction_importWalletFile', TemplateVar.get('filePath'), pw); TemplateVar.set('importing', true); - ipc.on('uiAction_importedWalletFile', function(e, error, address){ + ipc.on('uiAction_importedWalletFile', function (e, error, address) { TemplateVar.set(template, 'importing', false); TemplateVar.set(template, 'filePath', false); - if(address) { + if (address) { ipc.removeAllListeners('uiAction_importedWalletFile'); console.log('Imported account: ', address); // move to add account screen, when in the onboarding window - if($('.onboarding-start')[0]) { + if ($('.onboarding-start')[0]) { TemplateVar.setTo('.onboarding-account', 'newAccount', web3.toChecksumAddress(address)); TemplateVar.setTo('.onboarding-screen', 'currentActive', 'account'); @@ -334,14 +338,14 @@ Template['popupWindows_onboardingScreen_importAccount'].events({ } else { console.log('Import failed', error); - if(error === 'Decryption Failed') { + if (error === 'Decryption Failed') { GlobalNotification.warning({ content: TAPi18n.__('mist.popupWindows.onboarding.errors.wrongPassword'), duration: 4 }); } else { GlobalNotification.warning({ - content: TAPi18n.__('mist.popupWindows.onboarding.errors.importFailed', {error: error}), + content: TAPi18n.__('mist.popupWindows.onboarding.errors.importFailed', { error: error }), duration: 4 }); } @@ -355,7 +359,6 @@ Template['popupWindows_onboardingScreen_importAccount'].events({ }); - /** The onboardingScreen password template @@ -369,10 +372,10 @@ Template['popupWindows_onboardingScreen_password'].helpers({ @method showPassword */ - 'passwordInputType': function() { - return TemplateVar.get('passwordInputType')? 'text' : 'password' ; + 'passwordInputType': function () { + return TemplateVar.get('passwordInputType') ? 'text' : 'password'; } -}) +}); Template['popupWindows_onboardingScreen_password'].events({ @@ -381,7 +384,7 @@ Template['popupWindows_onboardingScreen_password'].events({ @event click button[type="button"] */ - 'click button[type="button"]': function(e, template){ + 'click button[type="button"]': function (e, template) { template.find('input.password').value = ''; template.find('input.password-repeat').value = ''; }, @@ -390,15 +393,15 @@ Template['popupWindows_onboardingScreen_password'].events({ @event click .show-password */ - 'click .show-password': function(e){ - TemplateVar.set('passwordInputType', e.currentTarget.checked) + 'click .show-password': function (e) { + TemplateVar.set('passwordInputType', e.currentTarget.checked); }, /** Password checks @event click button[type="button"] */ - 'input input, change input': function(e, template){ + 'input input, change input': function (e, template) { var pw = template.find('input.password').value, pwRepeat = template.find('input.password-repeat').value; @@ -411,11 +414,11 @@ Template['popupWindows_onboardingScreen_password'].events({ @event submit form */ - 'submit form': function(e, template){ + 'submit form': function (e, template) { var pw = template.find('input.password').value, pwRepeat = template.find('input.password-repeat').value; - if( pw !== pwRepeat) { + if (pw !== pwRepeat) { GlobalNotification.warning({ content: TAPi18n.__('mist.popupWindows.requestAccount.errors.passwordMismatch'), duration: 3 @@ -427,10 +430,10 @@ Template['popupWindows_onboardingScreen_password'].events({ }); } else if (pw && pw.length >= 9) { TemplateVar.set('creatingPassword', true); - web3.personal.newAccount(pw, function(e, res){ + web3.personal.newAccount(pw, function (e, res) { TemplateVar.set(template, 'creatingPassword', false); - if(!e) { + if (!e) { TemplateVar.setTo('.onboarding-account', 'newAccount', web3.toChecksumAddress(res)); TemplateVar.setTo('.onboarding-screen', 'currentActive', 'account'); diff --git a/interface/client/templates/popupWindows/requestAccount.js b/interface/client/templates/popupWindows/requestAccount.js index 294d2ed93..54a3f49c5 100644 --- a/interface/client/templates/popupWindows/requestAccount.js +++ b/interface/client/templates/popupWindows/requestAccount.js @@ -11,31 +11,31 @@ The request account popup window template @constructor */ -Template['popupWindows_requestAccount'].onRendered(function(){ +Template['popupWindows_requestAccount'].onRendered(function () { this.$('input.password').focus(); TemplateVar.set('showPassword', false); }); Template['popupWindows_requestAccount'].helpers({ - 'passwordInputType': function() { - return TemplateVar.get('showPassword')? 'text' : 'password'; + 'passwordInputType': function () { + return TemplateVar.get('showPassword') ? 'text' : 'password'; } }); Template['popupWindows_requestAccount'].events({ - 'click .cancel': function(){ + 'click .cancel': function () { ipc.send('backendAction_closePopupWindow'); - }, - 'click .show-password': function(e){ - TemplateVar.set('showPassword', e.currentTarget.checked) }, - 'submit form': function(e, template){ + 'click .show-password': function (e) { + TemplateVar.set('showPassword', e.currentTarget.checked); + }, + 'submit form': function (e, template) { e.preventDefault(); var pw = template.find('input.password').value; - var pwRepeat = template.find('input.password-repeat').value; + var pwRepeat = template.find('input.password-repeat').value; // ask for password repeat - if(!pwRepeat) { + if (!pwRepeat) { TemplateVar.set('password-repeat', true); template.$('input.password-repeat').focus(); @@ -43,19 +43,20 @@ Template['popupWindows_requestAccount'].events({ return; // check passwords - } else if(pwRepeat === pw) { + } else if (pwRepeat === pw) { TemplateVar.set('creating', true); - web3.personal.newAccount(pwRepeat, function(e, res){ - if(!e) + web3.personal.newAccount(pwRepeat, function (e, res) { + if (!e) { ipc.send('backendAction_windowMessageToOwner', null, res); - else + } else { ipc.send('backendAction_windowMessageToOwner', e); + } TemplateVar.set(template, 'creating', false); ipc.send('backendAction_closePopupWindow'); }); - + } else { template.$('.password').focus(); @@ -69,5 +70,5 @@ Template['popupWindows_requestAccount'].events({ template.find('input.password-repeat').value = ''; template.find('input.password').value = ''; pw = pwRepeat = null; - } + } }); diff --git a/interface/client/templates/popupWindows/sendTransactionConfirmation.js b/interface/client/templates/popupWindows/sendTransactionConfirmation.js index cad0bbb16..02b048214 100644 --- a/interface/client/templates/popupWindows/sendTransactionConfirmation.js +++ b/interface/client/templates/popupWindows/sendTransactionConfirmation.js @@ -4,11 +4,11 @@ Template Controllers @module Templates */ -var setWindowSize = function(template){ - Tracker.afterFlush(function(){ +var setWindowSize = function (template) { + Tracker.afterFlush(function () { ipc.send('backendAction_setWindowSize', 580, template.$('.popup-windows .inner-container').height() + 240); }); -} +}; var defaultEstimateGas = 50000000; @@ -27,22 +27,22 @@ human readable text signature. @method (lookupFunctionSignature) */ -var lookupFunctionSignature = function(data, remoteLookup) { - return new Q(function(resolve, reject) { - if(data && data.length > 8) { +var lookupFunctionSignature = function (data, remoteLookup) { + return new Q(function (resolve, reject) { + if (data && data.length > 8) { var bytesSignature = (data.substr(0, 2) === '0x') ? data.substr(0, 10) - : '0x'+ data.substr(0, 8); + : '0x' + data.substr(0, 8); if (remoteLookup) { - https.get('https://www.4byte.directory/api/v1/signatures/?hex_signature=' + bytesSignature, function(response) { + https.get('https://www.4byte.directory/api/v1/signatures/?hex_signature=' + bytesSignature, function (response) { var body = ''; - response.on('data', function(chunk){ + response.on('data', function (chunk) { body += chunk; }); - response.on('end', function(){ + response.on('end', function () { var responseData = JSON.parse(body); if (responseData.results.length) { resolve(responseData.results[0].text_signature); @@ -50,33 +50,30 @@ var lookupFunctionSignature = function(data, remoteLookup) { resolve(bytesSignature); } }); - }).on('error', function(error) { + }).on('error', function (error) { console.warn('Error querying Function Signature Registry.', err); reject(bytesSignature); }); - } else { - if (_.first(window.SIGNATURES[bytesSignature])) { + } else if (_.first(window.SIGNATURES[bytesSignature])) { resolve(_.first(window.SIGNATURES[bytesSignature])); - } - else { + } else { reject(bytesSignature); } - } } else { - reject(undefined); + reject(undefined); } }); -} +}; -var localSignatureLookup = function(data){ +var localSignatureLookup = function (data) { return lookupFunctionSignature(data, false); }; -var remoteSignatureLookup = function(data){ +var remoteSignatureLookup = function (data) { return lookupFunctionSignature(data, true); }; -var signatureLookupCallback = function(textSignature) { +var signatureLookupCallback = function (textSignature) { // Clean version of function signature. Striping params TemplateVar.set(template, 'executionFunction', textSignature.replace(/\(.+$/g, '')); TemplateVar.set(template, 'hasSignature', true); @@ -90,32 +87,33 @@ var signatureLookupCallback = function(textSignature) { }; -Template['popupWindows_sendTransactionConfirmation'].onCreated(function(){ +Template['popupWindows_sendTransactionConfirmation'].onCreated(function () { var template = this; - ipc.on('uiAction_decodedFunctionSignatures', function(event, params) { + ipc.on('uiAction_decodedFunctionSignatures', function (event, params) { console.log('params returned', params); TemplateVar.set(template, 'params', params); }); // check reactively if provided gas is enough - this.autorun(function(){ - if(TemplateVar.get('estimatedGas') > Number(TemplateVar.get('providedGas'))) + this.autorun(function () { + if (TemplateVar.get('estimatedGas') > Number(TemplateVar.get('providedGas'))) { TemplateVar.set('gasError', 'notEnoughGas'); - else if(TemplateVar.get('estimatedGas') > 4000000) + } else if (TemplateVar.get('estimatedGas') > 4000000) { TemplateVar.set('gasError', 'overBlockGasLimit'); - else + } else { TemplateVar.set('gasError', null); + } }); // check inital data and gas estimates - this.autorun(function(){ + this.autorun(function () { TemplateVar.set(template, 'displayDecodedParams', true); var data = Session.get('data'); - if(data) { + if (data) { // set window size @@ -126,26 +124,26 @@ Template['popupWindows_sendTransactionConfirmation'].onCreated(function(){ TemplateVar.set('initialProvidedGas', data.gas || 0); // add gasPrice if not set - if(!data.gasPrice) { - web3.eth.getGasPrice(function(e, res){ - if(!e) { - data.gasPrice = '0x'+ res.toString(16); + if (!data.gasPrice) { + web3.eth.getGasPrice(function (e, res) { + if (!e) { + data.gasPrice = '0x' + res.toString(16); Session.set('data', data); } }); } // check if to is a contract - if(data.to) { - web3.eth.getCode(data.to, function(e, res){ - if(!e && res && res.length > 2) { + if (data.to) { + web3.eth.getCode(data.to, function (e, res) { + if (!e && res && res.length > 2) { TemplateVar.set(template, 'toIsContract', true); setWindowSize(template); } }); if (data.data) { - localSignatureLookup(data.data).then(function(textSignature) { + localSignatureLookup(data.data).then(function (textSignature) { // Clean version of function signature. Striping params TemplateVar.set(template, 'executionFunction', textSignature.replace(/\(.+$/g, '')); TemplateVar.set(template, 'hasSignature', true); @@ -155,15 +153,15 @@ Template['popupWindows_sendTransactionConfirmation'].onCreated(function(){ TemplateVar.set(template, 'executionFunctionParamTypes', params); ipc.send('backendAction_decodeFunctionSignature', textSignature, data.data); } - }).catch(function(bytesSignature) { + }).catch(function (bytesSignature) { TemplateVar.set(template, 'executionFunction', bytesSignature); TemplateVar.set(template, 'hasSignature', false); }); } } - if(data.from) { - web3.eth.getCode(data.from, function(e, res){ - if(!e && res && res.length > 2) { + if (data.from) { + web3.eth.getCode(data.from, function (e, res) { + if (!e && res && res.length > 2) { TemplateVar.set(template, 'fromIsContract', true); } }); @@ -172,21 +170,22 @@ Template['popupWindows_sendTransactionConfirmation'].onCreated(function(){ // estimate gas usage var estimateData = _.clone(data); estimateData.gas = defaultEstimateGas; - web3.eth.estimateGas(estimateData, function(e, res){ + web3.eth.estimateGas(estimateData, function (e, res) { console.log('Estimated gas: ', res, e); - if(!e && res) { + if (!e && res) { // set the gas to the estimation, if not provided or lower - Tracker.nonreactive(function(){ + Tracker.nonreactive(function () { var gas = Number(TemplateVar.get(template, 'providedGas')); - if(res === defaultEstimateGas) + if (res === defaultEstimateGas) { return TemplateVar.set(template, 'estimatedGas', 'invalid'); + } TemplateVar.set(template, 'estimatedGas', res); - if(!gas && res) { + if (!gas && res) { TemplateVar.set(template, 'providedGas', res + 100000); TemplateVar.set(template, 'initialProvidedGas', res + 100000); } @@ -197,10 +196,10 @@ Template['popupWindows_sendTransactionConfirmation'].onCreated(function(){ }); }); -Template['popupWindows_sendTransactionConfirmation'].onRendered(function(){ +Template['popupWindows_sendTransactionConfirmation'].onRendered(function () { var template = this; - Meteor.setTimeout(function(){ + Meteor.setTimeout(function () { template.$('input[type="password"]').focus(); }, 200); }); @@ -211,40 +210,42 @@ Template['popupWindows_sendTransactionConfirmation'].helpers({ @method (totalAmount) */ - 'totalAmount': function(){ + 'totalAmount': function () { var amount = EthTools.formatBalance(this.value, '0,0.00[0000000000000000]', 'ether'); var dotPos = (~amount.indexOf('.')) ? amount.indexOf('.') + 3 : amount.indexOf(',') + 3; - return amount ? amount.substr(0, dotPos) + ''+ amount.substr(dotPos) +'' : '0'; + return amount ? amount.substr(0, dotPos) + '' + amount.substr(dotPos) + '' : '0'; }, /** Calculates the fee used for this transaction in ether @method (estimatedFee) */ - 'estimatedFee': function() { - var gas = TemplateVar.get('estimatedGas'); - if(gas && this.gasPrice) + 'estimatedFee': function () { + var gas = TemplateVar.get('estimatedGas'); + if (gas && this.gasPrice) { return EthTools.formatBalance(new BigNumber(gas, 10).times(new BigNumber(this.gasPrice, 10)), '0,0.0[0000000] unit', 'ether'); + } }, /** Calculates the provided gas amount in ether @method (providedGas) */ - 'providedGas': function() { - var gas = TemplateVar.get('providedGas'); - if(gas && this.gasPrice) + 'providedGas': function () { + var gas = TemplateVar.get('providedGas'); + if (gas && this.gasPrice) { return EthTools.formatBalance(new BigNumber(gas, 10).times(new BigNumber(this.gasPrice, 10)), '0,0.0[0000000]', 'ether'); + } }, /** Shortens the address to 0xffff...ffff @method (shortenAddress) */ - 'shortenAddress': function(address){ - if(_.isString(address)) { - return address.substr(0,6) +'...'+ address.substr(-4); + 'shortenAddress': function (address) { + if (_.isString(address)) { + return address.substr(0, 6) + '...' + address.substr(-4); } }, /** @@ -252,13 +253,13 @@ Template['popupWindows_sendTransactionConfirmation'].helpers({ @method (formattedData) */ - 'formattedData': function(){ + 'formattedData': function () { return (TemplateVar.get('toIsContract')) - ? this.data.replace(/([0]{2,})/g,'$1').replace(/(0x[a-f0-9]{8})/i,'$1') - : this.data.replace(/([0]{2,})/g,'$1'); + ? this.data.replace(/([0]{2,})/g, '$1').replace(/(0x[a-f0-9]{8})/i, '$1') + : this.data.replace(/([0]{2,})/g, '$1'); }, - 'params': function() { + 'params': function () { return TemplateVar.get('params'); }, /** @@ -266,7 +267,7 @@ Template['popupWindows_sendTransactionConfirmation'].helpers({ @method (showFormattedParams) */ - 'showFormattedParams': function() { + 'showFormattedParams': function () { return TemplateVar.get('params') && TemplateVar.get('displayDecodedParams'); }, /** @@ -274,7 +275,7 @@ Template['popupWindows_sendTransactionConfirmation'].helpers({ @method (transactionInvalid) */ - 'transactionInvalid': function() { + 'transactionInvalid': function () { return TemplateVar.get('estimatedGas') === 'invalid' || TemplateVar.get('estimatedGas') === 0 || typeof TemplateVar.get('estimatedGas') === 'undefined'; @@ -287,8 +288,8 @@ Template['popupWindows_sendTransactionConfirmation'].events({ @event change .provided-gas, input .provided-gas */ - 'change .provided-gas, input .provided-gas': function(e, template){ - var gas = template.$('.provided-gas').text().replace(/[, ]+/g,'');//template.$('.provided-gas').text(); + 'change .provided-gas, input .provided-gas': function (e, template) { + var gas = template.$('.provided-gas').text().replace(/[, ]+/g, '');// template.$('.provided-gas').text(); TemplateVar.set('providedGas', gas); }, @@ -297,7 +298,7 @@ Template['popupWindows_sendTransactionConfirmation'].events({ @event click .not-enough-gas */ - 'click .not-enough-gas': function(){ + 'click .not-enough-gas': function () { var gas = Number(TemplateVar.get('estimatedGas')) + 100000; TemplateVar.set('initialProvidedGas', gas); TemplateVar.set('providedGas', gas); @@ -307,7 +308,7 @@ Template['popupWindows_sendTransactionConfirmation'].events({ @event click .cancel */ - 'click .cancel': function(){ + 'click .cancel': function () { ipc.send('backendAction_unlockedAccountAndSentTransaction', 'Transaction not confirmed'); ipc.send('backendAction_closePopupWindow'); }, @@ -316,7 +317,7 @@ Template['popupWindows_sendTransactionConfirmation'].events({ @event submit form */ - 'submit form': function(e, template){ + 'submit form': function (e, template) { e.preventDefault(); var data = Session.get('data'), @@ -335,42 +336,43 @@ Template['popupWindows_sendTransactionConfirmation'].events({ console.log('Choosen Gas: ', gas, TemplateVar.get('providedGas')); - if(!gas || !_.isFinite(gas)) + if (!gas || !_.isFinite(gas)) { return; - else + } else { data.gas = gas; + } TemplateVar.set('unlocking', true); // unlock and send transaction! - web3.personal.sendTransaction(data, pw || '', function(e, res){ + web3.personal.sendTransaction(data, pw || '', function (e, res) { pw = null; TemplateVar.set(template, 'unlocking', false); - if(!e && res) { + if (!e && res) { ipc.send('backendAction_unlockedAccountAndSentTransaction', null, res); } else { - Tracker.afterFlush(function(){ + Tracker.afterFlush(function () { template.find('input[type="password"]').value = ''; template.$('input[type="password"]').focus(); }); - if(e.message.indexOf('Unable to connect to socket: timeout') !== -1) { + if (e.message.indexOf('Unable to connect to socket: timeout') !== -1) { GlobalNotification.warning({ content: TAPi18n.__('mist.popupWindows.sendTransactionConfirmation.errors.connectionTimeout'), duration: 5 }); - } else if(e.message.indexOf('could not decrypt key with given passphrase') !== -1) { + } else if (e.message.indexOf('could not decrypt key with given passphrase') !== -1) { GlobalNotification.warning({ content: TAPi18n.__('mist.popupWindows.sendTransactionConfirmation.errors.wrongPassword'), duration: 3 }); - } else if(e.message.indexOf('multiple keys match address') !== -1) { + } else if (e.message.indexOf('multiple keys match address') !== -1) { GlobalNotification.warning({ content: TAPi18n.__('mist.popupWindows.sendTransactionConfirmation.errors.multipleKeysMatchAddress'), duration: 10 }); - } else if(e.message.indexOf('Insufficient funds for gas * price + value') !== -1) { + } else if (e.message.indexOf('Insufficient funds for gas * price + value') !== -1) { GlobalNotification.warning({ content: TAPi18n.__('mist.popupWindows.sendTransactionConfirmation.errors.insufficientFundsForGas'), duration: 5 @@ -383,19 +385,19 @@ Template['popupWindows_sendTransactionConfirmation'].events({ } } }); - }, + }, - 'click .data .toggle-panel': function() { + 'click .data .toggle-panel': function () { TemplateVar.set('displayDecodedParams', true); - }, - 'click .parameters .toggle-panel': function() { + }, + 'click .parameters .toggle-panel': function () { TemplateVar.set('displayDecodedParams', false); - }, - 'click .lookup-function-signature': function(e, template) { + }, + 'click .lookup-function-signature': function (e, template) { var data = Session.get('data'); TemplateVar.set('lookingUpFunctionSignature', true); - remoteSignatureLookup(data.data).then(function(textSignature) { + remoteSignatureLookup(data.data).then(function (textSignature) { TemplateVar.set(template, 'lookingUpFunctionSignature', false); // Clean version of function signature. Striping params @@ -408,10 +410,10 @@ Template['popupWindows_sendTransactionConfirmation'].events({ TemplateVar.set(template, 'executionFunctionParamTypes', params); ipc.send('backendAction_decodeFunctionSignature', textSignature, data.data); } - }).catch(function(bytesSignature) { + }).catch(function (bytesSignature) { TemplateVar.set(template, 'lookingUpFunctionSignature', false); TemplateVar.set(template, 'executionFunction', bytesSignature); TemplateVar.set(template, 'hasSignature', false); }); - } + } }); diff --git a/interface/client/templates/popupWindows/splashScreen.js b/interface/client/templates/popupWindows/splashScreen.js index 08244ab3c..24ab06c37 100644 --- a/interface/client/templates/popupWindows/splashScreen.js +++ b/interface/client/templates/popupWindows/splashScreen.js @@ -22,11 +22,11 @@ var lastSyncData = {}, showNodeLog = true; -Template['popupWindows_splashScreen'].onCreated(function(){ +Template['popupWindows_splashScreen'].onCreated(function () { var template = this; template._intervalId = null; - ipc.on('uiAction_nodeLogText', function(e, text, data) { + ipc.on('uiAction_nodeLogText', function (e, text, data) { if (showNodeLog && data) { TemplateVar.set(template, 'logText', data); TemplateVar.set(template, 'syncStatusMessage', false); @@ -34,7 +34,7 @@ Template['popupWindows_splashScreen'].onCreated(function(){ } }); - ipc.on('uiAction_clientBinaryStatus', function(e, status) { + ipc.on('uiAction_clientBinaryStatus', function (e, status) { TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.clientBinaries.' + status)); TemplateVar.set(template, 'showNetworkIndicator', status === 'done'); TemplateVar.set(template, 'showProgressBar', false); @@ -43,48 +43,48 @@ Template['popupWindows_splashScreen'].onCreated(function(){ }); - ipc.on('uiAction_nodeStatus', function(e, status, errorTag) { + ipc.on('uiAction_nodeStatus', function (e, status, errorTag) { switch (status) { - case 'starting': - TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeStarting')); - showNodeLog = true; - TemplateVar.set(template, 'logText', null); - TemplateVar.set(template, 'showProgressBar', false); - TemplateVar.set(template, 'showStartAppButton', false); - break; - - case 'started': - TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeStarted')); - break; - - case 'connected': - TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeConnected')); - lastSyncData = {}; - break; - - case 'stopping': - TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeStopping')); - TemplateVar.set(template, 'showProgressBar', false); - TemplateVar.set(template, 'showStartAppButton', false); - break; - - case 'stopped': - TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeStopped')); - break; - - case 'connectionTimeout': - TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeConnectionTimeout')); - break; - - case 'error': - errorTag = 'mist.startScreen.' + (errorTag || 'nodeError'); - - TemplateVar.set(template, 'text', TAPi18n.__(errorTag)); - break; + case 'starting': + TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeStarting')); + showNodeLog = true; + TemplateVar.set(template, 'logText', null); + TemplateVar.set(template, 'showProgressBar', false); + TemplateVar.set(template, 'showStartAppButton', false); + break; + + case 'started': + TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeStarted')); + break; + + case 'connected': + TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeConnected')); + lastSyncData = {}; + break; + + case 'stopping': + TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeStopping')); + TemplateVar.set(template, 'showProgressBar', false); + TemplateVar.set(template, 'showStartAppButton', false); + break; + + case 'stopped': + TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeStopped')); + break; + + case 'connectionTimeout': + TemplateVar.set(template, 'text', TAPi18n.__('mist.startScreen.nodeConnectionTimeout')); + break; + + case 'error': + errorTag = 'mist.startScreen.' + (errorTag || 'nodeError'); + + TemplateVar.set(template, 'text', TAPi18n.__(errorTag)); + break; } }); - ipc.on('uiAction_nodeSyncStatus', function(e, status, data) { + ipc.on('uiAction_nodeSyncStatus', function (e, status, data) { console.trace('Node sync status', status, data); TemplateVar.set(template, 'smallClass', 'small'); @@ -102,11 +102,11 @@ Template['popupWindows_splashScreen'].onCreated(function(){ lastSyncData = _.extend(lastSyncData, data || {}); // Select the appropriate message - if(web3.net.peerCount > 0) { + if (web3.net.peerCount > 0) { // Check which state we are - if ( 0 < lastSyncData._displayKnownStates && ( + if (0 < lastSyncData._displayKnownStates && ( Number(lastSyncData.pulledStates) !== Math.round(lastSyncData._displayState) - || Number(lastSyncData.knownStates) !== Math.round(lastSyncData._displayKnownStates)) + || Number(lastSyncData.knownStates) !== Math.round(lastSyncData._displayKnownStates)) ) { // Mostly downloading new states translationString = 'mist.startScreen.nodeSyncInfoStates'; @@ -136,7 +136,7 @@ Template['popupWindows_splashScreen'].onCreated(function(){ translationString = 'mist.startScreen.nodeSyncConnecting'; } - TemplateVar.set(template, 'lastSyncData', {'peers': web3.net.peerCount}); + TemplateVar.set(template, 'lastSyncData', { 'peers': web3.net.peerCount }); } @@ -154,7 +154,7 @@ Template['popupWindows_splashScreen'].helpers({ @method mode */ - 'mode': function(){ + 'mode': function () { return window.mistMode; }, /** @@ -162,7 +162,7 @@ Template['popupWindows_splashScreen'].helpers({ @method iconPath */ - 'iconPath': function(){ + 'iconPath': function () { return 'file://' + window.dirname + '/icons/' + window.mistMode + '/icon2x.png'; }, /** @@ -170,17 +170,17 @@ Template['popupWindows_splashScreen'].helpers({ @method syncStatus */ - 'syncStatus' : function() { + 'syncStatus': function () { // This functions loops trhough numbers while waiting for the node to respond var template = Template.instance(); Meteor.clearInterval(template._intervalId); // Create an interval to quickly iterate trough the numbers - template._intervalId = Meteor.setInterval(function(){ + template._intervalId = Meteor.setInterval(function () { // loads data from templates var syncData = TemplateVar.get(template, 'lastSyncData', lastSyncData); - var translationString = TemplateVar.get(template, "syncStatusMessage"); + var translationString = TemplateVar.get(template, 'syncStatusMessage'); if (!(syncData._displayBlock > -1)) { // initialize the display numbers @@ -208,14 +208,14 @@ Template['popupWindows_splashScreen'].helpers({ stateProgress = (lastSyncData._displayState / lastSyncData._displayKnownStates) * 100; } - var progress = ((lastSyncData._displayBlock - Number(lastSyncData.startingBlock)) / (Number(lastSyncData._highestBlock) - Number(lastSyncData.startingBlock))) * 100 ; + var progress = ((lastSyncData._displayBlock - Number(lastSyncData.startingBlock)) / (Number(lastSyncData._highestBlock) - Number(lastSyncData.startingBlock))) * 100; // Saves data back to templates - TemplateVar.set(template, "syncStatusMessageLive", translatedMessage); + TemplateVar.set(template, 'syncStatusMessageLive', translatedMessage); TemplateVar.set(template, 'lastSyncData', syncData); // set progress value - if(_.isFinite(progress)) { + if (_.isFinite(progress)) { TemplateVar.set(template, 'showProgressBar', true); TemplateVar.set(template, 'progress', progress); if (null !== stateProgress) { @@ -226,13 +226,13 @@ Template['popupWindows_splashScreen'].helpers({ }, 10); - return TemplateVar.get(template, "syncStatusMessageLive"); + return TemplateVar.get(template, 'syncStatusMessageLive'); } }); Template['popupWindows_splashScreen'].events({ - 'click .start-app': function(){ + 'click .start-app': function () { ipc.send('backendAction_skipSync'); - } + } }); diff --git a/interface/client/templates/popupWindows/unlockMasterPassword.js b/interface/client/templates/popupWindows/unlockMasterPassword.js index 0a6ace426..49de9e486 100644 --- a/interface/client/templates/popupWindows/unlockMasterPassword.js +++ b/interface/client/templates/popupWindows/unlockMasterPassword.js @@ -11,18 +11,18 @@ The request account popup window template @constructor */ -Template['popupWindows_unlockMasterPassword'].onRendered(function(){ +Template['popupWindows_unlockMasterPassword'].onRendered(function () { var template = this; template.$('input.password').focus(); - template.autorun(function(){ + template.autorun(function () { var data = Session.get('data'); - if(data && data.masterPasswordWrong) { + if (data && data.masterPasswordWrong) { TemplateVar.set('unlocking', false); - Tracker.afterFlush(function(){ + Tracker.afterFlush(function () { template.$('input.password').focus(); }); @@ -38,10 +38,10 @@ Template['popupWindows_unlockMasterPassword'].onRendered(function(){ Template['popupWindows_unlockMasterPassword'].events({ - 'click .cancel': function(){ + 'click .cancel': function () { ipc.send('backendAction_closePopupWindow'); - }, - 'submit form': function(e, template){ + }, + 'submit form': function (e, template) { e.preventDefault(); var pw = template.find('input.password').value; @@ -51,5 +51,5 @@ Template['popupWindows_unlockMasterPassword'].events({ template.find('input.password').value = ''; pw = null; - } + } }); diff --git a/interface/client/templates/popupWindows/updateAvailable.js b/interface/client/templates/popupWindows/updateAvailable.js index 8244d3f56..7605ecbb1 100644 --- a/interface/client/templates/popupWindows/updateAvailable.js +++ b/interface/client/templates/popupWindows/updateAvailable.js @@ -10,7 +10,7 @@ The updateAvailable template @class [template] popupWindows_updateAvailable @constructor */ -Template['popupWindows_updateAvailable'].onCreated(function(){ +Template['popupWindows_updateAvailable'].onCreated(function () { var template = this; TemplateVar.set(template, 'checking', true); @@ -18,7 +18,7 @@ Template['popupWindows_updateAvailable'].onCreated(function(){ /* When app update check is in progress it. */ - ipc.on('uiAction_checkUpdateInProgress', function(e, update) { + ipc.on('uiAction_checkUpdateInProgress', function (e, update) { console.debug('Update check in progress...'); TemplateVar.set(template, 'checking', true); @@ -27,7 +27,7 @@ Template['popupWindows_updateAvailable'].onCreated(function(){ /* When app update data is received display it. */ - ipc.on('uiAction_checkUpdateDone', function(e, update) { + ipc.on('uiAction_checkUpdateDone', function (e, update) { console.debug('Update check done'); TemplateVar.set(template, 'checking', false); @@ -40,14 +40,13 @@ Template['popupWindows_updateAvailable'].onCreated(function(){ Template['popupWindows_updateAvailable'].events({ - 'click .get-update': function(e){ + 'click .get-update': function (e) { var update = TemplateVar.get('update'); if (update && update.url) { ipc.send('backendAction_openExternalUrl', update.url); } } -}); - +}); diff --git a/interface/client/templates/views/webview.js b/interface/client/templates/views/webview.js index e28d4b848..6f87cdaf7 100644 --- a/interface/client/templates/views/webview.js +++ b/interface/client/templates/views/webview.js @@ -12,24 +12,24 @@ The tab template @constructor */ -Template['views_webview'].onRendered(function(){ +Template['views_webview'].onRendered(function () { var template = this, tabId = template.data._id, webview = template.find('webview'); - ipc.on('uiAction_reloadSelectedTab', function(e) { + ipc.on('uiAction_reloadSelectedTab', function (e) { console.log('uiAction_reloadSelectedTab', LocalStore.get('selectedTab')); - if(LocalStore.get('selectedTab') === this._id){ + if (LocalStore.get('selectedTab') === this._id) { var webview = Helpers.getWebview(LocalStore.get('selectedTab')); webview.reload(); } }); - webview.addEventListener('did-start-loading', function(e){ + webview.addEventListener('did-start-loading', function (e) { TemplateVar.set(template, 'loading', true); }); - webview.addEventListener('did-stop-loading', function(e){ + webview.addEventListener('did-stop-loading', function (e) { TemplateVar.set(template, 'loading', false); }); @@ -40,22 +40,22 @@ Template['views_webview'].onRendered(function(){ webview.addEventListener('did-stop-loading', webviewChangeUrl.bind(webview, tabId)); // set page history - webview.addEventListener('dom-ready', function(e){ + webview.addEventListener('dom-ready', function (e) { var titleFull = webview.getTitle(), title = titleFull; - if(titleFull && titleFull.length > 40) { + if (titleFull && titleFull.length > 40) { title = titleFull.substr(0, 40); title += '…'; } // update the title - Tabs.update(tabId, {$set: { + Tabs.update(tabId, { $set: { name: title, nameFull: titleFull, // url: webview.getURL(), - }}); + } }); webviewLoadStop.call(this, tabId, e); }); @@ -84,16 +84,16 @@ Template['views_webview'].helpers({ @method (preloaderFile) */ - 'preloaderFile': function(){ - switch(this._id) { - case 'browser': - return 'file://'+ Helpers.preloaderDirname +'/browser.js'; - case 'wallet': - return 'file://'+ Helpers.preloaderDirname +'/wallet.js'; - case 'tests': - return 'file://'+ Helpers.preloaderDirname +'/tests.js'; - default: - return 'file://'+ Helpers.preloaderDirname +'/dapps.js'; + 'preloaderFile': function () { + switch (this._id) { + case 'browser': + return 'file://' + Helpers.preloaderDirname + '/browser.js'; + case 'wallet': + return 'file://' + Helpers.preloaderDirname + '/wallet.js'; + case 'tests': + return 'file://' + Helpers.preloaderDirname + '/tests.js'; + default: + return 'file://' + Helpers.preloaderDirname + '/dapps.js'; } }, /** @@ -101,7 +101,7 @@ Template['views_webview'].helpers({ @method (isVisible) */ - 'isVisible': function(){ + 'isVisible': function () { return (LocalStore.get('selectedTab') === this._id) ? '' : 'hidden'; }, /** @@ -109,48 +109,48 @@ Template['views_webview'].helpers({ @method (checkedUrl) */ - 'checkedUrl': function(){ + 'checkedUrl': function () { var template = Template.instance(); - var tab = Tabs.findOne(this._id, {fields: {redirect: 1}}); + var tab = Tabs.findOne(this._id, { fields: { redirect: 1 } }); var url; - if(tab) { + if (tab) { // set url only once - if(tab.redirect) { + if (tab.redirect) { url = tab.redirect; // remove redirect - Tabs.update(this._id, {$unset: { + Tabs.update(this._id, { $unset: { redirect: '' - }}); + } }); } // allow error pages - if(url && url.indexOf('file://'+ dirname + '/errorPages/') === 0) { + if (url && url.indexOf('file://' + dirname + '/errorPages/') === 0) { return url; } // CHECK URL and throw error if not allowed - if(!Helpers.sanitizeUrl(url, true)) { + if (!Helpers.sanitizeUrl(url, true)) { // Prevent websites usingt the history back attacks - if(template.view.isRendered) { + if (template.view.isRendered) { // get the current webview var webview = template.find('webview'); webview.clearHistory(); } - console.warn('Not allowed URL: '+ template.url); - return 'file://'+ dirname + '/errorPages/400.html'; + console.warn('Not allowed URL: ' + template.url); + return 'file://' + dirname + '/errorPages/400.html'; } // add url - if(url) { + if (url) { template.url = url; - Tabs.update(this._id, {$set: { + Tabs.update(this._id, { $set: { url: url - }}); + } }); } return Helpers.formatUrl(url); diff --git a/interface/client/templates/webviewEvents.js b/interface/client/templates/webviewEvents.js index 332676911..a742e83dc 100644 --- a/interface/client/templates/webviewEvents.js +++ b/interface/client/templates/webviewEvents.js @@ -1,56 +1,58 @@ -showError = function(tabId, e){ - if(e.isMainFrame || e.killed) { +showError = function (tabId, e) { + if (e.isMainFrame || e.killed) { var url, - path = 'file://'+ dirname + '/errorPages/'; + path = 'file://' + dirname + '/errorPages/'; - if(e.killed) { + if (e.killed) { e.errorCode = 500; } - switch(e.errorCode) { - case -105: - url = path +'404.html'; - break; - case 500: - url = path +'500.html'; - break; + switch (e.errorCode) { + case -105: + url = path + '404.html'; + break; + case 500: + url = path + '500.html'; + break; } - if(url) { - Tabs.update(tabId, {$set: { + if (url) { + Tabs.update(tabId, { $set: { redirect: url - }}); + } }); } } }; -webviewChangeUrl = function(tabId, e){ - if(e.type === 'did-navigate-in-page' && !e.isMainFrame) +webviewChangeUrl = function (tabId, e) { + if (e.type === 'did-navigate-in-page' && !e.isMainFrame) { return; + } var url = Helpers.sanitizeUrl(e.url || this.getURL()); console.log(e.type, tabId, url); - if(e.type === 'did-navigate') { + if (e.type === 'did-navigate') { // destroy socket when navigating away ipc.send('ipcProvider-destroy', this.getWebContents().id); } // make sure to not store error pages in history - if(!url || url.indexOf('mist/errorPages/') !== -1) + if (!url || url.indexOf('mist/errorPages/') !== -1) { return; + } // update the URL - Tabs.update(tabId, {$set: { + Tabs.update(tabId, { $set: { url: url - }}); + } }); }; // fired by "did-stop-loading" -webviewLoadStop = function(tabId, e){ +webviewLoadStop = function (tabId, e) { var webview = this, url = Helpers.sanitizeUrl(webview.getURL()), title = webview.getTitle(); @@ -58,36 +60,40 @@ webviewLoadStop = function(tabId, e){ console.log(e.type, tabId, url); // IS BROWSER - if(tabId === 'browser') { + if (tabId === 'browser') { // ADD to doogle last visited pages - if((find = _.find(LastVisitedPages.find().fetch(), function(historyEntry){ - if(!historyEntry.url) return; - var historyEntryOrigin = new URL(historyEntry.url).origin; - return (url.indexOf(historyEntryOrigin) !== -1); - }))) - LastVisitedPages.update(find._id, {$set: { + if ((find = _.find(LastVisitedPages.find().fetch(), function (historyEntry) { + if (!historyEntry.url) { + return; + } + var historyEntryOrigin = new URL(historyEntry.url).origin; + return (url.indexOf(historyEntryOrigin) !== -1); + }))) { + LastVisitedPages.update(find._id, { $set: { timestamp: moment().unix(), url: url - }}); - else + } }); + } else { LastVisitedPages.insert({ name: title, url: url, // icon: '', timestamp: moment().unix() }); + } // ADD to doogle history - if(find = History.findOne({url: url})) - History.update(find._id, {$set: {timestamp: moment().unix()}}); - else + if (find = History.findOne({ url: url })) { + History.update(find._id, { $set: { timestamp: moment().unix() } }); + } else { History.insert({ name: title, url: url, // icon: '', timestamp: moment().unix() }); + } } }; @@ -95,34 +101,36 @@ webviewLoadStop = function(tabId, e){ // fired by "did-get-redirect-request" // fired by "new-window" // fired by "will-navigate" -webviewLoadStart = function(currentTabId, e){ +webviewLoadStart = function (currentTabId, e) { var webview = this; - if(e.type === 'did-get-redirect-request' && !e.isMainFrame) + if (e.type === 'did-get-redirect-request' && !e.isMainFrame) { return; + } console.log(e.type, currentTabId, e); - + // stop this action, as the redirect happens reactive through setting the URL attribute e.preventDefault(); // doesnt work webview.stop(); // doesnt work ipc.sendSync('backendAction_stopWebviewNavigation', webview.getWebContents().id); - + var url = Helpers.sanitizeUrl(e.newURL || e.url); var tabId = Helpers.getTabIdByUrl(url); // if new window (_blank) open in tab, or browser - if(e.type === 'new-window' && tabId === currentTabId) + if (e.type === 'new-window' && tabId === currentTabId) { tabId = 'browser'; + } var tab = Tabs.findOne(tabId); - if(tab.url !== url) { - Tabs.update(tabId, {$set: { + if (tab.url !== url) { + Tabs.update(tabId, { $set: { redirect: url, url: url - }}); + } }); } LocalStore.set('selectedTab', tabId); -}; \ No newline at end of file +}; diff --git a/interface/client/windowEvents.js b/interface/client/windowEvents.js index 5547be7fa..4b78209f5 100644 --- a/interface/client/windowEvents.js +++ b/interface/client/windowEvents.js @@ -1,7 +1,7 @@ // add the platform to the HTML tag -setTimeout(function(){ - document.getElementsByTagName('html')[0].className = window.mist.platform; +setTimeout(function () { + document.getElementsByTagName('html')[0].className = window.mist.platform; if (window.basePathHref) { var base = document.createElement('base'); @@ -14,15 +14,15 @@ setTimeout(function(){ }, 200); -$(window).on('blur', function(e){ +$(window).on('blur', function (e) { $('body').addClass('app-blur'); }); -$(window).on('focus', function(e){ +$(window).on('focus', function (e) { $('body').removeClass('app-blur'); }); // make sure files can only be dropped in the browser webview -$(window).on('dragenter', function(e) { +$(window).on('dragenter', function (e) { LocalStore.set('selectedTab', 'browser'); ipc.send('backendAction_focusMainWindow'); });