aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/utils/utils.ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-06-16 09:02:33 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-06-16 09:02:46 +0800
commit0cf99271328a0bee0730a33659fe30aa426c59da (patch)
treeb43aab0830f07095790fa81be52a1ec8f59d24bb /packages/website/ts/utils/utils.ts
parent5993125cc7d5129aead37a06663741d42ff0189e (diff)
downloaddexon-sol-tools-0cf99271328a0bee0730a33659fe30aa426c59da.tar
dexon-sol-tools-0cf99271328a0bee0730a33659fe30aa426c59da.tar.gz
dexon-sol-tools-0cf99271328a0bee0730a33659fe30aa426c59da.tar.bz2
dexon-sol-tools-0cf99271328a0bee0730a33659fe30aa426c59da.tar.lz
dexon-sol-tools-0cf99271328a0bee0730a33659fe30aa426c59da.tar.xz
dexon-sol-tools-0cf99271328a0bee0730a33659fe30aa426c59da.tar.zst
dexon-sol-tools-0cf99271328a0bee0730a33659fe30aa426c59da.zip
Add all steps to their own file
Diffstat (limited to 'packages/website/ts/utils/utils.ts')
-rw-r--r--packages/website/ts/utils/utils.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts
index fdee264b2..414361c1b 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -3,6 +3,7 @@ import { OrderError } from '@0xproject/order-utils';
import { constants as sharedConstants, Networks } from '@0xproject/react-shared';
import { ECSignature, Provider } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import deepEqual = require('deep-equal');
import * as _ from 'lodash';
import * as moment from 'moment';
@@ -17,6 +18,7 @@ import {
SideToAssetToken,
Token,
TokenByAddress,
+ TokenState,
} from 'ts/types';
import { configs } from 'ts/utils/configs';
import { constants } from 'ts/utils/constants';
@@ -332,4 +334,13 @@ export const utils = {
const token = _.find(tokens, { symbol });
return token;
},
+ getFormattedAmountFromToken(token: Token, tokenState: TokenState): string {
+ return utils.getFormattedAmount(tokenState.balance, token.decimals, token.symbol);
+ },
+ getFormattedAmount(amount: BigNumber, decimals: number, symbol: string): string {
+ const unitAmount = Web3Wrapper.toUnitAmount(amount, decimals);
+ const precision = Math.min(constants.TOKEN_AMOUNT_DISPLAY_PRECISION, unitAmount.decimalPlaces());
+ const formattedAmount = unitAmount.toFixed(precision);
+ return `${formattedAmount} ${symbol}`;
+ },
};