Skip to content

Commit

Permalink
[BRG-512] fix eslint errors (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickolai Borsuk authored Dec 2, 2019
1 parent 648fbd7 commit ea55536
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
{
"SwitchCase": 1
}
]
],
"no-console": 0
}
}
2 changes: 2 additions & 0 deletions extension/SignTransaction.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-underscore-dangle */

import { serializers, Signature } from 'echojs-lib';

import { EXPIRATION_INFELICITY, GLOBAL_ID_1 } from '../src/constants/GlobalConstants';
Expand Down
30 changes: 23 additions & 7 deletions extension/background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-nested-ternary */
import echo, { Transaction, PrivateKey, aes, ED25519, crypto as echojsCrypto } from 'echojs-lib';
import { throttle } from 'lodash';
import { throttle, uniqBy } from 'lodash';
import urlParse from 'url-parse';

import EventEmitter from '../libs/CustomAwaitEmitter';
Expand Down Expand Up @@ -101,7 +101,9 @@ const sendOnPorts = (portsToSend, comparator, method, res, error) => {
portsToSend.forEach((portObject) => {
const { port, origin } = portObject;

if (!isPortApproved(portObject) && method && ![MESSAGE_METHODS.GET_ACCESS, MESSAGE_METHODS.CHECK_ACCESS].includes(method)) {
if (!isPortApproved(portObject)
&& method
&& ![MESSAGE_METHODS.GET_ACCESS, MESSAGE_METHODS.CHECK_ACCESS].includes(method)) {
return;
}

Expand Down Expand Up @@ -129,7 +131,13 @@ const sendOnPorts = (portsToSend, comparator, method, res, error) => {
* @param {Object|String} error
*/
const sendOnPortsViaMethod = (portsToSend, requestedMethod, res, error) => {
sendOnPorts(portsToSend, (({ method }) => method === requestedMethod), requestedMethod, res, error);
sendOnPorts(
portsToSend,
(({ method }) => method === requestedMethod),
requestedMethod,
res,
error,
);
};

/**
Expand All @@ -140,7 +148,13 @@ const sendOnPortsViaMethod = (portsToSend, requestedMethod, res, error) => {
* @param {Object|String} error
*/
const sendOnPortsViaId = (portsToSend, requestedId, res, error) => {
sendOnPorts(portsToSend, (({ id }) => id === requestedId), null, res, error);
sendOnPorts(
portsToSend,
(({ id }) => id === requestedId),
null,
res,
error,
);
};

/**
Expand All @@ -151,7 +165,7 @@ const getProviderApprovalTaskCount = () => {
const filterPorts = ports.filter(({ pendingTasks }) =>
pendingTasks.find(({ method }) =>
method === MESSAGE_METHODS.GET_ACCESS));
const providerApprovalTaskCount = _.uniqBy(filterPorts, ({ origin }) => origin).length;
const providerApprovalTaskCount = uniqBy(filterPorts, ({ origin }) => origin).length;
return providerApprovalTaskCount;
};

Expand Down Expand Up @@ -390,7 +404,8 @@ const resolveActiveAccount = async (portsToSend) => {
*/
const resolveNetwork = async (portsToSend) => {
const result = await getNetwork();
sendOnPortsViaMethod(portsToSend, MESSAGE_METHODS.GET_NETWORK, JSON.parse(JSON.stringify(result)));
const stringifiedResult = JSON.parse(JSON.stringify(result));
sendOnPortsViaMethod(portsToSend, MESSAGE_METHODS.GET_NETWORK, stringifiedResult);
};

/**
Expand Down Expand Up @@ -434,7 +449,8 @@ const onMessageHandler = (request, portObj) => {
const { origin } = urlParse(sender.tab.url);
const { id, method } = request;

const sendResponse = (reposneObject) => portObj.port.postMessage({ ...reposneObject, origin, method });
const sendResponse =
(reposneObject) => portObj.port.postMessage({ ...reposneObject, origin, method });

if (!request.id || !request.method || !request.appId || request.appId !== APP_ID) return false;

Expand Down
15 changes: 8 additions & 7 deletions extension/inpage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-underscore-dangle */
import * as echojslib from 'echojs-lib';
import lodash from 'lodash';

Expand Down Expand Up @@ -295,18 +296,18 @@ echojslib.Transaction.prototype.signWithBridge = async function signWithBridge()
return;
}

const signData = JSON.parse(data.res);
const signResult = JSON.parse(data.res);

if (this._operations[0][1].from) {
this._operations[0][1].from = signData.accountId;
this._operations[0][1].from = signResult.accountId;
} else if (this._operations[0][1].registrar) {
this._operations[0][1].registrar = signData.accountId;
this._operations[0][1].registrar = signResult.accountId;
}

this._refBlockNum = signData.ref_block_num;
this._refBlockPrefix = signData.ref_block_prefix;
this._expiration = signData.expiration;
this._signatures = signData.serializedSignatures.map((hexString) => new Signat(hexString));
this._refBlockNum = signResult.ref_block_num;
this._refBlockPrefix = signResult.ref_block_prefix;
this._expiration = signResult.expiration;
this._signatures = signResult.serializedSignatures.map((hexString) => new Signat(hexString));

this._finalized = true;

Expand Down
64 changes: 34 additions & 30 deletions libs/CustomAwaitEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,86 +35,88 @@ function onceListener(fn) {
}

function AwaitEventEmitter() {
this._events = {};
this.events = {};
}

function on(type, fn) {
assertType(type);
assertFn(fn);
this._events[type] = this._events[type] || [];
this._events[type].push(alwaysListener(fn));
this.events[type] = this.events[type] || [];
this.events[type].push(alwaysListener(fn));
return this;
}

function prepend(type, fn) {
assertType(type);
assertFn(fn);
this._events[type] = this._events[type] || [];
this._events[type].unshift(alwaysListener(fn));
this.events[type] = this.events[type] || [];
this.events[type].unshift(alwaysListener(fn));
return this;
}

function prependOnce(type, fn) {
assertType(type);
assertFn(fn);
this._events[type] = this._events[type] || [];
this._events[type].unshift(onceListener(fn));
this.events[type] = this.events[type] || [];
this.events[type].unshift(onceListener(fn));
return this;
}

function listeners(type) {
return (this._events[type] || []).map((x) => x.fn);
return (this.events[type] || []).map((x) => x.fn);
}

function once(type, fn) {
assertType(type);
assertFn(fn);
this._events[type] = this._events[type] || [];
this._events[type].push(onceListener(fn));
this.events[type] = this.events[type] || [];
this.events[type].push(onceListener(fn));
return this;
}

function removeListener(type, nullOrFn) {
assertType(type);

const listeners = this.listeners(type);
const listenersItems = this.listeners(type);
if (typeof nullOrFn === 'function') {
let index,
found = false;
while ((index = listeners.indexOf(nullOrFn)) >= 0) {
listeners.splice(index, 1);
this._events[type].splice(index, 1);
let index;
let found = false;
/* eslint-disable no-cond-assign */
while ((index = listenersItems.indexOf(nullOrFn)) >= 0) {
listenersItems.splice(index, 1);
this.events[type].splice(index, 1);
found = true;
}
return found;
}
return delete this._events[type];
return delete this.events[type];

}

function removeAllListeners() {
Object.keys(this._events).forEach((eventType) => delete this._events[eventType]);
Object.keys(this.events).forEach((eventType) => delete this.events[eventType]);

return true;
}

async function emit(type, ...args) {
assertType(type);
const listeners = this.listeners(type);
const listenersItems = this.listeners(type);

const onceListeners = [];
if (listeners && listeners.length) {
for (let i = 0; i < listeners.length; i++) {
const event = listeners[i];
if (listenersItems && listenersItems.length) {
for (let i = 0; i < listenersItems.length; i += 1) {
const event = listenersItems[i];

try {
const rlt = event.apply(this, args);

if (isPromise(rlt)) {
/* eslint-disable no-await-in-loop */
await rlt;
}

if (this._events[type][i][TYPE_KEYNAME] === 'once') {
if (this.events[type][i][TYPE_KEYNAME] === 'once') {
onceListeners.push(event);
}
} catch (e) {
Expand All @@ -132,14 +134,14 @@ async function emit(type, ...args) {

function emitSync(type, ...args) {
assertType(type);
const listeners = this.listeners(type);
const listenersItems = this.listeners(type);
const onceListeners = [];
if (listeners && listeners.length) {
for (let i = 0; i < listeners.length; i++) {
const event = listeners[i];
if (listenersItems && listenersItems.length) {
for (let i = 0; i < listenersItems.length; i += 1) {
const event = listenersItems[i];
event.apply(this, args);

if (this._events[type][i][TYPE_KEYNAME] === 'once') {
if (this.events[type][i][TYPE_KEYNAME] === 'once') {
onceListeners.push(event);
}
}
Expand All @@ -151,11 +153,13 @@ function emitSync(type, ...args) {
return false;
}

AwaitEventEmitter.prototype.on = AwaitEventEmitter.prototype.addListener = on;
AwaitEventEmitter.prototype.on = on;
AwaitEventEmitter.prototype.addListener = on;
AwaitEventEmitter.prototype.once = once;
AwaitEventEmitter.prototype.prependListener = prepend;
AwaitEventEmitter.prototype.prependOnceListener = prependOnce;
AwaitEventEmitter.prototype.off = AwaitEventEmitter.prototype.removeListener = removeListener;
AwaitEventEmitter.prototype.off = removeListener;
AwaitEventEmitter.prototype.removeListener = removeListener;
AwaitEventEmitter.prototype.removeAllListeners = removeAllListeners;
AwaitEventEmitter.prototype.emit = emit;
AwaitEventEmitter.prototype.emitSync = emitSync;
Expand Down
1 change: 1 addition & 0 deletions src/components/Avatar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Avatar extends React.Component {
return name ?
<div
className="avatar-image"
/* eslint-disable react/no-danger */
dangerouslySetInnerHTML={{ __html: svgAvatar(name, size) }}
/> :
<img
Expand Down

0 comments on commit ea55536

Please sign in to comment.