Skip to content

Commit 724c7e7

Browse files
committed
feat: fetch outgoing transactions
1 parent b17c331 commit 724c7e7

File tree

5 files changed

+70
-69
lines changed

5 files changed

+70
-69
lines changed

apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/actions/fetchActivity.ts renamed to apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/actions/fetchTxActivity.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,36 @@ export interface Transaction {
3333
}
3434

3535
interface InsightsResponse {
36-
meta: {
37-
address: string;
38-
signature: string;
39-
page: number;
40-
total_items: number;
41-
total_pages: number;
42-
limit_per_chain: number;
43-
chain_ids: number[];
44-
};
45-
data: Transaction[];
36+
meta: {
37+
address: string;
38+
signature: string;
39+
page: number;
40+
total_items: number;
41+
total_pages: number;
42+
limit_per_chain: number;
43+
chain_ids: number[];
44+
};
45+
data: Transaction[];
4646
}
4747

48-
export async function fetchActivity(args: {
48+
export async function fetchTxActivity(args: {
4949
chainId: number;
5050
address: string;
51-
page?: string;
51+
limit?: number,
52+
page?: number;
5253
}): Promise<InsightsResponse> {
53-
const { chainId, address, page } = args;
54+
let { chainId, address, limit, page } = args;
55+
if (!limit) limit = 100;
56+
if (!page) page = 0;
5457

5558
const response = await fetch(
56-
`https://insight.thirdweb.com/v1/transactions?chain=${chainId}&filter_from_address=${address}&page=${page}&limit=10&sort_by=block_number&sort_order=desc`,
57-
{
58-
headers: {
59-
"x-client-id": DASHBOARD_THIRDWEB_CLIENT_ID,
60-
},
61-
},
62-
);
59+
`https://insight.thirdweb-dev.com/v1/transactions?chain=${chainId}&filter_from_address=${address}&page=${page}&limit=${limit}&sort_by=block_number&sort_order=desc`,
60+
{
61+
headers: {
62+
"x-client-id": DASHBOARD_THIRDWEB_CLIENT_ID,
63+
},
64+
},
65+
);
6366

6467
if (!response.ok) {
6568
throw new Error('Failed to fetch transaction history');

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useState } from "react";
1414

1515
interface Transaction {
1616
id: string;
17-
type: string;
17+
// type: string;
1818
amount: string;
1919
to?: string;
2020
from?: string;
@@ -74,7 +74,7 @@ export function ActivityOverview({
7474
<Table>
7575
<TableHeader>
7676
<TableRow>
77-
<TableHead>Type</TableHead>
77+
{/* <TableHead>Type</TableHead> */}
7878
<TableHead>Amount</TableHead>
7979
<TableHead>Details</TableHead>
8080
<TableHead>Date</TableHead>
@@ -83,7 +83,7 @@ export function ActivityOverview({
8383
<TableBody>
8484
{transactions.map((tx) => (
8585
<TableRow key={tx.id}>
86-
<TableCell>{tx.type}</TableCell>
86+
{/* <TableCell>{tx.type}</TableCell> */}
8787
<TableCell>{tx.amount}</TableCell>
8888
<TableCell>
8989
{tx.to && `To: ${tx.to} `}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22
import type { ChainMetadata } from "thirdweb/chains";
33
import { useBalance } from "../hooks/getBalance";
4-
import { useGetActivity } from "../hooks/useGetActivity";
4+
import { useGetTxActivity } from "../hooks/useGetTxActivity";
55
import { useGetERC20Tokens } from "../hooks/useGetERC20Tokens";
66
import { useGetNFTs } from "../hooks/useGetNFTs";
77
import { mockWalletData } from "../utils/mockData";
@@ -38,7 +38,7 @@ export function WalletDashboard(props: {
3838
// console.error("Error fetching NFTs:", errorNFTs);
3939
// }
4040

41-
const { activity, isLoading: isLoadingActivity } = useGetActivity(props.chain.chainId, props.address)
41+
const { txActivity, isLoading: isLoadingActivity } = useGetTxActivity(props.chain.chainId, props.address)
4242

4343
return (
4444
<div className="grid gap-6">
@@ -48,7 +48,7 @@ export function WalletDashboard(props: {
4848
isLoading={isLoadingBalance}
4949
/>
5050
<ActivityOverview
51-
transactions={activity}
51+
transactions={txActivity}
5252
isLoading={isLoadingActivity}
5353
contracts={mockWalletData.contracts}
5454
/>

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

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { useEffect, useState } from "react";
2+
import { fetchTxActivity } from "../actions/fetchTxActivity";
3+
4+
interface TxActivityItem {
5+
id: string;
6+
// all txs we retrieve for now are outgoing
7+
// TODO: add incoming
8+
// type: string;
9+
amount: string;
10+
to?: string;
11+
from?: string;
12+
method?: string;
13+
date: string;
14+
}
15+
16+
export function useGetTxActivity(chainId: number, address: string) {
17+
const [txActivity, setTxActivity] = useState<TxActivityItem[]>([]);
18+
const [isLoading, setIsLoading] = useState(true);
19+
20+
useEffect(() => {
21+
(async () => {
22+
const response = await fetchTxActivity({ chainId, address });
23+
const activity = response.data.map((tx): TxActivityItem => {
24+
// let type = tx.to_address?.toLowerCase() === address.toLowerCase() ? "Receive" : "Send";
25+
return {
26+
id: tx.hash,
27+
// type,
28+
amount: `${tx.value / Math.pow(10, 18)} ETH`,
29+
to: tx.to_address || undefined,
30+
from: tx.from_address,
31+
method: tx.function_selector || undefined,
32+
date: new Date(tx.block_timestamp * 1000).toLocaleString(),
33+
};
34+
})
35+
setTxActivity(activity);
36+
setIsLoading(false);
37+
})();
38+
}, [address, chainId]);
39+
40+
return { txActivity, isLoading };
41+
}

0 commit comments

Comments
 (0)