Skip to content

Commit 9055e7c

Browse files
committed
fix: use server for Insight calls
1 parent 6abac56 commit 9055e7c

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/actions/fetchRecentTransactions.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
"use server";
12
import assert from "node:assert";
2-
import { DASHBOARD_THIRDWEB_CLIENT_ID } from "@/constants/env";
33

44
interface Transaction {
55
chain_id: number;
@@ -54,26 +54,33 @@ export async function fetchRecentTransactions(args: {
5454
}): Promise<Transaction[]> {
5555
// const { NEXT_PUBLIC_INSIGHT_URL } = process.env;
5656
const NEXT_PUBLIC_INSIGHT_URL = "https://insight.thirdweb-dev.com";
57-
console.log("[DEBUG] NEXT_PUBLIC_INSIGHT_URL:", NEXT_PUBLIC_INSIGHT_URL);
5857
assert(NEXT_PUBLIC_INSIGHT_URL, "NEXT_PUBLIC_INSIGHT_URL is not set");
5958

59+
const { DASHBOARD_SECRET_KEY } = process.env;
60+
assert(DASHBOARD_SECRET_KEY, "DASHBOARD_SECRET_KEY is not set");
61+
6062
const { chainId, address, limit_per_type = 100, page = 0 } = args;
6163

6264
const [outgoingTransactionsResponse, incomingTransactionsResponse] =
6365
await Promise.all([
6466
fetch(
6567
`${NEXT_PUBLIC_INSIGHT_URL}/v1/transactions?chain=${chainId}&filter_from_address=${address}&page=${page}&limit=${limit_per_type}&sort_by=block_number&sort_order=desc`,
6668
{
67-
headers: { "x-client-id": DASHBOARD_THIRDWEB_CLIENT_ID },
69+
headers: {
70+
"x-secret-key": DASHBOARD_SECRET_KEY,
71+
},
6872
},
6973
),
7074
fetch(
7175
`${NEXT_PUBLIC_INSIGHT_URL}/v1/transactions?chain=${chainId}&filter_to_address=${address}&page=${page}&limit=${limit_per_type}&sort_by=block_number&sort_order=desc`,
7276
{
73-
headers: { "x-client-id": DASHBOARD_THIRDWEB_CLIENT_ID },
77+
headers: {
78+
"x-secret-key": DASHBOARD_SECRET_KEY,
79+
},
7480
},
7581
),
7682
]);
83+
7784
if (!outgoingTransactionsResponse.ok || !incomingTransactionsResponse.ok) {
7885
throw new Error("Failed to fetch transaction history");
7986
}
@@ -83,11 +90,10 @@ export async function fetchRecentTransactions(args: {
8390
const incomingTxsData: InsightsResponse =
8491
await incomingTransactionsResponse.json();
8592

93+
console.log("outgoingTxsData", JSON.stringify(outgoingTxsData, null, 2));
94+
console.log("incomingTxsData", JSON.stringify(incomingTxsData, null, 2));
95+
8696
return [...outgoingTxsData.data, ...incomingTxsData.data].sort(
8797
(a, b) => b.block_number - a.block_number,
8898
);
89-
} catch (err) {
90-
console.log("Failed to fetch tx activity", err);
91-
return [];
92-
}
9399
}

apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/components/ActivityOverview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useState } from "react";
1616
import type { ChainMetadata } from "thirdweb/chains";
1717
import { shortenHex } from "thirdweb/utils";
1818
import type { TransactionDetails } from "../hooks/useGetRecentTransactions";
19+
import { formatDistanceToNow } from "date-fns";
1920

2021
interface Contract {
2122
address: string;

apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/components/WalletDashboard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function WalletDashboard(props: {
2525

2626
return (
2727
<div className="grid gap-6">
28-
{!isLoadingERC20 && !isLoadingNFTs && (
28+
{/* {!isLoadingERC20 && !isLoadingNFTs && (
2929
<NebulaInterface
3030
chain={props.chain}
3131
address={props.address}
@@ -34,7 +34,7 @@ export function WalletDashboard(props: {
3434
tokens={tokens}
3535
nfts={nfts}
3636
/>
37-
)}
37+
)} */}
3838

3939
<ActivityOverview
4040
chain={props.chain}

apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/hooks/useGetTxActivity.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function useGetRecentTransactions(chainId: number, address: string) {
2828
value: toEther(BigInt(tx.value)).toString(),
2929
to: tx.to_address || undefined,
3030
from: tx.from_address,
31+
// TODO: fix method retrieval
3132
method: tx.function_selector || undefined,
3233
date: new Date(tx.block_timestamp * 1000).toLocaleString(),
3334
};

0 commit comments

Comments
 (0)