From 330e5834ed9bb2e18691d382cabaef4787521d5e Mon Sep 17 00:00:00 2001 From: Tadeuchi Date: Wed, 20 Dec 2023 09:29:12 +0100 Subject: [PATCH] interactions loader - previous sk instead of offset --- src/__tests__/unit/gateway-interactions.loader.test.ts | 8 ++++---- src/core/modules/impl/WarpGatewayInteractionsLoader.ts | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/__tests__/unit/gateway-interactions.loader.test.ts b/src/__tests__/unit/gateway-interactions.loader.test.ts index 42954a54..2ed9b7d3 100644 --- a/src/__tests__/unit/gateway-interactions.loader.test.ts +++ b/src/__tests__/unit/gateway-interactions.loader.test.ts @@ -97,7 +97,7 @@ describe('WarpGatewayInteractionsLoader -> load', () => { it('should be called with correct params', async () => { const loader = getLoader(); await loader.load(contractId, fromBlockHeight, toBlockHeight); - expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true`); + expect(fetchMock).toBeCalledWith(`${baseUrl}&fromSdk=true`); }); it('should be called accordingly to the amount of pages', async () => { const fetchMock = jest.spyOn(global, 'fetch').mockImplementation( @@ -110,7 +110,7 @@ describe('WarpGatewayInteractionsLoader -> load', () => { ); const loader = getLoader(); await loader.load(contractId, fromBlockHeight, toBlockHeight); - expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true`); + expect(fetchMock).toBeCalledWith(`${baseUrl}&fromSdk=true`); /*expect(fetchMock).toBeCalledWith(`${baseUrl}&page=2&fromSdk=true`); expect(fetchMock).toBeCalledWith(`${baseUrl}&page=3&fromSdk=true`); expect(fetchMock).toBeCalledWith(`${baseUrl}&page=4&fromSdk=true`); @@ -120,12 +120,12 @@ describe('WarpGatewayInteractionsLoader -> load', () => { it('should be called with confirmationStatus set to "confirmed"', async () => { const loader = getLoader({ confirmed: true }); await loader.load(contractId, fromBlockHeight, toBlockHeight); - expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true&confirmationStatus=confirmed`); + expect(fetchMock).toBeCalledWith(`${baseUrl}&fromSdk=true&confirmationStatus=confirmed`); }); it('should be called with confirmationStatus set to "not_corrupted"', async () => { const loader = getLoader({ notCorrupted: true }); await loader.load(contractId, fromBlockHeight, toBlockHeight); - expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true&confirmationStatus=not_corrupted`); + expect(fetchMock).toBeCalledWith(`${baseUrl}&fromSdk=true&confirmationStatus=not_corrupted`); }); it('should throw an error in case of timeout', async () => { jest.spyOn(global, 'fetch').mockImplementation(() => Promise.reject({ status: 504, ok: false })); diff --git a/src/core/modules/impl/WarpGatewayInteractionsLoader.ts b/src/core/modules/impl/WarpGatewayInteractionsLoader.ts index f2b752db..196d7184 100644 --- a/src/core/modules/impl/WarpGatewayInteractionsLoader.ts +++ b/src/core/modules/impl/WarpGatewayInteractionsLoader.ts @@ -72,7 +72,7 @@ export class WarpGatewayInteractionsLoader implements InteractionsLoader { this.logger.debug('Loading interactions: for ', { contractId, fromSortKey, toSortKey }); const interactions: GQLNodeInterface[] = []; - let page = 0; + let page = 1; let limit = 0; let items = 0; const pagesPerBatch = evaluationOptions?.transactionsPagesPerBatch || Number.MAX_SAFE_INTEGER; @@ -97,7 +97,6 @@ export class WarpGatewayInteractionsLoader implements InteractionsLoader { ...(this._warp.whoAmI ? { client: this._warp.whoAmI } : ''), ...(fromSortKey ? { from: fromSortKey } : ''), ...(toSortKey ? { to: toSortKey } : ''), - page: (++page).toString(), fromSdk: 'true', ...(this.confirmationStatus && this.confirmationStatus.confirmed ? { confirmationStatus: 'confirmed' } @@ -114,6 +113,8 @@ export class WarpGatewayInteractionsLoader implements InteractionsLoader { interactions.push(...response.interactions); limit = response.paging.limit; items = response.paging.items; + fromSortKey = interactions[interactions.length - 1]?.sortKey; + page++; this.logger.debug(`Loaded interactions length: ${interactions.length}, from: ${fromSortKey}, to: ${toSortKey}`); } while (items == limit && page < pagesPerBatch); // note: items < limit means that we're on the last page