-
Notifications
You must be signed in to change notification settings - Fork 619
wallet txns activity #6090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
catalyst17
merged 5 commits into
hackweek-wallet-explainer
from
vt-hackweek-wallet-analysis-activity
Jan 29, 2025
Merged
wallet txns activity #6090
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b17c331
wip: use insights to fetch wallet activity
724c7e7
feat: fetch outgoing transactions
catalyst17 6b78ad6
feat: pages for activity
catalyst17 3f08e8d
feat: add incoming txs
catalyst17 f9822c0
refactor: linting and formatting
catalyst17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/actions/fetchTxActivity.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { DASHBOARD_THIRDWEB_CLIENT_ID } from "@/constants/env"; | ||
|
|
||
| export interface Transaction { | ||
| chain_id: number; | ||
| hash: string; | ||
| nonce: number; | ||
| block_hash: string; | ||
| block_number: number; | ||
| block_timestamp: number; | ||
| transaction_index: number; | ||
| from_address: string; | ||
| to_address: string | null; | ||
| value: number; | ||
| gas: number; | ||
| gas_price: number | null; | ||
| data: string | null; | ||
| function_selector: string | null; | ||
| max_fee_per_gas: number | null; | ||
| max_priority_fee_per_gas: number | null; | ||
| transaction_type: number | null; | ||
| r: string | null; | ||
| s: string | null; | ||
| v: number | null; | ||
| access_list_json: string | null; | ||
| contract_address: string | null; | ||
| gas_used: number | null; | ||
| cumulative_gas_used: number | null; | ||
| effective_gas_price: number | null; | ||
| blob_gas_used: number | null; | ||
| blob_gas_price: number | null; | ||
| logs_bloom: string | null; | ||
| status: boolean | null; // true for success, false for failure | ||
| } | ||
|
|
||
| interface InsightsResponse { | ||
| meta: { | ||
| address: string; | ||
| signature: string; | ||
| page: number; | ||
| total_items: number; | ||
| total_pages: number; | ||
| limit_per_chain: number; | ||
| chain_ids: number[]; | ||
| }; | ||
| data: Transaction[]; | ||
| } | ||
|
|
||
| export async function fetchTxActivity(args: { | ||
| chainId: number; | ||
| address: string; | ||
| limit_per_type?: number, | ||
| page?: number; | ||
| }): Promise<Transaction[]> { | ||
| let { chainId, address, limit_per_type, page } = args; | ||
| if (!limit_per_type) limit_per_type = 100; | ||
| if (!page) page = 0; | ||
|
|
||
| const outgoingTxsResponse = await fetch( | ||
| `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`, | ||
| { | ||
| headers: { | ||
| "x-client-id": DASHBOARD_THIRDWEB_CLIENT_ID, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| const incomingTxsResponse = await fetch( | ||
| `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`, | ||
| { | ||
| headers: { | ||
| "x-client-id": DASHBOARD_THIRDWEB_CLIENT_ID, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| if (!outgoingTxsResponse.ok || !incomingTxsResponse.ok) { | ||
| throw new Error('Failed to fetch transaction history'); | ||
| } | ||
|
|
||
| const outgoingTxsData: InsightsResponse = await outgoingTxsResponse.json(); | ||
catalyst17 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const incomingTxsData: InsightsResponse = await incomingTxsResponse.json(); | ||
|
|
||
| return [...outgoingTxsData.data, ...incomingTxsData.data].sort((a, b) => b.block_number - a.block_number); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/hooks/useGetTxActivity.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { fetchTxActivity } from "../actions/fetchTxActivity"; | ||
|
|
||
| interface TxActivityItem { | ||
| id: string; | ||
| // all txs we retrieve for now are outgoing | ||
| // TODO: add incoming | ||
| type: "out" | "in"; | ||
| amount: string; | ||
| to?: string; | ||
| from?: string; | ||
| method?: string; | ||
| date: string; | ||
| } | ||
|
|
||
| export function useGetTxActivity(chainId: number, address: string) { | ||
| const [txActivity, setTxActivity] = useState<TxActivityItem[]>([]); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
|
|
||
| useEffect(() => { | ||
| (async () => { | ||
| const response = await fetchTxActivity({ chainId, address }); | ||
| const activity = response.map((tx): TxActivityItem => { | ||
| let type = tx.to_address?.toLowerCase() === address.toLowerCase() ? "in" : "out"; | ||
| return { | ||
| id: tx.hash, | ||
| type, | ||
| amount: `${tx.value / Math.pow(10, 18)} ETH`, | ||
catalyst17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| to: tx.to_address || undefined, | ||
| from: tx.from_address, | ||
| method: tx.function_selector || undefined, | ||
| date: new Date(tx.block_timestamp * 1000).toLocaleString(), | ||
| }; | ||
| }) | ||
| setTxActivity(activity); | ||
| setIsLoading(false); | ||
| })(); | ||
| }, [address, chainId]); | ||
|
|
||
| return { txActivity, isLoading }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.