Skip to content

Commit 3f08e8d

Browse files
committed
feat: add incoming txs
1 parent 6b78ad6 commit 3f08e8d

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,37 @@ interface InsightsResponse {
4848
export async function fetchTxActivity(args: {
4949
chainId: number;
5050
address: string;
51-
limit?: number,
51+
limit_per_type?: number,
5252
page?: number;
53-
}): Promise<InsightsResponse> {
54-
let { chainId, address, limit, page } = args;
55-
if (!limit) limit = 100;
53+
}): Promise<Transaction[]> {
54+
let { chainId, address, limit_per_type, page } = args;
55+
if (!limit_per_type) limit_per_type = 100;
5656
if (!page) page = 0;
5757

58-
const response = await fetch(
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`,
58+
const outgoingTxsResponse = await fetch(
59+
`https://insight.thirdweb-dev.com/v1/transactions?chain=${chainId}&filter_from_address=${address}&page=${page}&limit=${limit_per_type}&sort_by=block_number&sort_order=desc`,
6060
{
6161
headers: {
6262
"x-client-id": DASHBOARD_THIRDWEB_CLIENT_ID,
6363
},
6464
},
6565
);
6666

67-
if (!response.ok) {
67+
const incomingTxsResponse = await fetch(
68+
`https://insight.thirdweb-dev.com/v1/transactions?chain=${chainId}&filter_to_address=${address}&page=${page}&limit=${limit_per_type}&sort_by=block_number&sort_order=desc`,
69+
{
70+
headers: {
71+
"x-client-id": DASHBOARD_THIRDWEB_CLIENT_ID,
72+
},
73+
},
74+
);
75+
76+
if (!outgoingTxsResponse.ok || !incomingTxsResponse.ok) {
6877
throw new Error('Failed to fetch transaction history');
6978
}
7079

71-
const data: InsightsResponse = await response.json();
72-
return data;
80+
const outgoingTxsData: InsightsResponse = await outgoingTxsResponse.json();
81+
const incomingTxsData: InsightsResponse = await incomingTxsResponse.json();
82+
83+
return [...outgoingTxsData.data, ...incomingTxsData.data].sort((a, b) => b.block_number - a.block_number);
7384
}

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: "out" | "in";
1818
amount: string;
1919
to?: string;
2020
from?: string;
@@ -84,7 +84,7 @@ export function ActivityOverview({
8484
<Table>
8585
<TableHeader>
8686
<TableRow>
87-
{/* <TableHead>Type</TableHead> */}
87+
<TableHead>Type</TableHead>
8888
<TableHead>Amount</TableHead>
8989
<TableHead>Details</TableHead>
9090
<TableHead>Date</TableHead>
@@ -93,7 +93,7 @@ export function ActivityOverview({
9393
<TableBody>
9494
{currentTransactions.map((tx) => (
9595
<TableRow key={tx.id}>
96-
{/* <TableCell>{tx.type}</TableCell> */}
96+
<TableCell>{tx.type}</TableCell>
9797
<TableCell>{tx.amount}</TableCell>
9898
<TableCell>
9999
{tx.to && `To: ${tx.to} `}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface TxActivityItem {
55
id: string;
66
// all txs we retrieve for now are outgoing
77
// TODO: add incoming
8-
// type: string;
8+
type: "out" | "in";
99
amount: string;
1010
to?: string;
1111
from?: string;
@@ -20,11 +20,11 @@ export function useGetTxActivity(chainId: number, address: string) {
2020
useEffect(() => {
2121
(async () => {
2222
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";
23+
const activity = response.map((tx): TxActivityItem => {
24+
let type = tx.to_address?.toLowerCase() === address.toLowerCase() ? "in" : "out";
2525
return {
2626
id: tx.hash,
27-
// type,
27+
type,
2828
amount: `${tx.value / Math.pow(10, 18)} ETH`,
2929
to: tx.to_address || undefined,
3030
from: tx.from_address,

0 commit comments

Comments
 (0)