Skip to content

Commit 8a8fa70

Browse files
committed
Merge remote-tracking branch 'origin/hackweek-wallet-explainer' into hackweek-wallet-explainer
2 parents b1a54f4 + ca7186e commit 8a8fa70

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

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

Lines changed: 11 additions & 4 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
}

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
@@ -17,6 +17,7 @@ import { useState } from "react";
1717
import type { ChainMetadata } from "thirdweb/chains";
1818
import { shortenHex } from "thirdweb/utils";
1919
import type { TransactionDetails } from "../hooks/useGetRecentTransactions";
20+
import { formatDistanceToNow } from "date-fns";
2021

2122
interface Contract {
2223
address: string;

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ export function TokenHoldings({
3030
isLoading,
3131
}: TokenHoldingsProps) {
3232
const [activeTab, setActiveTab] = useState<"erc20" | "nft">("erc20");
33+
const [currentPage, setCurrentPage] = useState(1);
34+
const itemsPerPage = 5; // Set items per page
35+
36+
// Calculate the index of the last token on the current page
37+
const lastIndex = currentPage * itemsPerPage;
38+
// Calculate the index of the first token on the current page
39+
const firstIndex = lastIndex - itemsPerPage;
40+
// Get the current tokens to display
41+
const currentTokens = tokens.slice(firstIndex, lastIndex);
42+
// Calculate total pages
43+
const totalPages = Math.ceil(tokens.length / itemsPerPage);
3344

3445
return (
3546
<Card>
@@ -58,7 +69,35 @@ export function TokenHoldings({
5869
{isLoading ? (
5970
<Spinner />
6071
) : activeTab === "erc20" ? (
61-
<ERC20Table chain={chain} tokens={tokens} isLoading={isLoading} />
72+
<>
73+
<ERC20Table chain={chain} tokens={currentTokens} isLoading={isLoading} />
74+
{/* Pagination Controls */}
75+
<div className="pagination">
76+
<TabButtons
77+
tabs={[
78+
{
79+
name: "Previous",
80+
isActive: currentPage === 1,
81+
isEnabled: currentPage > 1,
82+
onClick: () => setCurrentPage((prev) => Math.max(prev - 1, 1)),
83+
},
84+
{
85+
name: `Page ${currentPage} of ${totalPages}`,
86+
isActive: true,
87+
isEnabled: false,
88+
onClick: () => {}, // No action needed
89+
},
90+
{
91+
name: "Next",
92+
isActive: currentPage === totalPages,
93+
isEnabled: currentPage < totalPages,
94+
onClick: () => setCurrentPage((prev) => Math.min(prev + 1, totalPages)),
95+
},
96+
]}
97+
tabClassName="font-medium !text-sm"
98+
/>
99+
</div>
100+
</>
62101
) : activeTab === "nft" ? (
63102
<div className="mt-4 grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4">
64103
{nfts.map((nft, idx) => (

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)