-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: implement pagination for
Account
methods (#2408)
- Loading branch information
1 parent
17bd929
commit aa7e656
Showing
22 changed files
with
863 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@fuel-ts/account": minor | ||
--- | ||
|
||
feat!: implement pagination for `Account` methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
apps/docs-snippets/src/guide/provider/pagination.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import type { GqlPageInfo } from '@fuel-ts/account/dist/providers/__generated__/operations'; | ||
import type { CursorPaginationArgs } from 'fuels'; | ||
import { FUEL_NETWORK_URL, Provider, Wallet } from 'fuels'; | ||
|
||
/** | ||
* @group node | ||
*/ | ||
describe('querying the chain', () => { | ||
it('pagination snippet test 1', () => { | ||
// #region pagination-1 | ||
const paginationArgs: CursorPaginationArgs = { | ||
after: 'cursor', | ||
first: 10, | ||
before: 'cursor', | ||
last: 10, | ||
}; | ||
// #endregion pagination-1 | ||
|
||
// #region pagination-2 | ||
const pageInfo: GqlPageInfo = { | ||
endCursor: 'cursor', | ||
hasNextPage: true, | ||
startCursor: 'cursor', | ||
hasPreviousPage: true, | ||
}; | ||
// #endregion pagination-2 | ||
|
||
expect(paginationArgs).toBeDefined(); | ||
expect(pageInfo).toBeDefined(); | ||
}); | ||
|
||
it('pagination snippet test 2', async () => { | ||
// #region pagination-3 | ||
// #import { Provider, CursorPaginationArgs, FUEL_NETWORK_URL, Wallet }; | ||
|
||
const provider = await Provider.create(FUEL_NETWORK_URL); | ||
const baseAssetId = provider.getBaseAssetId(); | ||
const myWallet = Wallet.generate({ provider }); | ||
|
||
let paginationArgs: CursorPaginationArgs = { | ||
first: 10, // It will return only the first 10 coins | ||
}; | ||
|
||
const { coins, pageInfo } = await provider.getCoins( | ||
myWallet.address, | ||
baseAssetId, | ||
paginationArgs | ||
); | ||
|
||
if (pageInfo.hasNextPage) { | ||
paginationArgs = { | ||
after: pageInfo.endCursor, | ||
first: 10, | ||
}; | ||
// The coins array will include the next 10 coins after the last one in the previous array | ||
await provider.getCoins(myWallet.address, baseAssetId, paginationArgs); | ||
} | ||
// #endregion pagination-3 | ||
|
||
// #region pagination-4 | ||
if (pageInfo.hasPreviousPage) { | ||
paginationArgs = { | ||
before: pageInfo.startCursor, | ||
last: 10, | ||
}; | ||
|
||
// It will includes the previous 10 coins before the first one in the previous array | ||
await provider.getCoins(myWallet.address, baseAssetId, paginationArgs); | ||
} | ||
// #endregion pagination-4 | ||
|
||
expect(paginationArgs).toBeDefined(); | ||
expect(coins).toBeDefined(); | ||
expect(pageInfo).toBeDefined(); | ||
}); | ||
|
||
it('pagination snippet test 3', () => { | ||
// #region pagination-5 | ||
const paginationArgs = { after: 'cursor', first: 10 }; | ||
// #endregion pagination-5 | ||
|
||
expect(paginationArgs).toBeDefined(); | ||
}); | ||
it('pagination snippet test 4', () => { | ||
// #region pagination-6 | ||
const paginationArgs = { before: 'cursor', last: 10 }; | ||
// #endregion pagination-6 | ||
|
||
expect(paginationArgs).toBeDefined(); | ||
}); | ||
|
||
it('pagination snippet test 5', async () => { | ||
// #region pagination-7 | ||
// #import { Provider, FUEL_NETWORK_URL, Wallet }; | ||
|
||
const provider = await Provider.create(FUEL_NETWORK_URL); | ||
const myWallet = Wallet.generate({ provider }); | ||
|
||
// It will return the first 100 coins of the base asset | ||
const { coins, pageInfo } = await provider.getCoins(myWallet.address); | ||
// #endregion pagination-7 | ||
|
||
expect(coins).toBeDefined(); | ||
expect(pageInfo).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.