Skip to content

Commit

Permalink
feat: custom display decimals for amount format
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmnthn committed Jun 5, 2023
1 parent 10a4c52 commit e52f1da
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/utils/src/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ export const bnToFloat = (num: BigNumberish, decimals = 6) => {
/**
* format value with give decimals and get original value with unScaled values with 3 decimals with comma and all decimals
* @param value - value to format
* @param decimals - number of decimals
* @returns formatted value using decimals
* @param decimals - number of decimals to format (default: 6) (optional)
* @param displayDecimals - number of decimals to display (default: 3) (optional)
* @returns formatted value as object with base, formatted and formattedFull values as string
*/
export const getFormattedAmount = (value: number | string, decimals = 6): AmountFormat => {
export const getFormattedAmount = (value: number | string, decimals = 6, displayDecimals = 3): AmountFormat => {
const valueFormatted = formatUnits(value, decimals)
return {
base: `${value}`,
formatted: shortenDecimals(commify(valueFormatted), 3, true),
formatted: shortenDecimals(commify(valueFormatted), displayDecimals, true),
formattedFull: removeExtraZeros(valueFormatted),
}
}
Expand Down

0 comments on commit e52f1da

Please sign in to comment.