From 0b627cc640d6d7daa26f8f85a8879097be529e35 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Mon, 6 Mar 2017 16:57:42 +0100 Subject: [PATCH 1/3] Autofix eslint errors --- src/app/app.js | 2 +- src/app/components/login/login.js | 220 ++++++++-------- src/app/components/lsk/lsk.js | 10 +- src/app/components/main/main.js | 92 +++---- src/app/components/send/send.js | 110 ++++---- src/app/components/timestamp/timestamp.js | 36 +-- src/app/components/top/top.js | 10 +- .../components/transactions/transactions.js | 76 +++--- src/app/filters/lsk.js | 4 +- src/app/index.js | 54 ++-- src/app/services/error.js | 26 +- src/app/services/lsk.js | 20 +- src/app/services/peers/peer.js | 239 +++++++++--------- src/app/services/peers/peers.js | 40 +-- src/app/services/success.js | 26 +- src/app/theme/theme.js | 66 ++--- .../util/animateOnChange/animateOnChange.js | 20 +- 17 files changed, 514 insertions(+), 537 deletions(-) diff --git a/src/app/app.js b/src/app/app.js index 4ee794a18..8b2072c99 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -5,4 +5,4 @@ export default angular.module('app', [ 'ngAnimate', 'ngCookies', 'md.data.table', -]) +]); diff --git a/src/app/components/login/login.js b/src/app/components/login/login.js index 82066df26..4848d129b 100644 --- a/src/app/components/login/login.js +++ b/src/app/components/login/login.js @@ -1,9 +1,9 @@ -import crypto from 'crypto' -import mnemonic from 'bitcore-mnemonic' +import crypto from 'crypto'; +import mnemonic from 'bitcore-mnemonic'; -import './login.less' -import './save.less' +import './login.less'; +import './save.less'; app.component('login', { template: require('./login.pug')(), @@ -12,193 +12,191 @@ app.component('login', { onLogin: '&', }, controller: class login { - constructor ($scope, $rootScope, $timeout, $document, $mdDialog, $mdMedia, $cookies) { - this.$scope = $scope - this.$rootScope = $rootScope - this.$timeout = $timeout - this.$document = $document - this.$mdDialog = $mdDialog - this.$mdMedia = $mdMedia - this.$cookies = $cookies - - this.$scope.$watch('$ctrl.input_passphrase', this.isValid.bind(this)) - this.$timeout(this.devTestAccount.bind(this), 200) - - this.$scope.$watch(() => { - return this.$mdMedia('xs') || this.$mdMedia('sm'); - }, (wantsFullScreen) => { - this.$scope.customFullscreen = wantsFullScreen === true - }) + constructor($scope, $rootScope, $timeout, $document, $mdDialog, $mdMedia, $cookies) { + this.$scope = $scope; + this.$rootScope = $rootScope; + this.$timeout = $timeout; + this.$document = $document; + this.$mdDialog = $mdDialog; + this.$mdMedia = $mdMedia; + this.$cookies = $cookies; + + this.$scope.$watch('$ctrl.input_passphrase', this.isValid.bind(this)); + this.$timeout(this.devTestAccount.bind(this), 200); + + this.$scope.$watch(() => this.$mdMedia('xs') || this.$mdMedia('sm'), (wantsFullScreen) => { + this.$scope.customFullscreen = wantsFullScreen === true; + }); } - reset () { - this.input_passphrase = '' - this.progress = 0 - this.seed = this.emptyBytes().map(v => '00') + reset() { + this.input_passphrase = ''; + this.progress = 0; + this.seed = this.emptyBytes().map(v => '00'); } - stop () { - this.random = false - this.$document.unbind('mousemove', this.listener) + stop() { + this.random = false; + this.$document.unbind('mousemove', this.listener); } - go () { - this.passphrase = this.fix(this.input_passphrase) + go() { + this.passphrase = this.fix(this.input_passphrase); - this.reset() - this.$timeout(this.onLogin) + this.reset(); + this.$timeout(this.onLogin); } - isValid (value) { - value = this.fix(value) + isValid(value) { + value = this.fix(value); if (value === '') { - this.valid = 2 + this.valid = 2; } else if (value.split(' ').length < 12 || !mnemonic.isValid(value)) { - this.valid = 0 + this.valid = 0; } else { - this.valid = 1 + this.valid = 1; } } - start () { - this.reset() + start() { + this.reset(); - this.random = true + this.random = true; - let last = [0, 0] - let used = this.emptyBytes() + let last = [0, 0]; + let used = this.emptyBytes(); - let turns = 10 + parseInt(Math.random() * 10) - let steps = 2 - let total = turns * used.length - let count = 0 + const turns = 10 + parseInt(Math.random() * 10); + const steps = 2; + const total = turns * used.length; + let count = 0; this.listener = (ev) => { - let distance = Math.sqrt(Math.pow(ev.pageX - last[0], 2) + Math.pow(ev.pageY - last[1], 2)) + const distance = Math.sqrt(Math.pow(ev.pageX - last[0], 2) + Math.pow(ev.pageY - last[1], 2)); if (distance > 60 || ev.isTrigger) { for (let p = 0; p < steps; p++) { - let pos - let available = [] + let pos; + const available = []; - for (let i in used) { + for (const i in used) { if (!used[i]) { - available.push(i) + available.push(i); } } if (!available.length) { - used = used.map(v => 0) - pos = parseInt(Math.random() * used.length) + used = used.map(v => 0); + pos = parseInt(Math.random() * used.length); } else { - pos = available[parseInt(Math.random() * available.length)] + pos = available[parseInt(Math.random() * available.length)]; } - count++ + count++; if (!ev.isTrigger) { - last = [ev.pageX, ev.pageY] + last = [ev.pageX, ev.pageY]; } - used[pos] = 1 + used[pos] = 1; - let update = () => { - this.seed[pos] = this.lpad(crypto.randomBytes(1)[0].toString(16), '0', 2) - this.progress = parseInt(count / total * 100) - } + const update = () => { + this.seed[pos] = this.lpad(crypto.randomBytes(1)[0].toString(16), '0', 2); + this.progress = parseInt(count / total * 100); + }; if (this.$scope.$root.$$phase != '$apply' && this.$scope.$root.$$phase != '$digest') { - this.$scope.$apply(update) + this.$scope.$apply(update); } else { - update() + update(); } if (count >= total) { - this.stop() - this.setNew() - return + this.stop(); + this.setNew(); + return; } } } - } + }; - this.$timeout(() => this.$document.mousemove(this.listener), 300) + this.$timeout(() => this.$document.mousemove(this.listener), 300); } - asd () { - this.$document.mousemove() + asd() { + this.$document.mousemove(); } - setNew () { - let passphrase = (new mnemonic(new Buffer(this.seed.join(''), 'hex'))).toString() - let ok = () => { - this.input_passphrase = passphrase - this.$timeout(this.go.bind(this), 100) - } + setNew() { + const passphrase = (new mnemonic(new Buffer(this.seed.join(''), 'hex'))).toString(); + const ok = () => { + this.input_passphrase = passphrase; + this.$timeout(this.go.bind(this), 100); + }; this.$mdDialog.show({ controllerAs: '$ctrl', - controller: /*@ngInject*/ class save { - constructor ($scope, $mdDialog) { - this.$mdDialog = $mdDialog - this.passphrase = passphrase + controller: /* @ngInject*/ class save { + constructor($scope, $mdDialog) { + this.$mdDialog = $mdDialog; + this.passphrase = passphrase; $scope.$watch('$ctrl.missing_input', () => { - this.missing_ok = this.missing_input && this.missing_input === this.missing_word - }) + this.missing_ok = this.missing_input && this.missing_input === this.missing_word; + }); } - next () { - this.enter = true + next() { + this.enter = true; - let words = this.passphrase.split(' ') - let missing_number = parseInt(Math.random() * words.length) + const words = this.passphrase.split(' '); + const missing_number = parseInt(Math.random() * words.length); - this.missing_word = words[missing_number] - this.pre = words.slice(0, missing_number).join(' ') - this.pos = words.slice(missing_number + 1).join(' ') + this.missing_word = words[missing_number]; + this.pre = words.slice(0, missing_number).join(' '); + this.pos = words.slice(missing_number + 1).join(' '); } - ok () { - ok() - this.close() + ok() { + ok(); + this.close(); } - close () { - this.$mdDialog.hide() + close() { + this.$mdDialog.hide(); } }, template: require('./save.pug')(), - fullscreen: (this.$mdMedia('sm') || this.$mdMedia('xs')) && this.$scope.customFullscreen - }) + fullscreen: (this.$mdMedia('sm') || this.$mdMedia('xs')) && this.$scope.customFullscreen, + }); } - devTestAccount () { + devTestAccount() { this.input_passphrase = this.$cookies.get('passphrase'); if (this.input_passphrase) { - this.$timeout(this.go.bind(this), 100) + this.$timeout(this.go.bind(this), 100); } } - fix (v) { - return (v || '').replace(/ +/g, ' ').trim().toLowerCase() + fix(v) { + return (v || '').replace(/ +/g, ' ').trim().toLowerCase(); } - lpad (str, pad, length) { - while (str.length < length) str = pad + str - return str + lpad(str, pad, length) { + while (str.length < length) str = pad + str; + return str; } - emptyBytes () { - return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + emptyBytes() { + return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; } - mobileAndTabletcheck () { + mobileAndTabletcheck() { let check = false - ;(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera) - return check - }; - } -}) + ;(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; }(navigator.userAgent || navigator.vendor || window.opera)); + return check; + } + }, +}); diff --git a/src/app/components/lsk/lsk.js b/src/app/components/lsk/lsk.js index 513e21090..633a72637 100644 --- a/src/app/components/lsk/lsk.js +++ b/src/app/components/lsk/lsk.js @@ -1,5 +1,5 @@ -import './lsk.less' +import './lsk.less'; app.component('lsk', { template: require('./lsk.pug')(), @@ -7,8 +7,8 @@ app.component('lsk', { amount: '<', }, controller: class lsk { - constructor ($attrs) { - this.append = typeof $attrs.append !== 'undefined' + constructor($attrs) { + this.append = typeof $attrs.append !== 'undefined'; } - } -}) + }, +}); diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js index 6babca8ce..7397837b4 100644 --- a/src/app/components/main/main.js +++ b/src/app/components/main/main.js @@ -1,84 +1,84 @@ -import './main.less' +import './main.less'; -import lisk from 'lisk-js' +import lisk from 'lisk-js'; -const UPDATE_INTERVAL_BALANCE = 10000 +const UPDATE_INTERVAL_BALANCE = 10000; app.component('main', { template: require('./main.pug')(), controller: class main { - constructor ($scope, $rootScope, $timeout, $q, $peers, error) { - this.$scope = $scope - this.$rootScope = $rootScope - this.$timeout = $timeout - this.$q = $q - this.$peers = $peers - this.error = error + constructor($scope, $rootScope, $timeout, $q, $peers, error) { + this.$scope = $scope; + this.$rootScope = $rootScope; + this.$timeout = $timeout; + this.$q = $q; + this.$peers = $peers; + this.error = error; - this.$scope.$on('login', this.login.bind(this)) - this.$scope.$on('peerUpdate', this.update.bind(this)) + this.$scope.$on('login', this.login.bind(this)); + this.$scope.$on('peerUpdate', this.update.bind(this)); $scope.$watch('$ctrl.$peers.active', (peer, old) => { if (peer && old) { - this.$peers.check() - this.$rootScope.$broadcast('peerUpdate') + this.$peers.check(); + this.$rootScope.$broadcast('peerUpdate'); } - }) + }); } - reset () { - this.$timeout.cancel(this.timeout) + reset() { + this.$timeout.cancel(this.timeout); } - login (attempts = 0) { - this.prelogged = true + login(attempts = 0) { + this.prelogged = true; - this.$peers.setActive() + this.$peers.setActive(); - let kp = lisk.crypto.getKeys(this.passphrase) - this.address = lisk.crypto.getAddress(kp.publicKey) + const kp = lisk.crypto.getKeys(this.passphrase); + this.address = lisk.crypto.getAddress(kp.publicKey); this.update() .then(() => { - this.prelogged = false - this.logged = true + this.prelogged = false; + this.logged = true; }) .catch((res) => { if (attempts < 10) { - this.$timeout(() => this.login(++attempts), 1000) + this.$timeout(() => this.login(++attempts), 1000); } else { - this.error.dialog({ text: 'No peer connection' }) - this.logout() + this.error.dialog({ text: 'No peer connection' }); + this.logout(); } - }) + }); } - logout () { - this.reset() - this.$peers.reset(true) + logout() { + this.reset(); + this.$peers.reset(true); - this.logged = false - this.prelogged = false - this.account = {} - this.passphrase = '' + this.logged = false; + this.prelogged = false; + this.account = {}; + this.passphrase = ''; } - update () { - this.reset() + update() { + this.reset(); return this.$peers.active.getAccount(this.address) - .then(res => { - this.account = res + .then((res) => { + this.account = res; }) .catch((res) => { - this.account.balance = undefined - return this.$q.reject(res) + this.account.balance = undefined; + return this.$q.reject(res); }) .finally(() => { - this.timeout = this.$timeout(this.update.bind(this), UPDATE_INTERVAL_BALANCE) - return this.$q.resolve() - }) + this.timeout = this.$timeout(this.update.bind(this), UPDATE_INTERVAL_BALANCE); + return this.$q.resolve(); + }); } - } -}) + }, +}); diff --git a/src/app/components/send/send.js b/src/app/components/send/send.js index e5cfaf6fe..6ed7da98c 100644 --- a/src/app/components/send/send.js +++ b/src/app/components/send/send.js @@ -1,8 +1,8 @@ -import './send.less' +import './send.less'; -const ADDRESS_VALID_RE = '^[0-9]{1,21}[L|l]$' -const AMOUNT_VALID_RE = '^[0-9]+(\.[0-9]{1,8})?$' +const ADDRESS_VALID_RE = '^[0-9]{1,21}[L|l]$'; +const AMOUNT_VALID_RE = '^[0-9]+(\.[0-9]{1,8})?$'; app.component('send', { template: require('./send.pug')(), @@ -11,66 +11,66 @@ app.component('send', { passphrase: '<', }, controller: class send { - constructor ($scope, $peers, lsk, success, error, $mdDialog, $q) { - this.$scope = $scope - this.$peers = $peers - this.success = success - this.error = error - this.$mdDialog = $mdDialog - this.$q = $q + constructor($scope, $peers, lsk, success, error, $mdDialog, $q) { + this.$scope = $scope; + this.$peers = $peers; + this.success = success; + this.error = error; + this.$mdDialog = $mdDialog; + this.$q = $q; this.recipient = { regexp: ADDRESS_VALID_RE, - } + }; this.amount = { regexp: AMOUNT_VALID_RE, - } + }; this.$scope.$watch('$ctrl.amount.value', () => { - this.amount.raw = lsk.from(this.amount.value) || 0 - }) + this.amount.raw = lsk.from(this.amount.value) || 0; + }); this.$scope.$watch('$ctrl.account.balance', () => { - this.amount.max = parseFloat(lsk.normalize(this.account.balance)) - 0.1 - }) + this.amount.max = parseFloat(lsk.normalize(this.account.balance)) - 0.1; + }); } - reset () { - this.recipient.value = '' - this.amount.value = '' + reset() { + this.recipient.value = ''; + this.amount.value = ''; } - promptSecondPassphrase () { + promptSecondPassphrase() { return this.$q((resolve, reject) => { if (this.account.secondSignature) { this.$mdDialog.show({ controllerAs: '$ctrl', template: require('./second.pug')(), - controller: /*@ngInject*/ class second { - constructor ($scope, $mdDialog) { - this.$mdDialog = $mdDialog + controller: /* @ngInject*/ class second { + constructor($scope, $mdDialog) { + this.$mdDialog = $mdDialog; } - ok () { - this.$mdDialog.hide() - resolve(this.value) + ok() { + this.$mdDialog.hide(); + resolve(this.value); } - cancel () { - this.$mdDialog.hide() - reject() + cancel() { + this.$mdDialog.hide(); + reject(); } - } - }) + }, + }); } else { - resolve() + resolve(); } - }) + }); } - go () { - this.loading = true + go() { + this.loading = true; this.promptSecondPassphrase() .then((secondPassphrase) => { @@ -78,34 +78,30 @@ app.component('send', { this.passphrase, secondPassphrase, this.recipient.value, - this.amount.raw + this.amount.raw, ) .then( - (res) => { - return this.success.dialog({ text: `${this.amount.value} sent to ${this.recipient.value}` }) + res => this.success.dialog({ text: `${this.amount.value} sent to ${this.recipient.value}` }) .then(() => { - this.reset() - }) - }, + this.reset(); + }), (res) => { - this.error.dialog({ text: res && res.message ? res.message : 'An error occurred while sending the transaction.' }) - } + this.error.dialog({ text: res && res.message ? res.message : 'An error occurred while sending the transaction.' }); + }, ) .finally(() => { - this.loading = false - }) + this.loading = false; + }); }, () => { - this.loading = false - }) + this.loading = false; + }); } - } -}) + }, +}); -app.directive('ignoreMouseWheel', () => { - return { - restrict: 'A', - link: (scope, element, attrs) => { - element.bind('mousewheel', event => element.blur()) - } - } -}) +app.directive('ignoreMouseWheel', () => ({ + restrict: 'A', + link: (scope, element, attrs) => { + element.bind('mousewheel', event => element.blur()); + }, +})); diff --git a/src/app/components/timestamp/timestamp.js b/src/app/components/timestamp/timestamp.js index 4a49e215c..f60f1ba69 100644 --- a/src/app/components/timestamp/timestamp.js +++ b/src/app/components/timestamp/timestamp.js @@ -1,9 +1,9 @@ -import './timestamp.less' +import './timestamp.less'; -import moment from 'moment' +import moment from 'moment'; -const UPDATE_INTERVAL_UPDATE = 15000 +const UPDATE_INTERVAL_UPDATE = 15000; app.component('timestamp', { template: require('./timestamp.pug')(), @@ -11,28 +11,28 @@ app.component('timestamp', { data: '<', }, controller: class timestamp { - constructor ($scope, $timeout) { - this.$timeout = $timeout + constructor($scope, $timeout) { + this.$timeout = $timeout; - $scope.$watch('$ctrl.data', this.update.bind(this)) + $scope.$watch('$ctrl.data', this.update.bind(this)); } - $onDestroy () { - this.$timeout.cancel(this.timeout) + $onDestroy() { + this.$timeout.cancel(this.timeout); } - update () { - this.$timeout.cancel(this.timeout) + update() { + this.$timeout.cancel(this.timeout); - let obj = moment(this.fix(this.data)) - this.full = obj.format('LL LTS') - this.time_ago = obj.fromNow(true) + const obj = moment(this.fix(this.data)); + this.full = obj.format('LL LTS'); + this.time_ago = obj.fromNow(true); - this.timeout = this.$timeout(this.update.bind(this), UPDATE_INTERVAL_UPDATE) + this.timeout = this.$timeout(this.update.bind(this), UPDATE_INTERVAL_UPDATE); } - fix (value) { - return new Date((((Date.UTC(2016, 4, 24, 17, 0, 0, 0) / 1000) + value) * 1000)) + fix(value) { + return new Date((((Date.UTC(2016, 4, 24, 17, 0, 0, 0) / 1000) + value) * 1000)); } - } -}) + }, +}); diff --git a/src/app/components/top/top.js b/src/app/components/top/top.js index 8d7afc687..772042238 100644 --- a/src/app/components/top/top.js +++ b/src/app/components/top/top.js @@ -1,5 +1,5 @@ -import './top.less' +import './top.less'; app.component('top', { template: require('./top.pug')(), @@ -7,8 +7,8 @@ app.component('top', { account: '<', }, controller: class top { - constructor ($peers) { - this.$peers = $peers + constructor($peers) { + this.$peers = $peers; } - } -}) + }, +}); diff --git a/src/app/components/transactions/transactions.js b/src/app/components/transactions/transactions.js index 5d671d2d0..4f5cede13 100644 --- a/src/app/components/transactions/transactions.js +++ b/src/app/components/transactions/transactions.js @@ -1,7 +1,7 @@ -import './transactions.less' +import './transactions.less'; -const UPDATE_INTERVAL = 20000 +const UPDATE_INTERVAL = 20000; app.component('transactions', { template: require('./transactions.pug')(), @@ -9,72 +9,72 @@ app.component('transactions', { account: '=', }, controller: class transactions { - constructor ($scope, $timeout, $q, $peers) { - this.$scope = $scope - this.$timeout = $timeout - this.$q = $q - this.$peers = $peers + constructor($scope, $timeout, $q, $peers) { + this.$scope = $scope; + this.$timeout = $timeout; + this.$q = $q; + this.$peers = $peers; - this.loaded = false - this.transactions = [] + this.loaded = false; + this.transactions = []; - this.reset() - this.update() + this.reset(); + this.update(); this.$scope.$on('peerUpdate', () => { - this.reset() - this.update(true) - }) + this.reset(); + this.update(true); + }); } - $onDestroy () { - this.$timeout.cancel(this.timeout) + $onDestroy() { + this.$timeout.cancel(this.timeout); } - reset () { - this.loaded = false + reset() { + this.loaded = false; } - update (show, more) { - this.loading = true + update(show, more) { + this.loading = true; if (show) { - this.loading_show = true + this.loading_show = true; } - this.$timeout.cancel(this.timeout) + this.$timeout.cancel(this.timeout); - let limit = (this.transactions.length || 10) + (more ? 10 : 0) + let limit = (this.transactions.length || 10) + (more ? 10 : 0); if (limit < 10) { - limit = 10 + limit = 10; } return this.$peers.active.getTransactions(this.account.address, limit) - .then(res => { - this.transactions = res.transactions - this.total = res.count + .then((res) => { + this.transactions = res.transactions; + this.total = res.count; if (this.total > this.transactions.length) { - this.more = this.total - this.transactions.length + this.more = this.total - this.transactions.length; } else { - this.more = 0 + this.more = 0; } }) .catch(() => { - this.transactions = [] - this.more = 0 + this.transactions = []; + this.more = 0; }) .finally(() => { - this.loaded = true - this.loading = false + this.loaded = true; + this.loading = false; if (show) { - this.loading_show = false + this.loading_show = false; } - this.timeout = this.$timeout(this.update.bind(this), UPDATE_INTERVAL) - }) + this.timeout = this.$timeout(this.update.bind(this), UPDATE_INTERVAL); + }); } - } -}) + }, +}); diff --git a/src/app/filters/lsk.js b/src/app/filters/lsk.js index d78b721ad..a1a76a40e 100644 --- a/src/app/filters/lsk.js +++ b/src/app/filters/lsk.js @@ -1,4 +1,2 @@ -app.filter('lsk', (lsk) => { - return lsk.normalize -}) +app.filter('lsk', lsk => lsk.normalize); diff --git a/src/app/index.js b/src/app/index.js index 11071190f..ab7d34c24 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -1,35 +1,35 @@ -import 'jquery' +import 'jquery'; -import 'angular' -import 'angular-animate' -import 'angular-cookies' -import 'angular-aria' -import 'angular-messages' -import 'angular-material' -import 'angular-material/angular-material.css' -import 'angular-material-data-table/dist/md-data-table.js' -import 'angular-material-data-table/dist/md-data-table.css' +import 'angular'; +import 'angular-animate'; +import 'angular-cookies'; +import 'angular-aria'; +import 'angular-messages'; +import 'angular-material'; +import 'angular-material/angular-material.css'; +import 'angular-material-data-table/dist/md-data-table.js'; +import 'angular-material-data-table/dist/md-data-table.css'; -import './index.less' +import './index.less'; -import './theme/theme' -import './util/animateOnChange/animateOnChange' -import './components/main/main' -import './components/login/login' -import './components/top/top' -import './components/send/send' -import './components/transactions/transactions' -import './components/timestamp/timestamp' -import './components/lsk/lsk' +import './theme/theme'; +import './util/animateOnChange/animateOnChange'; +import './components/main/main'; +import './components/login/login'; +import './components/top/top'; +import './components/send/send'; +import './components/transactions/transactions'; +import './components/timestamp/timestamp'; +import './components/lsk/lsk'; -import './services/peers/peers' -import './services/lsk' -import './services/success' -import './services/error' +import './services/peers/peers'; +import './services/lsk'; +import './services/success'; +import './services/error'; -import './filters/lsk' +import './filters/lsk'; angular.element(document).ready(() => { - angular.bootstrap(document, ['app']) -}) + angular.bootstrap(document, ['app']); +}); diff --git a/src/app/services/error.js b/src/app/services/error.js index cab90bcd8..f7a9756b0 100644 --- a/src/app/services/error.js +++ b/src/app/services/error.js @@ -1,20 +1,18 @@ -app.factory('error', ($mdDialog, $mdToast) => { - return { - toast ({ text }) { - return $mdToast.show( +app.factory('error', ($mdDialog, $mdToast) => ({ + toast({ text }) { + return $mdToast.show( $mdToast.simple() .textContent(text) - .position('bottom right') - ) - }, - dialog ({ title = 'Error', text, button = 'OK' }) { - return $mdDialog.show( + .position('bottom right'), + ); + }, + dialog({ title = 'Error', text, button = 'OK' }) { + return $mdDialog.show( $mdDialog.alert() .title(title) .textContent(text) - .ok(button) - ) - } - } -}) + .ok(button), + ); + }, +})); diff --git a/src/app/services/lsk.js b/src/app/services/lsk.js index 7d521ef79..031973916 100644 --- a/src/app/services/lsk.js +++ b/src/app/services/lsk.js @@ -1,13 +1,11 @@ -import numeral from 'numeral' +import numeral from 'numeral'; -app.factory('lsk', () => { - return { - normalize (value) { - return numeral(parseInt(value) || 0).divide(Math.pow(10, 8)).format('0.0[0000000]') - }, - from (value) { - return parseInt(value * Math.pow(10, 8)) - } - } -}) +app.factory('lsk', () => ({ + normalize(value) { + return numeral(parseInt(value) || 0).divide(Math.pow(10, 8)).format('0.0[0000000]'); + }, + from(value) { + return parseInt(value * Math.pow(10, 8)); + }, +})); diff --git a/src/app/services/peers/peer.js b/src/app/services/peers/peer.js index 77a6ce50f..dda9dbdce 100644 --- a/src/app/services/peers/peer.js +++ b/src/app/services/peers/peer.js @@ -1,154 +1,147 @@ -import lisk from 'lisk-js' - -const API_PEERS = '/api/peers' -const API_ACCOUNT = '/api/accounts' -const API_BALANCE = '/api/accounts/getBalance' -const API_TRANSACTIONS = '/api/transactions' -const API_NETHASH = '/api/blocks/getNetHash' -const API_SEND_TRANSACTION = '/peer/transactions' -const API_STATUS = '/api/loader/status' - -const REQUEST_TIMEOUT = 12000 - -const TRANSACTION_HEADER_OS = 'nanowallet' -const TRANSACTION_HEADER_PORT = '8000' -const TRANSACTION_HEADER_VERSION = '0.5.0' - -app.factory('$peer', ($http, $log, $q, $timeout) => { - return class $peer { - constructor ({ host, port = 8000, ssl = false }) { - this.host = host - this.port = port - this.ssl = !!ssl - this.enabled = false - } +import lisk from 'lisk-js'; + +const API_PEERS = '/api/peers'; +const API_ACCOUNT = '/api/accounts'; +const API_BALANCE = '/api/accounts/getBalance'; +const API_TRANSACTIONS = '/api/transactions'; +const API_NETHASH = '/api/blocks/getNetHash'; +const API_SEND_TRANSACTION = '/peer/transactions'; +const API_STATUS = '/api/loader/status'; + +const REQUEST_TIMEOUT = 12000; + +const TRANSACTION_HEADER_OS = 'nanowallet'; +const TRANSACTION_HEADER_PORT = '8000'; +const TRANSACTION_HEADER_VERSION = '0.5.0'; + +app.factory('$peer', ($http, $log, $q, $timeout) => class $peer { + constructor({ host, port = 8000, ssl = false }) { + this.host = host; + this.port = port; + this.ssl = !!ssl; + this.enabled = false; + } - get uri () { - return `${this.host}` + (this.port ? `:${this.port}` : '') - } + get uri() { + return `${this.host}${this.port ? `:${this.port}` : ''}`; + } - get url () { - return (this.ssl ? 'https' : 'http') + `://${this.uri}` + get url() { + return `${this.ssl ? 'https' : 'http'}://${this.uri}`; + } + + request(method, api, data, headers) { + const url = this.url + api; + + const config = { + url, + method, + headers, + timeout: REQUEST_TIMEOUT, + }; + + if (method === 'post') { + config.data = data; + } else { + config.params = data; } - request (method, api, data, headers) { - let url = this.url + api - - let config = { - url, - method, - headers, - timeout: REQUEST_TIMEOUT, - } - - if (method === 'post') { - config.data = data - } else { - config.params = data - } - - return $http(config) - .then(res => { - $log.info(`${method} ${url}`) - return res + return $http(config) + .then((res) => { + $log.info(`${method} ${url}`); + return res; }) - .then(res => { + .then((res) => { if (!res.data.success) { - return $q.reject({ message: res.data.message || res.data.error || null }) - } else { - return res + return $q.reject({ message: res.data.message || res.data.error || null }); } - }) - } + return res; + }); + } - get (api, data, headers) { - return this.request('get', api, data, headers) - } + get(api, data, headers) { + return this.request('get', api, data, headers); + } - post (api, data, headers) { - return this.request('post', api, data, headers) - } + post(api, data, headers) { + return this.request('post', api, data, headers); + } - getPeers () { - let data = { - state: 2, - } + getPeers() { + const data = { + state: 2, + }; - return this.get(API_PEERS, data) - .then(res => res.data.peers) - } + return this.get(API_PEERS, data) + .then(res => res.data.peers); + } - getAccount (address) { - return this.get(API_ACCOUNT, { address }) + getAccount(address) { + return this.get(API_ACCOUNT, { address }) .then(res => res.data.account) - .catch(res => { - return this.getBalance(address) - .then(balance => { - return { - address, - balance, - } - }) - }) - } + .catch(res => this.getBalance(address) + .then(balance => ({ + address, + balance, + }))); + } - getBalance (address) { - let data = { - address, - } + getBalance(address) { + const data = { + address, + }; - return this.get(API_BALANCE, data) - .then(res => res.data.balance) - } + return this.get(API_BALANCE, data) + .then(res => res.data.balance); + } - getTransactions (address, limit = 100, orderBy = 'timestamp:desc') { - let data = { - senderId: address, - recipientId: address, - limit, - orderBy - } + getTransactions(address, limit = 100, orderBy = 'timestamp:desc') { + const data = { + senderId: address, + recipientId: address, + limit, + orderBy, + }; - return this.get(API_TRANSACTIONS, data) - .then(res => res.data) - } + return this.get(API_TRANSACTIONS, data) + .then(res => res.data); + } - getNetHash () { - return this.get(API_NETHASH) - .then(res => res.data.nethash) - } + getNetHash() { + return this.get(API_NETHASH) + .then(res => res.data.nethash); + } - sendTransaction (passphrase, secondPassphrase, recipient, amount) { - let transaction + sendTransaction(passphrase, secondPassphrase, recipient, amount) { + let transaction; - try { - transaction = lisk.transaction.createTransaction( + try { + transaction = lisk.transaction.createTransaction( recipient, amount, passphrase, - secondPassphrase - ) - } catch (e) { - return $q.reject() - } - - return this.getNetHash() - .then(nethash => { - let headers = { + secondPassphrase, + ); + } catch (e) { + return $q.reject(); + } + + return this.getNetHash() + .then((nethash) => { + const headers = { nethash, os: TRANSACTION_HEADER_OS, version: TRANSACTION_HEADER_VERSION, port: TRANSACTION_HEADER_PORT, - } + }; - return this.post(API_SEND_TRANSACTION, { transaction }, headers) - }) - } + return this.post(API_SEND_TRANSACTION, { transaction }, headers); + }); + } - status () { - return this.get(API_STATUS) - .then(res => res.data) - } + status() { + return this.get(API_STATUS) + .then(res => res.data); } -}) + }); diff --git a/src/app/services/peers/peers.js b/src/app/services/peers/peers.js index 6fb508bcc..3d4b5930e 100644 --- a/src/app/services/peers/peers.js +++ b/src/app/services/peers/peers.js @@ -1,13 +1,13 @@ -import _ from 'lodash' +import _ from 'lodash'; -import './peer' +import './peer'; -const UPDATE_INTERVAL_CHECK = 10000 +const UPDATE_INTERVAL_CHECK = 10000; app.factory('$peers', ($peer, $timeout, $cookies) => { class $peers { - constructor () { + constructor() { this.stack = { official: [ new $peer({ host: 'node01.lisk.io' }), @@ -22,46 +22,46 @@ app.factory('$peers', ($peer, $timeout, $cookies) => { public: [], testnet: [ new $peer({ host: 'testnet.lisk.io', port: null, ssl: true }), - ] - } + ], + }; - this.check() + this.check(); } - reset (active) { - $timeout.cancel(this.timeout) + reset(active) { + $timeout.cancel(this.timeout); if (active) { - this.active = undefined + this.active = undefined; } } - setActive () { + setActive() { this.active = _.chain([]) .concat($cookies.get('peerStack') == 'testnet' ? this.stack.testnet : this.stack.official, this.stack.public) .sample() - .value() + .value(); - this.check() + this.check(); } - check () { - this.reset() + check() { + this.reset(); - let next = () => this.timeout = $timeout(this.check.bind(this), UPDATE_INTERVAL_CHECK) + const next = () => this.timeout = $timeout(this.check.bind(this), UPDATE_INTERVAL_CHECK); if (!this.active) { - return next() + return next(); } this.active.status() .then(() => this.online = true) .catch(() => this.online = false) - .finally(() => next()) + .finally(() => next()); } } - return new $peers() -}) + return new $peers(); +}); diff --git a/src/app/services/success.js b/src/app/services/success.js index 587d9daf0..0c3ead726 100644 --- a/src/app/services/success.js +++ b/src/app/services/success.js @@ -1,20 +1,18 @@ -app.factory('success', ($mdDialog, $mdToast) => { - return { - toast ({ text }) { - $mdToast.show( +app.factory('success', ($mdDialog, $mdToast) => ({ + toast({ text }) { + $mdToast.show( $mdToast.simple() .textContent(text) - .position('bottom right') - ) - }, - dialog ({ title = 'Success', text, button = 'OK' }) { - return $mdDialog.show( + .position('bottom right'), + ); + }, + dialog({ title = 'Success', text, button = 'OK' }) { + return $mdDialog.show( $mdDialog.alert() .title(title) .textContent(text) - .ok(button) - ) - } - } -}) + .ok(button), + ); + }, +})); diff --git a/src/app/theme/theme.js b/src/app/theme/theme.js index 3c0c7b774..c893fd4eb 100644 --- a/src/app/theme/theme.js +++ b/src/app/theme/theme.js @@ -3,42 +3,42 @@ app.config(($mdThemingProvider) => { $mdThemingProvider.definePalette('customPrimary', { - '50': '#55c2fd', - '100': '#3cb9fd', - '200': '#23b0fd', - '300': '#09a7fd', - '400': '#0298ea', - '500': '#0288d1', - '600': '#0278b8', - '700': '#02679e', - '800': '#015785', - '900': '#01466c', - 'A100': '#6ecbfe', - 'A200': '#88d4fe', - 'A400': '#a1ddfe', - 'A700': '#013653', - 'contrastDefaultColor': 'light' - }) + 50: '#55c2fd', + 100: '#3cb9fd', + 200: '#23b0fd', + 300: '#09a7fd', + 400: '#0298ea', + 500: '#0288d1', + 600: '#0278b8', + 700: '#02679e', + 800: '#015785', + 900: '#01466c', + A100: '#6ecbfe', + A200: '#88d4fe', + A400: '#a1ddfe', + A700: '#013653', + contrastDefaultColor: 'light', + }); $mdThemingProvider.definePalette('customAccent', { - '50': '#181b1c', - '100': '#24282a', - '200': '#303537', - '300': '#3c4245', - '400': '#474f53', - '500': '#535c60', - '600': '#6b767c', - '700': '#778389', - '800': '#849095', - '900': '#929ca1', - 'A100': '#6b767c', - 'A200': '#5f696e', - 'A400': '#535c60', - 'A700': '#a0a8ad' - }) + 50: '#181b1c', + 100: '#24282a', + 200: '#303537', + 300: '#3c4245', + 400: '#474f53', + 500: '#535c60', + 600: '#6b767c', + 700: '#778389', + 800: '#849095', + 900: '#929ca1', + A100: '#6b767c', + A200: '#5f696e', + A400: '#535c60', + A700: '#a0a8ad', + }); $mdThemingProvider .theme('default') .primaryPalette('customPrimary') - .accentPalette('customAccent') -}) + .accentPalette('customAccent'); +}); diff --git a/src/app/util/animateOnChange/animateOnChange.js b/src/app/util/animateOnChange/animateOnChange.js index ac65c10eb..5f5d71b52 100644 --- a/src/app/util/animateOnChange/animateOnChange.js +++ b/src/app/util/animateOnChange/animateOnChange.js @@ -1,12 +1,10 @@ -app.directive('animateOnChange', ($animate, $timeout) => { - return (scope, elem, attr) => { - scope.$watch(attr.animateOnChange, (nv, ov) => { - if (nv != ov) { - $animate.addClass(elem, 'change').then(() => { - $timeout(() => $animate.removeClass(elem, 'change')) - }) - } - }) - } -}) +app.directive('animateOnChange', ($animate, $timeout) => (scope, elem, attr) => { + scope.$watch(attr.animateOnChange, (nv, ov) => { + if (nv != ov) { + $animate.addClass(elem, 'change').then(() => { + $timeout(() => $animate.removeClass(elem, 'change')); + }); + } + }); +}); From d9b206b104fadcb0f94700d11b9c584766ba02c8 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Mon, 6 Mar 2017 18:15:46 +0100 Subject: [PATCH 2/3] Fix all other eslint errors #45 --- src/.eslintrc.json | 18 ++++++- src/app/components/login/login.js | 53 +++++++++---------- src/app/components/main/main.js | 7 ++- src/app/components/send/send.js | 8 +-- src/app/components/timestamp/timestamp.js | 5 +- src/app/index.js | 2 +- src/app/services/lsk.js | 4 +- src/app/services/peers/peer.js | 4 +- src/app/services/peers/peers.js | 5 +- .../util/animateOnChange/animateOnChange.js | 2 +- 10 files changed, 59 insertions(+), 49 deletions(-) diff --git a/src/.eslintrc.json b/src/.eslintrc.json index be3b285ad..cdaf371d8 100644 --- a/src/.eslintrc.json +++ b/src/.eslintrc.json @@ -2,5 +2,21 @@ "extends": "airbnb-base", "plugins": [ "import" - ] + ], + "globals": { + "angular": true, + "app": true + }, + "env": { + "browser": true, + "node": true + }, + "rules": { + "new-cap": ["error", { "newIsCapExceptions": ["mnemonic"]}], + "global-require": "off", + "no-return-assign": "off", + "no-plusplus": "off", + "no-loop-func": "off", + "func-names": "off" + } } diff --git a/src/app/components/login/login.js b/src/app/components/login/login.js index 4848d129b..7e1ae478a 100644 --- a/src/app/components/login/login.js +++ b/src/app/components/login/login.js @@ -32,7 +32,7 @@ app.component('login', { reset() { this.input_passphrase = ''; this.progress = 0; - this.seed = this.emptyBytes().map(v => '00'); + this.seed = this.emptyBytes().map(() => '00'); } stop() { @@ -48,11 +48,11 @@ app.component('login', { } isValid(value) { - value = this.fix(value); + const fixedValue = this.fix(value); - if (value === '') { + if (fixedValue === '') { this.valid = 2; - } else if (value.split(' ').length < 12 || !mnemonic.isValid(value)) { + } else if (fixedValue.split(' ').length < 12 || !mnemonic.isValid(fixedValue)) { this.valid = 0; } else { this.valid = 1; @@ -67,30 +67,24 @@ app.component('login', { let last = [0, 0]; let used = this.emptyBytes(); - const turns = 10 + parseInt(Math.random() * 10); + const turns = 10 + parseInt(Math.random() * 10, 10); const steps = 2; const total = turns * used.length; let count = 0; this.listener = (ev) => { - const distance = Math.sqrt(Math.pow(ev.pageX - last[0], 2) + Math.pow(ev.pageY - last[1], 2)); + const distance = Math.sqrt(((ev.pageX - last[0]) ** 2) + ((ev.pageY - last[1]) ** 2)); if (distance > 60 || ev.isTrigger) { for (let p = 0; p < steps; p++) { let pos; - const available = []; - - for (const i in used) { - if (!used[i]) { - available.push(i); - } - } + const available = used.filter(u => u); if (!available.length) { - used = used.map(v => 0); - pos = parseInt(Math.random() * used.length); + used = used.map(() => 0); + pos = parseInt(Math.random() * used.length, 10); } else { - pos = available[parseInt(Math.random() * available.length)]; + pos = available[parseInt(Math.random() * available.length, 10)]; } count++; @@ -103,10 +97,10 @@ app.component('login', { const update = () => { this.seed[pos] = this.lpad(crypto.randomBytes(1)[0].toString(16), '0', 2); - this.progress = parseInt(count / total * 100); + this.progress = parseInt((count / total) * 100, 10); }; - if (this.$scope.$root.$$phase != '$apply' && this.$scope.$root.$$phase != '$digest') { + if (this.$scope.$root.$$phase !== '$apply' && this.$scope.$root.$$phase !== '$digest') { this.$scope.$apply(update); } else { update(); @@ -151,11 +145,11 @@ app.component('login', { this.enter = true; const words = this.passphrase.split(' '); - const missing_number = parseInt(Math.random() * words.length); + const missingNumber = parseInt(Math.random() * words.length, 10); - this.missing_word = words[missing_number]; - this.pre = words.slice(0, missing_number).join(' '); - this.pos = words.slice(missing_number + 1).join(' '); + this.missing_word = words[missingNumber]; + this.pre = words.slice(0, missingNumber).join(' '); + this.pos = words.slice(missingNumber + 1).join(' '); } ok() { @@ -180,22 +174,23 @@ app.component('login', { } } - fix(v) { + static fix(v) { return (v || '').replace(/ +/g, ' ').trim().toLowerCase(); } - lpad(str, pad, length) { - while (str.length < length) str = pad + str; - return str; + static lpad(str, pad, length) { + let result = str; + while (result.length < length) result = pad + str; + return result; } - emptyBytes() { + static emptyBytes() { return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; } - mobileAndTabletcheck() { + static mobileAndTabletcheck() { let check = false - ;(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; }(navigator.userAgent || navigator.vendor || window.opera)); + ;(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd(m|p|t)|hei|hi(pt|ta)|hp( i|ip)|hsc|ht(c(| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i(20|go|ma)|i230|iac( ||\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|[a-w])|libw|lynx|m1w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|mcr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|([1-8]|c))|phil|pire|pl(ay|uc)|pn2|po(ck|rt|se)|prox|psio|ptg|qaa|qc(07|12|21|32|60|[2-7]|i)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h|oo|p)|sdk\/|se(c(|0|1)|47|mc|nd|ri)|sgh|shar|sie(|m)|sk0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h|v|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl|tdg|tel(i|m)|tim|tmo|to(pl|sh)|ts(70|m|m3|m5)|tx9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas|your|zeto|zte/i.test(a.substr(0, 4))) check = true; }(navigator.userAgent || navigator.vendor || window.opera)); return check; } }, diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js index 7397837b4..ba8362378 100644 --- a/src/app/components/main/main.js +++ b/src/app/components/main/main.js @@ -1,8 +1,7 @@ +import lisk from 'lisk-js'; import './main.less'; -import lisk from 'lisk-js'; - const UPDATE_INTERVAL_BALANCE = 10000; app.component('main', { @@ -44,9 +43,9 @@ app.component('main', { this.prelogged = false; this.logged = true; }) - .catch((res) => { + .catch(() => { if (attempts < 10) { - this.$timeout(() => this.login(++attempts), 1000); + this.$timeout(() => this.login(attempts + 1), 1000); } else { this.error.dialog({ text: 'No peer connection' }); this.logout(); diff --git a/src/app/components/send/send.js b/src/app/components/send/send.js index 6ed7da98c..b75429450 100644 --- a/src/app/components/send/send.js +++ b/src/app/components/send/send.js @@ -2,7 +2,7 @@ import './send.less'; const ADDRESS_VALID_RE = '^[0-9]{1,21}[L|l]$'; -const AMOUNT_VALID_RE = '^[0-9]+(\.[0-9]{1,8})?$'; +const AMOUNT_VALID_RE = '^[0-9]+(.[0-9]{1,8})?$'; app.component('send', { template: require('./send.pug')(), @@ -81,7 +81,7 @@ app.component('send', { this.amount.raw, ) .then( - res => this.success.dialog({ text: `${this.amount.value} sent to ${this.recipient.value}` }) + () => this.success.dialog({ text: `${this.amount.value} sent to ${this.recipient.value}` }) .then(() => { this.reset(); }), @@ -101,7 +101,7 @@ app.component('send', { app.directive('ignoreMouseWheel', () => ({ restrict: 'A', - link: (scope, element, attrs) => { - element.bind('mousewheel', event => element.blur()); + link: (scope, element) => { + element.bind('mousewheel', () => element.blur()); }, })); diff --git a/src/app/components/timestamp/timestamp.js b/src/app/components/timestamp/timestamp.js index f60f1ba69..5a01a0c8d 100644 --- a/src/app/components/timestamp/timestamp.js +++ b/src/app/components/timestamp/timestamp.js @@ -1,8 +1,7 @@ +import moment from 'moment'; import './timestamp.less'; -import moment from 'moment'; - const UPDATE_INTERVAL_UPDATE = 15000; app.component('timestamp', { @@ -31,7 +30,7 @@ app.component('timestamp', { this.timeout = this.$timeout(this.update.bind(this), UPDATE_INTERVAL_UPDATE); } - fix(value) { + static fix(value) { return new Date((((Date.UTC(2016, 4, 24, 17, 0, 0, 0) / 1000) + value) * 1000)); } }, diff --git a/src/app/index.js b/src/app/index.js index ab7d34c24..57ca76e60 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -8,7 +8,7 @@ import 'angular-aria'; import 'angular-messages'; import 'angular-material'; import 'angular-material/angular-material.css'; -import 'angular-material-data-table/dist/md-data-table.js'; +import 'angular-material-data-table/dist/md-data-table'; import 'angular-material-data-table/dist/md-data-table.css'; import './index.less'; diff --git a/src/app/services/lsk.js b/src/app/services/lsk.js index 031973916..8316f03cf 100644 --- a/src/app/services/lsk.js +++ b/src/app/services/lsk.js @@ -3,9 +3,9 @@ import numeral from 'numeral'; app.factory('lsk', () => ({ normalize(value) { - return numeral(parseInt(value) || 0).divide(Math.pow(10, 8)).format('0.0[0000000]'); + return numeral(parseInt(value, 10) || 0).divide(10 ** 8).format('0.0[0000000]'); }, from(value) { - return parseInt(value * Math.pow(10, 8)); + return parseInt(value * (10 ** 8), 10); }, })); diff --git a/src/app/services/peers/peer.js b/src/app/services/peers/peer.js index dda9dbdce..a2232c495 100644 --- a/src/app/services/peers/peer.js +++ b/src/app/services/peers/peer.js @@ -15,7 +15,7 @@ const TRANSACTION_HEADER_OS = 'nanowallet'; const TRANSACTION_HEADER_PORT = '8000'; const TRANSACTION_HEADER_VERSION = '0.5.0'; -app.factory('$peer', ($http, $log, $q, $timeout) => class $peer { +app.factory('$peer', ($http, $log, $q) => class $peer { constructor({ host, port = 8000, ssl = false }) { this.host = host; this.port = port; @@ -80,7 +80,7 @@ app.factory('$peer', ($http, $log, $q, $timeout) => class $peer { getAccount(address) { return this.get(API_ACCOUNT, { address }) .then(res => res.data.account) - .catch(res => this.getBalance(address) + .catch(() => this.getBalance(address) .then(balance => ({ address, balance, diff --git a/src/app/services/peers/peers.js b/src/app/services/peers/peers.js index 3d4b5930e..eeb74351d 100644 --- a/src/app/services/peers/peers.js +++ b/src/app/services/peers/peers.js @@ -38,7 +38,7 @@ app.factory('$peers', ($peer, $timeout, $cookies) => { setActive() { this.active = _.chain([]) - .concat($cookies.get('peerStack') == 'testnet' ? + .concat($cookies.get('peerStack') === 'testnet' ? this.stack.testnet : this.stack.official, this.stack.public) .sample() @@ -53,7 +53,8 @@ app.factory('$peers', ($peer, $timeout, $cookies) => { const next = () => this.timeout = $timeout(this.check.bind(this), UPDATE_INTERVAL_CHECK); if (!this.active) { - return next(); + next(); + return; } this.active.status() diff --git a/src/app/util/animateOnChange/animateOnChange.js b/src/app/util/animateOnChange/animateOnChange.js index 5f5d71b52..519c1b2c3 100644 --- a/src/app/util/animateOnChange/animateOnChange.js +++ b/src/app/util/animateOnChange/animateOnChange.js @@ -1,7 +1,7 @@ app.directive('animateOnChange', ($animate, $timeout) => (scope, elem, attr) => { scope.$watch(attr.animateOnChange, (nv, ov) => { - if (nv != ov) { + if (nv !== ov) { $animate.addClass(elem, 'change').then(() => { $timeout(() => $animate.removeClass(elem, 'change')); }); From 9f13b5e0c13e60772d13e3f886ec37121e3099f1 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Tue, 7 Mar 2017 09:54:03 +0100 Subject: [PATCH 3/3] Turn off no-restricted-properties eslint rule ... as '**' exponent oprator doesn't work in babel --- src/.eslintrc.json | 1 + src/app/components/login/login.js | 3 ++- src/app/services/lsk.js | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/.eslintrc.json b/src/.eslintrc.json index cdaf371d8..640820c73 100644 --- a/src/.eslintrc.json +++ b/src/.eslintrc.json @@ -12,6 +12,7 @@ "node": true }, "rules": { + "no-restricted-properties": "off", "new-cap": ["error", { "newIsCapExceptions": ["mnemonic"]}], "global-require": "off", "no-return-assign": "off", diff --git a/src/app/components/login/login.js b/src/app/components/login/login.js index 7e1ae478a..f47b99ee0 100644 --- a/src/app/components/login/login.js +++ b/src/app/components/login/login.js @@ -73,7 +73,8 @@ app.component('login', { let count = 0; this.listener = (ev) => { - const distance = Math.sqrt(((ev.pageX - last[0]) ** 2) + ((ev.pageY - last[1]) ** 2)); + const distance = Math.sqrt(Math.pow(ev.pageX - last[0], 2) + + (Math.pow(ev.pageY - last[1]), 2)); if (distance > 60 || ev.isTrigger) { for (let p = 0; p < steps; p++) { diff --git a/src/app/services/lsk.js b/src/app/services/lsk.js index 8316f03cf..b2125057a 100644 --- a/src/app/services/lsk.js +++ b/src/app/services/lsk.js @@ -3,9 +3,9 @@ import numeral from 'numeral'; app.factory('lsk', () => ({ normalize(value) { - return numeral(parseInt(value, 10) || 0).divide(10 ** 8).format('0.0[0000000]'); + return numeral(parseInt(value, 10) || 0).divide(Math.pow(10, 8)).format('0.0[0000000]'); }, from(value) { - return parseInt(value * (10 ** 8), 10); + return parseInt(value * Math.pow(10, 8), 10); }, }));