Skip to content

Commit

Permalink
v6.1.1: do not fetch all assets if only is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Apr 11, 2022
1 parent 8b9075c commit ef94ef6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 49 deletions.
32 changes: 17 additions & 15 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,24 @@ var dripAssets = async (options) => {

// All other assets

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();
}
if(options.only == undefined || Object.keys(options.only).every((list)=>list.length == 0)) {
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();
}
})
})
})
})));
})));
}

await Promise.all(promises);

Expand Down
32 changes: 17 additions & 15 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,24 @@

// All other assets

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();
}
if(options.only == undefined || Object.keys(options.only).every((list)=>list.length == 0)) {
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();
}
})
})
})
})));
})));
}

await Promise.all(promises);

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.0",
"version": "6.1.1",
"description": "",
"main": "dist/umd/index.js",
"module": "dist/esm/index.js",
Expand Down
32 changes: 17 additions & 15 deletions src/dripAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,24 @@ export default async (options) => {

// All other assets

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()
}
if(options.only == undefined || Object.keys(options.only).every((list)=>list.length == 0)) {
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()
}
})
})
})
})))
})))
}

await Promise.all(promises)

Expand Down
3 changes: 0 additions & 3 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import 'regenerator-runtime/runtime'

import fetch from 'cross-fetch'
global.fetch = fetch

0 comments on commit ef94ef6

Please sign in to comment.