11import React from 'react'
22import classNames from 'classnames'
3- import _round from 'lodash/round '
3+ import BigNumber from 'bignumber.js '
44
55export const amountStyle = ( amount ) => {
66 const val = parseFloat ( amount )
@@ -26,7 +26,11 @@ export const insertIf = (condition, ...elements) => (condition ? elements : [])
2626
2727export const filterSelectorItem = ( query , item ) => item . toLowerCase ( ) . indexOf ( query . toLowerCase ( ) ) >= 0
2828
29- export const fixedFloat = ( val , num = 8 ) => ( typeof val === 'number' ? val && val . toFixed ( num ) : val )
29+ export const fixedFloat = ( val , num = 8 ) => {
30+ if ( ! val && val !== 0 ) return val
31+ const bn = new BigNumber ( val )
32+ return bn . isNaN ( ) ? val : bn . toFixed ( num )
33+ }
3034
3135export const formatThousands = ( value ) => {
3236 const parts = value . toString ( ) . split ( '.' )
@@ -71,11 +75,12 @@ export const formatAmount = (val, options = {}) => {
7175 formatThousands : shouldFormatThousands = false ,
7276 dollarSign = false ,
7377 } = options
74- let roundedValue = _round ( val , 8 )
78+ const bnValue = new BigNumber ( val )
79+ let roundedValue = bnValue . dp ( 8 , BigNumber . ROUND_HALF_UP ) . toFixed ( )
7580
7681 const classes = classNames ( 'bitfinex-amount' , {
77- 'bitfinex-green-text' : color ? color === 'green' : roundedValue > 0 ,
78- 'bitfinex-red-text' : color ? color === 'red' : roundedValue < 0 ,
82+ 'bitfinex-green-text' : color ? color === 'green' : bnValue . gt ( 0 ) ,
83+ 'bitfinex-red-text' : color ? color === 'red' : bnValue . lt ( 0 ) ,
7984 } )
8085
8186 if ( fixFraction ) {
@@ -106,7 +111,7 @@ export const formatAmount = (val, options = {}) => {
106111 )
107112}
108113
109- export const formatFee = ( fee ) => formatAmount ( fee * 100 , { color : 'white' , minDigits : 2 } )
114+ export const formatFee = ( fee ) => formatAmount ( new BigNumber ( fee ) . times ( 100 ) , { color : 'white' , minDigits : 2 } )
110115
111116export const formatColor = ( value , color ) => {
112117 const classes = classNames ( {
0 commit comments