Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
shared files for seeing account balances
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Jul 10, 2018
0 parents commit c350e2a
Show file tree
Hide file tree
Showing 27 changed files with 4,008 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"plugins": ["prettier"],
"extends": ["react-app", "prettier"],
"rules": {
"jsx-a11y/href-no-hash": "off",
"array-callback-return": "off",
"prettier/prettier": "error"
},
"globals": {
"document": true,
"window": true
}
}
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

IGNORE_*
package-lock.json
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"parser": "flow"
}
676 changes: 676 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "balance-common",
"description": "Common library for web and mobile",
"version": "0.1.0",
"author": "Jin Chung <[email protected]>",
"license": "GPL-3",
"repository": {
"type": "git",
"url": "https://github.com/balance-io/balance-common.git"
},
"bugs": {
"url": "https://github.com/balance-io/balance-common/issues"
},
"dependencies": {
"axios": "^0.18.0",
"bignumber.js": "^7.0.1",
"i18next": "^11.3.2",
"jsonp": "^0.2.1",
"lodash": "^4.17.5",
"redux": "^4.0.0"
},
"scripts": {
"precommit": "lint-staged",
"format": "prettier --write \"src/**/*.js\"",
"lint": "eslint src --ext .js"
},
"lint-staged": {
"src/**/*.js": [
"eslint src --ext .js",
"prettier --write",
"git add"
]
},
"devDependencies": {
"babel-eslint": "^8.2.2",
"cross-env": "^5.2.0",
"eslint-config-prettier": "^2.9.0",
"eslint-config-react-app": "^2.1.0",
"eslint-plugin-flowtype": "^2.46.1",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.7.0",
"husky": "^0.14.3",
"lint-staged": "^7.1.0",
"prettier": "^1.13.5"
}
}
67 changes: 67 additions & 0 deletions src/handlers/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import axios from 'axios';
import { parseAccountAssets } from './parsers';
import nativeCurrencies from '../references/native-currencies.json';

const cryptocompareApiKey = process.env.REACT_APP_CRYPTOCOMPARE_API_KEY || '';

/**
* Configuration for cryptocompare api
* @type axios instance
*/
const cryptocompare = axios.create({
baseURL: 'https://min-api.cryptocompare.com/data/',
timeout: 30000, // 30 secs
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
});

/**
* @desc get all assets prices
* @param {Array} [asset=[]]
* @return {Promise}
*/
export const apiGetPrices = (assets = []) => {
const assetsQuery = JSON.stringify(assets).replace(/[[\]"]/gi, '');
const nativeQuery = JSON.stringify(Object.keys(nativeCurrencies)).replace(
/[[\]"]/gi,
'',
);
return cryptocompare.get(
`/pricemultifull?fsyms=${assetsQuery}&tsyms=${nativeQuery}&apiKey=${cryptocompareApiKey}`,
);
};

/**
* Configuration for balance api
* @type axios instance
*/
const api = axios.create({
baseURL: 'https://indexer.balance.io',
timeout: 30000, // 30 secs
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
});

/**
* @desc get account balances
* @param {String} [address = '']
* @param {String} [network = 'mainnet']
* @return {Promise}
*/
export const apiGetAccountBalances = async (
address = '',
network = 'mainnet',
) => {
try {
const { data } = await api.get(`/get_balances/${network}/${address}`);
const accountInfo = parseAccountAssets(data, address);
const result = { data: accountInfo };
return result;
} catch (error) {
throw error;
}
};
28 changes: 28 additions & 0 deletions src/handlers/opensea-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import axios from 'axios';
import { parseAccountUniqueTokens } from './parsers';

const openseaApiKey = process.env.REACT_APP_OPENSEA_API_KEY || '';

/**
* Configuration for opensea api
* @type axios instance
*/
const api = axios.create({
baseURL: 'https://api.opensea.io/api/v1',
timeout: 30000, // 30 secs
headers: {
Accept: 'application/json',
'X-API-KEY': openseaApiKey,
},
});

/**
* @desc get opensea unique tokens
* @param {String} [address='']
* @return {Promise}
*/
export const apiGetAccountUniqueTokens = async (address = '') => {
const data = await api.get(`/assets?owner=${address}`);
const result = parseAccountUniqueTokens(data);
return result;
};
Loading

0 comments on commit c350e2a

Please sign in to comment.