From 23b165669202c1bdf4bd7d7e509b9bfe06e3ef8a Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 25 Oct 2018 14:37:34 -0700 Subject: feat: support defaultAssetBuyAmount setting --- packages/instant/public/index.html | 3 ++- packages/instant/src/components/zero_ex_instant.tsx | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/instant/public/index.html b/packages/instant/public/index.html index ba31a86ac..95216a929 100644 --- a/packages/instant/public/index.html +++ b/packages/instant/public/index.html @@ -62,7 +62,8 @@ const renderOptionsOverrides = { liquiditySource: liquiditySourceOverride === 'provided' ? [providedOrder] : liquiditySourceOverride, assetData: queryParams.getQueryParamValue('assetData'), - network: parseInt(queryParams.getQueryParamValue('network'), 10), + network: +queryParams.getQueryParamValue('network'), + defaultAssetBuyAmount: +queryParams.getQueryParamValue('defaultAssetBuyAmount'), } const renderOptions = Object.assign({}, renderOptionsDefaults, removeUndefined(renderOptionsOverrides)); zeroExInstant.render(renderOptions); diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index 63d944654..9018c9427 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -1,5 +1,6 @@ import { AssetBuyer } from '@0x/asset-buyer'; import { ObjectMap, SignedOrder } from '@0x/types'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import * as React from 'react'; import { Provider } from 'react-redux'; @@ -28,6 +29,7 @@ export interface ZeroExInstantRequiredProps { } export interface ZeroExInstantOptionalProps { + defaultAssetBuyAmount?: number; additionalAssetMetaDataMap: ObjectMap; network: Network; } @@ -35,12 +37,7 @@ export interface ZeroExInstantOptionalProps { export class ZeroExInstant extends React.Component { private readonly _store: Store; private static _mergeInitialStateWithProps(props: ZeroExInstantProps, state: State = INITIAL_STATE): State { - // Create merged object such that properties in props override default settings - const optionalPropsWithDefaults: ZeroExInstantOptionalProps = { - additionalAssetMetaDataMap: props.additionalAssetMetaDataMap || {}, - network: props.network || state.network, - }; - const { network } = optionalPropsWithDefaults; + const network = props.network || state.network; // TODO: Provider needs to not be hard-coded to injected web3. const provider = getProvider(); const assetBuyerOptions = { @@ -65,6 +62,9 @@ export class ZeroExInstant extends React.Component { assetBuyer, network, selectedAsset: assetUtils.createAssetFromAssetData(props.assetData, completeAssetMetaDataMap, network), + selectedAssetAmount: _.isUndefined(props.defaultAssetBuyAmount) + ? state.selectedAssetAmount + : new BigNumber(props.defaultAssetBuyAmount), assetMetaDataMap: completeAssetMetaDataMap, }; return storeStateFromProps; -- cgit v1.2.3