1- import { defineChain } from "thirdweb" ;
2- import { type ChainMetadata , getChainMetadata } from "thirdweb/chains" ;
1+ "use client" ;
2+ import { useSetResponsiveSearchParams } from "responsive-rsc" ;
3+ import type { ChainMetadata } from "thirdweb/chains" ;
34import { cn } from "@/lib/utils" ;
45import type { UserOpStats } from "@/types/analytics" ;
56import { BarChart } from "../../../components/Analytics/BarChart" ;
67import { CombinedBarChartCard } from "../../../components/Analytics/CombinedBarChartCard" ;
78import { EmptyAccountAbstractionChartContent } from "../../[project_slug]/(sidebar)/account-abstraction/AccountAbstractionAnalytics/SponsoredTransactionsChartCard" ;
89
9- export async function TotalSponsoredChartCardUI ( {
10- data,
11- aggregatedData,
12- searchParams,
10+ const chartConfig = {
11+ mainnet : {
12+ color : "hsl(var(--chart-1))" ,
13+ label : "Mainnet Chains" ,
14+ } ,
15+ testnet : {
16+ color : "hsl(var(--chart-2))" ,
17+ label : "Testnet Chains" ,
18+ } ,
19+ total : {
20+ color : "hsl(var(--chart-3))" ,
21+ label : "All Chains" ,
22+ } ,
23+ } ;
24+
25+ export function TotalSponsoredChartCardUI ( {
26+ processedAggregatedData,
27+ selectedChart,
1328 className,
1429 onlyMainnet,
1530 title,
31+ chains,
32+ data,
1633 description,
34+ selectedChartQueryParam,
1735} : {
1836 data : UserOpStats [ ] ;
19- aggregatedData : UserOpStats [ ] ;
20- searchParams ?: { [ key : string ] : string | string [ ] | undefined } ;
37+ selectedChart : string | undefined ;
2138 className ?: string ;
2239 onlyMainnet ?: boolean ;
2340 title ?: string ;
41+ selectedChartQueryParam : string ;
2442 description ?: string ;
43+ chains : ChainMetadata [ ] ;
44+ processedAggregatedData : {
45+ mainnet : number ;
46+ testnet : number ;
47+ total : number ;
48+ } ;
2549} ) {
26- const chains = await Promise . all (
27- data . map (
28- ( item ) =>
29- // eslint-disable-next-line no-restricted-syntax
30- item . chainId && getChainMetadata ( defineChain ( Number ( item . chainId ) ) ) ,
31- ) ,
32- ) . then ( ( chains ) => chains . filter ( ( c ) => c ) as ChainMetadata [ ] ) ;
50+ const setResponsiveSearchParams = useSetResponsiveSearchParams ( ) ;
3351
3452 // Process data to combine by date and chain type
3553 const dateMap = new Map < string , { mainnet : number ; testnet : number } > ( ) ;
@@ -55,35 +73,6 @@ export async function TotalSponsoredChartCardUI({
5573 } ) )
5674 . sort ( ( a , b ) => new Date ( a . date ) . getTime ( ) - new Date ( b . date ) . getTime ( ) ) ;
5775
58- const processedAggregatedData = {
59- mainnet : aggregatedData
60- . filter (
61- ( d ) => ! chains . find ( ( c ) => c . chainId === Number ( d . chainId ) ) ?. testnet ,
62- )
63- . reduce ( ( acc , curr ) => acc + curr . sponsoredUsd , 0 ) ,
64- testnet : aggregatedData
65- . filter (
66- ( d ) => chains . find ( ( c ) => c . chainId === Number ( d . chainId ) ) ?. testnet ,
67- )
68- . reduce ( ( acc , curr ) => acc + curr . sponsoredUsd , 0 ) ,
69- total : aggregatedData . reduce ( ( acc , curr ) => acc + curr . sponsoredUsd , 0 ) ,
70- } ;
71-
72- const chartConfig = {
73- mainnet : {
74- color : "hsl(var(--chart-1))" ,
75- label : "Mainnet Chains" ,
76- } ,
77- testnet : {
78- color : "hsl(var(--chart-2))" ,
79- label : "Testnet Chains" ,
80- } ,
81- total : {
82- color : "hsl(var(--chart-3))" ,
83- label : "All Chains" ,
84- } ,
85- } ;
86-
8776 if ( onlyMainnet ) {
8877 const filteredData = timeSeriesData . filter ( ( d ) => d . mainnet > 0 ) ;
8978 return (
@@ -106,15 +95,23 @@ export async function TotalSponsoredChartCardUI({
10695 return (
10796 < CombinedBarChartCard
10897 activeChart = {
109- ( searchParams ?. totalSponsored as keyof typeof chartConfig ) ?? "mainnet"
98+ selectedChart && selectedChart in chartConfig
99+ ? ( selectedChart as keyof typeof chartConfig )
100+ : "mainnet"
110101 }
102+ onSelect = { ( key ) => {
103+ setResponsiveSearchParams ( ( v ) => {
104+ return {
105+ ...v ,
106+ [ selectedChartQueryParam ] : key ,
107+ } ;
108+ } ) ;
109+ } }
111110 aggregateFn = { ( _data , key ) => processedAggregatedData [ key ] }
112111 chartConfig = { chartConfig }
113112 className = { className }
114113 data = { timeSeriesData }
115- existingQueryParams = { searchParams }
116114 isCurrency
117- queryKey = "totalSponsored"
118115 title = { title || "Gas Sponsored" }
119116 // Get the trend from the last two COMPLETE periods
120117 trendFn = { ( data , key ) =>
0 commit comments