@@ -8,6 +8,7 @@ import { THIRDWEB_ANALYTICS_API_HOST, THIRDWEB_API_HOST } from "constants/urls";
88import invariant from "tiny-invariant" ;
99import { accountKeys , apiKeys , authorizedWallets } from "../cache-keys" ;
1010import { useLoggedInUser } from "./useLoggedInUser" ;
11+ import { useAllChainsData } from "hooks/chains/allChains" ;
1112
1213// FIXME: We keep repeating types, API server should provide them
1314
@@ -259,17 +260,17 @@ export interface BillingCredit {
259260
260261interface UseAccountInput {
261262 refetchInterval ?:
262- | number
263- | false
264- | ( (
265- query : Query <
266- Account ,
267- Error ,
268- Account ,
269- readonly [ "account" , string , "me" ]
270- > ,
271- ) => number | false | undefined )
272- | undefined ;
263+ | number
264+ | false
265+ | ( (
266+ query : Query <
267+ Account ,
268+ Error ,
269+ Account ,
270+ readonly [ "account" , string , "me" ]
271+ > ,
272+ ) => number | false | undefined )
273+ | undefined ;
273274}
274275
275276export function useAccount ( { refetchInterval } : UseAccountInput = { } ) {
@@ -434,6 +435,7 @@ export function useUserOpUsageAggregate(args: {
434435} ) {
435436 const { clientId, from, to } = args ;
436437 const { user, isLoggedIn } = useLoggedInUser ( ) ;
438+ const chainStore = useAllChainsData ( ) ;
437439
438440 return useQuery < UserOpStats > ( {
439441 queryKey : accountKeys . userOpStats (
@@ -444,16 +446,25 @@ export function useUserOpUsageAggregate(args: {
444446 "all" ,
445447 ) ,
446448 queryFn : async ( ) => {
447- const userOpStats : UserOpStats [ ] = await getUserOpUsage ( {
448- clientId,
449- from,
450- to,
451- period : "all" ,
452- } ) ;
449+ const userOpStats : ( UserOpStats & { chainId ?: string } ) [ ] =
450+ await getUserOpUsage ( {
451+ clientId,
452+ from,
453+ to,
454+ period : "all" ,
455+ } ) ;
453456
454457 // Aggregate stats across wallet types
455458 return userOpStats . reduce (
456459 ( acc , curr ) => {
460+ // Skip testnets from the aggregated stats
461+ if ( curr . chainId ) {
462+ const chain = chainStore . idToChain . get ( Number ( curr . chainId ) ) ;
463+ if ( chain ?. testnet ) {
464+ return acc ;
465+ }
466+ }
467+
457468 acc . successful += curr . successful ;
458469 acc . failed += curr . failed ;
459470 acc . sponsoredUsd += curr . sponsoredUsd ;
0 commit comments