Skip to content

Commit f2abc8b

Browse files
committed
Dashboard: Remove chakra usage from contract analytics page, style tweaks
1 parent 386138e commit f2abc8b

File tree

2 files changed

+51
-36
lines changed

2 files changed

+51
-36
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/analytics/ContractAnalyticsPage.tsx

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22
import { ThirdwebBarChart } from "@/components/blocks/charts/bar-chart";
3-
import { Skeleton, Stat, StatLabel, StatNumber } from "@chakra-ui/react";
3+
import { SkeletonContainer } from "@/components/ui/skeleton";
44
import type { UseQueryResult } from "@tanstack/react-query";
55
import {
66
type AnalyticsQueryParams,
@@ -14,9 +14,9 @@ import {
1414
useTotalContractTransactionAnalytics,
1515
useTotalContractUniqueWallets,
1616
} from "data/analytics/hooks";
17-
import { Suspense, useMemo, useState } from "react";
17+
import { formatDate } from "date-fns";
18+
import { useMemo, useState } from "react";
1819
import type { ThirdwebContract } from "thirdweb";
19-
import { Card } from "tw-components";
2020
import {
2121
DateRangeSelector,
2222
type Range,
@@ -121,13 +121,23 @@ type ChartProps = {
121121
startDate: Date;
122122
endDate: Date;
123123
};
124+
125+
function toolTipLabelFormatter(_v: string, item: unknown) {
126+
if (Array.isArray(item)) {
127+
const time = item[0].payload.time as number;
128+
return formatDate(new Date(time), "MMM d, yyyy");
129+
}
130+
return undefined;
131+
}
132+
124133
function UniqueWalletsChart(props: ChartProps) {
125134
const analyticsQuery = useContractUniqueWalletAnalytics(props);
126135

127136
return (
128137
<ThirdwebBarChart
129138
header={{
130139
title: "Unique Wallets",
140+
titleClassName: "mb-0.5 text-xl",
131141
description:
132142
"The number of unique wallet addresses that have sent a transaction to this contract.",
133143
}}
@@ -140,6 +150,8 @@ function UniqueWalletsChart(props: ChartProps) {
140150
},
141151
}}
142152
chartClassName="aspect-[1.5] lg:aspect-[4.5]"
153+
hideLabel={false}
154+
toolTipLabelFormatter={toolTipLabelFormatter}
143155
/>
144156
);
145157
}
@@ -156,6 +168,7 @@ function TotalTransactionsChart(props: ChartProps) {
156168
<ThirdwebBarChart
157169
header={{
158170
title: "Total Transactions",
171+
titleClassName: "mb-0.5 text-xl",
159172
description:
160173
"The number of transactions that have been sent to this contract.",
161174
}}
@@ -168,6 +181,8 @@ function TotalTransactionsChart(props: ChartProps) {
168181
},
169182
}}
170183
chartClassName="aspect-[1.5] lg:aspect-[4.5]"
184+
hideLabel={false}
185+
toolTipLabelFormatter={toolTipLabelFormatter}
171186
/>
172187
);
173188
}
@@ -179,6 +194,7 @@ function TotalEventsChart(props: ChartProps) {
179194
<ThirdwebBarChart
180195
header={{
181196
title: "Total Events",
197+
titleClassName: "mb-0.5 text-xl",
182198
description:
183199
"The number of on-chain events that have been emitted from this contract.",
184200
}}
@@ -191,6 +207,8 @@ function TotalEventsChart(props: ChartProps) {
191207
},
192208
}}
193209
chartClassName="aspect-[1.5] lg:aspect-[4.5]"
210+
hideLabel={false}
211+
toolTipLabelFormatter={toolTipLabelFormatter}
194212
/>
195213
);
196214
}
@@ -227,6 +245,7 @@ function FunctionBreakdownChart(
227245
<ThirdwebBarChart
228246
header={{
229247
title: "Function Breakdown",
248+
titleClassName: "mb-0.5 text-xl",
230249
description:
231250
"The breakdown of calls to each write function from transactions.",
232251
}}
@@ -247,6 +266,8 @@ function FunctionBreakdownChart(
247266
)}
248267
chartClassName="aspect-[1.5] lg:aspect-[4.5]"
249268
showLegend
269+
hideLabel={false}
270+
toolTipLabelFormatter={toolTipLabelFormatter}
250271
/>
251272
);
252273
}
@@ -283,6 +304,7 @@ function EventBreakdownChart(
283304
<ThirdwebBarChart
284305
header={{
285306
title: "Event Breakdown",
307+
titleClassName: "mb-0.5 text-xl",
286308
description: "The breakdown of events emitted by this contract.",
287309
}}
288310
data={mappedQueryData || []}
@@ -302,6 +324,8 @@ function EventBreakdownChart(
302324
)}
303325
chartClassName="aspect-[1.5] lg:aspect-[4.5]"
304326
showLegend
327+
hideLabel={false}
328+
toolTipLabelFormatter={toolTipLabelFormatter}
305329
/>
306330
);
307331
}
@@ -320,25 +344,12 @@ const AnalyticsStat: React.FC<AnalyticsStatProps> = ({
320344
useTotal,
321345
}) => {
322346
return (
323-
<Suspense fallback={<AnalyticsSkeleton label={label} />}>
324-
<AnalyticsData
325-
chainId={chainId}
326-
contractAddress={contractAddress}
327-
useTotal={useTotal}
328-
label={label}
329-
/>
330-
</Suspense>
331-
);
332-
};
333-
334-
const AnalyticsSkeleton: React.FC<{ label: string }> = ({ label }) => {
335-
return (
336-
<Card as={Stat} className="bg-card">
337-
<StatLabel mb={{ base: 1, md: 0 }}>{label}</StatLabel>
338-
<Skeleton isLoaded={false}>
339-
<StatNumber>{0}</StatNumber>
340-
</Skeleton>
341-
</Card>
347+
<AnalyticsData
348+
chainId={chainId}
349+
contractAddress={contractAddress}
350+
useTotal={useTotal}
351+
label={label}
352+
/>
342353
);
343354
};
344355

