Skip to content

Commit

Permalink
chore: layer package bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Feb 27, 2024
1 parent 0de617f commit 64ba728
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 65 deletions.
78 changes: 16 additions & 62 deletions layer/composables/useSharedBigNumberFormatted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const ZERO_IN_BASE = new BigNumberInBase(0)
const DEFAULT_DECIMAL_PLACES = 2
const DEFAULT_MINIMAL_DISPLAY_DECIMAL_PLACES = 4
const DEFAULT_MAX_MINIMAL_DISPLAY_DECIMAL_PLACES = 12
const DEFAULT_INJ_FEE = 0.005
const DEFAULT_ROUNDING_MODE = BigNumberInBase.ROUND_DOWN

const getFormattedZeroValue = (decimalPlaces: number) => {
Expand Down Expand Up @@ -118,7 +117,6 @@ export function useSharedBigNumberFormatter(
decimalPlaces?: number
minimalDecimalPlaces?: number
abbreviationFloor?: number /** Wether we should abbreviate numbers, for example 1,234,455 => 1M */
injFee?: number
roundingMode?: BigNumber.RoundingMode
displayAbsoluteDecimalPlace?: boolean /** Explained above */
shouldTruncate?: Boolean
Expand All @@ -136,9 +134,8 @@ export function useSharedBigNumberFormatter(
return new BigNumberInBase(value.value as string)
})

const decimalPlaces = options.decimalPlaces ?? DEFAULT_DECIMAL_PLACES
const injFee = options.injFee ?? DEFAULT_INJ_FEE
const roundingMode = options.roundingMode || DEFAULT_ROUNDING_MODE
const decimalPlaces = options.decimalPlaces ?? DEFAULT_DECIMAL_PLACES
const displayAbsoluteDecimalPlace = !!options.displayAbsoluteDecimalPlace

const valueToFixed = computed(() => {
Expand All @@ -155,11 +152,16 @@ export function useSharedBigNumberFormatter(
return abbreviateNumber(valueToBigNumber.value.toNumber())
}

const roundedValue = valueToBigNumber.value.toFixed(
decimalPlaces,
roundingMode
)

if (options.shouldTruncate) {
return valueToBigNumber.value.toFixed()
return new BigNumberInBase(roundedValue).toFixed()
}

return valueToBigNumber.value.toFixed(decimalPlaces, roundingMode)
return roundedValue
})

const valueToString = computed(() => {
Expand All @@ -183,73 +185,25 @@ export function useSharedBigNumberFormatter(
displayAbsoluteDecimalPlace
)

if (options.shouldTruncate) {
return valueToBigNumber.value.toFormat()
}

if (valueToBigNumber.value.abs().lt(minimalDisplayAmount)) {
return `< ${minimalDisplayAmount.toFormat(minimalDecimalPlaces)}`
}

return valueToBigNumber.value.toFormat(decimalPlaces, roundingMode)
})

const valueWithGasBuffer = computed(() => {
if (valueToBigNumber.value.isNaN() || valueToBigNumber.value.lte(injFee)) {
return new BigNumberInBase(0)
}

return valueToBigNumber.value.minus(injFee)
})

const valueWithGasBufferToFixed = computed(() => {
if (valueToBigNumber.value.isNaN() || valueToBigNumber.value.isZero()) {
return getFormattedZeroValue(decimalPlaces)
}

if (options.shouldTruncate) {
valueWithGasBuffer.value.toFixed()
}

return valueWithGasBuffer.value.toFixed(decimalPlaces, roundingMode)
})

const valueWithGasBufferToString = computed(() => {
if (valueToBigNumber.value.isNaN() || valueToBigNumber.value.isZero()) {
return getFormattedZeroValue(decimalPlaces)
}

if (
!!options.abbreviationFloor &&
valueToBigNumber.value.gte(options.abbreviationFloor)
) {
return abbreviateNumber(valueToBigNumber.value.toNumber())
}

const { minimalDecimalPlaces, minimalDisplayAmount } =
getNumberMinimalDecimals(
valueToBigNumber,
options.minimalDecimalPlaces,
displayAbsoluteDecimalPlace
)
const roundedValue = valueToBigNumber.value.toFixed(
decimalPlaces,
roundingMode
)

if (options.shouldTruncate) {
valueWithGasBuffer.value.toFormat()
return new BigNumberInBase(roundedValue).toFormat()
}

if (valueWithGasBuffer.value.abs().lt(minimalDisplayAmount)) {
if (valueToBigNumber.value.abs().lt(minimalDisplayAmount)) {
return `< ${minimalDisplayAmount.toFormat(minimalDecimalPlaces)}`
}

return valueWithGasBuffer.value.toFormat(decimalPlaces, roundingMode)
return new BigNumberInBase(roundedValue).toFormat(decimalPlaces)
})

return {
valueToBigNumber,
valueToFixed,
valueToString,
valueWithGasBuffer,
valueWithGasBufferToFixed,
valueWithGasBufferToString
valueToBigNumber
}
}
6 changes: 3 additions & 3 deletions layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@injectivelabs/nuxt-bugsnag": "0.0.3",
"@injectivelabs/utils": "1.14.6-beta.10",
"@injectivelabs/networks": "1.14.6-beta.13",
"@injectivelabs/sdk-ts": "1.14.6-beta.53",
"@injectivelabs/sdk-ui-ts": "1.14.6-beta.60",
"@injectivelabs/sdk-ts": "1.14.6-beta.54",
"@injectivelabs/sdk-ui-ts": "1.14.6-beta.61",
"@injectivelabs/token-metadata": "1.14.6-beta.45",
"@injectivelabs/wallet-ts": "1.14.6-beta.60",
"@injectivelabs/wallet-ts": "1.14.6-beta.61",
"@vueuse/integrations": "^10.7.1",
"floating-vue": "2.0.0-beta.24",
"vue-gtag": "^2.0.1",
Expand Down

0 comments on commit 64ba728

Please sign in to comment.