Skip to content

Commit e1cffcc

Browse files
committed
refactor(FormattedAmount): simplify component by removing trailing zero trimming and directly returning formatted amount for cleaner code and improved readability
1 parent 44be756 commit e1cffcc

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

app/components/common/FormattedAmount.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import { formatBalance } from "@polkadot/util";
22
import { useAtomValue } from "jotai";
33
import { formatOptionsAtom } from "../../atoms";
44

5-
function trimTrailingZeros(value: string): string {
6-
// Remove trailing zeros after decimal point, and the decimal point itself if no decimals left
7-
return value.replace(/\.?0+$/, "");
8-
}
9-
105
type FormattedAmountProps = {
116
value: number | bigint;
127
decimals?: number;
@@ -23,19 +18,10 @@ export function FormattedAmount({
2318
return null;
2419
}
2520
const options = {
26-
withUnit: Boolean(unit) || formatOptions.unit,
21+
withUnit: unit || formatOptions.unit,
2722
decimals: decimals ?? formatOptions.decimals,
28-
withSi: true,
29-
unit: unit,
23+
withZero: false,
3024
};
3125
const formattedAmount = formatBalance(BigInt(value), options);
32-
// Split the amount and unit to handle them separately
33-
const [amount, displayUnit] = formattedAmount.split(" ");
34-
const cleanAmount = trimTrailingZeros(amount);
35-
return (
36-
<>
37-
{cleanAmount}
38-
{displayUnit ? ` ${unit || displayUnit}` : ""}
39-
</>
40-
);
26+
return <>{formattedAmount}</>;
4127
}

0 commit comments

Comments
 (0)