@@ -5,6 +5,10 @@ import {
5
5
MenuButton ,
6
6
MenuList ,
7
7
Stack ,
8
+ Stat ,
9
+ StatLabel ,
10
+ StatNumber ,
11
+ useBreakpointValue ,
8
12
useColorMode ,
9
13
} from "@chakra-ui/react" ;
10
14
import { AppLayout } from "components/app-layouts/app" ;
@@ -48,6 +52,7 @@ const RADIAN = Math.PI / 180;
48
52
49
53
const DashboardWalletsAnalytics : ThirdwebNextPage = ( ) => {
50
54
const { colorMode } = useColorMode ( ) ;
55
+ const isMobile = useBreakpointValue ( { base : true , md : false } ) ;
51
56
const barColors = useMemo ( ( ) => {
52
57
if ( colorMode === "light" ) {
53
58
return BAR_COLORS_LIGHT ;
@@ -134,6 +139,18 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
134
139
)
135
140
: [ ] ;
136
141
} , [ 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 ] ) ;
137
154
138
155
const renderActiveShape = ( props : any ) => {
139
156
const {
@@ -282,13 +299,23 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
282
299
< Flex flexDir = "column" gap = { 8 } >
283
300
{ statsQuery . data && statsQuery . data . timeSeries . length > 0 ? (
284
301
< >
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 >
285
312
< Flex
286
313
flexDir = "column"
287
314
gap = { 4 }
288
315
as = { Card }
289
316
bg = "backgroundHighlight"
290
317
>
291
- < Stack spacing = { 0 } padding = { 6 } >
318
+ < Stack spacing = { 0 } padding = { { base : 2 , md : 6 } } >
292
319
< Heading as = "h3" size = "subtitle.sm" >
293
320
Users Connected
294
321
</ Heading >
@@ -314,7 +341,7 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
314
341
as = { Card }
315
342
bg = "backgroundHighlight"
316
343
>
317
- < Stack spacing = { 0 } padding = { 6 } >
344
+ < Stack spacing = { 0 } padding = { { base : 2 , md : 6 } } >
318
345
< Heading as = "h3" size = "subtitle.sm" >
319
346
Wallet Connectors
320
347
</ Heading >
@@ -341,24 +368,23 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
341
368
as = { Card }
342
369
bg = "backgroundHighlight"
343
370
>
344
- < Stack spacing = { 0 } padding = { 6 } >
371
+ < Stack spacing = { 0 } padding = { { base : 2 , md : 6 } } >
345
372
< Heading as = "h3" size = "subtitle.sm" >
346
373
Wallet Distribution
347
374
</ Heading >
348
375
< Text >
349
376
Distribution of wallet types used to connect to your app.
350
377
</ Text >
351
378
</ Stack >
352
- < ChartContainer w = "full" ratio = { 21 / 9 } >
379
+ < ChartContainer w = "full" ratio = { isMobile ? 1.5 : 21 / 9 } >
353
380
< ResponsiveContainer width = "100%" height = "100%" >
354
381
< PieChart >
355
382
< Pie
356
383
activeIndex = { activeIndex }
357
384
activeShape = { renderActiveShape }
358
385
onMouseEnter = { onPieEnter }
359
386
data = { pieChartData }
360
- cx = { "50%" }
361
- cy = { "45%" }
387
+ outerRadius = { "70%" }
362
388
dataKey = "totalWallets"
363
389
valueKey = "walletType"
364
390
nameKey = "walletType"
@@ -372,7 +398,10 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
372
398
/>
373
399
) ) }
374
400
</ Pie >
375
- < Legend layout = "radial" verticalAlign = "middle" />
401
+ < Legend
402
+ layout = { isMobile ? "horizontal" : "radial" }
403
+ verticalAlign = { isMobile ? "bottom" : "middle" }
404
+ />
376
405
</ PieChart >
377
406
</ ResponsiveContainer >
378
407
</ ChartContainer >
@@ -413,6 +442,18 @@ const DashboardWalletsAnalytics: ThirdwebNextPage = () => {
413
442
) ;
414
443
} ;
415
444
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
+
416
457
DashboardWalletsAnalytics . getLayout = ( page , props ) => (
417
458
< AppLayout { ...props } hasSidebar = { true } >
418
459
< WalletsSidebar activePage = "analytics" />
0 commit comments