Skip to content

Commit

Permalink
1.1.0: allows to provide account address fetching assets for
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Aug 31, 2021
1 parent 1bcd2f5 commit 78102c1
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 5 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ let assets = await getAssets({ blockchain: 'bsc', apiKey: 'XXX' })
//]
```

Also allows you to retrieve assets for a given account for a given blockchain:

```javascript
let assets = await getAssets({ account: '0xEcA533Ef096f191A35DE76aa4580FA3A722724bE', blockchain: 'bsc', apiKey: 'XXX' })
//[
// {
// "name": "PancakeSwap Token",
// "symbol": "CAKE",
// "address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
// "blockchain": "bsc",
// "type": "BEP20",
// "balance": "2221112213212321"
// }
//]
```

## Development

### Get started
Expand Down
7 changes: 6 additions & 1 deletion dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ const getAssets = async (options) => {
let wallet = await depayWeb3Wallets.getWallet();
if (!wallet) { return }

let account = await wallet.account();
let account;
if(options.account) {
account = options.account;
} else {
account = await wallet.account();
}
if (!account) { return }

if(options.apiKey == undefined) { throw 'Web3Wallets: Please pass an apiKey. See documentation.' }
Expand Down
7 changes: 6 additions & 1 deletion dist/es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ const getAssets = async (options) => {
let wallet = await getWallet();
if (!wallet) { return }

let account = await wallet.account();
let account;
if(options.account) {
account = options.account;
} else {
account = await wallet.account();
}
if (!account) { return }

if(options.apiKey == undefined) { throw 'Web3Wallets: Please pass an apiKey. See documentation.' }
Expand Down
7 changes: 6 additions & 1 deletion dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
let wallet = await depayWeb3Wallets.getWallet();
if (!wallet) { return }

let account = await wallet.account();
let account;
if(options.account) {
account = options.account;
} else {
account = await wallet.account();
}
if (!account) { return }

if(options.apiKey == undefined) { throw 'Web3Wallets: Please pass an apiKey. See documentation.' }
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": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ const getAssets = async (options) => {
let wallet = await getWallet()
if (!wallet) { return }

let account = await wallet.account()
let account
if(options.account) {
account = options.account
} else {
account = await wallet.account()
}
if (!account) { return }

if(options.apiKey == undefined) { throw 'Web3Wallets: Please pass an apiKey. See documentation.' }
Expand Down
38 changes: 38 additions & 0 deletions tests/units/getAssets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,43 @@ describe('assets', ()=>{
}
])
})

it('fetches the assets for a given account', async()=> {
let account = '0xEcA533Ef096f191A35DE76aa4580FA3A722724bE'
fetchMock.get({
url: `https://api.depay.pro/v1/assets?account=${account}&blockchain=ethereum`,
headers: { 'X-Api-Key': 'TEST-123' }
}, [{
"name": "Ether",
"symbol": "ETH",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"type": "NATIVE",
"balance": "1300000000000000000"
}, {
"name": "DePay",
"symbol": "DEPAY",
"address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
"type": "ERC20",
"balance": "1000000000000000000"
}]
)
expect(await getAssets({ account, blockchain: 'ethereum', apiKey: 'TEST-123' })).toEqual([
{
"blockchain": "ethereum",
"name": "Ether",
"symbol": "ETH",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"type": "NATIVE",
"balance": "1300000000000000000"
}, {
"blockchain": "ethereum",
"name": "DePay",
"symbol": "DEPAY",
"address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
"type": "ERC20",
"balance": "1000000000000000000"
}
])
})
})
})

0 comments on commit 78102c1

Please sign in to comment.