@@ -355,20 +366,23 @@ const AnalyticsData: React.FC<AnalyticsStatProps> = ({
355366
chainId,
356367
});
357368

358-
const data = useMemo(() => {
359-
if (!totalQuery.data) {
360-
return 0;
361-
}
362-
363-
return totalQuery.data.count;
364-
}, [totalQuery.data]);
369+
return <AnalyticsStatUI label={label} data={totalQuery.data?.count} />;
370+
};
365371

372+
function AnalyticsStatUI(props: {
373+
label: string;
374+
data: number | undefined;
375+
}) {
366376
return (
367-
<Card as={Stat} className="bg-card">
368-
<StatLabel mb={{ base: 1, md: 0 }}>{label}</StatLabel>
369-
<Skeleton isLoaded={totalQuery.isFetched}>
370-
<StatNumber>{data.toLocaleString()}</StatNumber>
371-
</Skeleton>
372-
</Card>
377+
<dl className="rounded-lg border bg-card p-4">
378+
<dt className="font-semibold">{props.label}</dt>
379+
<SkeletonContainer
380+
skeletonData={10000}
381+
loadedData={props.data}
382+
render={(v) => {
383+
return <dd className="font-normal text-xl">{v.toLocaleString()}</dd>;
384+
}}
385+
/>
386+
</dl>
373387
);
374-
};
388+
}

apps/dashboard/src/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,5 @@ input:-webkit-autofill:active {
198198
body {
199199
--chakra-zIndices-modal: 50;
200200
--chakra-zIndices-overlay: 50;
201+
--chakra-colors-chakra-border-color: hsl(var(--border));
201202
}

0 commit comments

Comments
 (0)