Skip to content

Commit 1c60d7c

Browse files
polish wallet analytics tab (#1810)
1 parent f623200 commit 1c60d7c

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

pages/dashboard/wallets/analytics.tsx

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import {
55
MenuButton,
66
MenuList,
77
Stack,
8+
Stat,
9+
StatLabel,
10+
StatNumber,
11+
useBreakpointValue,
812
useColorMode,
913
} from "@chakra-ui/react";
1014
import { AppLayout } from "components/app-layouts/app";
@@ -48,6 +52,7 @@ const RADIAN = Math.PI / 180;
4852

4953
const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
5054
const { colorMode } = useColorMode();
55+
const isMobile = useBreakpointValue({ base: true, md: false });
5156
const barColors = useMemo(() => {
5257
if (colorMode === "light") {
5358
return BAR_COLORS_LIGHT;
@@ -134,6 +139,18 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
134139
)
135140
: [];
136141
}, [statsQuery.data]);
142+
const totalStasData = useMemo(() => {
143+
return statsQuery.data
144+
? statsQuery.data.timeSeries.reduce(
145+
(acc, curr) => {
146+
acc.totalWallets += curr.totalWallets;
147+
acc.uniqueWallets += curr.uniqueWallets;
148+
return acc;
149+
},
150+
{ uniqueWallets: 0, totalWallets: 0 },
151+
)
152+
: { uniqueWallets: 0, totalWallets: 0 };
153+
}, [statsQuery.data]);
137154

138155
const renderActiveShape = (props: any) => {
139156
const {
@@ -282,13 +299,23 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
282299
<Flex flexDir="column" gap={8}>
283300
{statsQuery.data && statsQuery.data.timeSeries.length > 0 ? (
284301
<>
302+
<Flex gap={4}>
303+
<WalletStatCard
304+
label="Connections"
305+
value={totalStasData.totalWallets}
306+
/>
307+
<WalletStatCard
308+
label="Unique Users"
309+
value={totalStasData.uniqueWallets}
310+
/>
311+
</Flex>
285312
<Flex
286313
flexDir="column"
287314
gap={4}
288315
as={Card}
289316
bg="backgroundHighlight"
290317
>
291-
<Stack spacing={0} padding={6}>
318+
<Stack spacing={0} padding={{ base: 2, md: 6 }}>
292319
<Heading as="h3" size="subtitle.sm">
293320
Users Connected
294321
</Heading>
@@ -314,7 +341,7 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
314341
as={Card}
315342
bg="backgroundHighlight"
316343
>
317-
<Stack spacing={0} padding={6}>
344+
<Stack spacing={0} padding={{ base: 2, md: 6 }}>
318345
<Heading as="h3" size="subtitle.sm">
319346
Wallet Connectors
320347
</Heading>
@@ -341,24 +368,23 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
341368
as={Card}
342369
bg="backgroundHighlight"
343370
>
344-
<Stack spacing={0} padding={6}>
371+
<Stack spacing={0} padding={{ base: 2, md: 6 }}>
345372
<Heading as="h3" size="subtitle.sm">
346373
Wallet Distribution
347374
</Heading>
348375
<Text>
349376
Distribution of wallet types used to connect to your app.
350377
</Text>
351378
</Stack>
352-
<ChartContainer w="full" ratio={21 / 9}>
379+
<ChartContainer w="full" ratio={isMobile ? 1.5 : 21 / 9}>
353380
<ResponsiveContainer width="100%" height="100%">
354381
<PieChart>
355382
<Pie
356383
activeIndex={activeIndex}
357384
activeShape={renderActiveShape}
358385
onMouseEnter={onPieEnter}
359386
data={pieChartData}
360-
cx={"50%"}
361-
cy={"45%"}
387+
outerRadius={"70%"}
362388
dataKey="totalWallets"
363389
valueKey="walletType"
364390
nameKey="walletType"
@@ -372,7 +398,10 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
372398
/>
373399
))}
374400
</Pie>
375-
<Legend layout="radial" verticalAlign="middle" />
401+
<Legend
402+
layout={isMobile ? "horizontal" : "radial"}
403+
verticalAlign={isMobile ? "bottom" : "middle"}
404+
/>
376405
</PieChart>
377406
</ResponsiveContainer>
378407
</ChartContainer>
@@ -413,6 +442,18 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
413442
);
414443
};
415444

445+
const WalletStatCard: React.FC<{ label: string; value?: number }> = ({
446+
label,
447+
value,
448+
}) => {
449+
return (
450+
<Card as={Stat}>
451+
<StatLabel mb={{ base: 1, md: 0 }}>{label}</StatLabel>
452+
<StatNumber>{value}</StatNumber>
453+
</Card>
454+
);
455+
};
456+
416457
DashboardWalletsAnalytics.getLayout = (page, props) => (
417458
<AppLayout {...props} hasSidebar={true}>
418459
<WalletsSidebar activePage="analytics" />

0 commit comments

Comments
 (0)