diff options
author | Fabio Berger <me@fabioberger.com> | 2018-11-12 05:11:10 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-11-12 05:11:10 +0800 |
commit | 0391f93490cffdc69f6cb32f11762d174ed04e37 (patch) | |
tree | 3a8b30a04de1193aa21e5b84bd572db24979a8bf /packages/instant/src/components/zero_ex_instant.tsx | |
parent | 399a7d5fec9af4f3491a77f0c2d46738f3d8ffa7 (diff) | |
parent | 397b4e289015f9bb0831c1a0ce6fee601670b487 (diff) | |
download | dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.gz dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.bz2 dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.lz dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.xz dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.zst dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.zip |
merge development
Diffstat (limited to 'packages/instant/src/components/zero_ex_instant.tsx')
-rw-r--r-- | packages/instant/src/components/zero_ex_instant.tsx | 85 |
1 files changed, 14 insertions, 71 deletions
diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index ffa5a8250..b945f9908 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -1,75 +1,18 @@ -import { AssetBuyer } from '@0x/asset-buyer'; -import { ObjectMap } from '@0x/types'; import * as React from 'react'; -import { Provider } from 'react-redux'; -import { SelectedAssetThemeProvider } from '../containers/selected_asset_theme_provider'; -import { asyncData } from '../redux/async_data'; -import { INITIAL_STATE, State } from '../redux/reducer'; -import { store, Store } from '../redux/store'; -import { fonts } from '../style/fonts'; -import { AssetMetaData, Network } from '../types'; -import { assetUtils } from '../util/asset'; -import { getProvider } from '../util/provider'; +import { INJECTED_DIV_CLASS } from '../constants'; import { ZeroExInstantContainer } from './zero_ex_instant_container'; - -fonts.include(); - -export type ZeroExInstantProps = ZeroExInstantRequiredProps & Partial<ZeroExInstantOptionalProps>; - -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; -} - -export interface ZeroExInstantOptionalProps { - additionalAssetMetaDataMap: ObjectMap<AssetMetaData>; - network: Network; -} - -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; - // TODO: Provider needs to not be hard-coded to injected web3. - const assetBuyer = AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(getProvider(), props.liquiditySource, { - networkId: network, - }); - const completeAssetMetaDataMap = { - ...props.additionalAssetMetaDataMap, - ...state.assetMetaDataMap, - }; - const storeStateFromProps: State = { - ...state, - assetBuyer, - network, - selectedAsset: assetUtils.createAssetFromAssetData(props.assetData, completeAssetMetaDataMap, network), - assetMetaDataMap: completeAssetMetaDataMap, - }; - return storeStateFromProps; - } - constructor(props: ZeroExInstantProps) { - super(props); - this._store = store.create(ZeroExInstant._mergeInitialStateWithProps(this.props, INITIAL_STATE)); - // tslint:disable-next-line:no-floating-promises - asyncData.fetchAndDispatchToStore(this._store); - } - - public render(): React.ReactNode { - return ( - <Provider store={this._store}> - <SelectedAssetThemeProvider> - <ZeroExInstantContainer /> - </SelectedAssetThemeProvider> - </Provider> - ); - } -} +import { ZeroExInstantProvider, ZeroExInstantProviderProps } from './zero_ex_instant_provider'; + +export type ZeroExInstantProps = ZeroExInstantProviderProps; + +export const ZeroExInstant: React.StatelessComponent<ZeroExInstantProps> = props => { + return ( + <div className={INJECTED_DIV_CLASS}> + <ZeroExInstantProvider {...props}> + <ZeroExInstantContainer /> + </ZeroExInstantProvider> + </div> + ); +}; |