diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-26 05:37:34 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-26 05:37:34 +0800 |
commit | 23b165669202c1bdf4bd7d7e509b9bfe06e3ef8a (patch) | |
tree | 28391ad5e06b532075e1d93ce4fa381d96e2f12e /packages/instant | |
parent | d06b40bd8a938557ebba993afa78d20493ad71ef (diff) | |
download | dexon-0x-contracts-23b165669202c1bdf4bd7d7e509b9bfe06e3ef8a.tar.gz dexon-0x-contracts-23b165669202c1bdf4bd7d7e509b9bfe06e3ef8a.tar.zst dexon-0x-contracts-23b165669202c1bdf4bd7d7e509b9bfe06e3ef8a.zip |
feat: support defaultAssetBuyAmount setting
Diffstat (limited to 'packages/instant')
-rw-r--r-- | packages/instant/public/index.html | 3 | ||||
-rw-r--r-- | 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<AssetMetaData>; network: Network; } @@ -35,12 +37,7 @@ export interface ZeroExInstantOptionalProps { export class ZeroExInstant extends React.Component<ZeroExInstantProps> { 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<ZeroExInstantProps> { assetBuyer, network, selectedAsset: assetUtils.createAssetFromAssetData(props.assetData, completeAssetMetaDataMap, network), + selectedAssetAmount: _.isUndefined(props.defaultAssetBuyAmount) + ? state.selectedAssetAmount + : new BigNumber(props.defaultAssetBuyAmount), assetMetaDataMap: completeAssetMetaDataMap, }; return storeStateFromProps; |