File tree Expand file tree Collapse file tree 3 files changed +28
-10
lines changed Expand file tree Collapse file tree 3 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,9 @@ export class HttpRequestWithSecurityHeaders extends BaseHttpRequest {
168168 ) {
169169 super ( openAPIConfig ) ;
170170
171- this . axiosClient = axios . create ( ) ;
171+ this . axiosClient = axios . create ( {
172+ timeout : 30000 ,
173+ } ) ;
172174
173175 this . axiosClient . interceptors . request . use ( ( request ) => {
174176 log . debug ( 'Sending HTTP request' , { request } ) ;
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ describe.skipIf(noTransfersCapability)('Withdrawals', () => {
9393 const accounts = await arrayFromAsyncGenerator ( paginated ( getAccounts ) ) ;
9494 accountsMap = new Map < string , Account > ( ) ;
9595 accounts . forEach ( ( account ) => accountsMap . set ( account . id , account ) ) ;
96- } ) ;
96+ } , 60000 ) ;
9797
9898 describe ( 'Capabilities' , ( ) => {
9999 it ( 'should return only known assets in response' , ( ) => {
@@ -205,7 +205,7 @@ describe.skipIf(noTransfersCapability)('Withdrawals', () => {
205205 getSubAccountWithdrawals ,
206206 transfersCapableAccountIds
207207 ) ;
208- } ) ;
208+ } , 60000 ) ;
209209
210210 it ( 'should be sorted by creation time in a descending order' , ( ) => {
211211 const allWithdrawalResponses = [
Original file line number Diff line number Diff line change 11import config from '../../src/config' ;
22
33const LIMIT = config . get ( 'paginationLimit' ) ;
4-
54// Function supporting pagination
65export type Pageable < T > = ( limit : number , startingAfter ?: string ) => Promise < T [ ] > ;
7-
86/**
97 * Wraps a pageable function with a generator function, returning all the items
108 * one by one while automagically managing the pagination behind the scene.
119 */
1210export async function * paginated < T > ( f : Pageable < T > , idPropName = 'id' ) : AsyncGenerator < T > {
13- let page = await f ( LIMIT ) ;
14- while ( page . length > 0 ) {
15- for ( const item of page ) {
11+ const MAX_PAGES = 1000 ;
12+ let pageCount = 0 ;
13+ let startingAfter : string | undefined ;
14+
15+ while ( pageCount < MAX_PAGES ) {
16+ const currentPage = await f ( LIMIT , startingAfter ) ;
17+
18+ if ( currentPage . length === 0 ) {
19+ break ;
20+ }
21+
22+ pageCount ++ ;
23+
24+ for ( const item of currentPage ) {
1625 yield item ;
1726 }
18- const startingAfter = page . at ( - 1 ) ?. [ idPropName ] ;
19- page = await f ( LIMIT , startingAfter ) ;
27+
28+ const lastItem = currentPage [ currentPage . length - 1 ] ;
29+ const lastItemId = lastItem ?. [ idPropName ] ;
30+
31+ if ( ! lastItemId || lastItemId === startingAfter ) {
32+ break ;
33+ }
34+
35+ startingAfter = lastItemId ;
2036 }
2137}
2238
You can’t perform that action at this time.
0 commit comments