diff options
Diffstat (limited to 'packages/order-utils/src/parsing_utils.ts')
-rw-r--r-- | packages/order-utils/src/parsing_utils.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/order-utils/src/parsing_utils.ts b/packages/order-utils/src/parsing_utils.ts new file mode 100644 index 000000000..73841c1a2 --- /dev/null +++ b/packages/order-utils/src/parsing_utils.ts @@ -0,0 +1,27 @@ +import { BigNumber } from '@0xproject/utils'; +import * as _ from 'lodash'; + +export const orderParsingUtils = { + convertStringsFieldsToBigNumbers(obj: any, fields: string[]): any { + const result = _.assign({}, obj); + _.each(fields, field => { + _.update(result, field, (value: string) => { + if (_.isUndefined(value)) { + throw new Error(`Could not find field '${field}' while converting string fields to BigNumber.`); + } + return new BigNumber(value); + }); + }); + return result; + }, + convertOrderStringFieldsToBigNumber(order: any): any { + return orderParsingUtils.convertStringsFieldsToBigNumbers(order, [ + 'makerAssetAmount', + 'takerAssetAmount', + 'makerFee', + 'takerFee', + 'expirationTimeSeconds', + 'salt', + ]); + } +}
\ No newline at end of file |