From d53382c10fa67ee5b97dacb4ecb4a6fa4c4d3e07 Mon Sep 17 00:00:00 2001 From: Sebastian Pape Date: Sun, 10 Apr 2022 12:04:55 +0200 Subject: [PATCH] v6.0.1: do not return assets with balance 0 --- dist/esm/index.js | 30 +++++++++++++++++++++--------- dist/umd/index.js | 30 +++++++++++++++++++++--------- package.json | 2 +- src/dripAssets.js | 30 +++++++++++++++++++++--------- tests/units/dripAssets.spec.js | 11 ++--------- 5 files changed, 66 insertions(+), 37 deletions(-) diff --git a/dist/esm/index.js b/dist/esm/index.js index 1c18581..a4f7bc3 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -81,9 +81,13 @@ var dripAssets = async (options) => { balance: (await token.balance(options.accounts[asset.blockchain])).toString() } ); - assets.push(completedAsset); - if(typeof options.drip == 'function') { options.drip(completedAsset); } - resolve(completedAsset); + if(completedAsset.balance != '0') { + assets.push(completedAsset); + if(typeof options.drip == 'function') { options.drip(completedAsset); } + resolve(completedAsset); + } else { + resolve(); + } }) })); @@ -103,9 +107,13 @@ var dripAssets = async (options) => { new Token(asset).balance(options.accounts[asset.blockchain]) .then((balance)=>{ const assetWithBalance = reduceAssetWithBalance(asset, balance); - assets.push(assetWithBalance); - if(typeof options.drip == 'function') { options.drip(assetWithBalance); } - resolve(assetWithBalance); + if(assetWithBalance.balance != '0') { + assets.push(assetWithBalance); + if(typeof options.drip == 'function') { options.drip(assetWithBalance); } + resolve(assetWithBalance); + } else { + resolve(); + } }).catch((error)=>{ console.log(error); }); }) })); @@ -120,9 +128,13 @@ var dripAssets = async (options) => { } else { return new Token(asset).balance(options.accounts[asset.blockchain]).then((balance)=>{ const assetWithBalance = reduceAssetWithBalance(asset, balance); - assets.push(assetWithBalance); - if(typeof options.drip == 'function') { options.drip(assetWithBalance); } - resolve(assetWithBalance); + if(assetWithBalance.balance != '0') { + assets.push(assetWithBalance); + if(typeof options.drip == 'function') { options.drip(assetWithBalance); } + resolve(assetWithBalance); + } else { + resolve(); + } }) } }) diff --git a/dist/umd/index.js b/dist/umd/index.js index 89467b5..50116f6 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -82,9 +82,13 @@ balance: (await token.balance(options.accounts[asset.blockchain])).toString() } ); - assets.push(completedAsset); - if(typeof options.drip == 'function') { options.drip(completedAsset); } - resolve(completedAsset); + if(completedAsset.balance != '0') { + assets.push(completedAsset); + if(typeof options.drip == 'function') { options.drip(completedAsset); } + resolve(completedAsset); + } else { + resolve(); + } }) })); @@ -104,9 +108,13 @@ new web3Tokens.Token(asset).balance(options.accounts[asset.blockchain]) .then((balance)=>{ const assetWithBalance = reduceAssetWithBalance(asset, balance); - assets.push(assetWithBalance); - if(typeof options.drip == 'function') { options.drip(assetWithBalance); } - resolve(assetWithBalance); + if(assetWithBalance.balance != '0') { + assets.push(assetWithBalance); + if(typeof options.drip == 'function') { options.drip(assetWithBalance); } + resolve(assetWithBalance); + } else { + resolve(); + } }).catch((error)=>{ console.log(error); }); }) })); @@ -121,9 +129,13 @@ } else { return new web3Tokens.Token(asset).balance(options.accounts[asset.blockchain]).then((balance)=>{ const assetWithBalance = reduceAssetWithBalance(asset, balance); - assets.push(assetWithBalance); - if(typeof options.drip == 'function') { options.drip(assetWithBalance); } - resolve(assetWithBalance); + if(assetWithBalance.balance != '0') { + assets.push(assetWithBalance); + if(typeof options.drip == 'function') { options.drip(assetWithBalance); } + resolve(assetWithBalance); + } else { + resolve(); + } }) } }) diff --git a/package.json b/package.json index 1b7489b..13133aa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-assets", "moduleName": "Web3Assets", - "version": "6.0.0", + "version": "6.0.1", "description": "", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/src/dripAssets.js b/src/dripAssets.js index 9d6801f..114486c 100644 --- a/src/dripAssets.js +++ b/src/dripAssets.js @@ -32,9 +32,13 @@ export default async (options) => { balance: (await token.balance(options.accounts[asset.blockchain])).toString() } ) - assets.push(completedAsset) - if(typeof options.drip == 'function') { options.drip(completedAsset) } - resolve(completedAsset) + if(completedAsset.balance != '0') { + assets.push(completedAsset) + if(typeof options.drip == 'function') { options.drip(completedAsset) } + resolve(completedAsset) + } else { + resolve() + } }) })) @@ -55,9 +59,13 @@ export default async (options) => { new Token(asset).balance(options.accounts[asset.blockchain]) .then((balance)=>{ const assetWithBalance = reduceAssetWithBalance(asset, balance) - assets.push(assetWithBalance) - if(typeof options.drip == 'function') { options.drip(assetWithBalance) } - resolve(assetWithBalance) + if(assetWithBalance.balance != '0') { + assets.push(assetWithBalance) + if(typeof options.drip == 'function') { options.drip(assetWithBalance) } + resolve(assetWithBalance) + } else { + resolve() + } }).catch((error)=>{ console.log(error) }) }) })) @@ -72,9 +80,13 @@ export default async (options) => { } else { return new Token(asset).balance(options.accounts[asset.blockchain]).then((balance)=>{ const assetWithBalance = reduceAssetWithBalance(asset, balance) - assets.push(assetWithBalance) - if(typeof options.drip == 'function') { options.drip(assetWithBalance) } - resolve(assetWithBalance) + if(assetWithBalance.balance != '0') { + assets.push(assetWithBalance) + if(typeof options.drip == 'function') { options.drip(assetWithBalance) } + resolve(assetWithBalance) + } else { + resolve() + } }) } }) diff --git a/tests/units/dripAssets.spec.js b/tests/units/dripAssets.spec.js index 48f8de0..d05d087 100644 --- a/tests/units/dripAssets.spec.js +++ b/tests/units/dripAssets.spec.js @@ -282,6 +282,7 @@ describe('dripAssets', ()=>{ mock({ call: { return: 'Wrapped Ether', to: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', api: Token['ethereum'].DEFAULT, method: 'name' }, provider: providerFor('ethereum'), blockchain: 'ethereum' }) mock({ call: { return: 'WETH', to: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', api: Token['ethereum'].DEFAULT, method: 'symbol' }, provider: providerFor('ethereum'), blockchain: 'ethereum' }) mock({ call: { return: 18, to: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', api: Token['ethereum'].DEFAULT, method: 'decimals' }, provider: providerFor('ethereum'), blockchain: 'ethereum' }) + mock({ call: { return: '0', to: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', api: Token['ethereum'].DEFAULT, method: 'balanceOf', params: accounts[0] }, provider: providerFor('ethereum'), blockchain: 'ethereum' }) mock({ call: { return: 'Wrapped BNB', to: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', api: Token['bsc'].DEFAULT, method: 'name' }, provider: providerFor('bsc'), blockchain: 'bsc' }) mock({ call: { return: 'BNB', to: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', api: Token['bsc'].DEFAULT, method: 'symbol' }, provider: providerFor('bsc'), blockchain: 'bsc' }) @@ -301,7 +302,7 @@ describe('dripAssets', ()=>{ } }) - expect(dripsCount).toEqual(20) + expect(dripsCount).toEqual(19) let expectedAssets = [ { @@ -320,14 +321,6 @@ describe('dripAssets', ()=>{ decimals: 18, balance: '56789' }, - { - blockchain: 'ethereum', - address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', - name: 'Wrapped Ether', - symbol: 'WETH', - decimals: 18, - balance: '123456789' - }, { blockchain: 'bsc', address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',