Skip to content

Commit

Permalink
Revert "Implement fees ceiling"
Browse files Browse the repository at this point in the history
This reverts commit 5fdceac.
  • Loading branch information
kpyszkowski committed Aug 13, 2024
1 parent 4be544e commit 9e2e806
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTokenAmountField } from "#/components/shared/TokenAmountForm/TokenAm
import { FeesTooltip } from "#/components/TransactionModal/FeesTooltip"
import { useMinDepositAmount, useTransactionDetails } from "#/hooks"
import { CurrencyType } from "#/types"
import { DESIRED_DECIMALS_FOR_FEE, FEE_CEIL_PRECISION } from "#/constants"
import { DESIRED_DECIMALS_FOR_FEE } from "#/constants"

function StakeDetails({ currency }: { currency: CurrencyType }) {
const { value = 0n } = useTokenAmountField()
Expand Down Expand Up @@ -36,7 +36,6 @@ function StakeDetails({ currency }: { currency: CurrencyType }) {
currency,
amount: total,
desiredDecimals: DESIRED_DECIMALS_FOR_FEE,
ceilPrecision: FEE_CEIL_PRECISION,
}}
to={{
currency: "usd",
Expand Down
6 changes: 2 additions & 4 deletions dapp/src/components/shared/CurrencyBalance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export type CurrencyBalanceProps = {
amount?: AmountType
shouldBeFormatted?: boolean
desiredDecimals?: number
ceilPrecision?: number
size?: ResponsiveValue<string>
variant?: ResponsiveValue<
| "greater-balance-md"
Expand All @@ -35,7 +34,6 @@ export function CurrencyBalance({
amount,
shouldBeFormatted = true,
desiredDecimals: customDesiredDecimals,
ceilPrecision,
size,
variant,
balanceFontWeight = "bold",
Expand All @@ -60,10 +58,10 @@ export function CurrencyBalance({
const balance = useMemo(() => {
const value = amount ?? 0
if (shouldBeFormatted || typeof value === "bigint")
return formatTokenAmount(value, decimals, desiredDecimals, ceilPrecision)
return formatTokenAmount(value, decimals, desiredDecimals)

return numberToLocaleString(value, desiredDecimals)
}, [amount, decimals, desiredDecimals, shouldBeFormatted, ceilPrecision])
}, [amount, decimals, desiredDecimals, shouldBeFormatted])

return (
<Box as={as} __css={styles.container}>
Expand Down
1 change: 0 additions & 1 deletion dapp/src/constants/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Currency, CurrencyType } from "#/types"
import env from "./env"

export const DESIRED_DECIMALS_FOR_FEE = 5
export const FEE_CEIL_PRECISION = 4

export const BITCOIN: Currency = {
name: "Bitcoin",
Expand Down
8 changes: 1 addition & 7 deletions dapp/src/utils/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,18 @@ export const formatTokenAmount = (
amount: number | string | bigint,
decimals = 18,
desiredDecimals = 2,
ceilPrecision = desiredDecimals,
) => {
const fixedPoint = BigInt(amount)

if (fixedPoint === 0n) {
return `0.${"0".repeat(desiredDecimals)}`
}

let formattedAmount = bigIntToUserAmount(
const formattedAmount = bigIntToUserAmount(
fixedPoint,
decimals,
desiredDecimals,
)
if (ceilPrecision !== desiredDecimals) {
formattedAmount =
Math.ceil(formattedAmount * 10 ** ceilPrecision) / 10 ** ceilPrecision
}

const minAmountToDisplay = 1 / 10 ** Math.min(desiredDecimals, decimals)

if (minAmountToDisplay > formattedAmount) {
Expand Down

0 comments on commit 9e2e806

Please sign in to comment.