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

Leaderboard number format. #99

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 25 additions & 12 deletions components/Leaderboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Leaderboard: FC<ILeaderboard> = ({
id: "juicer",
width: "10%",
minWidth: "140px",
whiteSpace: 'nowrap',
whiteSpace: "nowrap",
align: "left",
Cell: ({ value }: { value: JuicerColumn["juicer"] }) => {
return <Text>{value}</Text>;
Expand All @@ -58,19 +58,28 @@ const Leaderboard: FC<ILeaderboard> = ({
Header: "Juice Pressed",
accessor: "juiceAmount",
sortType: (rowA, rowB, _columnId, desc) => {
const diff: BigNumber = BigNumber.from(rowA.values.juiceAmount).sub(BigNumber.from(rowB.values.juiceAmount))
const diff: BigNumber = BigNumber.from(rowA.values.juiceAmount).sub(
BigNumber.from(rowB.values.juiceAmount)
);
if (diff.isZero()) {
return 0
return 0;
} else if (desc && diff.gt(0)) {
return 1
return 1;
} else {
return -1
return -1;
}
},
id: "juiceAmount",
align: "right",
Cell: ({ value }: { value: JuicerColumn["juiceAmount"] }) => {
return <Box>{formatJuice(BigNumber.from(value)) || "xxxx"}</Box>;
return (
<Box>
{formatJuice(BigNumber.from(value), {
minimumFractionDigits: 3,
maximumFractionDigits: 3,
}) || "xxxx"}
</Box>
);
},
},
],
Expand All @@ -93,12 +102,16 @@ const Leaderboard: FC<ILeaderboard> = ({

useEffect(() => {
const _data = getData();
setData(_data && _data.map(value => {
if (isAddress(value.juicer)) {
value.juicer = getTruncatedAddress(value.juicer)
}
return value
}) || []);
setData(
(_data &&
_data.map((value) => {
if (isAddress(value.juicer)) {
value.juicer = getTruncatedAddress(value.juicer);
}
return value;
})) ||
[]
);
}, [getData]);

const segmentData: { label: string; key: LeaderboardRange }[] = [];
Expand Down
4 changes: 2 additions & 2 deletions utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const isValidEmail = (email?: string) =>

type Nullable<T> = T | null | undefined;

export const formatJuice = (amount: Nullable<ethers.BigNumberish>) =>
Number(ethers.utils.formatUnits(amount || 0, juiceDecimals)).toLocaleString();
export const formatJuice = (amount: Nullable<ethers.BigNumberish>, options?: Intl.NumberFormatOptions) =>
Number(ethers.utils.formatUnits(amount || 0, juiceDecimals)).toLocaleString(undefined, options);

export const parseJuice = (amount: Nullable<string | number>) =>
ethers.utils.parseUnits(amount?.toString() || "0", juiceDecimals);
Expand Down