aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src
diff options
context:
space:
mode:
authorDavid Sun <dvsuner@protonmail.com>2019-02-05 00:19:18 +0800
committerDavid Sun <dvsuner@protonmail.com>2019-02-05 00:19:18 +0800
commit59f48d6d5702210acea868c3ac2ede6315f0c8ec (patch)
treeb45232aabd34fa217f5dceeea72a4a98f170710d /packages/instant/src
parent1d3fff32a29b4e958cd32acb016577683df95d3d (diff)
downloaddexon-0x-contracts-59f48d6d5702210acea868c3ac2ede6315f0c8ec.tar.gz
dexon-0x-contracts-59f48d6d5702210acea868c3ac2ede6315f0c8ec.tar.zst
dexon-0x-contracts-59f48d6d5702210acea868c3ac2ede6315f0c8ec.zip
working on big number coercion function
Diffstat (limited to 'packages/instant/src')
-rw-r--r--packages/instant/src/index.umd.ts7
-rw-r--r--packages/instant/src/util/signed_order_coercion.ts25
2 files changed, 32 insertions, 0 deletions
diff --git a/packages/instant/src/index.umd.ts b/packages/instant/src/index.umd.ts
index 0acf3f2ad..0c2ce5ec1 100644
--- a/packages/instant/src/index.umd.ts
+++ b/packages/instant/src/index.umd.ts
@@ -19,6 +19,7 @@ import { analytics } from './util/analytics';
import { assert } from './util/assert';
import { providerFactory } from './util/provider_factory';
import { util } from './util/util';
+import { coerceSignedOrderBigNumberOfString } from './util/signed_order_coercion'
const isInstantRendered = (): boolean => !!document.getElementById(INJECTED_DIV_ID);
@@ -94,6 +95,12 @@ export interface ZeroExInstantConfig extends ZeroExInstantOverlayProps {
export const render = (config: ZeroExInstantConfig, selector: string = DEFAULT_ZERO_EX_CONTAINER_SELECTOR) => {
validateInstantRenderConfig(config, selector);
+
+ // TODO(David Sun) test functionality of order bignumber version coercion
+ if (!_.isString(config.orderSource)) {
+ config.orderSource = config.orderSource.map(coerceSignedOrderBigNumberOfString);
+ }
+
if (config.shouldDisablePushToHistory) {
if (!isInstantRendered()) {
renderInstant(config, selector);
diff --git a/packages/instant/src/util/signed_order_coercion.ts b/packages/instant/src/util/signed_order_coercion.ts
new file mode 100644
index 000000000..649596a3d
--- /dev/null
+++ b/packages/instant/src/util/signed_order_coercion.ts
@@ -0,0 +1,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),
+ };
+};