diff --git a/dist/esm/index.js b/dist/esm/index.js index 26d1375..020b83a 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -51,9 +51,17 @@ var getAssets = async (options) => { return new Promise((resolve, reject)=>{ const address = options.accounts[blockchain]; - fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`) + const controller = new AbortController(); + setTimeout(()=>controller.abort(), 10000); + fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`, { signal: controller.signal }) .catch((error) => { console.log(error); resolve([]); }) - .then((response) => response.json()) + .then((response) => { + if(response.success) { + return response.json() + } else { + resolve([]); + } + }) .then(async (assets) => { return await ensureNativeTokenAsset({ address, diff --git a/dist/umd/index.js b/dist/umd/index.js index cfe38d0..f39769b 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -52,9 +52,17 @@ return new Promise((resolve, reject)=>{ const address = options.accounts[blockchain]; - fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`) + const controller = new AbortController(); + setTimeout(()=>controller.abort(), 10000); + fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`, { signal: controller.signal }) .catch((error) => { console.log(error); resolve([]); }) - .then((response) => response.json()) + .then((response) => { + if(response.success) { + return response.json() + } else { + resolve([]); + } + }) .then(async (assets) => { return await ensureNativeTokenAsset({ address, diff --git a/package.json b/package.json index e903ea6..a4fcd77 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-assets", "moduleName": "Web3Assets", - "version": "6.1.5", + "version": "6.2.0", "description": "", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/src/getAssets.js b/src/getAssets.js index 7c5f52c..c62a036 100644 --- a/src/getAssets.js +++ b/src/getAssets.js @@ -49,16 +49,26 @@ export default async (options) => { return new Promise((resolve, reject)=>{ const address = options.accounts[blockchain] - fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`) + const controller = new AbortController() + setTimeout(()=>controller.abort(), 10000) + fetch(`https://public.depay.fi/accounts/${blockchain}/${address}/assets`, { signal: controller.signal }) .catch((error) => { console.log(error); resolve([]) }) - .then((response) => response.json()) + .then((response) => { + if(response && response.success) { + return response.json() + } else { + resolve([]) + } + }) .then(async (assets) => { - return await ensureNativeTokenAsset({ - address, - options, - assets: filterAssets({ assets, blockchain, options }).map((asset) => Object.assign(asset, { blockchain })), - blockchain - }) + if(assets && assets.length) { + return await ensureNativeTokenAsset({ + address, + options, + assets: filterAssets({ assets, blockchain, options }).map((asset) => Object.assign(asset, { blockchain })), + blockchain + }) + } }) .then(resolve) .catch((error) => { console.log(error); resolve([]) })