Skip to content

Commit

Permalink
Merge pull request #6 from ensdomains/fix/eth-display
Browse files Browse the repository at this point in the history
fix: eth display
  • Loading branch information
TateB authored Aug 9, 2024
2 parents c46b34e + fce7df6 commit 03654c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DeedComponent } from "./Deed";
import { lookupDeed } from "./query/lookupDeed";
import { getDeedStatsQueryFn, getDeedsForAccountQueryFn } from "./query/reclaimSubgraph";
import { useSimpleSearch } from "./query/useSimpleSearch";
import { shortenAddress } from "./utils";
import { createDisplayEth, shortenAddress } from "./utils";

const getWarning = () => false;

Expand Down Expand Up @@ -135,11 +135,11 @@ function App() {
<Typography>
There are currently{" "}
<Skeleton style={{ display: "inline-block" }} loading={isDeedStatsLoading}>
{deedStats?.numOfDeeds ?? "12345"}
<b>{deedStats?.numOfDeeds ?? "12345"}</b>
</Skeleton>{" "}
deeds holding{" "}
<Skeleton style={{ display: "inline-block" }} loading={isDeedStatsLoading}>
{deedStats?.currentValue ? formatEther(deedStats.currentValue) : "0.0000"}
<b>{deedStats?.currentValue ? createDisplayEth(deedStats.currentValue) : "0.0000"}</b>
</Skeleton>
<br />
To understand more about these unclaimed deposits,{" "}
Expand Down
20 changes: 20 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import { formatEther } from "viem";

export const shortenAddress = (address = "", maxLength = 10, leftSlice = 5, rightSlice = 5) => {
if (address.length < maxLength) {
return address;
}

return `${address.slice(0, leftSlice + 2)}...${address.slice(-rightSlice)}`;
};

export const createDisplayEth = (value: bigint) => {
const number = Number(formatEther(value));
const options: Intl.NumberFormatOptions & { [x: string]: string } = {
style: "currency",
currency: "eth",
// @ts-expect-error
useGrouping: "auto",
trailingZeroDisplay: "auto",
};
if (number < 0.00001) {
options.maximumSignificantDigits = 1;
}
options.minimumFractionDigits = 4;
options.maximumFractionDigits = 4;
options.currencyDisplay = "name";
return new Intl.NumberFormat(undefined, options).format(number);
};

0 comments on commit 03654c4

Please sign in to comment.