Skip to content

Commit

Permalink
v6.1.2: continue resolving in case individual assets fail loading (ju…
Browse files Browse the repository at this point in the history
…st continue)
  • Loading branch information
10xSebastian committed Apr 12, 2022
1 parent ef94ef6 commit 5a01764
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 91 deletions.
63 changes: 33 additions & 30 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
})
Expand All @@ -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(); });
})
})));

Expand All @@ -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(); })
})
})));
}
Expand Down
63 changes: 33 additions & 30 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
})
Expand All @@ -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(); });
})
})));

Expand All @@ -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(); })
})
})));
}
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.1",
"version": "6.1.2",
"description": "",
"main": "dist/umd/index.js",
"module": "dist/esm/index.js",
Expand Down
63 changes: 33 additions & 30 deletions src/dripAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
Expand All @@ -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() })
})
})))

Expand All @@ -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() })
})
})))
}
Expand Down

0 comments on commit 5a01764

Please sign in to comment.