|
1 | 1 | import { useEffect, useState } from "react"; |
2 | | -import { fetchTxActivity } from "../actions/fetchTxActivity"; |
| 2 | +import { fetchTxActivity as getRecentTransactions } from "../actions/fetchTxActivity"; |
3 | 3 |
|
4 | | -interface TxActivityItem { |
| 4 | +export interface TransactionDetails { |
5 | 5 | id: string; |
6 | | - // all txs we retrieve for now are outgoing |
7 | | - // TODO: add incoming |
8 | 6 | type: "out" | "in"; |
9 | | - amount: string; |
| 7 | + value: bigint; |
10 | 8 | to?: string; |
11 | 9 | from?: string; |
12 | 10 | method?: string; |
13 | 11 | date: string; |
14 | 12 | } |
15 | 13 |
|
16 | | -export function useGetTxActivity(chainId: number, address: string) { |
17 | | - const [txActivity, setTxActivity] = useState<TxActivityItem[]>([]); |
| 14 | +export function useGetRecentTransactions(chainId: number, address: string) { |
| 15 | + const [txActivity, setTxActivity] = useState<TransactionDetails[]>([]); |
18 | 16 | const [isLoading, setIsLoading] = useState(true); |
19 | 17 |
|
20 | 18 | useEffect(() => { |
21 | 19 | (async () => { |
22 | | - const response = await fetchTxActivity({ chainId, address }); |
23 | | - const activity = response.map((tx): TxActivityItem => { |
| 20 | + const response = await getRecentTransactions({ chainId, address }); |
| 21 | + const activity = response.map((tx): TransactionDetails => { |
24 | 22 | const type = |
25 | 23 | tx.to_address?.toLowerCase() === address.toLowerCase() ? "in" : "out"; |
26 | 24 | return { |
27 | 25 | id: tx.hash, |
28 | 26 | type, |
29 | | - amount: `${tx.value / 10 ** 18} ETH`, |
| 27 | + value: BigInt(tx.value), |
30 | 28 | to: tx.to_address || undefined, |
31 | 29 | from: tx.from_address, |
32 | 30 | method: tx.function_selector || undefined, |
|
0 commit comments