Skip to content

Commit

Permalink
Showing 23 changed files with 5,279 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
}
},
settings: {
},
extends: [
],
plugins: [],
root: true,
env: {
node: true
},
rules: {
},
}
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint

on: push

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: npm install
run: |
npm install
- name: yarn lint
run: |
yarn lint
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test

on: push

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: npm install
run: |
npm install
- name: npm run build
run: |
npm run build
- name: Run Tests
run: |
yarn test
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dependencies
/node_modules

# Jest
/coverage

# Cypress
/cypress/videos
/cypress/screenshots

# IDE - VSCode
.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# Various
npm-debug.log*
yarn-error.log
24 changes: 24 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# source code
src
index.html

# compiler
tsconfig.json
webpack.config.js
postcss.config.js


# tests
test
jest.config.js
coverage

# lint
.eslintrc.js
.prettierrc

# IDE - VSCode
.vscode

# git
.git
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 DePay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
124 changes: 124 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
## Quickstart

```
yarn add depay-web3-assets
```

or

```
npm install --save depay-web3-assets
```

```javascript
import { getAssets } from 'depay-web3-assets'

let assets = await getAssets({ apiKey: 'XXX' })
//[
// {
// "name": "Dai Stablecoin",
// "symbol": "DAI",
// "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
// "blockchain": "ethereum",
// "type": "ERC20",
// "balance": "8007804249707967889272"
// }, {
// "name": "DePay",
// "symbol": "DEPAY",
// "address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
// "blockchain": "ethereum",
// "type": "ERC20",
// "balance": "212816860003097638129"
// }, {
// "name": "PancakeSwap Token",
// "symbol": "CAKE",
// "address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
// "blockchain": "bsc",
// "type": "BEP20",
// "balance": "2221112213212321"
// }
//]
```

