Skip to content

Commit

Permalink
code style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Furter committed Apr 4, 2019
1 parent db28ca4 commit e8418c8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
9 changes: 5 additions & 4 deletions packages/web3-core-method/lib/methods/AbstractMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default class AbstractMethod {
*
* @param {AbstractWeb3Module} moduleInstance - The package where the method is called from for example Eth.
*/
beforeExecution(moduleInstance) {}
beforeExecution(moduleInstance) {
}

/**
* This method will be executed after the RPC request.
Expand Down Expand Up @@ -200,13 +201,13 @@ export default class AbstractMethod {
*
* @param {IArguments} args
*/
setArguments(arguments_) {
let parameters = cloneDeep([...arguments_]);
setArguments(args) {
let parameters = cloneDeep([...args]);
let callback = null;

if (parameters.length > this.parametersAmount) {
if (!isFunction(parameters[parameters.length - 1])) {
throw new TypeError("The latest parameter should be a function otherwise it can't be used as callback");
throw new TypeError('The latest parameter should be a function otherwise it can\'t be used as callback');
}

callback = parameters.pop();
Expand Down
13 changes: 1 addition & 12 deletions packages/web3-core-method/src/observers/TransactionObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class TransactionObserver {
*/
observe(transactionHash) {
return Observable.create((observer) => {
if (this.isSocketBasedProvider()) {
if (this.provider.supportsSubscriptions()) {
this.startSocketObserver(transactionHash, observer);
} else {
this.startHttpObserver(transactionHash, observer);
Expand Down Expand Up @@ -270,17 +270,6 @@ export default class TransactionObserver {
return this.confirmationChecks === this.timeout;
}

/**
* Checks if the given provider is a socket based provider.
*
* @method isSocketBasedProvider
*
* @returns {Boolean}
*/
isSocketBasedProvider() {
return !!this.provider.supportsSubscriptions();
}

/**
* Increases the blockNumber hash by one.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('IpcProviderTest', () => {

ipcProvider.onMessage(objectWithToString);

expect(objectWithToString.toString).toHaveBeenCalledWith();
expect(objectWithToString.toString).toHaveBeenCalled();
});

it('calls onMessage with more than one chunk', (done) => {
Expand Down
18 changes: 9 additions & 9 deletions packages/web3-utils/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,30 +181,30 @@ export const rightPad = (string, chars, sign) => {
*
* @method utf8ToHex
*
* @param {String} str
* @param {String} value
*
* @returns {String} hex representation of input string
*/
export const utf8ToHex = (string) => {
string = utf8.encode(string);
export const utf8ToHex = (value) => {
value = utf8.encode(string);
let hex = '';

/* eslint-disable no-control-regex */
// remove \u0000 padding from either side
string = string.replace(/^(?:\u0000)*/, '');
string = string
value = value.replace(/^(?:\u0000)*/, '');
value = value
.split('')
.reverse()
.join('');
string = string.replace(/^(?:\u0000)*/, '');
string = string
value = value.replace(/^(?:\u0000)*/, '');
value = value
.split('')
.reverse()
.join('');
/* eslint-enable no-control-regex */

for (let i = 0; i < string.length; i++) {
const code = string.charCodeAt(i);
for (let i = 0; i < value.length; i++) {
const code = value.charCodeAt(i);
// if (code !== 0) {
const n = code.toString(16);
hex += n.length < 2 ? `0${n}` : n;
Expand Down
14 changes: 7 additions & 7 deletions packages/web3-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const _flattenTypes = (includeTuple, puts) => {
export const hexToAscii = (hex) => {
if (!utils.isHexStrict(hex)) throw new Error('The parameter must be a valid HEX string.');

let string = '';
let value = '';

let i = 0;
const l = hex.length;
Expand All @@ -114,27 +114,27 @@ export const hexToAscii = (hex) => {
}
for (; i < l; i += 2) {
const code = parseInt(hex.substr(i, 2), 16);
string += String.fromCharCode(code);
value += String.fromCharCode(code);
}

return string;
return value;
};

/**
* Should be called to get hex representation (prefixed by 0x) of ascii string
*
* @method asciiToHex
*
* @param {String} str
* @param {String} value
* @param {Number} length
*
* @returns {String} hex representation of input string
*/
export const asciiToHex = (string, length = 32) => {
export const asciiToHex = (value, length = 32) => {
let hex = '';

for (let i = 0; i < string.length; i++) {
const code = string.charCodeAt(i);
for (let i = 0; i < value.length; i++) {
const code = value.charCodeAt(i);
const n = code.toString(16);
hex += n.length < 2 ? `0${n}` : n;
}
Expand Down

0 comments on commit e8418c8

Please sign in to comment.