diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-06-16 09:02:33 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-06-16 09:02:46 +0800 |
commit | 0cf99271328a0bee0730a33659fe30aa426c59da (patch) | |
tree | b43aab0830f07095790fa81be52a1ec8f59d24bb /packages/website/ts/utils | |
parent | 5993125cc7d5129aead37a06663741d42ff0189e (diff) | |
download | dexon-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')
-rw-r--r-- | packages/website/ts/utils/constants.ts | 1 | ||||
-rw-r--r-- | packages/website/ts/utils/utils.ts | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/packages/website/ts/utils/constants.ts b/packages/website/ts/utils/constants.ts index d281c5738..25670ef27 100644 --- a/packages/website/ts/utils/constants.ts +++ b/packages/website/ts/utils/constants.ts @@ -6,6 +6,7 @@ export const constants = { ETHER_TOKEN_SYMBOL: 'WETH', ZRX_TOKEN_SYMBOL: 'ZRX', ETHER_SYMBOL: 'ETH', + TOKEN_AMOUNT_DISPLAY_PRECISION: 5, GENESIS_ORDER_BLOCK_BY_NETWORK_ID: { 1: 4145578, 42: 3117574, 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}`; + }, }; |