aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-10-19 01:43:41 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-10-19 01:43:41 +0800
commita764dfa789ba44e519371b4a1e4569db7f551fb7 (patch)
tree80cd8aff6fcf941269afdec8022d0dd5759700fa /packages/instant/src/util
parent5ec4b27200297708298deca97603849a37b2f66a (diff)
downloaddexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.gz
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/util')
-rw-r--r--packages/instant/src/util/asset.ts34
-rw-r--r--packages/instant/src/util/asset_buyer.ts9
2 files changed, 34 insertions, 9 deletions
diff --git a/packages/instant/src/util/asset.ts b/packages/instant/src/util/asset.ts
new file mode 100644
index 000000000..ec22276ae
--- /dev/null
+++ b/packages/instant/src/util/asset.ts
@@ -0,0 +1,34 @@
+import { assetDataUtils } from '@0xproject/order-utils';
+import { AssetProxyId, ObjectMap } from '@0xproject/types';
+import * as _ from 'lodash';
+
+import { assetDataNetworkMapping } from '../data/asset_data_network_mapping';
+import { Asset, AssetMetaData, Network, ZeroExInstantError } from '../types';
+
+export const assetUtils = {
+ createAssetFromAssetData: (assetData: string, assetMetaDataMap: ObjectMap<AssetMetaData>): Asset => {
+ return {
+ assetProxyId: assetDataUtils.decodeAssetProxyId(assetData),
+ assetData,
+ metaData: assetUtils.getMetaDataOrThrow(assetData, assetMetaDataMap),
+ };
+ },
+ getMetaDataOrThrow: (
+ assetData: string,
+ metaDataMap: ObjectMap<AssetMetaData>,
+ network: Network = Network.Mainnet,
+ ): AssetMetaData => {
+ let mainnetAssetData: string | undefined = assetData;
+ if (network !== Network.Mainnet) {
+ mainnetAssetData = assetDataNetworkMapping.getAssociatedAssetDataIfExists(assetData, network);
+ }
+ if (_.isUndefined(mainnetAssetData)) {
+ throw new Error(ZeroExInstantError.AssetMetaDataNotAvailable);
+ }
+ const metaData = metaDataMap[mainnetAssetData];
+ if (_.isUndefined(metaData)) {
+ throw new Error();
+ }
+ return metaData;
+ },
+};
diff --git a/packages/instant/src/util/asset_buyer.ts b/packages/instant/src/util/asset_buyer.ts
deleted file mode 100644
index 27d66d600..000000000
--- a/packages/instant/src/util/asset_buyer.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { AssetBuyer } from '@0xproject/asset-buyer';
-
-import { sraApiUrl } from '../constants';
-
-import { getProvider } from './provider';
-
-const provider = getProvider();
-
-export const assetBuyer = AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(provider, sraApiUrl);