aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-10-19 06:48:35 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-10-19 06:48:35 +0800
commitb4fb6b5ff3106c9223508469a2bee583bcea8da0 (patch)
treec34de19c59aa3c167dbb3daf0941b57079ac9311 /packages
parentc87e68f833a2d8a87846d70a9d4a727b46323eea (diff)
downloaddexon-sol-tools-b4fb6b5ff3106c9223508469a2bee583bcea8da0.tar
dexon-sol-tools-b4fb6b5ff3106c9223508469a2bee583bcea8da0.tar.gz
dexon-sol-tools-b4fb6b5ff3106c9223508469a2bee583bcea8da0.tar.bz2
dexon-sol-tools-b4fb6b5ff3106c9223508469a2bee583bcea8da0.tar.lz
dexon-sol-tools-b4fb6b5ff3106c9223508469a2bee583bcea8da0.tar.xz
dexon-sol-tools-b4fb6b5ff3106c9223508469a2bee583bcea8da0.tar.zst
dexon-sol-tools-b4fb6b5ff3106c9223508469a2bee583bcea8da0.zip
fix: add error message and move more logic to assetUtils
Diffstat (limited to 'packages')
-rw-r--r--packages/instant/src/data/asset_data_network_mapping.ts12
-rw-r--r--packages/instant/src/util/asset.ts11
2 files changed, 10 insertions, 13 deletions
diff --git a/packages/instant/src/data/asset_data_network_mapping.ts b/packages/instant/src/data/asset_data_network_mapping.ts
index 9e14462f8..e8ccbf011 100644
--- a/packages/instant/src/data/asset_data_network_mapping.ts
+++ b/packages/instant/src/data/asset_data_network_mapping.ts
@@ -7,19 +7,9 @@ interface AssetDataByNetwork {
[Network.Mainnet]?: string;
}
-const sameAssetDatas: AssetDataByNetwork[] = [
+export const assetDataNetworkMapping: AssetDataByNetwork[] = [
{
[Network.Mainnet]: '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498',
[Network.Kovan]: '0xf47261b00000000000000000000000002002d3812f58e35f0ea1ffbf80a75a38c32175fa',
},
];
-
-export const assetDataNetworkMapping = {
- getAssociatedAssetDataIfExists: (assetData: string, network: Network): string | undefined => {
- const assetDataGroupIfExists = _.find(sameAssetDatas, value => value[network] === assetData);
- if (_.isUndefined(assetDataGroupIfExists)) {
- return;
- }
- return assetDataGroupIfExists[Network.Mainnet];
- },
-};
diff --git a/packages/instant/src/util/asset.ts b/packages/instant/src/util/asset.ts
index edeac0da3..e0d5ffcb7 100644
--- a/packages/instant/src/util/asset.ts
+++ b/packages/instant/src/util/asset.ts
@@ -19,14 +19,14 @@ export const assetUtils = {
): AssetMetaData => {
let mainnetAssetData: string | undefined = assetData;
if (network !== Network.Mainnet) {
- mainnetAssetData = assetDataNetworkMapping.getAssociatedAssetDataIfExists(assetData, network);
+ mainnetAssetData = assetUtils.getAssociatedAssetDataIfExists(assetData, network);
}
if (_.isUndefined(mainnetAssetData)) {
throw new Error(ZeroExInstantError.AssetMetaDataNotAvailable);
}
const metaData = metaDataMap[mainnetAssetData];
if (_.isUndefined(metaData)) {
- throw new Error();
+ throw new Error(ZeroExInstantError.AssetMetaDataNotAvailable);
}
return metaData;
},
@@ -44,4 +44,11 @@ export const assetUtils = {
return defaultName;
}
},
+ getAssociatedAssetDataIfExists: (assetData: string, network: Network): string | undefined => {
+ const assetDataGroupIfExists = _.find(assetDataNetworkMapping, value => value[network] === assetData);
+ if (_.isUndefined(assetDataGroupIfExists)) {
+ return;
+ }
+ return assetDataGroupIfExists[Network.Mainnet];
+ },
};