-
Notifications
You must be signed in to change notification settings - Fork 618
[MNY-304] Move engine tx summary request to client side to fix page crash #8379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
112 changes: 81 additions & 31 deletions
112
...(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/analytics/analytics-page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,95 @@ | ||
| import { ResponsiveSearchParamsProvider } from "responsive-rsc"; | ||
| "use client"; | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import { Spinner } from "@workspace/ui/components/spinner"; | ||
| import type { ThirdwebClient } from "thirdweb"; | ||
| import type { Project } from "@/api/project/projects"; | ||
| import { UnifiedTransactionsTable } from "../components/transactions-table.client"; | ||
| import { getTransactionAnalyticsSummary } from "../lib/analytics-summary.client"; | ||
| import type { Wallet } from "../server-wallets/wallet-table/types"; | ||
| import { TransactionAnalyticsFilter } from "./filter"; | ||
| import { TransactionsChartCard } from "./tx-chart/tx-chart"; | ||
| import type { SolanaWallet } from "../solana-wallets/wallet-table/types"; | ||
| import { EngineChecklist } from "./ftux.client"; | ||
| import { TransactionAnalyticsSummary } from "./summary"; | ||
| import { TransactionsAnalytics } from "./tx-chart/tx-chart"; | ||
|
|
||
| export function TransactionsAnalyticsPageContent(props: { | ||
| searchParams: { | ||
| from?: string | undefined | string[]; | ||
| to?: string | undefined | string[]; | ||
| interval?: string | undefined | string[]; | ||
| }; | ||
| project: Project; | ||
| showAnalytics: boolean; | ||
| wallets?: Wallet[]; | ||
| wallets: Wallet[]; | ||
| teamSlug: string; | ||
| client: ThirdwebClient; | ||
| authToken: string; | ||
| teamId: string; | ||
| isManagedVault: boolean; | ||
| testTxWithWallet: string | undefined; | ||
| testSolanaTxWithWallet: string | undefined; | ||
| solanaWallets: SolanaWallet[]; | ||
| }) { | ||
| return ( | ||
| <ResponsiveSearchParamsProvider value={props.searchParams}> | ||
| <div className="flex grow flex-col gap-6"> | ||
| {props.showAnalytics && ( | ||
| <> | ||
| <div className="flex justify-end"> | ||
| <TransactionAnalyticsFilter /> | ||
| </div> | ||
| <TransactionsChartCard | ||
| project={props.project} | ||
| searchParams={props.searchParams} | ||
| teamSlug={props.teamSlug} | ||
| wallets={props.wallets ?? []} | ||
| /> | ||
| </> | ||
| )} | ||
| <UnifiedTransactionsTable | ||
| client={props.client} | ||
| project={props.project} | ||
| teamSlug={props.teamSlug} | ||
| /> | ||
| const engineTxSummaryQuery = useQuery({ | ||
| queryKey: [ | ||
| "engine-tx-analytics-summary", | ||
| props.teamId, | ||
| props.project.publishableKey, | ||
| props.authToken, | ||
| ], | ||
| queryFn: async () => { | ||
| const data = await getTransactionAnalyticsSummary({ | ||
| clientId: props.project.publishableKey, | ||
| teamId: props.teamId, | ||
| authToken: props.authToken, | ||
| }); | ||
| return data; | ||
| }, | ||
| refetchOnWindowFocus: false, | ||
| refetchOnMount: false, | ||
| }); | ||
|
|
||
| if (engineTxSummaryQuery.isPending) { | ||
| return ( | ||
| <div className="flex h-[642px] grow items-center justify-center bg-card rounded-xl border"> | ||
| <Spinner className="size-10" /> | ||
| </div> | ||
| </ResponsiveSearchParamsProvider> | ||
| ); | ||
| } | ||
|
|
||
| const hasTransactions = engineTxSummaryQuery.data | ||
| ? engineTxSummaryQuery.data.totalCount > 0 | ||
| : false; | ||
|
|
||
| return ( | ||
| <div className="flex grow flex-col gap-10"> | ||
| <EngineChecklist | ||
| isManagedVault={props.isManagedVault} | ||
| client={props.client} | ||
| hasTransactions={hasTransactions} | ||
| project={props.project} | ||
| teamSlug={props.teamSlug} | ||
| testTxWithWallet={props.testTxWithWallet} | ||
| testSolanaTxWithWallet={props.testSolanaTxWithWallet} | ||
| wallets={props.wallets} | ||
| solanaWallets={props.solanaWallets} | ||
| /> | ||
|
|
||
| {props.showAnalytics && hasTransactions && ( | ||
| <div className="flex flex-col gap-6"> | ||
| <TransactionAnalyticsSummary | ||
| clientId={props.project.publishableKey} | ||
| teamId={props.project.teamId} | ||
| initialData={engineTxSummaryQuery.data} | ||
| /> | ||
| <TransactionsAnalytics | ||
| project={props.project} | ||
| authToken={props.authToken} | ||
| teamSlug={props.teamSlug} | ||
| wallets={props.wallets ?? []} | ||
| /> | ||
| </div> | ||
| )} | ||
|
|
||
| <UnifiedTransactionsTable | ||
| client={props.client} | ||
| project={props.project} | ||
| teamSlug={props.teamSlug} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
51 changes: 0 additions & 51 deletions
51
...src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/analytics/filter.tsx
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...rc/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/analytics/summary.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...p/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/analytics/tx-chart/data.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| "use client"; | ||
| import { NEXT_PUBLIC_ENGINE_CLOUD_URL } from "@/constants/public-envs"; | ||
| import type { TransactionStats } from "@/types/analytics"; | ||
|
|
||
| export async function getTransactionsChartData({ | ||
| teamId, | ||
| clientId, | ||
| from, | ||
| to, | ||
| interval, | ||
| authToken, | ||
| }: { | ||
| teamId: string; | ||
| clientId: string; | ||
| from: string; | ||
| to: string; | ||
| interval: "day" | "week"; | ||
| authToken: string; | ||
| }): Promise<TransactionStats[]> { | ||
| const filters = { | ||
| endDate: to, | ||
| resolution: interval, | ||
| startDate: from, | ||
| }; | ||
|
|
||
| const response = await fetch( | ||
| `${NEXT_PUBLIC_ENGINE_CLOUD_URL}/v1/transactions/analytics`, | ||
| { | ||
| body: JSON.stringify(filters), | ||
| headers: { | ||
| Authorization: `Bearer ${authToken}`, | ||
| "Content-Type": "application/json", | ||
| "x-client-id": clientId, | ||
| "x-team-id": teamId, | ||
| }, | ||
| method: "POST", | ||
| }, | ||
| ); | ||
|
|
||
| if (!response.ok) { | ||
| if (response.status === 401 || response.status === 400) { | ||
| return []; | ||
| } | ||
|
|
||
| // TODO - need to handle this error state, like we do with the connect charts | ||
| throw new Error( | ||
| `Error fetching transactions chart data: ${response.status} ${ | ||
| response.statusText | ||
| } - ${await response.text().catch(() => "Unknown error")}`, | ||
| ); | ||
| } | ||
|
|
||
| type TransactionsChartResponse = { | ||
| result: { | ||
| analytics: Array<{ | ||
| timeBucket: string; | ||
| chainId: string; | ||
| count: number; | ||
| }>; | ||
| metadata: { | ||
| resolution: string; | ||
| startDate: string; | ||
| endDate: string; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| const data = (await response.json()) as TransactionsChartResponse; | ||
|
|
||
| return data.result.analytics.map((stat) => ({ | ||
| chainId: Number(stat.chainId), | ||
| count: stat.count, | ||
| date: stat.timeBucket, | ||
| })); | ||
| } | ||
MananTank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Remove
authTokenfrom the query key and addstaleTime.The queryKey currently includes
authToken(a secret), which should never be part of the cache key. Only use non-secret identifiers liketeamIdandpublishableKey. Additionally, addstaleTime: 60_000(≥ 60s) per coding guidelines. Based on learnings.Apply this diff:
const engineTxSummaryQuery = useQuery({ queryKey: [ "engine-tx-analytics-summary", props.teamId, props.project.publishableKey, - props.authToken, ], + staleTime: 60_000, queryFn: async () => { const data = await getTransactionAnalyticsSummary({ clientId: props.project.publishableKey, teamId: props.teamId, authToken: props.authToken, }); return data; }, refetchOnWindowFocus: false, refetchOnMount: false, });🤖 Prompt for AI Agents