This requires you to have a [DePay PRO apiKey](https://depay.fi/documentation/api#introduction).

## Support

This library supports the following blockchains:

- [Ethereum](https://ethereum.org)
- [Binance Smart Chain](https://www.binance.org/en/smartChain)

This library supports the following wallets:

- [MetaMask](https://metamask.io)

## Functionalities

### getAssets

Retrieves all assets of the connected crypto wallet account for all supported blockchains at once.

This requires you to have a [DePay PRO apiKey](https://depay.fi/documentation/api#introduction).

```javascript

import { getAssets } from 'depay-web3-assets'

let assets = await getAssets({ apiKey: 'XXX' })
//[
// {
// "name": "Dai Stablecoin",
// "symbol": "DAI",
// "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
// "blockchain": "ethereum",
// "type": "ERC20",
// "balance": "8007804249707967889272"
// }, {
// "name": "DePay",
// "symbol": "DEPAY",
// "address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
// "blockchain": "ethereum",
// "type": "ERC20",
// "balance": "212816860003097638129"
// }, {
// "name": "PancakeSwap Token",
// "symbol": "CAKE",
// "address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
// "blockchain": "bsc",
// "type": "BEP20",
// "balance": "2221112213212321"
// }
//]
```

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

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

## Development

### Get started

```
yarn install
yarn dev
```

### Release

```
npm publish
```
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@babel/preset-env'],
};
5 changes: 5 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"pluginsFile": false,
"supportFile": false,
"fixturesFolder": false
}
21 changes: 21 additions & 0 deletions dev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/png" href="https://depay.fi/favicon.png"/>
<title>Development</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdn.ethers.io/lib/ethers-5.4.umd.min.js" type="application/javascript"></script>
<script crossorigin src="https://unpkg.com/depay-web3-constants@3/dist/umd/index.js"></script>
<script crossorigin src="https://unpkg.com/depay-web3-blockchains@2/dist/umd/index.js"></script>
<script crossorigin src="https://unpkg.com/depay-web3-client@3/dist/umd/index.js"></script>
<script crossorigin src="https://unpkg.com/depay-web3-wallets@5/dist/umd/index.js"></script>
<script src="dist/umd/index.js"></script>
</head>
<body>
<div class="container">

</div>
</body>
</html>
64 changes: 64 additions & 0 deletions dist/cjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var depayWeb3Constants = require('depay-web3-constants');
var depayWeb3Wallets = require('depay-web3-wallets');
var depayWeb3Client = require('depay-web3-client');

const ensureNativeTokenAsset = async ({ account, assets, blockchain }) => {
if(assets.find((asset)=> {
return asset.address.toLowerCase() == depayWeb3Constants.CONSTANTS[blockchain].NATIVE.toLowerCase()
}) == undefined) {
let balance = await depayWeb3Client.request(
{
blockchain: blockchain,
address: account,
method: 'balance',
},
{ cache: 30000 }
);
assets = [{
name: depayWeb3Constants.CONSTANTS[blockchain].CURRENCY,
symbol: depayWeb3Constants.CONSTANTS[blockchain].SYMBOL,
address: depayWeb3Constants.CONSTANTS[blockchain].NATIVE,
type: 'NATIVE',
blockchain,
balance: balance.toString()
}, ...assets];
}
return assets
};

const getAssets = async (options) => {
if(options === undefined) { options = {}; }

let wallet = await depayWeb3Wallets.getWallet();
if (!wallet) { return }

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

if(options.apiKey == undefined) { throw 'Web3Wallets: Please pass an apiKey. See documentation.' }

let assets = Promise.all(
(options.blockchain ? [options.blockchain] : wallet.blockchains).map((blockchain) =>{

return fetch('https://api.depay.pro/v1/assets?account=' + account + '&blockchain=' + blockchain, {
headers: { 'X-Api-Key': options.apiKey }
})
.then((response) => response.json())
.then(async (assets) => {
return await ensureNativeTokenAsset({
account,
assets: assets.map((asset) => Object.assign(asset, { blockchain })),
blockchain
})
})
}),
).then((responses) => responses.flat());

return assets
};

exports.getAssets = getAssets;
60 changes: 60 additions & 0 deletions dist/es/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { CONSTANTS } from 'depay-web3-constants';
import { getWallet } from 'depay-web3-wallets';
import { request } from 'depay-web3-client';

const ensureNativeTokenAsset = async ({ account, assets, blockchain }) => {
if(assets.find((asset)=> {
return asset.address.toLowerCase() == CONSTANTS[blockchain].NATIVE.toLowerCase()
}) == undefined) {
let balance = await request(
{
blockchain: blockchain,
address: account,
method: 'balance',
},
{ cache: 30000 }
);
assets = [{
name: CONSTANTS[blockchain].CURRENCY,
symbol: CONSTANTS[blockchain].SYMBOL,
address: CONSTANTS[blockchain].NATIVE,
type: 'NATIVE',
blockchain,
balance: balance.toString()
}, ...assets];
}
return assets
};

const getAssets = async (options) => {
if(options === undefined) { options = {}; }

let wallet = await getWallet();
if (!wallet) { return }

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

if(options.apiKey == undefined) { throw 'Web3Wallets: Please pass an apiKey. See documentation.' }

let assets = Promise.all(
(options.blockchain ? [options.blockchain] : wallet.blockchains).map((blockchain) =>{

return fetch('https://api.depay.pro/v1/assets?account=' + account + '&blockchain=' + blockchain, {
headers: { 'X-Api-Key': options.apiKey }
})
.then((response) => response.json())
.then(async (assets) => {
return await ensureNativeTokenAsset({
account,
assets: assets.map((asset) => Object.assign(asset, { blockchain })),
blockchain
})
})
}),
).then((responses) => responses.flat());

return assets
};

export { getAssets };
66 changes: 66 additions & 0 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('depay-web3-constants'), require('depay-web3-wallets'), require('depay-web3-client')) :
typeof define === 'function' && define.amd ? define(['exports', 'depay-web3-constants', 'depay-web3-wallets', 'depay-web3-client'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Web3Assets = {}, global.Web3Constants, global.Web3Wallets, global.Web3Client));
}(this, (function (exports, depayWeb3Constants, depayWeb3Wallets, depayWeb3Client) { 'use strict';

const ensureNativeTokenAsset = async ({ account, assets, blockchain }) => {
if(assets.find((asset)=> {
return asset.address.toLowerCase() == depayWeb3Constants.CONSTANTS[blockchain].NATIVE.toLowerCase()
}) == undefined) {
let balance = await depayWeb3Client.request(
{
blockchain: blockchain,
address: account,
method: 'balance',
},
{ cache: 30000 }
);
assets = [{
name: depayWeb3Constants.CONSTANTS[blockchain].CURRENCY,
symbol: depayWeb3Constants.CONSTANTS[blockchain].SYMBOL,
address: depayWeb3Constants.CONSTANTS[blockchain].NATIVE,
type: 'NATIVE',
blockchain,
balance: balance.toString()
}, ...assets];
}
return assets
};

const getAssets = async (options) => {
if(options === undefined) { options = {}; }

let wallet = await depayWeb3Wallets.getWallet();
if (!wallet) { return }

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

if(options.apiKey == undefined) { throw 'Web3Wallets: Please pass an apiKey. See documentation.' }

let assets = Promise.all(
(options.blockchain ? [options.blockchain] : wallet.blockchains).map((blockchain) =>{

return fetch('https://api.depay.pro/v1/assets?account=' + account + '&blockchain=' + blockchain, {
headers: { 'X-Api-Key': options.apiKey }
})
.then((response) => response.json())
.then(async (assets) => {
return await ensureNativeTokenAsset({
account,
assets: assets.map((asset) => Object.assign(asset, { blockchain })),
blockchain
})
})
}),
).then((responses) => responses.flat());

return assets
};

exports.getAssets = getAssets;

Object.defineProperty(exports, '__esModule', { value: true });

})));
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['/node_modules/', '.git'],
setupFiles: ['./tests/setup.js'],
automock: false,
modulePaths: ['<rootDir>']
};
68 changes: 68 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "depay-web3-assets",
"moduleName": "Web3Assets",
"version": "1.0.0",
"description": "",
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
"source": "src/index.js",
"files": [
"dist"
],
"scripts": {
"build": "rm -rf dist && rollup -c rollup.module.config.js",
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
"lint:fix": "eslint \"src/**/*.{js,jsx,ts,tsx}\" --fix",
"prepublishOnly": "yarn build",
"dev": "rollup -c rollup.dev.config.js -w",
"test:units": "yarn build && npx jest --no-cache",
"test": "yarn test:units"
},
"repository": "git@github.com:DePayFi/depay-web3-assets.git",
"keywords": [
"web3",
"assets",
"tokens",
"crypto",
"blockchain"
],
"author": "depay.fi",
"license": "MIT",
"bugs": {
"url": "https://github.com/DePayFi/depay-web3-assets/issues"
},
"homepage": "https://github.com/DePayFi/depay-web3-assets#readme",
"private": false,
"dependencies": {
"depay-web3-blockchains": "^2.1.0",
"depay-web3-client": "^4.0.2",
"depay-web3-constants": "^3.0.0",
"depay-web3-wallets": "^5.0.0"
},
"peerDependencies": {},
"engines": {
"node": ">=10"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/preset-env": "^7.12.7",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-replace": "^2.4.2",
"@rollup/plugin-sucrase": "^3.1.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.2",
"babel-preset-env": "^1.7.0",
"depay-web3-mock": "^5.3.0",
"eslint": "^7.15.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.22.1",
"fetch-mock": "^9.11.0",
"node-fetch": "^2.6.1",
"regenerator-runtime": "^0.13.7",
"rollup": "^2.34.2",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-serve": "^1.1.0"
}
}
35 changes: 35 additions & 0 deletions rollup.dev.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import commonjs from '@rollup/plugin-commonjs'
import livereload from 'rollup-plugin-livereload'
import replace from '@rollup/plugin-replace'
import resolve from '@rollup/plugin-node-resolve'
import rollup from './rollup.module.config.js'
import serve from 'rollup-plugin-serve'
import sucrase from '@rollup/plugin-sucrase'
import { nodeResolve } from '@rollup/plugin-node-resolve'

