aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2019-01-18 19:53:04 +0800
committerGitHub <noreply@github.com>2019-01-18 19:53:04 +0800
commitc8212f1d4d255120e5e683664b86f1830fb45ae6 (patch)
tree73f1528a36b8fc8a0778e164b1579eb5865d944a /packages/instant/src
parent7d166dc7da23c30540fb554727a955015073286f (diff)
parentbef30e4209b26c8d4f443f8672e9acb9471c6a37 (diff)
downloaddexon-0x-contracts-c8212f1d4d255120e5e683664b86f1830fb45ae6.tar.gz
dexon-0x-contracts-c8212f1d4d255120e5e683664b86f1830fb45ae6.tar.zst
dexon-0x-contracts-c8212f1d4d255120e5e683664b86f1830fb45ae6.zip
Merge branch 'development' into feature/bignumber-8.0
Diffstat (limited to 'packages/instant/src')
-rw-r--r--packages/instant/src/index.umd.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/packages/instant/src/index.umd.ts b/packages/instant/src/index.umd.ts
index d172f4145..0acf3f2ad 100644
--- a/packages/instant/src/index.umd.ts
+++ b/packages/instant/src/index.umd.ts
@@ -1,3 +1,6 @@
+import { AssetBuyer, BigNumber } 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';
@@ -9,9 +12,12 @@ import {
INJECTED_DIV_ID,
NPM_PACKAGE_VERSION,
} 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);
@@ -122,6 +128,42 @@ export const render = (config: ZeroExInstantConfig, selector: string = DEFAULT_Z
window.onpopstate = onPopStateHandler;
};
+export const assetDataForERC20TokenAddress = (tokenAddress: string): string => {
+ assert.isETHAddressHex('tokenAddress', tokenAddress);
+ return assetDataUtils.encodeERC20AssetData(tokenAddress);
+};
+
+export const hasMetaDataForAssetData = (assetData: string): boolean => {
+ assert.isHexString('assetData', assetData);
+ return assetMetaDataMap[assetData] !== undefined;
+};
+
+export const hasLiquidityForAssetDataAsync = async (
+ assetData: string,
+ orderSource: OrderSource,
+ networkId: Network = Network.Mainnet,
+ provider?: Provider,
+): Promise<boolean> => {
+ 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 = _.isString(orderSource)
+ ? AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(bestProvider, orderSource, assetBuyerOptions)
+ : AssetBuyer.getAssetBuyerForProvidedOrders(bestProvider, orderSource, assetBuyerOptions);
+
+ const liquidity = await assetBuyer.getLiquidityForAssetDataAsync(assetData);
+ return liquidity.ethValueAvailableInWei.gt(new BigNumber(0));
+};
+
// Write version info to the exported object for debugging
export const GIT_SHA = GIT_SHA_FROM_CONSTANT;
export const NPM_VERSION = NPM_PACKAGE_VERSION;