Skip to content

hooks pagination changes #370

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions packages/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ const { data, isLoading, error } = useGetTransactionHistory({
chainId: 1, // optional
page: { // optional
pageSize: 10,
page: 1
},
{
// options param is optional and default values are below
Expand Down Expand Up @@ -189,8 +188,7 @@ const { data, isLoading, error } = useGetTokenBalancesSummary(
omitMetadata: false, // optional
page: {
// optional
pageSize: 10,
page: 1
pageSize: 10
}
},
{
Expand Down Expand Up @@ -222,8 +220,7 @@ const { data, isLoading, error } = useGetTokenBalancesDetails(
omitMetadata: false, // optional
page: {
// optional
pageSize: 10,
page: 1
pageSize: 10
}
},
{
Expand Down Expand Up @@ -255,8 +252,7 @@ const { data, isLoading, error } = useGetTokenBalancesByContract(
omitMetadata: false, // optional
page: {
// optional
pageSize: 10,
page: 1
pageSize: 10
}
},
{
Expand Down
12 changes: 4 additions & 8 deletions packages/hooks/src/hooks/Indexer/useGetTransactionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface GetTransactionHistoryArgs {
* - transfers: Optional array of transaction transfers
* - timestamp: Transaction timestamp
* - page: Pagination information:
* - page: Next page number
* - after: Next page cursor
* - more: Whether more results exist in the next page
* - pageSize: Number of results per page
* @property everything else that react query returns {@link UseInfiniteQueryResult}
Expand Down Expand Up @@ -142,18 +142,14 @@ export const useGetTransactionHistory = (
queryFn: ({ pageParam }) => {
return getTransactionHistory(indexerClient, {
...args,
page: { page: pageParam }
page: pageParam
})
},
getNextPageParam: ({ page }) => {
// Note: must return undefined instead of null to stop the infinite scroll
if (!page.more) {
return undefined
}

return page?.page || 1
return page?.more ? page : undefined
},
initialPageParam: 1,
initialPageParam: { pageSize: args.page?.pageSize } as Page,
retry: options?.retry ?? true,
staleTime: time.oneSecond * 30,
enabled: !!args.chainId && !!args.accountAddress && !options?.disabled
Expand Down
13 changes: 0 additions & 13 deletions packages/hooks/src/tests/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export const handlers = [

return HttpResponse.json(
{
page: {
page: 1
},
balances: [
{
chainId: 1,
Expand Down Expand Up @@ -86,9 +83,6 @@ export const handlers = [

return HttpResponse.json(
{
page: {
page: 1
},
balances: [
{
chainId: 1,
Expand Down Expand Up @@ -132,9 +126,6 @@ export const handlers = [

return HttpResponse.json(
{
page: {
page: 1
},
balances: [
{
chainId: 1,
Expand Down Expand Up @@ -165,9 +156,6 @@ export const handlers = [

return HttpResponse.json(
{
page: {
page: 1
},
tokenMetadata: [
{
contractType: 'ERC721',
Expand Down Expand Up @@ -224,7 +212,6 @@ export const handlers = [
http.post('*/GetTransactionHistory', async () => {
return HttpResponse.json(
{
page: { page: 1 },
transactions: [
{
txnHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
Expand Down