Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions apps/dashboard/src/@3rdweb-sdk/react/hooks/useApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
useQueryClient,
} from "@tanstack/react-query";
import { THIRDWEB_ANALYTICS_API_HOST, THIRDWEB_API_HOST } from "constants/urls";
import { useAllChainsData } from "hooks/chains/allChains";
import invariant from "tiny-invariant";
import { accountKeys, apiKeys, authorizedWallets } from "../cache-keys";
import { useLoggedInUser } from "./useLoggedInUser";
Expand Down Expand Up @@ -442,6 +443,7 @@ export function useUserOpUsageAggregate(args: {
}) {
const { clientId, from, to } = args;
const { user, isLoggedIn } = useLoggedInUser();
const chainStore = useAllChainsData();

return useQuery<UserOpStats>({
queryKey: accountKeys.userOpStats(
Expand All @@ -452,16 +454,25 @@ export function useUserOpUsageAggregate(args: {
"all",
),
queryFn: async () => {
const userOpStats: UserOpStats[] = await getUserOpUsage({
clientId,
from,
to,
period: "all",
});
const userOpStats: (UserOpStats & { chainId?: string })[] =
await getUserOpUsage({
clientId,
from,
to,
period: "all",
});

// Aggregate stats across wallet types
return userOpStats.reduce(
(acc, curr) => {
// Skip testnets from the aggregated stats
if (curr.chainId) {
const chain = chainStore.idToChain.get(Number(curr.chainId));
if (chain?.testnet) {
return acc;
}
}

acc.successful += curr.successful;
acc.failed += curr.failed;
acc.sponsoredUsd += curr.sponsoredUsd;
Expand Down
4 changes: 3 additions & 1 deletion apps/dashboard/src/components/analytics/stat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export const Stat: React.FC<{
<dl className="flex items-center justify-between gap-4 rounded-lg border border-border bg-muted/50 p-4 lg:p-6">
<div>
<dd className="font-semibold text-3xl tracking-tight lg:text-5xl">
{value && formatter ? formatter(value) : value?.toLocaleString()}
{value !== undefined && formatter
? formatter(value)
: value?.toLocaleString()}
</dd>
<dt className="font-medium text-muted-foreground text-sm tracking-tight lg:text-lg">
{label}
Expand Down
Loading