Skip to content

Commit 316cef1

Browse files
authored
[TOOL-4057] Dashboard: Update Storage pinning card in team usage page (#6697)
1 parent 1bfcd37 commit 316cef1

File tree

2 files changed

+46
-25
lines changed
  • apps/dashboard/src

2 files changed

+46
-25
lines changed

apps/dashboard/src/app/team/[team_slug]/(team)/~/usage/overview/components/Usage.tsx

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { subMonths } from "date-fns";
1111
import Link from "next/link";
1212
import { Suspense, useMemo } from "react";
1313
import type { ThirdwebClient } from "thirdweb";
14-
import { toPercent, toSize } from "utils/number";
1514
import { TotalSponsoredChartCardUI } from "../../../../_components/TotalSponsoredCard";
1615
import { SponsoredTransactionsTable } from "./SponsoredTransactionsTable";
1716
import { UsageCard } from "./UsageCard";
@@ -31,6 +30,11 @@ type UsageProps = {
3130
}[];
3231
};
3332

33+
const compactNumberFormatter = new Intl.NumberFormat("en-US", {
34+
minimumFractionDigits: 0,
35+
notation: "compact",
36+
});
37+
3438
export const Usage: React.FC<UsageProps> = ({
3539
usage: usageData,
3640
subscriptions,
@@ -39,23 +43,6 @@ export const Usage: React.FC<UsageProps> = ({
3943
client,
4044
projects,
4145
}) => {
42-
// TODO - get this from team instead of account
43-
const storageMetrics = useMemo(() => {
44-
if (!usageData) {
45-
return {};
46-
}
47-
48-
const consumedBytes = usageData.usage.storage.sumFileSizeBytes;
49-
const limitBytes = usageData.limits.storage;
50-
const percent = toPercent(consumedBytes, limitBytes);
51-
52-
return {
53-
total: `${toSize(Math.min(consumedBytes, limitBytes), "MB")} of ${toSize(limitBytes)} included storage used`,
54-
progress: percent,
55-
totalUsage: `Total Usage: ${toSize(consumedBytes, "MB")}`,
56-
};
57-
}, [usageData]);
58-
5946
// TODO - get this from team instead of account
6047
const rpcMetrics = useMemo(() => {
6148
if (!usageData) {
@@ -66,7 +53,8 @@ export const Usage: React.FC<UsageProps> = ({
6653
title: "Unlimited Requests",
6754
total: (
6855
<span className="text-muted-foreground">
69-
{usageData.rateLimits.rpc} Requests Per Second
56+
{compactNumberFormatter.format(usageData.rateLimits.rpc)} Requests Per
57+
Second
7058
</span>
7159
),
7260
};
@@ -81,7 +69,8 @@ export const Usage: React.FC<UsageProps> = ({
8169
title: "Unlimited Requests",
8270
total: (
8371
<span className="text-muted-foreground">
84-
{usageData.rateLimits.storage} Requests Per Second
72+
{compactNumberFormatter.format(usageData.rateLimits.storage)} Requests
73+
Per Second
8574
</span>
8675
),
8776
};
@@ -100,6 +89,8 @@ export const Usage: React.FC<UsageProps> = ({
10089
? new Date(usageSub.currentPeriodEnd)
10190
: new Date();
10291

92+
const storageUsage = team.capabilities.storage.upload;
93+
10394
return (
10495
<div className="flex grow flex-col gap-8">
10596
<InAppWalletUsersChartCard
@@ -139,7 +130,15 @@ export const Usage: React.FC<UsageProps> = ({
139130
/>
140131

141132
<UsageCard
142-
{...storageMetrics}
133+
title={`${formatStorageBytes(storageUsage.totalFileSizeBytesLimit)} Storage`}
134+
total={
135+
storageUsage.rateLimit > 10_000 ? undefined : (
136+
<p className="text-muted-foreground">
137+
{compactNumberFormatter.format(storageUsage.rateLimit)} Requests
138+
Per Second
139+
</p>
140+
)
141+
}
143142
name="Storage Pinning"
144143
description="Amount of IPFS Storage pinning allowed in your plan"
145144
>
@@ -274,3 +273,29 @@ async function AsyncTotalSponsoredChartCard(
274273
/>
275274
);
276275
}
276+
277+
function formatStorageBytes(bytes: number) {
278+
const ONE_KB = 1024;
279+
const ONE_MB = ONE_KB * 1024;
280+
const ONE_GB = ONE_MB * 1024;
281+
282+
if (bytes < ONE_KB) {
283+
return `${bytes} bytes`;
284+
}
285+
286+
if (bytes < ONE_MB) {
287+
return `${compactNumberFormatter.format(bytes / ONE_KB)} KB`;
288+
}
289+
290+
if (bytes < ONE_GB) {
291+
return `${compactNumberFormatter.format(bytes / ONE_MB)} MB`;
292+
}
293+
294+
const gbs = bytes / ONE_GB;
295+
296+
if (gbs > 1000) {
297+
return "Unlimited";
298+
}
299+
300+
return `${compactNumberFormatter.format(gbs)} GB`;
301+
}

apps/dashboard/src/utils/number.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,3 @@ export const toSize = (value: number | bigint, defaultUnit?: string) => {
3030

3131
return formatted;
3232
};
33-
34-
export const toPercent = (num1: number, num2: number) => {
35-
return Math.round(((num1 / num2) * 100 * 10) / 10);
36-
};

0 commit comments

Comments
 (0)