aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/signed_order_coercion.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/instant/src/util/signed_order_coercion.ts')
-rw-r--r--packages/instant/src/util/signed_order_coercion.ts41
1 files changed, 21 insertions, 20 deletions
diff --git a/packages/instant/src/util/signed_order_coercion.ts b/packages/instant/src/util/signed_order_coercion.ts
index 649596a3d..4209e05e1 100644
--- a/packages/instant/src/util/signed_order_coercion.ts
+++ b/packages/instant/src/util/signed_order_coercion.ts
@@ -1,25 +1,26 @@
-import { BigNumber } from '@0x/asset-buyer';
import { SignedOrder } from '@0x/types';
+import { BigNumber } from '@0x/utils';
+import * as _ from 'lodash';
-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;
+import { maybeBigNumberUtil } from './maybe_big_number';
+
+const coerceBigNumberOrString = (value: any): BigNumber => {
+ const bn = maybeBigNumberUtil.bigNumberOrStringToMaybeBigNumber(value);
+ return !!bn ? bn : 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),
- };
+// function implies that the signed order already has been validated
+export const signedOrderCoercionUtil = {
+ // coerces order big number values to the BigNumber version utilized by 0x
+ bigNumberCoercion: (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),
+ };
+ },
};