export default Object.assign({}, rollup, {
plugins: [
sucrase({
exclude: ['node_modules/**'],
transforms: ['typescript', 'jsx']
}),
resolve({
extensions: ['.js', '.ts', '.jsx']
}),
nodeResolve(),
commonjs({
include: 'node_modules/**'
}),
replace({
'process.env.NODE_ENV': JSON.stringify( 'production' ),
preventAssignment: true
}),
serve({
open: 'true',
openPage: '/dev.html'
}),
livereload({
watch: 'dist'
})
],
})
6 changes: 6 additions & 0 deletions rollup.globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
'depay-web3-blockchains': 'Web3Blockchains',
'depay-web3-constants': 'Web3Constants',
'depay-web3-client': 'Web3Client',
'depay-web3-wallets': 'Web3Wallets',
}
52 changes: 52 additions & 0 deletions rollup.module.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import commonjs from '@rollup/plugin-commonjs'
import del from 'rollup-plugin-delete'
import globals from './rollup.globals'
import pkg from './package.json'
import replace from '@rollup/plugin-replace'
import resolve from '@rollup/plugin-node-resolve'
import sucrase from '@rollup/plugin-sucrase'
import { nodeResolve } from '@rollup/plugin-node-resolve'

export default {
input: 'src/index.js',
output: [
{
format: 'cjs',
globals: globals,
file: 'dist/cjs/index.js'
},
{
format: 'es',
globals: globals,
file: 'dist/es/index.js'
},
{
format: 'umd',
name: pkg.moduleName,
globals: globals,
file: 'dist/umd/index.js'
},
],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
plugins: [
del({ targets: 'dist/*' }),
sucrase({
exclude: ['node_modules/**'],
transforms: ['jsx']
}),
resolve({
extensions: ['.js', '.jsx']
}),
nodeResolve(),
commonjs({
include: 'node_modules/**'
}),
replace({
'process.env.NODE_ENV': JSON.stringify( 'production' ),
preventAssignment: true
})
]
}
60 changes: 60 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { CONSTANTS } from 'depay-web3-constants'
import { getWallet } from 'depay-web3-wallets'
import { request } from 'depay-web3-client'

