Skip to content

Commit 6abac56

Browse files
committed
Merge remote-tracking branch 'origin/hackweek-wallet-explainer' into hackweek-wallet-explainer
2 parents 9533832 + 67dd7e3 commit 6abac56

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export async function fetchERC20Tokens(args: {
7575
lastTransferredDate:
7676
token.queried_wallet_balances[0]?.last_transferred_date,
7777
}));
78-
const fungibleTokens = data.fungibles.map((token) => ({
78+
let fungibleTokens = data.fungibles.map((token) => ({
7979
name: token.name,
8080
symbol: token.symbol,
8181
contractAddress: token.fungible_id.split(".")[1] ?? "--",
@@ -90,6 +90,7 @@ export async function fetchERC20Tokens(args: {
9090
lastTransferredDate:
9191
token.queried_wallet_balances[0]?.last_transferred_date,
9292
}));
93+
fungibleTokens = fungibleTokens.filter(d => d.name != null || d.symbol != null);
9394
return [...nativeTokens, ...fungibleTokens];
9495
} catch (error) {
9596
console.error("Error fetching tokens:", error);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,8 @@ export async function fetchRecentTransactions(args: {
8686
return [...outgoingTxsData.data, ...incomingTxsData.data].sort(
8787
(a, b) => b.block_number - a.block_number,
8888
);
89+
} catch (err) {
90+
console.log("Failed to fetch tx activity", err);
91+
return [];
92+
}
8993
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
TableRow,
1212
} from "@/components/ui/table";
1313
import { TabButtons } from "@/components/ui/tabs";
14-
import { formatDistanceToNow } from "date-fns";
1514
import { ArrowLeft, ArrowRight, WalletIcon } from "lucide-react";
1615
import { useState } from "react";
1716
import type { ChainMetadata } from "thirdweb/chains";
@@ -68,12 +67,12 @@ export function ActivityOverview({
6867
isEnabled: true,
6968
onClick: () => setActiveTab("transactions"),
7069
},
71-
{
72-
name: "Contracts",
73-
isActive: activeTab === "contracts",
74-
isEnabled: true,
75-
onClick: () => setActiveTab("contracts"),
76-
},
70+
// {
71+
// name: "Contracts",
72+
// isActive: activeTab === "contracts",
73+
// isEnabled: true,
74+
// onClick: () => setActiveTab("contracts"),
75+
// },
7776
]}
7877
tabClassName="font-medium !text-sm"
7978
/>
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 as getRecentTransactions } from "../actions/fetchTxActivity";
3+
import { toEther } from "thirdweb/utils";
4+
5+
export interface TransactionDetails {
6+
id: string;
7+
type: "in" | "out";
8+
value: string;
9+
to?: string;
10+
from?: string;
11+
method?: string;
12+
date: string;
13+
}
14+
15+
export function useGetRecentTransactions(chainId: number, address: string) {
16+
const [txActivity, setTxActivity] = useState<TransactionDetails[]>([]);
17+
const [isLoading, setIsLoading] = useState(true);
18+
19+
useEffect(() => {
20+
(async () => {
21+
const response = await getRecentTransactions({ chainId, address });
22+
const activity = response.map((tx): TransactionDetails => {
23+
const type =
24+
tx.to_address?.toLowerCase() === address.toLowerCase() ? "in" : "out";
25+
return {
26+
id: tx.hash,
27+
type,
28+
value: toEther(BigInt(tx.value)).toString(),
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)