Skip to content

Commit cd22bca

Browse files
committed
[Dashboard] Fix: Exclude testnet $ from total sponsored (#5166)
<!-- start pr-codex --> ## PR-Codex overview This PR focuses on improving the handling of analytics data in the `useUserOpUsageAggregate` function by incorporating chain data and refining the conditional rendering in the `stat.tsx` component. ### Detailed summary - In `stat.tsx`, changed the conditional rendering to check for `value !== undefined` instead of `value &&`. - In `useApi.ts`, imported `useAllChainsData` for accessing chain data. - Added `chainStore` to hold all chains data. - Modified `userOpStats` type to include `chainId`. - Implemented a check to skip testnets in aggregated stats based on `chainId`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent e4b6d87 commit cd22bca

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

apps/dashboard/src/@3rdweb-sdk/react/hooks/useApi.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useQueryClient,
66
} from "@tanstack/react-query";
77
import { THIRDWEB_ANALYTICS_API_HOST, THIRDWEB_API_HOST } from "constants/urls";
8+
import { useAllChainsData } from "hooks/chains/allChains";
89
import invariant from "tiny-invariant";
910
import { accountKeys, apiKeys, authorizedWallets } from "../cache-keys";
1011
import { useLoggedInUser } from "./useLoggedInUser";
@@ -442,6 +443,7 @@ export function useUserOpUsageAggregate(args: {
442443
}) {
443444
const { clientId, from, to } = args;
444445
const { user, isLoggedIn } = useLoggedInUser();
446+
const chainStore = useAllChainsData();
445447

446448
return useQuery<UserOpStats>({
447449
queryKey: accountKeys.userOpStats(
@@ -452,16 +454,25 @@ export function useUserOpUsageAggregate(args: {
452454
"all",
453455
),
454456
queryFn: async () => {
455-
const userOpStats: UserOpStats[] = await getUserOpUsage({
456-
clientId,
457-
from,
458-
to,
459-
period: "all",
460-
});
457+
const userOpStats: (UserOpStats & { chainId?: string })[] =
458+
await getUserOpUsage({
459+
clientId,
460+
from,
461+
to,
462+
period: "all",
463+
});
461464

462465
// Aggregate stats across wallet types
463466
return userOpStats.reduce(
464467
(acc, curr) => {
468+
// Skip testnets from the aggregated stats
469+
if (curr.chainId) {
470+
const chain = chainStore.idToChain.get(Number(curr.chainId));
471+
if (chain?.testnet) {
472+
return acc;
473+
}
474+
}
475+
465476
acc.successful += curr.successful;
466477
acc.failed += curr.failed;
467478
acc.sponsoredUsd += curr.sponsoredUsd;

apps/dashboard/src/components/analytics/stat.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export const Stat: React.FC<{
88
<dl className="flex items-center justify-between gap-4 rounded-lg border border-border bg-muted/50 p-4 lg:p-6">
99
<div>
1010
<dd className="font-semibold text-3xl tracking-tight lg:text-5xl">
11-
{value && formatter ? formatter(value) : value?.toLocaleString()}
11+
{value !== undefined && formatter
12+
? formatter(value)
13+
: value?.toLocaleString()}
1214
</dd>
1315
<dt className="font-medium text-muted-foreground text-sm tracking-tight lg:text-lg">
1416
{label}

0 commit comments

Comments
 (0)