Skip to content

Commit

Permalink
fix: rem trailing zeros from display amt
Browse files Browse the repository at this point in the history
  • Loading branch information
ericHgorski committed Nov 1, 2024
1 parent 88152dc commit 663550d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const ErrorPageTransactionFailed = ({
description={
<>
<SmallText color={theme.error.text} textAlign="center" textWrap="balance">
This transaction encountered a critical error. <br />
Please contact our support team below.
</SmallText>
<Row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ export const SwapExecutionPageRouteDetailed = ({
onClickEditDestinationWallet: _onClickEditDestinationWallet,
swapExecutionState
}: SwapExecutionPageRouteProps) => {
const { route } = useAtomValue(
swapExecutionStateAtom
);
const { data: swapVenues } = useAtomValue(skipSwapVenuesAtom);
const { data: bridges } = useAtomValue(skipBridgesAtom);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { formatUSD } from "@/utils/intl";
import { copyToClipboard } from "@/utils/misc";
import {
limitDecimalsDisplayed,
removeTrailingZeros,
} from "@/utils/number";

export type SwapExecutionPageRouteSimpleRowProps = {
Expand Down Expand Up @@ -75,6 +76,11 @@ export const SwapExecutionPageRouteSimpleRow = ({
}
}, [account?.address, account?.wallet.logo, chainAddresses, context]);

const displayAmount = useMemo(() => {
return removeTrailingZeros(limitDecimalsDisplayed(assetDetails.amount))
}
, [assetDetails.amount]);

return (
<Row gap={25} align="center">
{assetDetails.assetImage && (
Expand All @@ -95,7 +101,7 @@ export const SwapExecutionPageRouteSimpleRow = ({
)}
<Column gap={5}>
<StyledSymbolAndAmount>
{limitDecimalsDisplayed(assetDetails.amount)} {assetDetails?.symbol}
{displayAmount} {assetDetails?.symbol}
</StyledSymbolAndAmount>
{usdValue && (
<SmallText>
Expand Down
1 change: 0 additions & 1 deletion packages/widget-v2/src/stories/ErrorState.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ const transactionFailedProps = (theme: Theme) => {
description: (
<>
<SmallText color={theme.error.text} textAlign="center">
This transaction encountered a critical error. <br />
Please contact our support team below.
</SmallText>
<Row
Expand Down
2 changes: 2 additions & 0 deletions packages/widget-v2/src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function formatNumberWithoutCommas(str: string | number) {
return str.toString().replace(/,/g, "");
}

export const removeTrailingZeros = (input: string | undefined) => input?.replace(/0+$/, '');

export function limitDecimalsDisplayed(input: string | number | undefined, decimalPlaces = 6) {
if (input === undefined) return "";

Expand Down

0 comments on commit 663550d

Please sign in to comment.