Skip to content

Commit

Permalink
v6.2.0: timeout getAssets after 10s
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Apr 19, 2022
1 parent c1ca591 commit 8960ac6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
12 changes: 10 additions & 2 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
26 changes: 18 additions & 8 deletions src/getAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]) })
Expand Down

0 comments on commit 8960ac6

Please sign in to comment.