diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-28 05:10:34 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:11 +0800 |
commit | f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76 (patch) | |
tree | 52cafb673165eff83d3c75938ff5298ffbd8a68c /packages/utils/src/abi_encoder/evm_data_types | |
parent | 2e79ce26cbeacdeb0ea52b7c2e3da68e8055e7c6 (diff) | |
download | dexon-sol-tools-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar dexon-sol-tools-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.gz dexon-sol-tools-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.bz2 dexon-sol-tools-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.lz dexon-sol-tools-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.xz dexon-sol-tools-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.zst dexon-sol-tools-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.zip |
Replaced null/undefined checks with lodash
Diffstat (limited to 'packages/utils/src/abi_encoder/evm_data_types')
4 files changed, 12 insertions, 9 deletions
diff --git a/packages/utils/src/abi_encoder/evm_data_types/array.ts b/packages/utils/src/abi_encoder/evm_data_types/array.ts index 8cf2cf7cf..a86283c2a 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/array.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/array.ts @@ -1,4 +1,5 @@ import { DataItem } from 'ethereum-types'; +import * as _ from 'lodash'; import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types'; import * as Constants from '../utils/constants'; @@ -14,15 +15,15 @@ export class Array extends AbstractDataTypes.Set { private static _decodeElementTypeAndLengthFromType(type: string): [string, undefined | number] { const matches = Array._MATCHER.exec(type); - if (matches === null || matches.length !== 3) { + if (_.isNull(matches) || matches.length !== 3) { throw new Error(`Could not parse array: ${type}`); - } else if (matches[1] === undefined) { + } else if (_.isUndefined(matches[1])) { throw new Error(`Could not parse array type: ${type}`); - } else if (matches[2] === undefined) { + } else if (_.isUndefined(matches[2])) { throw new Error(`Could not parse array length: ${type}`); } const arrayElementType = matches[1]; - const arrayLength = matches[2] === '' ? undefined : parseInt(matches[2], Constants.DEC_BASE); + const arrayLength = _.isEmpty(matches[2]) ? undefined : parseInt(matches[2], Constants.DEC_BASE); return [arrayElementType, arrayLength]; } @@ -47,13 +48,13 @@ export class Array extends AbstractDataTypes.Set { name: 'N/A', }; const elementComponents = this.getDataItem().components; - if (elementComponents !== undefined) { + if (!_.isUndefined(elementComponents)) { elementDataItem.components = elementComponents; } const elementDataType = this.getFactory().create(elementDataItem); const elementSignature = elementDataType.getSignature(); // Construct signature for array of type `element` - if (this._arrayLength === undefined) { + if (_.isUndefined(this._arrayLength)) { return `${elementSignature}[]`; } else { return `${elementSignature}[${this._arrayLength}]`; diff --git a/packages/utils/src/abi_encoder/evm_data_types/int.ts b/packages/utils/src/abi_encoder/evm_data_types/int.ts index 032cd045a..5c5193644 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/int.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/int.ts @@ -1,5 +1,6 @@ /* tslint:disable prefer-function-over-method */ import { DataItem } from 'ethereum-types'; +import * as _ from 'lodash'; import { BigNumber } from '../../configured_bignumber'; import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types'; @@ -25,7 +26,7 @@ export class Int extends AbstractDataTypes.Blob { private static _decodeWidthFromType(type: string): number { const matches = Int._MATCHER.exec(type); const width = - matches !== null && matches.length === 2 && matches[1] !== undefined + !_.isNull(matches) && matches.length === 2 && !_.isUndefined(matches[1]) ? parseInt(matches[1], Constants.DEC_BASE) : Int._DEFAULT_WIDTH; return width; diff --git a/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts b/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts index 2c649cb33..3a2ad410f 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts @@ -21,7 +21,7 @@ export class StaticBytes extends AbstractDataTypes.Blob { private static _decodeWidthFromType(type: string): number { const matches = StaticBytes._MATCHER.exec(type); const width = - matches !== null && matches.length === 3 && matches[2] !== undefined + !_.isNull(matches) && matches.length === 3 && !_.isUndefined(matches[2]) ? parseInt(matches[2], Constants.DEC_BASE) : StaticBytes._DEFAULT_WIDTH; return width; diff --git a/packages/utils/src/abi_encoder/evm_data_types/uint.ts b/packages/utils/src/abi_encoder/evm_data_types/uint.ts index b5b7683a2..76b944610 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/uint.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/uint.ts @@ -1,5 +1,6 @@ /* tslint:disable prefer-function-over-method */ import { DataItem } from 'ethereum-types'; +import * as _ from 'lodash'; import { BigNumber } from '../../configured_bignumber'; import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types'; @@ -25,7 +26,7 @@ export class UInt extends AbstractDataTypes.Blob { private static _decodeWidthFromType(type: string): number { const matches = UInt._MATCHER.exec(type); const width = - matches !== null && matches.length === 2 && matches[1] !== undefined + !_.isNull(matches) && matches.length === 2 && !_.isUndefined(matches[1]) ? parseInt(matches[1], Constants.DEC_BASE) : UInt._DEFAULT_WIDTH; return width; |