From 5a017643d5d43ea981e359ed6507bb6c990185b0 Mon Sep 17 00:00:00 2001 From: Sebastian Pape Date: Tue, 12 Apr 2022 11:00:05 +0200 Subject: [PATCH] v6.1.2: continue resolving in case individual assets fail loading (just continue) --- dist/esm/index.js | 63 +++++++++++++++++++++++++---------------------- dist/umd/index.js | 63 +++++++++++++++++++++++++---------------------- package.json | 2 +- src/dripAssets.js | 63 +++++++++++++++++++++++++---------------------- 4 files changed, 100 insertions(+), 91 deletions(-) diff --git a/dist/esm/index.js b/dist/esm/index.js index 7ad18dd..1945755 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -103,22 +103,26 @@ var dripAssets = async (options) => { promises = promises.concat((options.priority || []).map((asset)=>{ return new Promise(async (resolve, reject)=>{ - let token = new Token(asset); - let completedAsset = Object.assign({}, - asset, - { - name: await token.name(), - symbol: await token.symbol(), - decimals: await token.decimals(), - balance: (await token.balance(options.accounts[asset.blockchain])).toString() + try { + let token = new Token(asset); + let completedAsset = Object.assign({}, + asset, + { + name: await token.name(), + symbol: await token.symbol(), + decimals: await token.decimals(), + balance: (await token.balance(options.accounts[asset.blockchain])).toString() + } + ); + if(completedAsset.balance != '0') { + if(exists({ assets, asset })) { return resolve() } + assets.push(completedAsset); + if(typeof options.drip == 'function') { options.drip(completedAsset); } + resolve(completedAsset); + } else { + resolve(); } - ); - if(completedAsset.balance != '0') { - if(exists({ assets, asset })) { return resolve() } - assets.push(completedAsset); - if(typeof options.drip == 'function') { options.drip(completedAsset); } - resolve(completedAsset); - } else { + } catch (e) { resolve(); } }) @@ -143,10 +147,9 @@ var dripAssets = async (options) => { assets.push(assetWithBalance); if(typeof options.drip == 'function') { options.drip(assetWithBalance); } resolve(assetWithBalance); - } else { - resolve(); - } - }).catch((error)=>{ console.log(error); }); + } else { + resolve(); + }}).catch((error)=>{ console.log(error); resolve(); }); }) }))); @@ -156,17 +159,17 @@ var dripAssets = async (options) => { let allAssets = await getAssets(options); promises = promises.concat((allAssets.map((asset)=>{ return new Promise((resolve, reject)=>{ - return new Token(asset).balance(options.accounts[asset.blockchain]).then((balance)=>{ - if(exists({ assets, asset })) { return resolve() } - const assetWithBalance = reduceAssetWithBalance(asset, balance); - if(assetWithBalance.balance != '0') { - assets.push(assetWithBalance); - if(typeof options.drip == 'function') { options.drip(assetWithBalance); } - resolve(assetWithBalance); - } else { - resolve(); - } - }) + return new Token(asset).balance(options.accounts[asset.blockchain]) + .then((balance)=>{ + if(exists({ assets, asset })) { return resolve() } + const assetWithBalance = reduceAssetWithBalance(asset, balance); + if(assetWithBalance.balance != '0') { + assets.push(assetWithBalance); + if(typeof options.drip == 'function') { options.drip(assetWithBalance); } + resolve(assetWithBalance); + } else { + resolve(); + }}).catch((error)=>{ console.log(error); resolve(); }) }) }))); } diff --git a/dist/umd/index.js b/dist/umd/index.js index 692b857..f7e43a7 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -104,22 +104,26 @@ promises = promises.concat((options.priority || []).map((asset)=>{ return new Promise(async (resolve, reject)=>{ - let token = new web3Tokens.Token(asset); - let completedAsset = Object.assign({}, - asset, - { - name: await token.name(), - symbol: await token.symbol(), - decimals: await token.decimals(), - balance: (await token.balance(options.accounts[asset.blockchain])).toString() + try { + let token = new web3Tokens.Token(asset); + let completedAsset = Object.assign({}, + asset, + { + name: await token.name(), + symbol: await token.symbol(), + decimals: await token.decimals(), + balance: (await token.balance(options.accounts[asset.blockchain])).toString() + } + ); + if(completedAsset.balance != '0') { + if(exists({ assets, asset })) { return resolve() } + assets.push(completedAsset); + if(typeof options.drip == 'function') { options.drip(completedAsset); } + resolve(completedAsset); + } else { + resolve(); } - ); - if(completedAsset.balance != '0') { - if(exists({ assets, asset })) { return resolve() } - assets.push(completedAsset); - if(typeof options.drip == 'function') { options.drip(completedAsset); } - resolve(completedAsset); - } else { + } catch (e) { resolve(); } }) @@ -144,10 +148,9 @@ assets.push(assetWithBalance); if(typeof options.drip == 'function') { options.drip(assetWithBalance); } resolve(assetWithBalance); - } else { - resolve(); - } - }).catch((error)=>{ console.log(error); }); + } else { + resolve(); + }}).catch((error)=>{ console.log(error); resolve(); }); }) }))); @@ -157,17 +160,17 @@ let allAssets = await getAssets(options); promises = promises.concat((allAssets.map((asset)=>{ return new Promise((resolve, reject)=>{ - return new web3Tokens.Token(asset).balance(options.accounts[asset.blockchain]).then((balance)=>{ - if(exists({ assets, asset })) { return resolve() } - const assetWithBalance = reduceAssetWithBalance(asset, balance); - if(assetWithBalance.balance != '0') { - assets.push(assetWithBalance); - if(typeof options.drip == 'function') { options.drip(assetWithBalance); } - resolve(assetWithBalance); - } else { - resolve(); - } - }) + return new web3Tokens.Token(asset).balance(options.accounts[asset.blockchain]) + .then((balance)=>{ + if(exists({ assets, asset })) { return resolve() } + const assetWithBalance = reduceAssetWithBalance(asset, balance); + if(assetWithBalance.balance != '0') { + assets.push(assetWithBalance); + if(typeof options.drip == 'function') { options.drip(assetWithBalance); } + resolve(assetWithBalance); + } else { + resolve(); + }}).catch((error)=>{ console.log(error); resolve(); }) }) }))); } diff --git a/package.json b/package.json index 0707b3e..e297a5c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-assets", "moduleName": "Web3Assets", - "version": "6.1.1", + "version": "6.1.2", "description": "", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/src/dripAssets.js b/src/dripAssets.js index 8a292dd..1862bb7 100644 --- a/src/dripAssets.js +++ b/src/dripAssets.js @@ -37,22 +37,26 @@ export default async (options) => { promises = promises.concat((options.priority || []).map((asset)=>{ return new Promise(async (resolve, reject)=>{ - let token = new Token(asset) - let completedAsset = Object.assign({}, - asset, - { - name: await token.name(), - symbol: await token.symbol(), - decimals: await token.decimals(), - balance: (await token.balance(options.accounts[asset.blockchain])).toString() + try { + let token = new Token(asset) + let completedAsset = Object.assign({}, + asset, + { + name: await token.name(), + symbol: await token.symbol(), + decimals: await token.decimals(), + balance: (await token.balance(options.accounts[asset.blockchain])).toString() + } + ) + if(completedAsset.balance != '0') { + if(exists({ assets, asset })) { return resolve() } + assets.push(completedAsset) + if(typeof options.drip == 'function') { options.drip(completedAsset) } + resolve(completedAsset) + } else { + resolve() } - ) - if(completedAsset.balance != '0') { - if(exists({ assets, asset })) { return resolve() } - assets.push(completedAsset) - if(typeof options.drip == 'function') { options.drip(completedAsset) } - resolve(completedAsset) - } else { + } catch { resolve() } }) @@ -78,10 +82,9 @@ export default async (options) => { assets.push(assetWithBalance) if(typeof options.drip == 'function') { options.drip(assetWithBalance) } resolve(assetWithBalance) - } else { - resolve() - } - }).catch((error)=>{ console.log(error) }) + } else { + resolve() + }}).catch((error)=>{ console.log(error); resolve() }) }) }))) @@ -91,17 +94,17 @@ export default async (options) => { let allAssets = await getAssets(options) promises = promises.concat((allAssets.map((asset)=>{ return new Promise((resolve, reject)=>{ - return new Token(asset).balance(options.accounts[asset.blockchain]).then((balance)=>{ - if(exists({ assets, asset })) { return resolve() } - const assetWithBalance = reduceAssetWithBalance(asset, balance) - if(assetWithBalance.balance != '0') { - assets.push(assetWithBalance) - if(typeof options.drip == 'function') { options.drip(assetWithBalance) } - resolve(assetWithBalance) - } else { - resolve() - } - }) + return new Token(asset).balance(options.accounts[asset.blockchain]) + .then((balance)=>{ + if(exists({ assets, asset })) { return resolve() } + const assetWithBalance = reduceAssetWithBalance(asset, balance) + if(assetWithBalance.balance != '0') { + assets.push(assetWithBalance) + if(typeof options.drip == 'function') { options.drip(assetWithBalance) } + resolve(assetWithBalance) + } else { + resolve() + }}).catch((error)=>{ console.log(error); resolve() }) }) }))) }