formatAmounts wip

This commit is contained in:
Mikhail Mikheev 2019-10-01 19:31:25 +04:00
parent b3b4887fdb
commit f5d324fff8
2 changed files with 4 additions and 2 deletions

View File

@ -1,9 +1,10 @@
// @flow // @flow
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
export const formatAmount = (number: string | number) => { export const formatAmount = (number: string | number) => {
let numberFloat = parseFloat(number) let numberFloat = parseFloat(number)
if (numberFloat < 999.999999) { if (numberFloat < 999.999999) {
numberFloat = numberFloat.toFixed(2).toLocaleString() numberFloat = numberFloat.toFixed(5).toLocaleString()
} }
return numberFloat return numberFloat

View File

@ -3,6 +3,7 @@ import { List } from 'immutable'
import { type Token } from '~/logic/tokens/store/model/token' import { type Token } from '~/logic/tokens/store/model/token'
import { buildOrderFieldFrom, FIXED, type SortRow } from '~/components/Table/sorting' import { buildOrderFieldFrom, FIXED, type SortRow } from '~/components/Table/sorting'
import { type Column } from '~/components/Table/TableHead' import { type Column } from '~/components/Table/TableHead'
import { formatAmount } from '~/logic/tokens/utils/formatAmount'
export const BALANCE_TABLE_ASSET_ID = 'asset' export const BALANCE_TABLE_ASSET_ID = 'asset'
export const BALANCE_TABLE_BALANCE_ID = 'balance' export const BALANCE_TABLE_BALANCE_ID = 'balance'
@ -19,7 +20,7 @@ export const getBalanceData = (activeTokens: List<Token>): List<BalanceRow> => {
const rows = activeTokens.map((token: Token) => ({ const rows = activeTokens.map((token: Token) => ({
[BALANCE_TABLE_ASSET_ID]: { name: token.name, logoUri: token.logoUri }, [BALANCE_TABLE_ASSET_ID]: { name: token.name, logoUri: token.logoUri },
[buildOrderFieldFrom(BALANCE_TABLE_ASSET_ID)]: token.name, [buildOrderFieldFrom(BALANCE_TABLE_ASSET_ID)]: token.name,
[BALANCE_TABLE_BALANCE_ID]: `${token.balance} ${token.symbol}`, [BALANCE_TABLE_BALANCE_ID]: `${formatAmount(token.balance)} ${token.symbol}`,
[buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: Number(token.balance), [buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: Number(token.balance),
[FIXED]: token.get('symbol') === 'ETH', [FIXED]: token.get('symbol') === 'ETH',
})) }))