import { BigNumber } from "@ethersproject/bignumber" ; export const formatDollars = ( value , precision = 0 ) : string => { const formatter = new Intl . NumberFormat ( "en-US" , { style : "currency" , currency : "USD" , minimumFractionDigits : precision , maximumFractionDigits : precision , } ) ; return formatter . format ( value ) ; } ; export const formatPercentage = ( value , precision = 0 ) : string => value . toLocaleString ( "en-US" , { style : "percent" , minimumFractionDigits : precision , maximumFractionDigits : precision , } ) ; export const shortenAddress = ( address ) : string => `${ address . substring ( 0 , 5 ) }…${ address . substring ( address . length - 4 ) }` ; export const bigNumberToTokenNumber = ( number , tokenDecimals , displayDecimals ) : number => { let bn2 = BigNumber . from ( number . toString ( ) ) ; const decimalsToChop = tokenDecimals - displayDecimals ; if ( decimalsToChop > 11 ) { const denom1 = Math . floor ( decimalsToChop / 2 ) ; bn2 = bn2 . div ( Math . pow ( 10 , denom1 ) ) ; bn2 = bn2 . div ( Math . pow ( 10 , decimalsToChop - denom1 ) ) ; } else { bn2 = bn2 . div ( Math . pow ( 10 , decimalsToChop ) ) ; } const digits = bn2 . toString ( ) . length ; const digitsOver12 = digits > 11 ? digits - 11 : 0 ; bn2 = bn2 . div ( Math . pow ( 10 , digitsOver12 ) ) ; let numberPrePrecission = bn2 . toNumber ( ) ; return numberPrePrecission / Math . pow ( 10 , displayDecimals - digitsOver12 ) ; } ;