aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/signed_order_coercion.ts
blob: 649596a3ddb85e96da7e5a6b3d95cd62fb15a05e (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
import { BigNumber } from '@0x/asset-buyer';
import { SignedOrder } from '@0x/types';

export const coerceBigNumberOrString = (value: any): BigNumber => {
    if (typeof value === 'string') {
        return new BigNumber(value);
    }
    if (BigNumber.isBigNumber(value)) {
        return new BigNumber(value.toString());
    }
    return value;
};

// function implies that the signed order already has been invalidated
export const coerceSignedOrderBigNumberOfString = (order: SignedOrder): SignedOrder => {
    return {
        ...order,
        makerFee: coerceBigNumberOrString(order.makerFee),
        takerFee: coerceBigNumberOrString(order.takerFee),
        makerAssetAmount: coerceBigNumberOrString(order.makerAssetAmount),
        takerAssetAmount: coerceBigNumberOrString(order.takerAssetAmount),
        salt: coerceBigNumberOrString(order.salt),
        expirationTimeSeconds: coerceBigNumberOrString(order.expirationTimeSeconds),
    };
};