diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-26 02:43:53 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-26 02:43:53 +0800 |
commit | 2a1c2a55eda0f3d279aa1145b6157892d03001ae (patch) | |
tree | 812b5eb19248c021e8e1f9231e52f884a4683803 /packages/instant | |
parent | 46a8aad87a978567026881d8c1db998ac14eab4e (diff) | |
download | dexon-sol-tools-2a1c2a55eda0f3d279aa1145b6157892d03001ae.tar dexon-sol-tools-2a1c2a55eda0f3d279aa1145b6157892d03001ae.tar.gz dexon-sol-tools-2a1c2a55eda0f3d279aa1145b6157892d03001ae.tar.bz2 dexon-sol-tools-2a1c2a55eda0f3d279aa1145b6157892d03001ae.tar.lz dexon-sol-tools-2a1c2a55eda0f3d279aa1145b6157892d03001ae.tar.xz dexon-sol-tools-2a1c2a55eda0f3d279aa1145b6157892d03001ae.tar.zst dexon-sol-tools-2a1c2a55eda0f3d279aa1145b6157892d03001ae.zip |
feat: supply render options from URL
Diffstat (limited to 'packages/instant')
-rw-r--r-- | packages/instant/public/index.html | 43 | ||||
-rw-r--r-- | packages/instant/src/components/zero_ex_instant.tsx | 21 | ||||
-rw-r--r-- | packages/instant/src/util/error.ts | 1 |
3 files changed, 57 insertions, 8 deletions
diff --git a/packages/instant/public/index.html b/packages/instant/public/index.html index 14555fc64..4c1c52afd 100644 --- a/packages/instant/public/index.html +++ b/packages/instant/public/index.html @@ -6,6 +6,8 @@ <meta name="viewport" content="width=device-width, initial-scale=1"> <title>0x Instant Dev Environment</title> <script type="text/javascript" src="/main.bundle.js" charset="utf-8"></script> + <script type="text/javascript" src="https://unpkg.com/jsuri@1.3.1/Uri.js" charset="utf-8"></script> + <script type="text/javascript" src="https://unpkg.com/bignumber.js@4.1.0/bignumber.js" charset="utf-8"></script> <style> #zeroExInstantContainer { display: flex; @@ -24,10 +26,47 @@ <body> <div id="zeroExInstantContainer"></div> <script> - zeroExInstant.render({ + const removeUndefined = (obj) => { + for (let k in obj) if (obj[k] === undefined) delete obj[k]; + return obj; + } + BigNumber.config({ + EXPONENTIAL_AT: 1000, + DECIMAL_PLACES: 78, + }); + const providedOrder = { + senderAddress: '0x0000000000000000000000000000000000000000', + makerAddress: '0x14e2f1f157e7dd4057d02817436d628a37120fd1', + takerAddress: '0x0000000000000000000000000000000000000000', + makerFee: new BigNumber('0'), + takerFee: new BigNumber('0'), + makerAssetAmount: new BigNumber('100000000000000000000'), + takerAssetAmount: new BigNumber('10000000000000000'), + makerAssetData: '0xf47261b00000000000000000000000002002d3812f58e35f0ea1ffbf80a75a38c32175fa', + takerAssetData: '0xf47261b0000000000000000000000000d0a1e359811322d97991e03f863a0c30c2cf029c', + expirationTimeSeconds: new BigNumber('1591858800'), + feeRecipientAddress: '0x0000000000000000000000000000000000000000', + salt: new BigNumber( + '54983920541892966634674340965984367456810207583416050222519063020710969340046', + ), + signature: + '0x1b949656218421c845995457303569a656764afa2b979d41dcefff0009d57ce15001490268bc7caa4269894fd83b741465fc5a7a53eda6ece17eb91fb32655d83703', + exchangeAddress: '0x35dd2932454449b14cee11a94d3674a936d5d7b2', + }; + const queryParams = new Uri(window.location.search); + const renderOptionsDefaults = { liquiditySource: 'https://api.radarrelay.com/0x/v2/', assetData: '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498', - }); + } + const liquiditySourceOverride = queryParams.getQueryParamValue('liquiditySource'); + const renderOptionsOverrides = { + liquiditySource: liquiditySourceOverride === 'provided' ? [providedOrder] : liquiditySourceOverride, + assetData: queryParams.getQueryParamValue('assetData'), + network: +queryParams.getQueryParamValue('network'), + } + const renderOptions = Object.assign({}, renderOptionsDefaults, removeUndefined(renderOptionsOverrides)); + console.log(renderOptions) + zeroExInstant.render(renderOptions); </script> </body> diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index ffa5a8250..0fe494726 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 } from '@0x/types'; +import { ObjectMap, SignedOrder } from '@0x/types'; +import * as _ from 'lodash'; import * as React from 'react'; import { Provider } from 'react-redux'; @@ -21,8 +22,7 @@ export type ZeroExInstantProps = ZeroExInstantRequiredProps & Partial<ZeroExInst export interface ZeroExInstantRequiredProps { // TODO: Change API when we allow the selection of different assetDatas assetData: string; - // TODO: Allow for a function that returns orders - liquiditySource: string; + liquiditySource: string | SignedOrder[]; } export interface ZeroExInstantOptionalProps { @@ -40,9 +40,20 @@ export class ZeroExInstant extends React.Component<ZeroExInstantProps> { }; const { network } = optionalPropsWithDefaults; // TODO: Provider needs to not be hard-coded to injected web3. - const assetBuyer = AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(getProvider(), props.liquiditySource, { + const provider = getProvider(); + const assetBuyerOptions = { networkId: network, - }); + }; + let assetBuyer; + if (_.isString(props.liquiditySource)) { + assetBuyer = AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl( + provider, + props.liquiditySource, + assetBuyerOptions, + ); + } else { + assetBuyer = AssetBuyer.getAssetBuyerForProvidedOrders(provider, props.liquiditySource, assetBuyerOptions); + } const completeAssetMetaDataMap = { ...props.additionalAssetMetaDataMap, ...state.assetMetaDataMap, diff --git a/packages/instant/src/util/error.ts b/packages/instant/src/util/error.ts index 40fd24c7e..f5a3d2cb8 100644 --- a/packages/instant/src/util/error.ts +++ b/packages/instant/src/util/error.ts @@ -10,7 +10,6 @@ class ErrorFlasher { private _timeoutId?: number; public flashNewError(dispatch: Dispatch<Action>, error: any, delayMs: number = 7000): void { this._clearTimeout(); - // dispatch new message dispatch(actions.setError(error)); |