Skip to content

Commit

Permalink
commit thousand separator
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudCludfore committed Jun 21, 2024
1 parent 3772d81 commit fdb2db1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/app/get-aura/mobile-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./table-mobile.css";
import carretUp from "@/assets/icons/ic_carret_up.svg";
import clock from "@/assets/icons/ic_clock.svg";
import Image from "next/image";
import { formatNumber } from "../utils/numbers";

interface MobileTableItemProps {
txTime: string;
Expand All @@ -32,7 +33,7 @@ const MobileTableItem: React.FC<props> = ({ tableItem }) => {
</div>
<div className="time-and-message">
<div className="time">
<Image src={clock} alt="" height={14} />
<Image src={clock} alt="" height={14} />
<div className="cell-text2">{dayjs(tableItem.txTime).format("HH:mm:ss DD/MM/YYYY")}</div>
</div>
</div>
Expand All @@ -46,15 +47,15 @@ const MobileTableItem: React.FC<props> = ({ tableItem }) => {
setExpand(!expand);
}}
>
<Image src={carretUp} className={expand ? 'expanded': ''} alt="" height={16} />
<Image src={carretUp} className={expand ? "expanded" : ""} alt="" height={16} />
</div>
</div>
{expand && (
<div className="flex flex-col w-full gap-2">
<div className="line-18"></div>
<div className="frame-29708">
<div className="amount">Amount</div>
<div className="_200-aura">{formatUnits(BigInt(tableItem.amount), 18)} AURA</div>
<div className="_200-aura">{formatNumber(formatUnits(BigInt(tableItem?.amount), 18))} AURA</div>
</div>
<div className="frame-29707">
<div className="cosmos-tx-hash">Cosmos TX hash</div>
Expand Down
3 changes: 2 additions & 1 deletion src/app/get-aura/table-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Address from "@/components/address";
import dayjs from "dayjs";
import React from "react";
import { formatUnits } from "viem";
import { formatNumber } from "../utils/numbers";

interface TableItemProps {
txTime: string;
Expand Down Expand Up @@ -33,7 +34,7 @@ const TableItem: React.FC<props> = ({ tableItem }) => {
<Address address={tableItem?.depAddress} link={true} ellipsis={true} />
</div>
<div className="frame-561">
<div className="_20-aura">{formatUnits(BigInt(tableItem?.amount), 18)} AURA</div>
<div className="_20-aura">{formatNumber(formatUnits(BigInt(tableItem?.amount), 18))} AURA</div>
</div>
<div className="frame-572">
<div className={tableItem?.status?.toLowerCase()}>{tableItem?.status}</div>
Expand Down
15 changes: 15 additions & 0 deletions src/app/utils/numbers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function formatNumber(amount: number | null | undefined | string, maximumFractionDigits: number = 2, compact?: boolean) {
const { format } = new Intl.NumberFormat("en-US", {
maximumFractionDigits: maximumFractionDigits,
notation: compact ? "compact" : "standard",
});
if (amount === null || amount === undefined || amount === 0 || amount === "0") {
return "-";
}
if (Number(amount) >= 1000000000) {
return "1B";
}
return format(+amount);
}

export { formatNumber }

0 comments on commit fdb2db1

Please sign in to comment.