diff options
-rw-r--r-- | packages/instant/src/index.umd.ts | 7 | ||||
-rw-r--r-- | packages/instant/src/util/signed_order_coercion.ts | 25 |
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), + }; +}; |