Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪄 [QA] Update stage environments #693

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/shared/components/TokenAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export default function TokenAmountInput({
<div>
{label && (
<div className="label">{`${label} ${bigIntToDisplayUserAmount(
balance
balance,
18,
5
)} ${symbol}`}</div>
)}
<SharedInput
Expand All @@ -88,7 +90,7 @@ export default function TokenAmountInput({
isDisabled={disabled}
onMouseDown={(event) => {
event.preventDefault()
onChange(bigIntToUserAmount(balance))
onChange(bigIntToUserAmount(balance, 18, 18))
}}
>
Max
Expand Down
14 changes: 10 additions & 4 deletions src/shared/utils/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { FixedPointNumber } from "shared/types/stake"
const FLOATING_POINT_REGEX = /^[^0-9]*([0-9,]+)(?:\.([0-9]*))?$/

export const separateThousandsByComma = (
value: number | bigint | string
value: number | bigint | string,
decimals = 2
): string => {
const adjustedValue = typeof value === "string" ? +value : value
return adjustedValue.toLocaleString("en-US", { maximumFractionDigits: 2 })
return adjustedValue.toLocaleString("en-US", {
// @ts-expect-error - `maximumFractionDigits` wants to get number less than 21,
// but as the tokens have 18 decimals have, we can safely pass a parameter
maximumFractionDigits: decimals < 21 ? decimals : 2,
})
}

function parseToFixedPointNumber(
Expand Down Expand Up @@ -81,7 +86,7 @@ export function bigIntToUserAmount(
desiredDecimals = 2
): string {
const desiredDecimalsAmount =
amount / 10n ** BigInt(Math.max(1, decimals - desiredDecimals))
amount / 10n ** BigInt(Math.max(0, decimals - desiredDecimals))

return (
Number(desiredDecimalsAmount) /
Expand All @@ -98,6 +103,7 @@ export function bigIntToDisplayUserAmount(
const amountBigInt = typeof amount === "string" ? BigInt(amount) : amount

return separateThousandsByComma(
bigIntToUserAmount(amountBigInt, decimals, desiredDecimals)
bigIntToUserAmount(amountBigInt, decimals, desiredDecimals),
desiredDecimals
)
}
Loading