Skip to content

Commit 535e1df

Browse files
committed
[Dashboard] Fix: More Analytics Cleanup (#5365)
CNCT-2294 https://github.com/user-attachments/assets/29e5e8e7-ff03-46ff-aa68-4f8e13fe323f <!-- start pr-codex --> --- ## PR-Codex overview This PR primarily focuses on refactoring components and improving the organization of analytics-related files. It updates titles in story files, introduces new components, and modifies existing ones to enhance functionality and maintainability. ### Detailed summary - Updated story titles in `Stat`, `BarChart`, `PieChart`, `EmptyState`, and `CombinedBarChartCard` components. - Added `InAppWalletStats`, `EcosystemWalletStats`, and `UserOpStats` types for better analytics data handling. - Refactored `createUserOpStatsStub` to return `UserOpStats[]`. - Enhanced `BarChart` and `CombinedBarChartCard` to support currency formatting. - Introduced `EmptyStateCard` component for better UI handling of no data scenarios. - Removed deprecated `UserOpStatsByChain` type and updated related functions. - Improved data fetching functions to align with new analytics structure. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent a9375ce commit 535e1df

38 files changed

+961
-676
lines changed

apps/dashboard/src/@/api/analytics.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import { fetchAnalytics } from "data/analytics/fetch-analytics";
2+
3+
export interface WalletStats {
4+
date: string;
5+
uniqueWalletsConnected: number;
6+
totalConnections: number;
7+
walletType: string;
8+
}
9+
10+
export interface WalletUserStats {
11+
date: string;
12+
newUsers: number;
13+
returningUsers: number;
14+
totalUsers: number;
15+
}
16+
17+
export interface InAppWalletStats {
18+
date: string;
19+
authenticationMethod: string;
20+
uniqueWalletsConnected: number;
21+
}
22+
23+
export interface EcosystemWalletStats extends InAppWalletStats {}
24+
25+
export interface UserOpStats {
26+
date: string;
27+
successful: number;
28+
failed: number;
29+
sponsoredUsd: number;
30+
chainId?: string;
31+
}
32+
33+
interface AnalyticsQueryParams {
34+
clientId?: string;
35+
accountId?: string;
36+
from?: Date;
37+
to?: Date;
38+
period?: "day" | "week" | "month" | "year" | "all";
39+
}
40+
41+
function buildSearchParams(params: AnalyticsQueryParams): URLSearchParams {
42+
const searchParams = new URLSearchParams();
43+
if (params.clientId) {
44+
searchParams.append("clientId", params.clientId);
45+
}
46+
if (params.accountId) {
47+
searchParams.append("accountId", params.accountId);
48+
}
49+
if (params.from) {
50+
searchParams.append("from", params.from.toISOString());
51+
}
52+
if (params.to) {
53+
searchParams.append("to", params.to.toISOString());
54+
}
55+
if (params.period) {
56+
searchParams.append("period", params.period);
57+
}
58+
return searchParams;
59+
}
60+
61+
export async function getWalletConnections(
62+
params: AnalyticsQueryParams,
63+
): Promise<WalletStats[]> {
64+
const searchParams = buildSearchParams(params);
65+
const res = await fetchAnalytics(`v1/wallets?${searchParams.toString()}`, {
66+
method: "GET",
67+
headers: { "Content-Type": "application/json" },
68+
});
69+
70+
if (res?.status !== 200) {
71+
console.error("Failed to fetch wallet connections");
72+
return [];
73+
}
74+
75+
const json = await res.json();
76+
return json.data as WalletStats[];
77+
}
78+
79+
export async function getInAppWalletUsage(
80+
params: AnalyticsQueryParams,
81+
): Promise<InAppWalletStats[]> {
82+
const searchParams = buildSearchParams(params);
83+
const res = await fetchAnalytics(
84+
`v1/wallets/in-app?${searchParams.toString()}`,
85+
{
86+
method: "GET",
87+
headers: { "Content-Type": "application/json" },
88+
},
89+
);
90+
91+
if (res?.status !== 200) {
92+
console.error("Failed to fetch in-app wallet usage");
93+
return [];
94+
}
95+
96+
const json = await res.json();
97+
return json.data as InAppWalletStats[];
98+
}
99+
100+
export async function getUserOpUsage(
101+
params: AnalyticsQueryParams,
102+
): Promise<UserOpStats[]> {
103+
const searchParams = buildSearchParams(params);
104+
const res = await fetchAnalytics(`v1/user-ops?${searchParams.toString()}`, {
105+
method: "GET",
106+
headers: { "Content-Type": "application/json" },
107+
});
108+
109+
if (res?.status !== 200) {
110+
console.error("Failed to fetch user ops usage");
111+
return [];
112+
}
113+
114+
const json = await res.json();
115+
return json.data as UserOpStats[];
116+
}
117+
118+
export async function getWalletUsers(
119+
params: AnalyticsQueryParams,
120+
): Promise<WalletUserStats[]> {
121+
const searchParams = buildSearchParams(params);
122+
const res = await fetchAnalytics(
123+
`v1/wallets/users?${searchParams.toString()}`,
124+
{
125+
method: "GET",
126+
headers: { "Content-Type": "application/json" },
127+
},
128+
);
129+
130+
if (res?.status !== 200) {
131+
console.error("Failed to fetch wallet user stats");
132+
return [];
133+
}
134+
135+
const json = await res.json();
136+
return json.data as WalletUserStats[];
137+
}

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

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { UserOpStats } from "@/api/analytics";
12
import {
23
type Query,
34
useMutation,
@@ -231,43 +232,6 @@ export interface UsageBillableByService {
231232
};
232233
}
233234

234-
export interface WalletStats {
235-
date: string;
236-
uniqueWalletsConnected: number;
237-
totalConnections: number;
238-
walletType: string;
239-
}
240-
241-
export interface WalletUserStats {
242-
date: string;
243-
newUsers: number;
244-
returningUsers: number;
245-
totalUsers: number;
246-
}
247-
248-
export interface InAppWalletStats {
249-
date: string;
250-
authenticationMethod: string;
251-
uniqueWalletsConnected: number;
252-
}
253-
254-
export interface EcosystemWalletStats extends InAppWalletStats {}
255-
256-
export interface UserOpStats {
257-
date: string;
258-
successful: number;
259-
failed: number;
260-
sponsoredUsd: number;
261-
}
262-
263-
export interface UserOpStatsByChain {
264-
date: string;
265-
successful: number;
266-
failed: number;
267-
sponsoredUsd: number;
268-
chainId?: string;
269-
}
270-
271235
interface BillingProduct {
272236
name: string;
273237
id: string;

0 commit comments

Comments
 (0)