aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant
diff options
context:
space:
mode:
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;