-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.0.0: extracted from depay-web3-wallets
- v8.2.1
- v7.4.1
- v7.4.0
- v7.3.1
- v7.3.0
- v7.2.0
- v7.1.3
- v7.1.2
- v7.1.1
- v7.1.0
- v7.0.0
- v6.9.1
- v6.9.0
- v6.8.0
- v6.7.0
- v6.6.2
- v6.6.1
- v6.6.0
- v6.5.4
- v6.5.3
- v6.5.2
- v6.5.1
- v6.5.0
- v6.3.0
- v6.2.1
- v6.2.0
- v6.1.5
- v6.1.4
- v6.1.3
- v6.1.2
- v6.1.1
- v6.1.0
- v6.0.2
- v6.0.1
- v6.0.0
- v5.4.1
- v5.4.0
- v5.3.2
- v5.3.1
- v5.3.0
- v5.2.0
- v5.1.0
- v5.0.0
- v4.0.2
- v4.0.1
- v4.0.0
- v3.0.0
- v2.2.0
- v2.1.0
- v2.0.1
- v2.0.0
- v1.1.1
- v1.1.0
- v1.0.0
0 parents
commit 1bcd2f5
Showing
23 changed files
with
5,279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: { | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: ['@babel/preset-env'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"pluginsFile": false, | ||
"supportFile": false, | ||
"fixturesFolder": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
|
||
}))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}) | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'regenerator-runtime/runtime' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
]) | ||
}) | ||
}) | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.