Skip to content

Commit

Permalink
v6.0.1: do not return assets with balance 0
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Apr 10, 2022
1 parent 45eb9d5 commit d53382c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 37 deletions.
30 changes: 21 additions & 9 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
})
}));

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

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

Expand All @@ -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) })
})
}))
Expand All @@ -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()
}
})
}
})
Expand Down
11 changes: 2 additions & 9 deletions tests/units/dripAssets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand All @@ -301,7 +302,7 @@ describe('dripAssets', ()=>{
}
})

expect(dripsCount).toEqual(20)
expect(dripsCount).toEqual(19)

let expectedAssets = [
{
Expand All @@ -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',
Expand Down

0 comments on commit d53382c

Please sign in to comment.