aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/format.ts
diff options
context:
space:
mode:
authorHsuan Lee <hsuan@cobinhood.com>2019-01-19 18:42:04 +0800
committerHsuan Lee <hsuan@cobinhood.com>2019-01-19 18:42:04 +0800
commit7ae38906926dc09bc10670c361af0d2bf0050426 (patch)
tree5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/instant/src/util/format.ts
parentb5fd3c72a08aaa6957917d74c333387a16edf66b (diff)
downloaddexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.bz2
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.lz
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.xz
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip
Update dependency packages
Diffstat (limited to 'packages/instant/src/util/format.ts')
-rw-r--r--packages/instant/src/util/format.ts76
1 files changed, 0 insertions, 76 deletions
diff --git a/packages/instant/src/util/format.ts b/packages/instant/src/util/format.ts
deleted file mode 100644
index 61aeb839f..000000000
--- a/packages/instant/src/util/format.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import { BigNumber } from '@0x/utils';
-import { Web3Wrapper } from '@0x/web3-wrapper';
-import * as _ from 'lodash';
-
-import { BIG_NUMBER_ZERO, ETH_DECIMALS } from '../constants';
-
-export const format = {
- ethBaseUnitAmount: (
- ethBaseUnitAmount?: BigNumber,
- decimalPlaces: number = 4,
- defaultText: React.ReactNode = '0 ETH',
- ): React.ReactNode => {
- if (_.isUndefined(ethBaseUnitAmount)) {
- return defaultText;
- }
- const ethUnitAmount = Web3Wrapper.toUnitAmount(ethBaseUnitAmount, ETH_DECIMALS);
- return format.ethUnitAmount(ethUnitAmount, decimalPlaces);
- },
- ethUnitAmount: (
- ethUnitAmount?: BigNumber,
- decimalPlaces: number = 4,
- defaultText: React.ReactNode = '0 ETH',
- minUnitAmountToDisplay: BigNumber = new BigNumber('0.00001'),
- ): React.ReactNode => {
- if (_.isUndefined(ethUnitAmount)) {
- return defaultText;
- }
- let roundedAmount = ethUnitAmount.decimalPlaces(decimalPlaces).precision(decimalPlaces);
-
- if (roundedAmount.eq(BIG_NUMBER_ZERO) && ethUnitAmount.isGreaterThan(BIG_NUMBER_ZERO)) {
- // Sometimes for small ETH amounts (i.e. 0.000045) the amount rounded to 4 decimalPlaces is 0
- // If that is the case, show to 1 significant digit
- roundedAmount = new BigNumber(ethUnitAmount.toPrecision(1));
- }
-
- const displayAmount =
- roundedAmount.isGreaterThan(BIG_NUMBER_ZERO) && roundedAmount.isLessThan(minUnitAmountToDisplay)
- ? `< ${minUnitAmountToDisplay.toString()}`
- : roundedAmount.toString();
-
- return `${displayAmount} ETH`;
- },
- ethBaseUnitAmountInUsd: (
- ethBaseUnitAmount?: BigNumber,
- ethUsdPrice?: BigNumber,
- decimalPlaces: number = 2,
- defaultText: React.ReactNode = '$0.00',
- minUnitAmountToDisplay: BigNumber = new BigNumber('0.00001'),
- ): React.ReactNode => {
- if (_.isUndefined(ethBaseUnitAmount) || _.isUndefined(ethUsdPrice)) {
- return defaultText;
- }
- const ethUnitAmount = Web3Wrapper.toUnitAmount(ethBaseUnitAmount, ETH_DECIMALS);
- return format.ethUnitAmountInUsd(ethUnitAmount, ethUsdPrice, decimalPlaces, minUnitAmountToDisplay);
- },
- ethUnitAmountInUsd: (
- ethUnitAmount?: BigNumber,
- ethUsdPrice?: BigNumber,
- decimalPlaces: number = 2,
- defaultText: React.ReactNode = '$0.00',
- ): React.ReactNode => {
- if (_.isUndefined(ethUnitAmount) || _.isUndefined(ethUsdPrice)) {
- return defaultText;
- }
- const rawUsdPrice = ethUnitAmount.multipliedBy(ethUsdPrice);
- const roundedUsdPrice = rawUsdPrice.toFixed(decimalPlaces);
- if (roundedUsdPrice === '0.00' && rawUsdPrice.gt(BIG_NUMBER_ZERO)) {
- return '<$0.01';
- } else {
- return `$${roundedUsdPrice}`;
- }
- },
- ethAddress: (address: string): string => {
- return `0x${address.slice(2, 7)}…${address.slice(-5)}`;
- },
-};