import { reduce } from 'lodash' ; import { BigNumber } from '@0xproject/utils' ; BigNumber . config ( { ROUNDING_MODE : BigNumber . ROUND_FLOOR , DECIMAL_PLACES : 18 , FORMAT : { decimalSeparator : '.' , groupSeparator : '' , groupSize : 3 , secondaryGroupSize : 0 , fractionGroupSeparator : ' ' , fractionGroupSize : 0 , } , } ) ; export { BigNumber } ; export const toBN = ( obj ) : BigNumber => new BigNumber ( obj ) ; export const isBigNumber = ( v ) : boolean => { return ( v instanceof BigNumber || ( v && v . isBigNumber === true ) || ( v && v . _isBigNumber === true ) || false ) ; } ; export const orderBNToString = ( order ) => { return reduce ( order , ( acc , v , key ) => { acc [ key ] = isBigNumber ( v ) ? v . toString ( ) : v ; return acc ; } , { } ) ; } ; export const fromUnitToDecimalBN = ( balance , decimal ) : BigNumber => { const amountBN = toBN ( balance || 0 ) ; const decimalBN = toBN ( 10 ) . pow ( decimal ) ; return amountBN . times ( decimalBN ) . truncated ( ) ; } ; export const truncateAmount = ( amount , precision ) : number => { return + toBN ( amount ) . toFixed ( precision ) ; } ;