Skip to content

Commit 17e226e

Browse files
committed
feat(fractions): add percentage display for units in Fraction component
1 parent 657eb7f commit 17e226e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

components/hypercert/fractions.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ImageIcon } from "../user-icon/ImageIcon";
1919
import { SvgIcon } from "../user-icon/SvgIcon";
2020
import EthAddress from "../eth-address";
2121
import { UserName } from "../user-name";
22+
import { calculateBigIntPercentage } from "@/lib/calculateBigIntPercentage";
2223
const MAX_FRACTIONS_DISPLAYED = 5;
2324

2425
function Fraction({
@@ -38,6 +39,16 @@ function Fraction({
3839
address: address,
3940
});
4041

42+
const calculatedPercentage = calculateBigIntPercentage(
43+
units as string,
44+
totalUnits as string,
45+
);
46+
47+
const roundedPercentage =
48+
calculatedPercentage! < 1
49+
? "<1"
50+
: Math.round(calculatedPercentage!).toString();
51+
4152
if (isFetching) {
4253
return (
4354
<div className="flex flex-row gap-2 items-center">
@@ -68,7 +79,10 @@ function Fraction({
6879
<EthAddress address={address} showEnsName={true} />
6980
</div>
7081
)}
71-
&mdash; <FormattedUnits>{units as string}</FormattedUnits>
82+
<div className="flex flex-row items-center gap-2">
83+
&mdash; <FormattedUnits>{units as string}</FormattedUnits>
84+
<span>{`(${roundedPercentage}%)`}</span>
85+
</div>
7286
</>
7387
);
7488
}

0 commit comments

Comments
 (0)