Skip to content

Commit d331c54

Browse files
refactor
1 parent d1e5f9a commit d331c54

File tree

12 files changed

+158
-158
lines changed

12 files changed

+158
-158
lines changed

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/analytics/filter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "responsive-rsc";
88
import { DateRangeSelector } from "../../../../../../components/analytics/date-range-selector";
99
import { IntervalSelector } from "../../../../../../components/analytics/interval-selector";
10-
import { getTxAnalyticsFiltersFromSearchParams } from "./getTransactionAnalyticsFilter";
10+
import { getTxAnalyticsFiltersFromSearchParams } from "../lib/utils";
1111

1212
export function TransactionAnalyticsFilter() {
1313
const responsiveSearchParams = useResponsiveSearchParams();

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/analytics/summary.tsx

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,8 @@
1-
import { THIRDWEB_ENGINE_CLOUD_URL } from "@/constants/env";
2-
import { getAuthToken } from "app/api/lib/getAuthToken";
31
import { StatCard } from "components/analytics/stat"; // Assuming correct path
42
import { ActivityIcon, CoinsIcon } from "lucide-react";
53
import { Suspense } from "react";
6-
// Import the specific utility function needed
74
import { toEther } from "thirdweb/utils";
8-
9-
// Define the structure of the data we expect back from our fetch function
10-
type TransactionSummaryData = {
11-
totalCount: number;
12-
totalGasCostWei: string;
13-
totalGasUnitsUsed: string; // Keep fetched data structure
14-
};
15-
16-
// Define the structure of the API response
17-
type AnalyticsSummaryApiResponse = {
18-
result: {
19-
summary: {
20-
totalCount: number;
21-
totalGasCostWei: string;
22-
totalGasUnitsUsed: string;
23-
};
24-
metadata: {
25-
startDate?: string;
26-
endDate?: string;
27-
};
28-
};
29-
};
30-
31-
// Fetches data from the /analytics-summary endpoint
32-
async function getTransactionAnalyticsSummary(props: {
33-
teamId: string;
34-
clientId: string;
35-
}): Promise<TransactionSummaryData> {
36-
const authToken = await getAuthToken();
37-
const body = {};
38-
const defaultData: TransactionSummaryData = {
39-
totalCount: 0,
40-
totalGasCostWei: "0",
41-
totalGasUnitsUsed: "0",
42-
};
43-
44-
try {
45-
const response = await fetch(
46-
`${THIRDWEB_ENGINE_CLOUD_URL}/project/transactions/analytics-summary`,
47-
{
48-
method: "POST",
49-
headers: {
50-
"Content-Type": "application/json",
51-
"x-team-id": props.teamId,
52-
"x-client-id": props.clientId,
53-
Authorization: `Bearer ${authToken}`,
54-
},
55-
body: JSON.stringify(body),
56-
},
57-
);
58-
59-
if (!response.ok) {
60-
if (response.status === 401) {
61-
console.error("Unauthorized fetching transaction summary");
62-
return defaultData;
63-
}
64-
const errorText = await response.text();
65-
throw new Error(
66-
`Error fetching transaction summary: ${response.status} ${response.statusText} - ${errorText}`,
67-
);
68-
}
69-
70-
const data = (await response.json()) as AnalyticsSummaryApiResponse;
71-
72-
return {
73-
totalCount: data.result.summary.totalCount ?? 0,
74-
totalGasCostWei: data.result.summary.totalGasCostWei ?? "0",
75-
totalGasUnitsUsed: data.result.summary.totalGasUnitsUsed ?? "0",
76-
};
77-
} catch (error) {
78-
console.error("Failed to fetch transaction summary:", error);
79-
return defaultData;
80-
}
81-
}
5+
import type { TransactionSummaryData } from "../lib/analytics";
826

837
// Renders the UI based on fetched data or pending state
848
function TransactionAnalyticsSummaryUI(props: {
Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { ResponsiveSuspense } from "responsive-rsc";
2-
import { THIRDWEB_ENGINE_CLOUD_URL } from "../../../../../../../@/constants/env";
3-
import type { TransactionStats } from "../../../../../../../types/analytics";
4-
import { getAuthToken } from "../../../../../../api/lib/getAuthToken";
2+
import { getTransactionsChart } from "../../lib/analytics";
3+
import { getTxAnalyticsFiltersFromSearchParams } from "../../lib/utils";
54
import type { Wallet } from "../../server-wallets/wallet-table/types";
6-
import { getTxAnalyticsFiltersFromSearchParams } from "../getTransactionAnalyticsFilter";
75
import { TransactionsChartCardUI } from "./tx-chart-ui";
86

97
async function AsyncTransactionsChartCard(props: {
@@ -78,73 +76,3 @@ export function TransactionsChartCard(props: {
7876
</ResponsiveSuspense>
7977
);
8078
}
81-
82-
async function getTransactionsChart({
83-
teamId,
84-
clientId,
85-
from,
86-
to,
87-
interval,
88-
}: {
89-
teamId: string;
90-
clientId: string;
91-
from: string;
92-
to: string;
93-
interval: "day" | "week";
94-
}): Promise<TransactionStats[]> {
95-
const authToken = await getAuthToken();
96-
97-
const filters = {
98-
startDate: from,
99-
endDate: to,
100-
resolution: interval,
101-
};
102-
103-
const response = await fetch(
104-
`${THIRDWEB_ENGINE_CLOUD_URL}/project/transactions/analytics`,
105-
{
106-
method: "POST",
107-
headers: {
108-
"Content-Type": "application/json",
109-
"x-team-id": teamId,
110-
"x-client-id": clientId,
111-
Authorization: `Bearer ${authToken}`,
112-
},
113-
body: JSON.stringify(filters),
114-
},
115-
);
116-
117-
if (!response.ok) {
118-
if (response.status === 401) {
119-
return [];
120-
}
121-
122-
// TODO - need to handle this error state, like we do with the connect charts
123-
throw new Error(
124-
`Error fetching transactions chart data: ${response.status} ${response.statusText} - ${await response.text().catch(() => "Unknown error")}`,
125-
);
126-
}
127-
128-
type TransactionsChartResponse = {
129-
result: {
130-
analytics: Array<{
131-
timeBucket: string;
132-
chainId: string;
133-
count: number;
134-
}>;
135-
metadata: {
136-
resolution: string;
137-
startDate: string;
138-
endDate: string;
139-
};
140-
};
141-
};
142-
143-
const data = (await response.json()) as TransactionsChartResponse;
144-
145-
return data.result.analytics.map((stat) => ({
146-
date: stat.timeBucket,
147-
chainId: Number(stat.chainId),
148-
count: stat.count,
149-
}));
150-
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import { getFiltersFromSearchParams } from "@/lib/time";
2+
import { THIRDWEB_ENGINE_CLOUD_URL } from "../../../../../../@/constants/env";
3+
import type { TransactionStats } from "../../../../../../types/analytics";
4+
import { getAuthToken } from "../../../../../api/lib/getAuthToken";
5+
6+
// Define the structure of the data we expect back from our fetch function
7+
export type TransactionSummaryData = {
8+
totalCount: number;
9+
totalGasCostWei: string;
10+
totalGasUnitsUsed: string; // Keep fetched data structure
11+
};
12+
13+
// Define the structure of the API response
14+
type AnalyticsSummaryApiResponse = {
15+
result: {
16+
summary: {
17+
totalCount: number;
18+
totalGasCostWei: string;
19+
totalGasUnitsUsed: string;
20+
};
21+
metadata: {
22+
startDate?: string;
23+
endDate?: string;
24+
};
25+
};
26+
};
27+
28+
// Fetches data from the /analytics-summary endpoint
29+
export async function getTransactionAnalyticsSummary(props: {
30+
teamId: string;
31+
clientId: string;
32+
}): Promise<TransactionSummaryData> {
33+
const authToken = await getAuthToken();
34+
const body = {};
35+
const defaultData: TransactionSummaryData = {
36+
totalCount: 0,
37+
totalGasCostWei: "0",
38+
totalGasUnitsUsed: "0",
39+
};
40+
41+
try {
42+
const response = await fetch(
43+
`${THIRDWEB_ENGINE_CLOUD_URL}/project/transactions/analytics-summary`,
44+
{
45+
method: "POST",
46+
headers: {
47+
"Content-Type": "application/json",
48+
"x-team-id": props.teamId,
49+
"x-client-id": props.clientId,
50+
Authorization: `Bearer ${authToken}`,
51+
},
52+
body: JSON.stringify(body),
53+
},
54+
);
55+
56+
if (!response.ok) {
57+
if (response.status === 401) {
58+
console.error("Unauthorized fetching transaction summary");
59+
return defaultData;
60+
}
61+
const errorText = await response.text();
62+
throw new Error(
63+
`Error fetching transaction summary: ${response.status} ${response.statusText} - ${errorText}`,
64+
);
65+
}
66+
67+
const data = (await response.json()) as AnalyticsSummaryApiResponse;
68+
69+
return {
70+
totalCount: data.result.summary.totalCount ?? 0,
71+
totalGasCostWei: data.result.summary.totalGasCostWei ?? "0",
72+
totalGasUnitsUsed: data.result.summary.totalGasUnitsUsed ?? "0",
73+
};
74+
} catch (error) {
75+
console.error("Failed to fetch transaction summary:", error);
76+
return defaultData;
77+
}
78+
}
79+
80+
export async function getTransactionsChart({
81+
teamId,
82+
clientId,
83+
from,
84+
to,
85+
interval,
86+
}: {
87+
teamId: string;
88+
clientId: string;
89+
from: string;
90+
to: string;
91+
interval: "day" | "week";
92+
}): Promise<TransactionStats[]> {
93+
const authToken = await getAuthToken();
94+
95+
const filters = {
96+
startDate: from,
97+
endDate: to,
98+
resolution: interval,
99+
};
100+
101+
const response = await fetch(
102+
`${THIRDWEB_ENGINE_CLOUD_URL}/project/transactions/analytics`,
103+
{
104+
method: "POST",
105+
headers: {
106+
"Content-Type": "application/json",
107+
"x-team-id": teamId,
108+
"x-client-id": clientId,
109+
Authorization: `Bearer ${authToken}`,
110+
},
111+
body: JSON.stringify(filters),
112+
},
113+
);
114+
115+
if (!response.ok) {
116+
if (response.status === 401) {
117+
return [];
118+
}
119+
120+
// TODO - need to handle this error state, like we do with the connect charts
121+
throw new Error(
122+
`Error fetching transactions chart data: ${response.status} ${response.statusText} - ${await response.text().catch(() => "Unknown error")}`,
123+
);
124+
}
125+
126+
type TransactionsChartResponse = {
127+
result: {
128+
analytics: Array<{
129+
timeBucket: string;
130+
chainId: string;
131+
count: number;
132+
}>;
133+
metadata: {
134+
resolution: string;
135+
startDate: string;
136+
endDate: string;
137+
};
138+
};
139+
};
140+
141+
const data = (await response.json()) as TransactionsChartResponse;
142+
143+
return data.result.analytics.map((stat) => ({
144+
date: stat.timeBucket,
145+
chainId: Number(stat.chainId),
146+
count: stat.count,
147+
}));
148+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createAccessToken,
66
createVaultClient,
77
} from "@thirdweb-dev/vault-sdk";
8-
import { updateProjectClient } from "../../../../../../../@3rdweb-sdk/react/hooks/useApi";
8+
import { updateProjectClient } from "../../../../../../@3rdweb-sdk/react/hooks/useApi";
99

1010
const SERVER_WALLET_ACCESS_TOKEN_PURPOSE =
1111
"Access Token for All Server Wallets";

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { notFound, redirect } from "next/navigation";
55
import { getAuthToken } from "../../../../api/lib/getAuthToken";
66
import { TransactionsAnalyticsPageContent } from "./analytics/analytics-page";
77
import { TransactionAnalyticsSummary } from "./analytics/summary";
8-
import { initVaultClient } from "./server-wallets/lib/vault-utils";
8+
import { initVaultClient } from "./lib/vault-utils";
99
import type { Wallet } from "./server-wallets/wallet-table/types";
1010

1111
export default async function TransactionsAnalyticsPage(props: {

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/server-wallets/components/create-server-wallet.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
createWalletAccessToken,
2424
initVaultClient,
2525
maskSecret,
26-
} from "../lib/vault-utils";
26+
} from "../../lib/vault-utils";
2727

2828
export default function CreateServerWallet(props: {
2929
project: Project;

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/server-wallets/components/list-access-tokens.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
SERVER_WALLET_MANAGEMENT_ACCESS_TOKEN_PURPOSE,
3131
createWalletAccessToken,
3232
initVaultClient,
33-
} from "../lib/vault-utils";
33+
} from "../../lib/vault-utils";
3434

3535
export default function ListAccessTokensButton(props: {
3636
project: Project;

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/server-wallets/components/rotate-admin-key.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
createManagementAccessToken,
2525
initVaultClient,
2626
maskSecret,
27-
} from "../lib/vault-utils";
27+
} from "../../lib/vault-utils";
2828

2929
export default function RotateAdminKeyButton(props: { project: Project }) {
3030
const [modalOpen, setModalOpen] = useState(false);

0 commit comments

Comments
 (0)