From db77cd10c550803c4f3fac585adc0a7f6ffa8999 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 16 Oct 2018 11:25:52 -0700 Subject: feat(instant): Handle AssetBuyer errors --- packages/instant/src/util/asset_data.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 packages/instant/src/util/asset_data.ts (limited to 'packages/instant/src/util/asset_data.ts') diff --git a/packages/instant/src/util/asset_data.ts b/packages/instant/src/util/asset_data.ts new file mode 100644 index 000000000..958f500bb --- /dev/null +++ b/packages/instant/src/util/asset_data.ts @@ -0,0 +1,18 @@ +import { AssetProxyId } from '@0xproject/types'; + +import { assetMetaData } from '../data/asset_meta_data'; + +// TODO: tests for this +export const bestNameForAsset = (assetData: string | undefined, defaultString: string) => { + if (assetData === undefined) { + return defaultString; + } + const metaData = assetMetaData[assetData]; + if (metaData === undefined) { + return defaultString; + } + if (metaData.assetProxyId === AssetProxyId.ERC20) { + return metaData.symbol.toUpperCase(); + } + return defaultString; +}; -- cgit v1.2.3 From 32fa1bcc387e2eecae53db4b082e93f6fb09ae10 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 17 Oct 2018 13:31:28 -0700 Subject: export assetDataUtil big obj --- packages/instant/src/util/asset_data.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'packages/instant/src/util/asset_data.ts') diff --git a/packages/instant/src/util/asset_data.ts b/packages/instant/src/util/asset_data.ts index 958f500bb..4f3db8447 100644 --- a/packages/instant/src/util/asset_data.ts +++ b/packages/instant/src/util/asset_data.ts @@ -2,17 +2,18 @@ import { AssetProxyId } from '@0xproject/types'; import { assetMetaData } from '../data/asset_meta_data'; -// TODO: tests for this -export const bestNameForAsset = (assetData: string | undefined, defaultString: string) => { - if (assetData === undefined) { +export const assetDataUtil = { + bestNameForAsset: (assetData: string | undefined, defaultString: string) => { + if (assetData === undefined) { + return defaultString; + } + const metaData = assetMetaData[assetData]; + if (metaData === undefined) { + return defaultString; + } + if (metaData.assetProxyId === AssetProxyId.ERC20) { + return metaData.symbol.toUpperCase(); + } return defaultString; - } - const metaData = assetMetaData[assetData]; - if (metaData === undefined) { - return defaultString; - } - if (metaData.assetProxyId === AssetProxyId.ERC20) { - return metaData.symbol.toUpperCase(); - } - return defaultString; + }, }; -- cgit v1.2.3 From d052342df7247f1efc830797a8f69245db247166 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 17 Oct 2018 13:32:54 -0700 Subject: use lodash isUndefined per PR comment --- packages/instant/src/util/asset_data.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'packages/instant/src/util/asset_data.ts') diff --git a/packages/instant/src/util/asset_data.ts b/packages/instant/src/util/asset_data.ts index 4f3db8447..f7c5b78cd 100644 --- a/packages/instant/src/util/asset_data.ts +++ b/packages/instant/src/util/asset_data.ts @@ -1,14 +1,16 @@ +import * as _ from 'lodash'; + import { AssetProxyId } from '@0xproject/types'; import { assetMetaData } from '../data/asset_meta_data'; export const assetDataUtil = { bestNameForAsset: (assetData: string | undefined, defaultString: string) => { - if (assetData === undefined) { + if (_.isUndefined(assetData)) { return defaultString; } const metaData = assetMetaData[assetData]; - if (metaData === undefined) { + if (_.isUndefined(metaData)) { return defaultString; } if (metaData.assetProxyId === AssetProxyId.ERC20) { -- cgit v1.2.3