diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-19 01:43:41 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-19 01:43:41 +0800 |
commit | a764dfa789ba44e519371b4a1e4569db7f551fb7 (patch) | |
tree | 80cd8aff6fcf941269afdec8022d0dd5759700fa /packages/instant/src/components/zero_ex_instant.tsx | |
parent | 5ec4b27200297708298deca97603849a37b2f66a (diff) | |
download | dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.gz dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.bz2 dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.lz dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.xz dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.zst dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.zip |
feat: MVP of passing in sraApiUrl, assetData and other settings from render method
Diffstat (limited to 'packages/instant/src/components/zero_ex_instant.tsx')
-rw-r--r-- | packages/instant/src/components/zero_ex_instant.tsx | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index f6472e811..cc7b0ecb8 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -1,23 +1,59 @@ +import { AssetBuyer } from '@0xproject/asset-buyer'; +import { ObjectMap } from '@0xproject/types'; import * as React from 'react'; import { Provider } from 'react-redux'; +import { assetMetaDataMap } from '../data/asset_meta_data_map'; import { asyncData } from '../redux/async_data'; -import { store } from '../redux/store'; +import { State } from '../redux/reducer'; +import { store, Store } from '../redux/store'; import { fonts } from '../style/fonts'; import { theme, ThemeProvider } from '../style/theme'; +import { AssetMetaData } from '../types'; +import { assetUtils } from '../util/asset'; +import { getProvider } from '../util/provider'; import { ZeroExInstantContainer } from './zero_ex_instant_container'; fonts.include(); -// tslint:disable-next-line:no-floating-promises -asyncData.fetchAndDispatchToStore(); -export interface ZeroExInstantProps {} +export interface ZeroExInstantProps { + // TODO: Change API when we allow the selection of different assetDatas + assetData: string; + sraApiUrl: string; + additionalAssetMetaDataMap: ObjectMap<AssetMetaData>; +} -export const ZeroExInstant: React.StatelessComponent<ZeroExInstantProps> = () => ( - <Provider store={store}> - <ThemeProvider theme={theme}> - <ZeroExInstantContainer /> - </ThemeProvider> - </Provider> -); +export class ZeroExInstant extends React.Component<ZeroExInstantProps> { + public static defaultProps = { + additionalAssetMetaDataMap: {}, + }; + public store: Store; + constructor(props: ZeroExInstantProps) { + super(props); + // TODO: Provider needs to not be hard-coded to injected web3. + const assetBuyer = AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(getProvider(), props.sraApiUrl); + const completeAssetMetaDataMap = { + ...props.additionalAssetMetaDataMap, + ...assetMetaDataMap, + }; + const storeStateFromProps: Partial<State> = { + assetBuyer, + selectedAsset: assetUtils.createAssetFromAssetData(props.assetData, completeAssetMetaDataMap), + assetMetaDataMap: completeAssetMetaDataMap, + }; + this.store = store.create(storeStateFromProps); + // tslint:disable-next-line:no-floating-promises + asyncData.fetchAndDispatchToStore(this.store); + } + + public render(): React.ReactNode { + return ( + <Provider store={this.store}> + <ThemeProvider theme={theme}> + <ZeroExInstantContainer /> + </ThemeProvider> + </Provider> + ); + } +} |