Minor readability improvements (#952)

* Minor readability improvements

* trigger

* Additional

* Additional
This commit is contained in:
Jaco
2021-04-21 10:31:28 +02:00
committed by GitHub
parent 1de30914c2
commit 3a98323e8b
14 changed files with 52 additions and 70 deletions
+1 -5
View File
@@ -22,9 +22,5 @@ export function hexAddPrefix (value?: string | null): string {
return value;
}
const prefix = value && value.length % 2 === 1
? '0'
: '';
return `0x${prefix}${value || ''}`;
return `0x${value && value.length % 2 === 1 ? '0' : ''}${value || ''}`;
}
+2 -6
View File
@@ -22,13 +22,9 @@ const UNPREFIX_HEX_REGEX = /^[a-fA-F0-9]+$/;
export function hexStripPrefix (value?: string | null): string {
if (!value) {
return '';
}
if (hexHasPrefix(value)) {
} else if (hexHasPrefix(value)) {
return value.substr(2);
}
if (UNPREFIX_HEX_REGEX.test(value)) {
} else if (UNPREFIX_HEX_REGEX.test(value)) {
return value;
}
+1 -2
View File
@@ -16,7 +16,7 @@ function reverse (value: string): string {
/**
* @name hexToBn
* @summary Creates a BN.js bignumber object from a hex string.
* @summary Creates a BN.js object from a hex string.
* @description
* `null` inputs returns a `BN(0)` result. Hex input values return the actual value converted to a BN. Anything that is not a hex string (including the `0x` prefix) throws an error.
* @param _value The value to convert
@@ -43,7 +43,6 @@ export function hexToBn (value?: string | number | null, options: ToBnOptions |
// Backwards-compatibility
...(isBoolean(options) ? { isLe: options } : options)
};
const _value = hexStripPrefix(value as string);
// FIXME: Use BN's 3rd argument `isLe` once this issue is fixed