const ensureNativeTokenAsset = async ({ account, assets, blockchain }) => {
if(assets.find((asset)=> {
return asset.address.toLowerCase() == CONSTANTS[blockchain].NATIVE.toLowerCase()
}) == undefined) {
let balance = await request(
{
blockchain: blockchain,
address: account,
method: 'balance',
},
{ cache: 30000 }
)
assets = [{
name: CONSTANTS[blockchain].CURRENCY,
symbol: CONSTANTS[blockchain].SYMBOL,
address: CONSTANTS[blockchain].NATIVE,
type: 'NATIVE',
blockchain,
balance: balance.toString()
}, ...assets]
}
return assets
}

const getAssets = async (options) => {
if(options === undefined) { options = {} }

let wallet = await getWallet()
if (!wallet) { return }

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

if(options.apiKey == undefined) { throw 'Web3Wallets: Please pass an apiKey. See documentation.' }

let assets = Promise.all(
(options.blockchain ? [options.blockchain] : undefined || wallet.blockchains).map((blockchain) =>{

return fetch('https://api.depay.pro/v1/assets?account=' + account + '&blockchain=' + blockchain, {
headers: { 'X-Api-Key': options.apiKey }
})
.then((response) => response.json())
.then(async (assets) => {
return await ensureNativeTokenAsset({
account,
assets: assets.map((asset) => Object.assign(asset, { blockchain })),
blockchain
})
})
}),
).then((responses) => responses.flat())

return assets
}

export { getAssets }
1 change: 1 addition & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'regenerator-runtime/runtime'
Empty file added tests/units/.gitkeep
Empty file.
124 changes: 124 additions & 0 deletions tests/units/getAssets.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import fetchMock from 'fetch-mock'
import { getAssets } from 'src'
import { mock, resetMocks } from 'depay-web3-mock'

describe('assets', ()=>{

beforeEach(()=>fetchMock.reset())
beforeEach(resetMocks)
afterEach(resetMocks)

it('raises an error if api key is not set', async ()=>{
mock('ethereum')
global.fetch = jest.fn()
await expect(
()=>getAssets()
).rejects.toEqual('Web3Wallets: Please pass an apiKey. See documentation.')
})

describe('fetch assets', ()=>{

beforeEach(()=>{
mock({ blockchain: 'ethereum', wallet: 'metamask' })
fetchMock.get({
url: 'https://api.depay.pro/v1/assets?account=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&blockchain=ethereum',
headers: { 'X-Api-Key': 'TEST-123' }
}, [{
"name": "Ether",
"symbol": "ETH",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"type": "NATIVE"
}, {
"name": "Dai Stablecoin",
"symbol": "DAI",
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"type": "ERC20"
}]
)
fetchMock.get({
url: 'https://api.depay.pro/v1/assets?account=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&blockchain=bsc',
headers: { 'X-Api-Key': 'TEST-123' }
}, [{
"name": "Binance Coin",
"symbol": "BNB",
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"type": "NATIVE"
}, {
"name": "PancakeSwap",
"symbol": "CAKE",
"address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
"type": "BEP20"
}]
)
})

it('fetches all assets for all supported blockchains that the connected wallet supports', async ()=> {
let assets = await getAssets({ apiKey: 'TEST-123' })
expect(assets).toEqual([
{
name: 'Ether',
symbol: 'ETH',
address: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
type: 'NATIVE',
blockchain: 'ethereum'
},
{
name: 'Dai Stablecoin',
symbol: 'DAI',
address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
type: 'ERC20',
blockchain: 'ethereum'
},
{
name: 'Binance Coin',
symbol: 'BNB',
address: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
type: 'NATIVE',
blockchain: 'bsc'
},
{
name: 'PancakeSwap',
symbol: 'CAKE',
address: '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82',
type: 'BEP20',
blockchain: 'bsc'
}
])
})

it('fetches only the assets of the given blockchain', async()=> {
expect(await getAssets({ blockchain: 'ethereum', apiKey: 'TEST-123' })).toEqual([
{
name: 'Ether',
symbol: 'ETH',
address: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
type: 'NATIVE',
blockchain: 'ethereum'
},
{
name: 'Dai Stablecoin',
symbol: 'DAI',
address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
type: 'ERC20',
blockchain: 'ethereum'
}
])
expect(await getAssets({ blockchain: 'bsc', apiKey: 'TEST-123' })).toEqual([
{
name: 'Binance Coin',
symbol: 'BNB',
address: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
type: 'NATIVE',
blockchain: 'bsc'
},
{
name: 'PancakeSwap',
symbol: 'CAKE',
address: '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82',
type: 'BEP20',
blockchain: 'bsc'
}
])
})
})
})
4,430 changes: 4,430 additions & 0 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 1bcd2f5

Please sign in to comment.