diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-11-01 10:20:37 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-11-01 10:21:06 +0800 |
commit | 6091ee732d208eaf9889087b8308dfd0427b9be5 (patch) | |
tree | c13189159cc172c9f82340a8d3a2bd69eed47f6e /packages/instant/src/components | |
parent | 8c336925601127c759ad4cfbca119368a2edfd56 (diff) | |
download | dexon-sol-tools-6091ee732d208eaf9889087b8308dfd0427b9be5.tar dexon-sol-tools-6091ee732d208eaf9889087b8308dfd0427b9be5.tar.gz dexon-sol-tools-6091ee732d208eaf9889087b8308dfd0427b9be5.tar.bz2 dexon-sol-tools-6091ee732d208eaf9889087b8308dfd0427b9be5.tar.lz dexon-sol-tools-6091ee732d208eaf9889087b8308dfd0427b9be5.tar.xz dexon-sol-tools-6091ee732d208eaf9889087b8308dfd0427b9be5.tar.zst dexon-sol-tools-6091ee732d208eaf9889087b8308dfd0427b9be5.zip |
feat: modify public API to allow for passing in available assets, or fetch assets from SRA
Diffstat (limited to 'packages/instant/src/components')
-rw-r--r-- | packages/instant/src/components/zero_ex_instant.tsx | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index d54dfc153..ab6350010 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -24,13 +24,13 @@ fonts.include(); export type ZeroExInstantProps = ZeroExInstantRequiredProps & Partial<ZeroExInstantOptionalProps>; export interface ZeroExInstantRequiredProps { - // TODO: Change API when we allow the selection of different assetDatas - assetData: string; - liquiditySource: string | SignedOrder[]; + orderSource: string | SignedOrder[]; } export interface ZeroExInstantOptionalProps { + availableAssetDatas: string[]; defaultAssetBuyAmount?: number; + defaultSelectedAssetData?: string; additionalAssetMetaDataMap: ObjectMap<AssetMetaData>; networkId: Network; } @@ -45,14 +45,14 @@ export class ZeroExInstant extends React.Component<ZeroExInstantProps> { networkId, }; let assetBuyer; - if (_.isString(props.liquiditySource)) { + if (_.isString(props.orderSource)) { assetBuyer = AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl( provider, - props.liquiditySource, + props.orderSource, assetBuyerOptions, ); } else { - assetBuyer = AssetBuyer.getAssetBuyerForProvidedOrders(provider, props.liquiditySource, assetBuyerOptions); + assetBuyer = AssetBuyer.getAssetBuyerForProvidedOrders(provider, props.orderSource, assetBuyerOptions); } const completeAssetMetaDataMap = { ...props.additionalAssetMetaDataMap, @@ -62,7 +62,13 @@ export class ZeroExInstant extends React.Component<ZeroExInstantProps> { ...state, assetBuyer, network: networkId, - selectedAsset: assetUtils.createAssetFromAssetData(props.assetData, completeAssetMetaDataMap, networkId), + selectedAsset: _.isUndefined(props.defaultSelectedAssetData) + ? undefined + : assetUtils.createAssetFromAssetDataOrThrow( + props.defaultSelectedAssetData, + completeAssetMetaDataMap, + networkId, + ), selectedAssetAmount: _.isUndefined(props.defaultAssetBuyAmount) ? state.selectedAssetAmount : new BigNumberInput(props.defaultAssetBuyAmount), @@ -77,8 +83,14 @@ export class ZeroExInstant extends React.Component<ZeroExInstantProps> { } public componentDidMount(): void { + const state = this._store.getState(); // tslint:disable-next-line:no-floating-promises - asyncData.fetchAndDispatchToStore(this._store); + asyncData.fetchEthPriceAndDispatchToStore(this._store); + // fetch available assets if none are specified + if (_.isEmpty(state.availableAssets)) { + // tslint:disable-next-line:no-floating-promises + asyncData.fetchAvailableAssetDatasAndDispatchToStore(this._store); + } // warm up the gas price estimator cache just in case we can't // grab the gas price estimate when submitting the transaction |