Skip to content

Commit b12e36f

Browse files
Wallet analytics tab (#1800)
* WIP wallet stats * UI polish * empty states * fix merge
1 parent 3d1e88f commit b12e36f

File tree

8 files changed

+491
-11
lines changed

8 files changed

+491
-11
lines changed

@3rdweb-sdk/react/cache-keys.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const accountKeys = {
1515
[...accountKeys.wallet(walletAddress), "me"] as const,
1616
usage: (walletAddress: string) =>
1717
[...accountKeys.wallet(walletAddress), "usage"] as const,
18+
walletStats: (walletAddress: string, clientId: string) =>
19+
[...accountKeys.wallet(walletAddress), "wallets", clientId] as const,
1820
};
1921

2022
export const apiKeys = {

@3rdweb-sdk/react/hooks/useApi.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ export interface UsageBillableByService {
142142
};
143143
}
144144

145+
export interface WalletStats {
146+
timeSeries: {
147+
dayTime: string;
148+
clientId: string;
149+
walletType: string;
150+
totalWallets: number;
151+
uniqueWallets: number;
152+
}[];
153+
}
154+
145155
export function useAccount() {
146156
const { user, isLoggedIn } = useLoggedInUser();
147157

@@ -192,6 +202,34 @@ export function useAccountUsage() {
192202
);
193203
}
194204

205+
export function useWalletStats(clientId: string | undefined) {
206+
const { user, isLoggedIn } = useLoggedInUser();
207+
208+
return useQuery(
209+
accountKeys.walletStats(user?.address as string, clientId as string),
210+
async () => {
211+
const res = await fetch(
212+
`${THIRDWEB_API_HOST}/v1/account/wallets?clientId=${clientId}`,
213+
{
214+
method: "GET",
215+
credentials: "include",
216+
headers: {
217+
"Content-Type": "application/json",
218+
},
219+
},
220+
);
221+
const json = await res.json();
222+
223+
if (json.error) {
224+
throw new Error(json.message);
225+
}
226+
227+
return json.data as WalletStats;
228+
},
229+
{ enabled: !!clientId && !!user?.address && isLoggedIn },
230+
);
231+
}
232+
195233
export function useUpdateAccount() {
196234
const { user } = useLoggedInUser();
197235
const queryClient = useQueryClient();

components/analytics/auto-bar-chart.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ export interface AutoBarChartProps<
2727
};
2828
showXAxis?: boolean;
2929
showYAxis?: boolean;
30+
stacked?: boolean;
3031
}
3132

32-
const BAR_COLORS_LIGHT = [
33+
export const BAR_COLORS_LIGHT = [
3334
"#649CDD",
3435
"#92BBE8",
3536
"#407DCC",
@@ -50,7 +51,7 @@ const BAR_COLORS_LIGHT = [
5051
"#CEE9E9",
5152
];
5253

53-
const BAR_COLORS_DARK = [
54+
export const BAR_COLORS_DARK = [
5455
"#3682DA",
5556
"#6AADF5",
5657
"#1769D3",
@@ -79,6 +80,7 @@ export const AutoBarChart = <
7980
index,
8081
showXAxis,
8182
showYAxis,
83+
stacked,
8284
...boxProps
8385
}: AutoBarChartProps<TData, TIndexKey>) => {
8486
const { colorMode } = useColorMode();
@@ -161,7 +163,7 @@ export const AutoBarChart = <
161163
<Bar
162164
key={`${cat.id as string}`}
163165
dataKey={cat.id as string}
164-
stackId="a"
166+
stackId={stacked ? "a" : (cat.id as string)}
165167
stroke={cat.color || "#3385FF"}
166168
fill={`url(#bar_color_${id}_${cat.id as string})`}
167169
opacity={cat.id === hoverKey || !hoverKey ? 1 : 0.5}

contract-ui/tabs/analytics/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,13 @@ export const AnalyticsChart: React.FC<AnalyticsChartProps> = ({
274274

275275
if (categories === "auto") {
276276
return (
277-
<AutoBarChart data={data} index={{ id: index }} showXAxis showYAxis />
277+
<AutoBarChart
278+
data={data}
279+
index={{ id: index }}
280+
showXAxis
281+
showYAxis
282+
stacked
283+
/>
278284
);
279285
}
280286

core-ui/sidebar/wallets.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Route } from "./types";
44
type WalletsSidebarProps = {
55
activePage:
66
| "connect"
7+
| "analytics"
78
| "wallet-sdk"
89
| "smart-wallet"
910
| "embedded"
@@ -17,6 +18,11 @@ const links: Route[] = [
1718
title: "Connect",
1819
name: "connect",
1920
},
21+
{
22+
path: "/dashboard/wallets/analytics",
23+
title: "Analytics",
24+
name: "analytics",
25+
},
2026
{
2127
path: "/dashboard/wallets/smart-wallet",
2228
title: "Smart Wallet",

page-id.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ export enum PageId {
134134
DashboardWalletsLocal = "dashboard-wallets-local",
135135
// thirdweb.com/dashboard/wallets/auth
136136
DashboardWalletsAuth = "dashboard-wallets-auth",
137+
// thirdweb.com/dashboard/wallets/auth
138+
DashboardWalletsAnalytics = "dashboard-wallets-analytics",
137139

138140
// thirdweb.com/dashboard/contracts/build
139141
DashboardContractsBuild = "dashboard-contracts-build",

0 commit comments

Comments
 (0)