aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2019-01-12 00:14:57 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2019-01-12 00:14:57 +0800
commit742e5e039dd4e821209b5511fb6a194d11c6291c (patch)
treee7a5babe944632f4ec6c0d60fc39ace6d985ce4f /packages/instant
parent119231451013b37059327a676963a0931d7ed093 (diff)
downloaddexon-0x-contracts-742e5e039dd4e821209b5511fb6a194d11c6291c.tar.gz
dexon-0x-contracts-742e5e039dd4e821209b5511fb6a194d11c6291c.tar.zst
dexon-0x-contracts-742e5e039dd4e821209b5511fb6a194d11c6291c.zip
getLiquidityForAssetDataAsync helper method, and fix to assetBuyer to check for eth token in asset pairs
Diffstat (limited to 'packages/instant')
-rw-r--r--packages/instant/src/index.umd.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/instant/src/index.umd.ts b/packages/instant/src/index.umd.ts
index 5a1eb1608..5c0ab8eae 100644
--- a/packages/instant/src/index.umd.ts
+++ b/packages/instant/src/index.umd.ts
@@ -1,4 +1,6 @@
+import { AssetBuyer } from '@0x/asset-buyer';
import { assetDataUtils } from '@0x/order-utils';
+import { Provider } from 'ethereum-types';
import * as _ from 'lodash';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
@@ -12,8 +14,10 @@ import {
} from './constants';
import { assetMetaDataMap } from './data/asset_meta_data_map';
import { ZeroExInstantOverlay, ZeroExInstantOverlayProps } from './index';
+import { Network, OrderSource } from './types';
import { analytics } from './util/analytics';
import { assert } from './util/assert';
+import { providerFactory } from './util/provider_factory';
import { util } from './util/util';
const isInstantRendered = (): boolean => !!document.getElementById(INJECTED_DIV_ID);
@@ -134,6 +138,32 @@ export const hasMetaDataForAssetData = (assetData: string): boolean => {
return assetMetaDataMap[assetData] !== undefined;
};
+export const getLiquidityForAssetDataAsync = async (
+ assetData: string,
+ orderSource: OrderSource,
+ networkId: Network = Network.Mainnet,
+ provider?: Provider,
+) => {
+ assert.isHexString('assetData', assetData);
+ assert.isValidOrderSource('orderSource', orderSource);
+ assert.isNumber('networkId', networkId);
+
+ if (provider !== undefined) {
+ assert.isWeb3Provider('provider', provider);
+ }
+
+ const bestProvider: Provider = provider || providerFactory.getFallbackNoSigningProvider(networkId);
+
+ const assetBuyerOptions = { networkId };
+
+ const assetBuyer =
+ typeof orderSource === 'string'
+ ? AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(bestProvider, orderSource, assetBuyerOptions)
+ : AssetBuyer.getAssetBuyerForProvidedOrders(bestProvider, orderSource, assetBuyerOptions);
+
+ return assetBuyer.getLiquidityForAssetDataAsync(assetData);
+};
+
// Write version info to the exported object for debugging
export const GIT_SHA = GIT_SHA_FROM_CONSTANT;
export const NPM_VERSION = NPM_PACKAGE_VERSION;