Skip to content

Commit

Permalink
chore: layer add sharedToBalanceInTokenInBase helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Jan 16, 2024
1 parent 4320ae5 commit 18aff58
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion layer/utils/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export const sharedConvertTimestampToMilliseconds = (
return timestampInBigNumber.toNumber()
}

export const sharedToBalanceInTokenInBase = ({
value,
decimalPlaces = 18
}: {
value: string | number
decimalPlaces?: number
}): BigNumberInBase => {
return new BigNumberInWei(value).toBase(decimalPlaces)
}

export const sharedToBalanceInToken = ({
value,
fixedDecimals,
Expand All @@ -46,7 +56,10 @@ export const sharedToBalanceInToken = ({
fixedDecimals?: number
roundingMode?: BigNumber.RoundingMode
}): string => {
const balanceInToken = new BigNumberInWei(value).toBase(decimalPlaces)
const balanceInToken = sharedToBalanceInTokenInBase({
value,
decimalPlaces
})

if (fixedDecimals) {
return balanceInToken.toFixed(fixedDecimals, roundingMode)
Expand Down

0 comments on commit 18aff58

Please sign in to comment.