-
Notifications
You must be signed in to change notification settings - Fork 10
Add events tab to contract details page #40
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?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
83561e5 to
cd4c5b7
Compare
45f9f50 to
e89bebc
Compare
src/modules/ContractDetails/page.tsx
Outdated
| initialData: { | ||
| pages: [], | ||
| }, | ||
| enabled: !!contractAddress && !latestBlockQuery.isLoading && isLocalNode |
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.
| enabled: !!contractAddress && !latestBlockQuery.isLoading && isLocalNode | |
| enabled: contractAddress && !latestBlockQuery.isLoading && isLocalNode |
| const blockOffset = 10; | ||
| const fetchOffset = 5; | ||
| const eventsQuery = useInfiniteQuery({ | ||
| queryKey: ["contract", contractAddress, "events"], | ||
| queryFn: async ({ pageParam }) => { | ||
| const events = []; | ||
| let continuationToken = null; | ||
| while (continuationToken === null || !!continuationToken) { | ||
| const res = await RPC_PROVIDER.getEvents({ | ||
| address: contractAddress!, | ||
| chunk_size: 100, | ||
| from_block: pageParam.fromBlock, | ||
| to_block: pageParam.toBlock, | ||
| continuation_token: continuationToken ?? undefined | ||
| }); | ||
| continuationToken = res.continuation_token; | ||
| events.push(...res.events); | ||
| } | ||
|
|
||
| return events | ||
| }, | ||
| getNextPageParam: (_lastPage, _allPages, lastPageParam) => { | ||
| return { | ||
| fromBlock: { block_number: lastPageParam.fromBlock.block_number - blockOffset }, | ||
| toBlock: { block_number: lastPageParam.toBlock.block_number - blockOffset } | ||
| }; | ||
| }, | ||
| initialPageParam: { | ||
| fromBlock: { block_number: latestBlockQuery.data ? latestBlockQuery.data.block_number - blockOffset : undefined } as Block, | ||
| toBlock: { block_number: latestBlockQuery.data ? latestBlockQuery.data.block_number : undefined } as Block, | ||
| }, | ||
| initialData: { | ||
| pages: [], | ||
| }, |
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.
Can't this be simplified to:
- Limit the chunk size to
pageSize(ie the number of events we want to display per page) - Set
from_block== 0 andto_block== 'pending'- This avoid having to manually adjust the block offset
- Store the
continuation_tokenas a state - Return the
continuation_tokenfromgetNextPageParam
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.
Set from_block == 0 and to_block == 'pending'
Does it allows us to order by newest entries?
I tried from_block === "latest" and to_block === "0" but didn't work.
If it works, step 3 is unnecessary since it can be passed as a page param.
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.
Does it allows us to order by newest entries?
Yup, technically it should be ordered like so.
I tried
from_block === "latest"andto_block === "0"but didn't work.
The to_block should be a higher block than from_block, so it should be the other way around. And in this case, let's set the to_block to 'pending'
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.
wait, i still don't understand how to get the latest txs in desc without having block_number as a page params if to_block has to be higher than from_block?
(i.e. what's the query for fetching the latest N txs from block 0 to "pending"?)
Also, eventsQuery.fetchNextPage would be called from a transactions table as events are dependencies of fetching all txs related to the contract without indexer.
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.
Ah my bad sorry, I misunderstood your statement. I was assuming that you're fetching the events from oldest to newest (the default ordering).
(i.e. what's the query for fetching the latest N txs from block 0 to "pending"?)
Yea, this can't be done directly in the query. In which case, you're approach is valid then - to fetch from latest block to latest block - offset. But the chunk size can still be limited to the page size.
Assuming?? In this day and age?? What a blasphemy.
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 don't think limiting chunk size to page size would matter since all events between pageParam.fromBlock - pageParam.toBlock has to be fetched in order to sort in desc anyways. I can change the fixed chunk_size smaller tho in case current 100 is too big per request (or smaller block offset).
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.
Yea, make sense. Then, I think for now the chunk size and block offset value don't matter much considering this is only for local dev.
024d730 to
60e5590
Compare
60e5590 to
4f6ea6e
Compare
4f6ea6e to
5d7742d
Compare
|
The problem with this approach is that if there's no event in the latest blocks, it'll spam node with |
Incrementally fetch events by 10 blocks when table pagination hits the last 3 pages.