export assetDataUtil big obj
This commit is contained in:
parent
187bbc7fc1
commit
32fa1bcc38
@ -2,7 +2,7 @@ import { BigNumber } from '@0xproject/utils';
|
|||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import { bestNameForAsset } from '../util/asset_data';
|
import { assetDataUtil } from '../util/asset_data';
|
||||||
|
|
||||||
import { ColorOption } from '../style/theme';
|
import { ColorOption } from '../style/theme';
|
||||||
import { util } from '../util/util';
|
import { util } from '../util/util';
|
||||||
@ -26,7 +26,7 @@ export class AssetAmountInput extends React.Component<AssetAmountInputProps> {
|
|||||||
<AmountInput {...rest} onChange={this._handleChange} />
|
<AmountInput {...rest} onChange={this._handleChange} />
|
||||||
<Container display="inline-block" marginLeft="10px">
|
<Container display="inline-block" marginLeft="10px">
|
||||||
<Text fontSize={rest.fontSize} fontColor={ColorOption.white} textTransform="uppercase">
|
<Text fontSize={rest.fontSize} fontColor={ColorOption.white} textTransform="uppercase">
|
||||||
{bestNameForAsset(this.props.assetData, '???')}
|
{assetDataUtil.bestNameForAsset(this.props.assetData, '???')}
|
||||||
</Text>
|
</Text>
|
||||||
</Container>
|
</Container>
|
||||||
</Container>
|
</Container>
|
||||||
|
@ -2,17 +2,18 @@ import { AssetProxyId } from '@0xproject/types';
|
|||||||
|
|
||||||
import { assetMetaData } from '../data/asset_meta_data';
|
import { assetMetaData } from '../data/asset_meta_data';
|
||||||
|
|
||||||
// TODO: tests for this
|
export const assetDataUtil = {
|
||||||
export const bestNameForAsset = (assetData: string | undefined, defaultString: string) => {
|
bestNameForAsset: (assetData: string | undefined, defaultString: string) => {
|
||||||
if (assetData === undefined) {
|
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;
|
return defaultString;
|
||||||
}
|
},
|
||||||
const metaData = assetMetaData[assetData];
|
|
||||||
if (metaData === undefined) {
|
|
||||||
return defaultString;
|
|
||||||
}
|
|
||||||
if (metaData.assetProxyId === AssetProxyId.ERC20) {
|
|
||||||
return metaData.symbol.toUpperCase();
|
|
||||||
}
|
|
||||||
return defaultString;
|
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { AssetBuyerError } from '@0xproject/asset-buyer';
|
import { AssetBuyerError } from '@0xproject/asset-buyer';
|
||||||
|
|
||||||
import { bestNameForAsset } from '../util/asset_data';
|
import { assetDataUtil } from '../util/asset_data';
|
||||||
|
|
||||||
const humanReadableMessageForError = (error: Error, assetData?: string): string | undefined => {
|
const humanReadableMessageForError = (error: Error, assetData?: string): string | undefined => {
|
||||||
if (error.message === AssetBuyerError.InsufficientAssetLiquidity) {
|
if (error.message === AssetBuyerError.InsufficientAssetLiquidity) {
|
||||||
const assetName = bestNameForAsset(assetData, 'of this asset');
|
const assetName = assetDataUtil.bestNameForAsset(assetData, 'of this asset');
|
||||||
return `Not enough ${assetName} available`;
|
return `Not enough ${assetName} available`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user