Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

[ESLint] fix simple rule violations in 'interface' #1751

Merged
merged 22 commits into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions interface/client/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
6 changes: 3 additions & 3 deletions interface/client/lib/ethereum/1_web3js_init.js
Original file line number Diff line number Diff line change
@@ -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'));
}
43 changes: 24 additions & 19 deletions interface/client/lib/helpers/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

/**
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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;
}

Expand Down Expand Up @@ -128,7 +131,7 @@ Helpers.generateBreadcrumb = function (url) {
return el === '';
});

return new Spacebars.SafeString(filteredUrl.protocol +'//'+ _.flatten(['<span>' + filteredUrl.host + ' </span>', pathname]).join(' ▸ '));
return new Spacebars.SafeString(filteredUrl.protocol + '//' + _.flatten(['<span>' + filteredUrl.host + ' </span>', pathname]).join(' ▸ '));
};

/**
Expand All @@ -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;
});
Expand Down Expand Up @@ -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]);
};
Expand Down
47 changes: 23 additions & 24 deletions interface/client/lib/helpers/templateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -25,7 +25,7 @@ Returns the current block

@method (CurrentBlock)
**/
Template.registerHelper('CurrentBlock', function(){
Template.registerHelper('CurrentBlock', function () {
return EthBlocks.latest;
});

Expand All @@ -35,7 +35,7 @@ Return the dirname.

@method (dirname)
**/
Template.registerHelper('dirname', function(){
Template.registerHelper('dirname', function () {
return window.dirname;
});

Expand All @@ -44,7 +44,7 @@ Return the Mist API.

@method (mist)
**/
Template.registerHelper('mist', function(){
Template.registerHelper('mist', function () {
return window.mist;
});

Expand All @@ -54,7 +54,7 @@ Return the app mode.

@method (mode)
**/
Template.registerHelper('mode', function(){
Template.registerHelper('mode', function () {
return window.mistMode;
});

Expand All @@ -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';
});

Expand All @@ -72,16 +72,16 @@ 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';
});

/**
Get the current user agent

@method (useragent)
**/
Template.registerHelper('useragent', function(){
Template.registerHelper('useragent', function () {
return navigator.userAgent + ' Ethereum ' + (window.mistMode === 'mist' ? 'Mist' : 'Wallet');
});

Expand All @@ -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 } });
});

/**
Expand All @@ -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 = '<i class="icon-eye" title="Watch only"></i>';
else
} else {
icon = '<i class="icon-wallet" title="Wallet"></i>';
} else if(this.type === 'account')
}
} else if (this.type === 'account') {
icon = '<i class="icon-key" title="Account"></i>';
}

return new Spacebars.SafeString(icon);
});
Expand All @@ -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;
}
});

/**
Expand Down Expand Up @@ -176,7 +179,3 @@ Formats a number.
Template.registerHelper('formatBalance', Helpers.formatBalance);






2 changes: 1 addition & 1 deletion interface/client/lib/signatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -10187,4 +10187,4 @@ window.SIGNATURES = {
"0x4e077f2a": [
"addGasEther()"
]
};
};
2 changes: 1 addition & 1 deletion interface/client/lib/thirdParty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};
2 changes: 1 addition & 1 deletion interface/client/mistAPIBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions interface/client/templates/elements/img.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Template['elements_img'].helpers({

@method (preload)
*/
'preload': function(){
'preload': function () {
var template = Template.instance(),
data = this,
img = new Image();
Expand All @@ -30,4 +30,4 @@ Template['elements_img'].helpers({
};
img.src = data.src;
}
});
});
32 changes: 15 additions & 17 deletions interface/client/templates/elements/networkIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
Expand Down
Loading