From 810afdfc2b081b538c96da49544c85b5fe769142 Mon Sep 17 00:00:00 2001 From: Sebastian Pape Date: Wed, 13 Apr 2022 10:49:48 +0200 Subject: [PATCH] v6.1.4: fix resolve during fetch errors --- dist/esm/index.js | 27 +++++++++++++++------------ dist/umd/index.js | 27 +++++++++++++++------------ package.json | 2 +- src/getAssets.js | 27 +++++++++++++++------------ 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/dist/esm/index.js b/dist/esm/index.js index 3edfdc7..4f3aa01 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -49,19 +49,22 @@ var getAssets = async (options) => { let assets = Promise.all( (Object.keys(options.accounts)).map((blockchain) =>{ - const address = options.accounts[blockchain]; - - return fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`) - .catch((error) => { console.log(error); resolve(); }) - .then((response) => response.json()) - .then(async (assets) => { - return await ensureNativeTokenAsset({ - address, - options, - assets: filterAssets({ assets, blockchain, options }).map((asset) => Object.assign(asset, { blockchain })), - blockchain + return new Promise((resolve, reject)=>{ + const address = options.accounts[blockchain]; + fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`) + .catch((error) => { console.log(error); resolve(); }) + .then((response) => response.json()) + .then(async (assets) => { + return await ensureNativeTokenAsset({ + address, + options, + assets: filterAssets({ assets, blockchain, options }).map((asset) => Object.assign(asset, { blockchain })), + blockchain + }) }) - }).catch((error) => { console.log(error); }) + .then(resolve) + .catch((error) => { console.log(error); resolve(); }); + }) }), ).then((responses) => responses.flat()); diff --git a/dist/umd/index.js b/dist/umd/index.js index 003e91a..ba94618 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -50,19 +50,22 @@ let assets = Promise.all( (Object.keys(options.accounts)).map((blockchain) =>{ - const address = options.accounts[blockchain]; - - return fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`) - .catch((error) => { console.log(error); resolve(); }) - .then((response) => response.json()) - .then(async (assets) => { - return await ensureNativeTokenAsset({ - address, - options, - assets: filterAssets({ assets, blockchain, options }).map((asset) => Object.assign(asset, { blockchain })), - blockchain + return new Promise((resolve, reject)=>{ + const address = options.accounts[blockchain]; + fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`) + .catch((error) => { console.log(error); resolve(); }) + .then((response) => response.json()) + .then(async (assets) => { + return await ensureNativeTokenAsset({ + address, + options, + assets: filterAssets({ assets, blockchain, options }).map((asset) => Object.assign(asset, { blockchain })), + blockchain + }) }) - }).catch((error) => { console.log(error); }) + .then(resolve) + .catch((error) => { console.log(error); resolve(); }); + }) }), ).then((responses) => responses.flat()); diff --git a/package.json b/package.json index 7e1c6fc..3c860d9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-assets", "moduleName": "Web3Assets", - "version": "6.1.3", + "version": "6.1.4", "description": "", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/src/getAssets.js b/src/getAssets.js index dc9989b..b635017 100644 --- a/src/getAssets.js +++ b/src/getAssets.js @@ -47,19 +47,22 @@ export default async (options) => { let assets = Promise.all( (Object.keys(options.accounts)).map((blockchain) =>{ - const address = options.accounts[blockchain] - - return fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`) - .catch((error) => { console.log(error); resolve() }) - .then((response) => response.json()) - .then(async (assets) => { - return await ensureNativeTokenAsset({ - address, - options, - assets: filterAssets({ assets, blockchain, options }).map((asset) => Object.assign(asset, { blockchain })), - blockchain + return new Promise((resolve, reject)=>{ + const address = options.accounts[blockchain] + fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`) + .catch((error) => { console.log(error); resolve() }) + .then((response) => response.json()) + .then(async (assets) => { + return await ensureNativeTokenAsset({ + address, + options, + assets: filterAssets({ assets, blockchain, options }).map((asset) => Object.assign(asset, { blockchain })), + blockchain + }) }) - }).catch((error) => { console.log(error) }) + .then(resolve) + .catch((error) => { console.log(error); resolve() }) + }) }), ).then((responses) => responses.flat())