-
Notifications
You must be signed in to change notification settings - Fork 0
[Explorer]: Shinzohub Transactions and Transaction details #231
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
95ab833
ce3a61d
c8f29bd
0ae80dc
4f11d98
51b6eb5
de8143b
30d1444
b5d5985
02d5f05
384fc50
15b3eac
f64d465
547cf18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export { HomePage as default } from '@/pages/shinzohub/home'; | ||
| export { HomePage as default } from '@/pages/shinzohub-home'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { TransactionDetailPage as default } from '@/pages/transaction-details'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { TransactionsPage as default } from '@/pages/transactions'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,7 @@ export function useHomeBlocks({ count = 5 }: UseHomeBlocksOptions = {}) { | |
| return () => { | ||
| unwatch() | ||
| } | ||
| }, [count]) | ||
| }, [count, publicClient]) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint warning fix |
||
|
|
||
| return { blocks, isLoading, error } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| 'use client'; | ||
|
|
||
| import { useMemo } from 'react'; | ||
| import { useShinzohubTransactionIndex } from '../../hook/use-shinzohub-transaction-index'; | ||
| import { useShinzohubTransactionsSync } from '@/pages/transactions/hooks/shinzohub/use-shinzohub-transactions-sync'; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing hook is renamed for clarity |
||
|
|
||
| export type TransactionSummary = { | ||
| hash: `0x${string}`; | ||
|
|
@@ -18,7 +18,7 @@ type UseHomeTransactionsOptions = { | |
| export function useHomeTransactions( | ||
| { count, refetchIntervalMs = 10_000 }: UseHomeTransactionsOptions = {}, | ||
| ) { | ||
| const indexQuery = useShinzohubTransactionIndex({ refetchIntervalMs }); | ||
| const indexQuery = useShinzohubTransactionsSync({ refetchIntervalMs }); | ||
|
|
||
| const transactions = useMemo<TransactionSummary[]>(() => { | ||
| const indexed = indexQuery.data?.transactions ?? []; | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| 'use client'; | ||
|
|
||
| import { execute, graphql } from '@/shared/graphql'; | ||
| import { useChainPathSegment } from '@/widgets/chain-path-segment'; | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { useEthereumTransaction } from './use-ethereum-transaction'; | ||
|
|
||
| const TransactionLogsQuery = graphql(` | ||
| query TransactionLogs($hash: String) { | ||
|
|
@@ -24,10 +26,13 @@ interface UseTransactionLogsOptions { | |
| enabled?: boolean; | ||
| } | ||
|
|
||
| export const useTransactionLogs = ({ hash, enabled = true }: UseTransactionLogsOptions) => { | ||
| export const useTransactionLogs = ({ hash }: UseTransactionLogsOptions) => { | ||
| const {data: tx} = useEthereumTransaction({ hash }); | ||
| const chain = useChainPathSegment(); | ||
|
|
||
| return useQuery({ | ||
| queryKey: ['transaction-logs', hash], | ||
| enabled: !!hash && enabled, | ||
| queryKey: ['ethereum', 'transaction-logs', hash], | ||
| enabled: chain === 'ethereum' && !!hash && !!tx, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to make sure the api fetch call happens only for ethereum not shinzohub.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why could it possibly be called on shinzohub-related pages? Do you have this hook usages running globally? I imagine that ethereum-related hooks shouldn't even be called on shinzohub pages
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: refactor it in a way that the hook doesn't depend on useChainPathSegment hook. It should only be called in the pages where it is actually needed |
||
| staleTime: Infinity, | ||
| queryFn: async () => { | ||
| const res = await execute(TransactionLogsQuery, { hash }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { getPublicClient } from "@/shared/viem/client"; | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import type { Block } from "viem"; | ||
|
|
||
| const fetchShinzohubBlockByBlockNumber = async (blockNumber: bigint): Promise<Block> => { | ||
| const publicClient = getPublicClient('shinzohub'); | ||
| return publicClient.getBlock({ blockNumber }); | ||
| }; | ||
|
VanishMax marked this conversation as resolved.
|
||
|
|
||
| export const useShinzohubBlockByBlocknumber = (blockNumber: bigint | undefined) => { | ||
| return useQuery<Block>({ | ||
| queryKey: ['shinzohub', 'block-by-blocknumber', blockNumber?.toString()], | ||
| queryFn: () => fetchShinzohubBlockByBlockNumber(blockNumber!), | ||
| enabled: blockNumber != null, | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { getPublicClient } from "@/shared/viem/client"; | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import type { Hex, Transaction } from "viem"; | ||
|
|
||
| const fetchShinzohubTransactionDetails = async (hash: Hex): Promise<Transaction> => { | ||
| const publicClient = getPublicClient('shinzohub'); | ||
| const transaction = await publicClient.getTransaction({ hash }); | ||
|
|
||
| return transaction; | ||
| }; | ||
|
|
||
| export const useShinzohubTransactionDetails = (hash: Hex) => { | ||
| return useQuery<Transaction>({ | ||
| queryKey: ['shinzohub', 'transaction-details', hash], | ||
| queryFn: () => fetchShinzohubTransactionDetails(hash), | ||
| enabled: !!hash, | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { getPublicClient } from "@/shared/viem/client"; | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import type { Hex, TransactionReceipt } from "viem"; | ||
|
|
||
| const fetchShinzohubTransactionReceipt = async (hash: Hex): Promise<TransactionReceipt> => { | ||
| const publicClient = getPublicClient('shinzohub'); | ||
| const receipt = await publicClient.getTransactionReceipt({ hash }); | ||
|
|
||
| return receipt; | ||
| }; | ||
|
|
||
| export const useShinzohubTransactionReceipt = (hash: Hex) => { | ||
| return useQuery<TransactionReceipt>({ | ||
| queryKey: ['shinzohub', 'transaction-receipt', hash], | ||
| queryFn: () => fetchShinzohubTransactionReceipt(hash), | ||
| enabled: !!hash, | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export { TransactionDetailPage } from './page'; | ||
| export { TransactionDetailPage } from './ui/page'; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: add a proxy endpoint and make the viem client configurable to use the proxy when calling ShinzoHub. It would make the deployed Explorer load data correctly. Limit this proxy endpoint to same-site requests, so it won't be available for anyone else to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the url in this file just for testing guid lines, I have added the staging proxy url to the deployed app.