Skip to content

Commit

Permalink
Merge branch 'main' into disable-vercel-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 authored Dec 16, 2024
2 parents b52bfbe + f824abe commit a15e5e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 13 additions & 2 deletions packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,18 @@ export const useScaffoldEventHistory = <
},
enabled: enabled && isContractAddressAndClientReady,
initialPageParam: fromBlock,
getNextPageParam: () => {
return blockNumber;
getNextPageParam: (lastPage, allPages, lastPageParam) => {
if (!blockNumber || fromBlock >= blockNumber) return undefined;

const lastPageHighestBlock = Math.max(
Number(fromBlock),
...(lastPage || []).map(event => Number(event.blockNumber || 0)),
);
const nextBlock = BigInt(Math.max(Number(lastPageParam), lastPageHighestBlock) + 1);

if (nextBlock > blockNumber) return undefined;

return nextBlock;
},
select: data => {
const events = data.pages.flat();
Expand All @@ -133,6 +143,7 @@ export const useScaffoldEventHistory = <
TTransactionData,
TReceiptData
>;

return {
pages: eventHistoryData?.reverse(),
pageParams: data.pageParams,
Expand Down
3 changes: 1 addition & 2 deletions packages/nextjs/utils/scaffold-eth/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ export type UseScaffoldEventHistoryData<
| IsContractDeclarationMissing<
any[],
{
log: Log<bigint, number, false, TEvent, false, [TEvent], TEventName>;
args: AbiParametersToPrimitiveTypes<TEvent["inputs"]> &
GetEventArgs<
ContractAbi<TContractName>,
Expand All @@ -309,7 +308,7 @@ export type UseScaffoldEventHistoryData<
blockData: TBlockData extends true ? Block<bigint, true> : null;
receiptData: TReceiptData extends true ? GetTransactionReturnType : null;
transactionData: TTransactionData extends true ? GetTransactionReceiptReturnType : null;
}[]
} & Log<bigint, number, false, TEvent, false, [TEvent], TEventName>[]
>
| undefined;

Expand Down

0 comments on commit a15e5e0

Please sign in to comment.