From c7760343e40eb8bf9d07a2fefc55a571275d22e0 Mon Sep 17 00:00:00 2001 From: Sebastian Pape Date: Sun, 20 Aug 2023 15:24:30 +0200 Subject: [PATCH] v7.1.2: fix asset meta data completion (decimals, name etc.) --- dist/esm/index.evm.js | 14 ++++++++++++-- dist/esm/index.js | 14 ++++++++++++-- dist/esm/index.solana.js | 14 ++++++++++++-- dist/umd/index.evm.js | 14 ++++++++++++-- dist/umd/index.js | 14 ++++++++++++-- dist/umd/index.solana.js | 14 ++++++++++++-- examples/drip.md | 17 +++++++++++++++++ package.evm.json | 2 +- package.json | 2 +- package.solana.json | 2 +- src/dripAssets.js | 14 ++++++++++++-- 11 files changed, 104 insertions(+), 17 deletions(-) diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index 6e97612..092d869 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -230,11 +230,21 @@ 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)=>{ + const token = new Token(asset); + return token.balance(options.accounts[asset.blockchain]) + .then(async(balance)=>{ if(exists({ assets, asset })) { return resolve() } const assetWithBalance = reduceAssetWithBalance(asset, balance); if(assetWithBalance.balance != '0') { + if(assetWithBalance.name === undefined) { + assetWithBalance.name = await token.name(); + } + if(assetWithBalance.symbol === undefined) { + assetWithBalance.symbol = await token.symbol(); + } + if(assetWithBalance.decimals === undefined) { + assetWithBalance.decimals = await token.decimals(); + } assets.push(assetWithBalance); drip(assetWithBalance); resolve(assetWithBalance); diff --git a/dist/esm/index.js b/dist/esm/index.js index 8cdc901..879bfbf 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -230,11 +230,21 @@ 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)=>{ + const token = new Token(asset); + return token.balance(options.accounts[asset.blockchain]) + .then(async(balance)=>{ if(exists({ assets, asset })) { return resolve() } const assetWithBalance = reduceAssetWithBalance(asset, balance); if(assetWithBalance.balance != '0') { + if(assetWithBalance.name === undefined) { + assetWithBalance.name = await token.name(); + } + if(assetWithBalance.symbol === undefined) { + assetWithBalance.symbol = await token.symbol(); + } + if(assetWithBalance.decimals === undefined) { + assetWithBalance.decimals = await token.decimals(); + } assets.push(assetWithBalance); drip(assetWithBalance); resolve(assetWithBalance); diff --git a/dist/esm/index.solana.js b/dist/esm/index.solana.js index e29b5d3..071a556 100644 --- a/dist/esm/index.solana.js +++ b/dist/esm/index.solana.js @@ -230,11 +230,21 @@ 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)=>{ + const token = new Token(asset); + return token.balance(options.accounts[asset.blockchain]) + .then(async(balance)=>{ if(exists({ assets, asset })) { return resolve() } const assetWithBalance = reduceAssetWithBalance(asset, balance); if(assetWithBalance.balance != '0') { + if(assetWithBalance.name === undefined) { + assetWithBalance.name = await token.name(); + } + if(assetWithBalance.symbol === undefined) { + assetWithBalance.symbol = await token.symbol(); + } + if(assetWithBalance.decimals === undefined) { + assetWithBalance.decimals = await token.decimals(); + } assets.push(assetWithBalance); drip(assetWithBalance); resolve(assetWithBalance); diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index 132735b..ba80886 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -237,11 +237,21 @@ let allAssets = await getAssets(options); promises = promises.concat((allAssets.map((asset)=>{ return new Promise((resolve, reject)=>{ - return new Token__default['default'](asset).balance(options.accounts[asset.blockchain]) - .then((balance)=>{ + const token = new Token__default['default'](asset); + return token.balance(options.accounts[asset.blockchain]) + .then(async(balance)=>{ if(exists({ assets, asset })) { return resolve() } const assetWithBalance = reduceAssetWithBalance(asset, balance); if(assetWithBalance.balance != '0') { + if(assetWithBalance.name === undefined) { + assetWithBalance.name = await token.name(); + } + if(assetWithBalance.symbol === undefined) { + assetWithBalance.symbol = await token.symbol(); + } + if(assetWithBalance.decimals === undefined) { + assetWithBalance.decimals = await token.decimals(); + } assets.push(assetWithBalance); drip(assetWithBalance); resolve(assetWithBalance); diff --git a/dist/umd/index.js b/dist/umd/index.js index 966db73..516920f 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -237,11 +237,21 @@ let allAssets = await getAssets(options); promises = promises.concat((allAssets.map((asset)=>{ return new Promise((resolve, reject)=>{ - return new Token__default['default'](asset).balance(options.accounts[asset.blockchain]) - .then((balance)=>{ + const token = new Token__default['default'](asset); + return token.balance(options.accounts[asset.blockchain]) + .then(async(balance)=>{ if(exists({ assets, asset })) { return resolve() } const assetWithBalance = reduceAssetWithBalance(asset, balance); if(assetWithBalance.balance != '0') { + if(assetWithBalance.name === undefined) { + assetWithBalance.name = await token.name(); + } + if(assetWithBalance.symbol === undefined) { + assetWithBalance.symbol = await token.symbol(); + } + if(assetWithBalance.decimals === undefined) { + assetWithBalance.decimals = await token.decimals(); + } assets.push(assetWithBalance); drip(assetWithBalance); resolve(assetWithBalance); diff --git a/dist/umd/index.solana.js b/dist/umd/index.solana.js index b46204a..7f71d53 100644 --- a/dist/umd/index.solana.js +++ b/dist/umd/index.solana.js @@ -237,11 +237,21 @@ let allAssets = await getAssets(options); promises = promises.concat((allAssets.map((asset)=>{ return new Promise((resolve, reject)=>{ - return new Token__default['default'](asset).balance(options.accounts[asset.blockchain]) - .then((balance)=>{ + const token = new Token__default['default'](asset); + return token.balance(options.accounts[asset.blockchain]) + .then(async(balance)=>{ if(exists({ assets, asset })) { return resolve() } const assetWithBalance = reduceAssetWithBalance(asset, balance); if(assetWithBalance.balance != '0') { + if(assetWithBalance.name === undefined) { + assetWithBalance.name = await token.name(); + } + if(assetWithBalance.symbol === undefined) { + assetWithBalance.symbol = await token.symbol(); + } + if(assetWithBalance.decimals === undefined) { + assetWithBalance.decimals = await token.decimals(); + } assets.push(assetWithBalance); drip(assetWithBalance); resolve(assetWithBalance); diff --git a/examples/drip.md b/examples/drip.md index 8ab4154..35537d4 100644 --- a/examples/drip.md +++ b/examples/drip.md @@ -18,3 +18,20 @@ let allAssets = await Web3Assets.dripAssets({ console.log('allAssets', allAssets) ``` + + +```javascript +let allAssets = await Web3Assets.dripAssets({ + accounts: { + solana: '2UgCJaHU5y8NC4uWQcZYeV9a5RyYLF7iKYCybCsdFFD1', + }, + priority: [ + { blockchain: 'solana', address: Web3Blockchains.solana.currency.address }, + ], + drip: (asset)=>{ + console.log('drip asset', asset) + } +}) + +console.log('allAssets', allAssets) +``` diff --git a/package.evm.json b/package.evm.json index 04f97fe..7d0c551 100644 --- a/package.evm.json +++ b/package.evm.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-assets-evm", "moduleName": "Web3Assets", - "version": "7.1.1", + "version": "7.1.2", "description": "JavaScript library to retrieve Web3 assets of a given or connected wallet/account.", "main": "dist/umd/index.evm.js", "module": "dist/esm/index.evm.js", diff --git a/package.json b/package.json index 0abe355..ff0d1aa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-assets", "moduleName": "Web3Assets", - "version": "7.1.1", + "version": "7.1.2", "description": "JavaScript library to retrieve Web3 assets of a given or connected wallet/account.", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/package.solana.json b/package.solana.json index 59e6a2e..e9615d3 100644 --- a/package.solana.json +++ b/package.solana.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-assets-solana", "moduleName": "Web3Assets", - "version": "7.1.1", + "version": "7.1.2", "description": "JavaScript library to retrieve Web3 assets of a given or connected wallet/account.", "main": "dist/umd/index.solana.js", "module": "dist/esm/index.solana.js", diff --git a/src/dripAssets.js b/src/dripAssets.js index 11b6c25..61e352b 100644 --- a/src/dripAssets.js +++ b/src/dripAssets.js @@ -162,11 +162,21 @@ 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)=>{ + const token = new Token(asset) + return token.balance(options.accounts[asset.blockchain]) + .then(async(balance)=>{ if(exists({ assets, asset })) { return resolve() } const assetWithBalance = reduceAssetWithBalance(asset, balance) if(assetWithBalance.balance != '0') { + if(assetWithBalance.name === undefined) { + assetWithBalance.name = await token.name() + } + if(assetWithBalance.symbol === undefined) { + assetWithBalance.symbol = await token.symbol() + } + if(assetWithBalance.decimals === undefined) { + assetWithBalance.decimals = await token.decimals() + } assets.push(assetWithBalance) drip(assetWithBalance) resolve(assetWithBalance)