Skip to content

Commit f331bab

Browse files
andrewlee348SamueleA
authored andcommitted
changed requests' pagination to use cursors
1 parent df34433 commit f331bab

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

packages/hooks/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ const { data, isLoading, error } = useGetTransactionHistory({
122122
chainId: 1, // optional
123123
page: { // optional
124124
pageSize: 10,
125-
page: 1
126125
},
127126
{
128127
// options param is optional and default values are below
@@ -189,8 +188,7 @@ const { data, isLoading, error } = useGetTokenBalancesSummary(
189188
omitMetadata: false, // optional
190189
page: {
191190
// optional
192-
pageSize: 10,
193-
page: 1
191+
pageSize: 10
194192
}
195193
},
196194
{
@@ -222,8 +220,7 @@ const { data, isLoading, error } = useGetTokenBalancesDetails(
222220
omitMetadata: false, // optional
223221
page: {
224222
// optional
225-
pageSize: 10,
226-
page: 1
223+
pageSize: 10
227224
}
228225
},
229226
{
@@ -255,8 +252,7 @@ const { data, isLoading, error } = useGetTokenBalancesByContract(
255252
omitMetadata: false, // optional
256253
page: {
257254
// optional
258-
pageSize: 10,
259-
page: 1
255+
pageSize: 10
260256
}
261257
},
262258
{

packages/hooks/src/hooks/Indexer/useGetTransactionHistory.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface GetTransactionHistoryArgs {
2929
* - transfers: Optional array of transaction transfers
3030
* - timestamp: Transaction timestamp
3131
* - page: Pagination information:
32-
* - page: Next page number
32+
* - after: Next page cursor
3333
* - more: Whether more results exist in the next page
3434
* - pageSize: Number of results per page
3535
* @property everything else that react query returns {@link UseInfiniteQueryResult}
@@ -142,18 +142,14 @@ export const useGetTransactionHistory = (
142142
queryFn: ({ pageParam }) => {
143143
return getTransactionHistory(indexerClient, {
144144
...args,
145-
page: { page: pageParam }
145+
page: pageParam
146146
})
147147
},
148148
getNextPageParam: ({ page }) => {
149149
// Note: must return undefined instead of null to stop the infinite scroll
150-
if (!page.more) {
151-
return undefined
152-
}
153-
154-
return page?.page || 1
150+
return page?.more ? page : undefined
155151
},
156-
initialPageParam: 1,
152+
initialPageParam: { pageSize: args.page?.pageSize } as Page,
157153
retry: options?.retry ?? true,
158154
staleTime: time.oneSecond * 30,
159155
enabled: !!args.chainId && !!args.accountAddress && !options?.disabled

packages/hooks/src/tests/handlers.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export const handlers = [
2828

2929
return HttpResponse.json(
3030
{
31-
page: {
32-
page: 1
33-
},
3431
balances: [
3532
{
3633
chainId: 1,
@@ -86,9 +83,6 @@ export const handlers = [
8683

8784
return HttpResponse.json(
8885
{
89-
page: {
90-
page: 1
91-
},
9286
balances: [
9387
{
9488
chainId: 1,
@@ -132,9 +126,6 @@ export const handlers = [
132126

133127
return HttpResponse.json(
134128
{
135-
page: {
136-
page: 1
137-
},
138129
balances: [
139130
{
140131
chainId: 1,
@@ -165,9 +156,6 @@ export const handlers = [
165156

166157
return HttpResponse.json(
167158
{
168-
page: {
169-
page: 1
170-
},
171159
tokenMetadata: [
172160
{
173161
contractType: 'ERC721',
@@ -224,7 +212,6 @@ export const handlers = [
224212
http.post('*/GetTransactionHistory', async () => {
225213
return HttpResponse.json(
226214
{
227-
page: { page: 1 },
228215
transactions: [
229216
{
230217
txnHash: '0x0000000000000000000000000000000000000000000000000000000000000000',

0 commit comments

Comments
 (0)