Skip to content

Commit 13ebfc6

Browse files
more refactors
1 parent a89118c commit 13ebfc6

File tree

10 files changed

+144
-67
lines changed

10 files changed

+144
-67
lines changed

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Project } from "@/api/projects";
12
import { ResponsiveSearchParamsProvider } from "responsive-rsc";
23
import type { Wallet } from "../server-wallets/wallet-table/types";
34
import { TransactionAnalyticsFilter } from "./filter";
@@ -11,10 +12,7 @@ export function TransactionsAnalyticsPageContent(props: {
1112
to?: string | undefined | string[];
1213
interval?: string | undefined | string[];
1314
};
14-
teamId: string;
15-
clientId: string;
16-
project_slug: string;
17-
team_slug: string;
15+
project: Project;
1816
wallets?: Wallet[];
1917
expandTestTx?: boolean;
2018
}) {
@@ -28,22 +26,15 @@ export function TransactionsAnalyticsPageContent(props: {
2826
<div className="flex grow flex-col gap-6">
2927
<TransactionsChartCard
3028
searchParams={props.searchParams}
31-
teamId={props.teamId}
32-
clientId={props.clientId}
33-
project_slug={props.project_slug}
34-
team_slug={props.team_slug}
29+
project={props.project}
3530
wallets={props.wallets ?? []}
3631
/>
3732
<SendTestTransaction
3833
wallets={props.wallets}
39-
clientId={props.clientId}
34+
project={props.project}
4035
expanded={props.expandTestTx}
4136
/>
42-
<TransactionsTable
43-
teamId={props.teamId}
44-
clientId={props.clientId}
45-
wallets={props.wallets}
46-
/>
37+
<TransactionsTable project={props.project} wallets={props.wallets} />
4738
</div>
4839
</div>
4940
</ResponsiveSearchParamsProvider>

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/analytics/send-test-tx.client.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"use client";
2+
import type { Project } from "@/api/projects";
3+
import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
24
import { WalletAvatar } from "@/components/blocks/wallet-address";
5+
import { Button } from "@/components/ui/button";
36
import { Input } from "@/components/ui/input";
47
import {
58
Select,
@@ -18,8 +21,6 @@ import { useForm } from "react-hook-form";
1821
import { toast } from "sonner";
1922
import { shortenAddress } from "thirdweb/utils";
2023
import * as z from "zod";
21-
import { SingleNetworkSelector } from "../../../../../../@/components/blocks/NetworkSelectors";
22-
import { Button } from "../../../../../../@/components/ui/button";
2324
import type { Wallet } from "../server-wallets/wallet-table/types";
2425

2526
const formSchema = z.object({
@@ -33,7 +34,7 @@ type FormValues = z.infer<typeof formSchema>;
3334

3435
export function SendTestTransaction(props: {
3536
wallets?: Wallet[];
36-
clientId: string;
37+
project: Project;
3738
expanded?: boolean;
3839
}) {
3940
const [isOpen, setIsOpen] = useState(props.expanded ?? false);
@@ -112,7 +113,7 @@ export function SendTestTransaction(props: {
112113
chainId: data.chainId,
113114
});
114115
queryClient.invalidateQueries({
115-
queryKey: ["transactions", props.clientId],
116+
queryKey: ["transactions", props.project.id],
116117
});
117118
};
118119

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { StatCard } from "components/analytics/stat"; // Assuming correct path
22
import { ActivityIcon, CoinsIcon } from "lucide-react";
33
import { Suspense } from "react";
44
import { toEther } from "thirdweb/utils";
5-
import type { TransactionSummaryData } from "../lib/analytics";
5+
import {
6+
type TransactionSummaryData,
7+
getTransactionAnalyticsSummary,
8+
} from "../lib/analytics";
69

710
// Renders the UI based on fetched data or pending state
811
function TransactionAnalyticsSummaryUI(props: {

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/analytics/tx-chart/tx-chart-ui.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import type { Project } from "@/api/projects";
34
import { ExportToCSVButton } from "@/components/blocks/ExportToCSVButton";
45
import { ThirdwebBarChart } from "@/components/blocks/charts/bar-chart";
56
import { Button } from "@/components/ui/button";
@@ -20,8 +21,7 @@ type ChartData = Record<string, number> & {
2021
export function TransactionsChartCardUI(props: {
2122
userOpStats: TransactionStats[];
2223
isPending: boolean;
23-
project_slug: string;
24-
team_slug: string;
24+
project: Project;
2525
wallets: Wallet[];
2626
}) {
2727
const { userOpStats } = props;
@@ -145,20 +145,15 @@ export function TransactionsChartCardUI(props: {
145145
}}
146146
toolTipValueFormatter={(value) => formatTickerNumber(Number(value))}
147147
emptyChartState={
148-
<EmptyChartContent
149-
project_slug={props.project_slug}
150-
team_slug={props.team_slug}
151-
wallets={props.wallets}
152-
/>
148+
<EmptyChartContent project={props.project} wallets={props.wallets} />
153149
}
154150
/>
155151
);
156152
}
157153

158154
// TODO - update the title and doc links
159155
function EmptyChartContent(props: {
160-
project_slug: string;
161-
team_slug: string;
156+
project: Project;
162157
wallets: Wallet[];
163158
}) {
164159
const router = useDashboardRouter();
@@ -175,7 +170,7 @@ function EmptyChartContent(props: {
175170
variant="primary"
176171
onClick={() => {
177172
router.push(
178-
`/team/${props.team_slug}/${props.project_slug}/engine/server-wallets`,
173+
`/team/${props.project.teamId}/${props.project.id}/engine/server-wallets`,
179174
);
180175
}}
181176
>

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/analytics/tx-chart/tx-chart.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Project } from "@/api/projects";
12
import { ResponsiveSuspense } from "responsive-rsc";
23
import { getTransactionsChart } from "../../lib/analytics";
34
import { getTxAnalyticsFiltersFromSearchParams } from "../../lib/utils";
@@ -8,15 +9,12 @@ async function AsyncTransactionsChartCard(props: {
89
from: string;
910
to: string;
1011
interval: "day" | "week";
11-
teamId: string;
12-
clientId: string;
13-
project_slug: string;
14-
team_slug: string;
12+
project: Project;
1513
wallets: Wallet[];
1614
}) {
1715
const data = await getTransactionsChart({
18-
teamId: props.teamId,
19-
clientId: props.clientId,
16+
clientId: props.project.publishableKey,
17+
teamId: props.project.teamId,
2018
from: props.from,
2119
to: props.to,
2220
interval: props.interval,
@@ -26,8 +24,7 @@ async function AsyncTransactionsChartCard(props: {
2624
<TransactionsChartCardUI
2725
isPending={false}
2826
userOpStats={data}
29-
project_slug={props.project_slug}
30-
team_slug={props.team_slug}
27+
project={props.project}
3128
wallets={props.wallets}
3229
/>
3330
);
@@ -39,10 +36,7 @@ export function TransactionsChartCard(props: {
3936
to?: string | undefined | string[];
4037
interval?: string | undefined | string[];
4138
};
42-
teamId: string;
43-
clientId: string;
44-
project_slug: string;
45-
team_slug: string;
39+
project: Project;
4640
wallets: Wallet[];
4741
}) {
4842
const { range, interval } = getTxAnalyticsFiltersFromSearchParams(
@@ -57,8 +51,7 @@ export function TransactionsChartCard(props: {
5751
<TransactionsChartCardUI
5852
isPending={true}
5953
userOpStats={[]}
60-
project_slug={props.project_slug}
61-
team_slug={props.team_slug}
54+
project={props.project}
6255
wallets={[]}
6356
/>
6457
}
@@ -67,10 +60,7 @@ export function TransactionsChartCard(props: {
6760
from={range.from.toISOString()}
6861
to={range.to.toISOString()}
6962
interval={interval}
70-
teamId={props.teamId}
71-
clientId={props.clientId}
72-
project_slug={props.project_slug}
73-
team_slug={props.team_slug}
63+
project={props.project}
7464
wallets={props.wallets}
7565
/>
7666
</ResponsiveSuspense>

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/analytics/tx-table/tx-table-ui.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import type { Project } from "@/api/projects";
34
import { WalletAddress } from "@/components/blocks/wallet-address";
45
import { PaginationButtons } from "@/components/pagination-buttons";
56
import { CopyAddressButton } from "@/components/ui/CopyAddressButton";
@@ -27,14 +28,15 @@ import {
2728
TableRow,
2829
} from "@/components/ui/table";
2930
import { ToolTipLabel } from "@/components/ui/tooltip";
31+
import { useThirdwebClient } from "@/constants/thirdweb.client";
32+
import { useDashboardRouter } from "@/lib/DashboardRouter";
3033
import { keepPreviousData, useQuery } from "@tanstack/react-query";
3134
import { formatDistanceToNowStrict } from "date-fns";
3235
import { format } from "date-fns/format";
3336
import { useAllChainsData } from "hooks/chains/allChains";
3437
import { ExternalLinkIcon, InfoIcon } from "lucide-react";
3538
import Link from "next/link";
3639
import { useState } from "react";
37-
import { useThirdwebClient } from "../../../../../../../@/constants/thirdweb.client";
3840
import { ChainIconClient } from "../../../../../../../components/icons/ChainIcon";
3941
import type { Wallet } from "../../server-wallets/wallet-table/types";
4042
import type {
@@ -46,9 +48,10 @@ import type {
4648
// TODO - add Status selector dropdown here
4749
export function TransactionsTableUI(props: {
4850
getData: (params: { page: number }) => Promise<TransactionsResponse>;
49-
clientId: string;
51+
project: Project;
5052
wallets?: Wallet[];
5153
}) {
54+
const router = useDashboardRouter();
5255
const [autoUpdate, setAutoUpdate] = useState(true);
5356
const [status, setStatus] = useState<TransactionStatus | undefined>(
5457
undefined,
@@ -57,7 +60,7 @@ export function TransactionsTableUI(props: {
5760

5861
const pageSize = 10;
5962
const transactionsQuery = useQuery({
60-
queryKey: ["transactions", props.clientId, page],
63+
queryKey: ["transactions", props.project.id, page],
6164
queryFn: () => props.getData({ page }),
6265
refetchInterval: autoUpdate ? 4_000 : false,
6366
placeholderData: keepPreviousData,
@@ -132,6 +135,11 @@ export function TransactionsTableUI(props: {
132135
<TableRow
133136
key={`${tx.id}${tx.chainId}`}
134137
className="cursor-pointer hover:bg-accent/50"
138+
onClick={() => {
139+
router.push(
140+
`/team/${props.project.teamId}/project/${props.project.id}/engine/tx/${tx.id}`,
141+
);
142+
}}
135143
>
136144
{/* Queue ID */}
137145
<TableCell className="font-medium">

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/analytics/tx-table/tx-table.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
"use client";
22

33
import { engineCloudProxy } from "@/actions/proxies";
4+
import type { Project } from "@/api/projects";
45
import type { Wallet } from "../../server-wallets/wallet-table/types";
56
import { TransactionsTableUI } from "./tx-table-ui";
67
import type { TransactionsResponse } from "./types";
78

89
export function TransactionsTable(props: {
9-
teamId: string;
10-
clientId: string;
10+
project: Project;
1111
wallets?: Wallet[];
1212
}) {
1313
return (
1414
<TransactionsTableUI
1515
getData={async ({ page }) => {
1616
return await getTransactions({
17-
teamId: props.teamId,
18-
clientId: props.clientId,
17+
project: props.project,
1918
page,
2019
});
2120
}}
22-
clientId={props.clientId}
21+
project={props.project}
2322
wallets={props.wallets}
2423
/>
2524
);
2625
}
2726

2827
async function getTransactions({
29-
teamId,
30-
clientId,
28+
project,
29+
page,
3130
}: {
32-
teamId: string;
33-
clientId: string;
31+
project: Project;
3432
page: number;
3533
}) {
3634
const transactions = await engineCloudProxy<{ result: TransactionsResponse }>(
@@ -39,10 +37,13 @@ async function getTransactions({
3937
method: "POST",
4038
headers: {
4139
"Content-Type": "application/json",
42-
"x-team-id": teamId,
43-
"x-client-id": clientId,
40+
"x-team-id": project.teamId,
41+
"x-client-id": project.publishableKey,
4442
},
45-
body: JSON.stringify({}),
43+
body: JSON.stringify({
44+
page,
45+
limit: 20,
46+
}),
4647
},
4748
);
4849

0 commit comments

Comments
 (0)