aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src/parsing_utils.ts
blob: 232c54b7b57c0b3396c798a5d1383d9c4d805e1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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',
        ]);
    },
};