diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index 5139d6be..faa12d13 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 0f78cc04..e3559d41 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -5,13 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.2.4] - 2021-18-06 + +### Fixed + +- addressesTxsAll pagination +- addressesUtxosAll pagination + ## [0.2.3] - 2021-05-06 ### Fixed - array missing in some `/txs` types, see: https://github.com/blockfrost/openapi/releases/tag/v0.1.13 - ## [0.2.2] - 2021-05-02 ### Fixed diff --git a/package.json b/package.json index 2d2441b0..467a8557 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blockfrost/blockfrost-js", - "version": "0.2.3", + "version": "0.2.4", "description": "A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API", "files": [ "lib/**/*.js", diff --git a/src/endpoints/addresses/index.ts b/src/endpoints/addresses/index.ts index 20bfe0e1..87be0e1f 100644 --- a/src/endpoints/addresses/index.ts +++ b/src/endpoints/addresses/index.ts @@ -69,7 +69,7 @@ export async function addressesTxsAll( batchSize = 10, ): Promise { let page = 1; - let res: components['schemas']['address_txs_content'] = []; + const res: components['schemas']['address_txs_content'] = []; let shouldRun = true; const promisesBundle: Promise< components['schemas']['address_txs_content'] @@ -87,23 +87,17 @@ export async function addressesTxsAll( page++; } - await Promise.all( - promisesBundle.map(p => - p - .then(data => { - res = res.concat(data); - // some page is not full end search - if (data.length < DEFAULT_PAGINATION_PAGE_ITEMS_COUNT) { - shouldRun = false; - } - }) - .catch(error => { - console.log(error); - shouldRun = false; - return error; - }), - ), - ); + const result = await Promise.all(promisesBundle).then(values => { + values.map(batch => { + if (batch.length < DEFAULT_PAGINATION_PAGE_ITEMS_COUNT) { + shouldRun = false; + } + }); + + return values.flat(); + }); + + if (!shouldRun) return result; } return res; @@ -120,9 +114,7 @@ export async function addressesUtxos( axios .get( `${this.apiUrl}/addresses/${address}/utxos?page=${page}&count=${count}&order=${order}`, - { - headers: getHeaders(this.projectId), - }, + { headers: getHeaders(this.projectId) }, ) .then(resp => { resolve(resp.data); @@ -138,7 +130,7 @@ export async function addressesUtxosAll( batchSize = 10, ): Promise { let page = 1; - let res: components['schemas']['address_utxo_content'] = []; + const res: components['schemas']['address_utxo_content'] = []; let shouldRun = true; const promisesBundle: Promise< components['schemas']['address_utxo_content'] @@ -152,27 +144,22 @@ export async function addressesUtxosAll( DEFAULT_PAGINATION_PAGE_ITEMS_COUNT, order, ); + promisesBundle.push(promise); page++; } - await Promise.all( - promisesBundle.map(p => - p - .then(data => { - res = res.concat(data); - // some page is not full end search - if (data.length < DEFAULT_PAGINATION_PAGE_ITEMS_COUNT) { - shouldRun = false; - } - }) - .catch(error => { - console.log(error); - shouldRun = false; - return error; - }), - ), - ); + const result = await Promise.all(promisesBundle).then(values => { + values.map(batch => { + if (batch.length < DEFAULT_PAGINATION_PAGE_ITEMS_COUNT) { + shouldRun = false; + } + }); + + return values.flat(); + }); + + if (!shouldRun) return result; } return res;