Add order parsers to order-util
This commit is contained in:
@@ -6,6 +6,7 @@ export { eip712Utils } from './eip712_utils';
|
||||
export { marketUtils } from './market_utils';
|
||||
export { rateUtils } from './rate_utils';
|
||||
export { sortingUtils } from './sorting_utils';
|
||||
export { orderParsingUtils } from './parsing_utils';
|
||||
|
||||
export { OrderStateUtils } from './order_state_utils';
|
||||
export { AbstractBalanceAndProxyAllowanceFetcher } from './abstract/abstract_balance_and_proxy_allowance_fetcher';
|
||||
@@ -45,4 +46,4 @@ export {
|
||||
FindOrdersThatCoverMakerAssetFillAmountOpts,
|
||||
FeeOrdersAndRemainingFeeAmount,
|
||||
OrdersAndRemainingFillAmount,
|
||||
} from './types';
|
||||
} from './types';
|
||||
27
packages/order-utils/src/parsing_utils.ts
Normal file
27
packages/order-utils/src/parsing_utils.ts
Normal file
@@ -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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user