staker-hooks
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.getTokenPriceQueryUrl = exports.getTokenIdList = void 0; | ||
| var _toLower2 = _interopRequireDefault(require("lodash/toLower")); | ||
| var _coingecko_token_map = _interopRequireDefault(require("./coingecko_token_map.json")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| const getTokenIdList = (tokens = []) => { | ||
| return tokens.length > 0 ? tokens.map(symbol => _coingecko_token_map.default.find(entry => entry.symbol === (0, _toLower2.default)(symbol))).filter(entry => entry !== undefined) : []; | ||
| }; | ||
| exports.getTokenIdList = getTokenIdList; | ||
| const getTokenPriceQueryUrl = tokens => { | ||
| // console.log('tokens %O', TOKEN_MAP) | ||
| const tokenIdMap = getTokenIdList(tokens); // console.log('tokenIdMap %O', tokenIdMap) | ||
| const tokenNum = tokenIdMap.length; | ||
| const url = tokenNum > 0 ? `https://api.coingecko.com/api/v3/simple/price?ids=${tokenNum === 1 ? tokenIdMap[0].id : tokenIdMap.map(token => token.id).join('%2C')}&vs_currencies=usd` : ''; | ||
| return [url, tokenIdMap]; | ||
| }; | ||
| exports.getTokenPriceQueryUrl = getTokenPriceQueryUrl; |
| import _toLower from 'lodash/toLower' | ||
| import TOKEN_MAP from './coingecko_token_map.json' | ||
| export const getTokenIdList = (tokens = []) => { | ||
| return tokens.length > 0 | ||
| ? tokens.map((symbol) => | ||
| TOKEN_MAP.find((entry) => entry.symbol === _toLower(symbol)) | ||
| ) | ||
| .filter((entry) => entry !== undefined) | ||
| : [] | ||
| } | ||
| export const getTokenPriceQueryUrl = (tokens) => { | ||
| // console.log('tokens %O', TOKEN_MAP) | ||
| const tokenIdMap = getTokenIdList(tokens) | ||
| // console.log('tokenIdMap %O', tokenIdMap) | ||
| const tokenNum = tokenIdMap.length | ||
| const url = tokenNum > 0 | ||
| ? `https://api.coingecko.com/api/v3/simple/price?ids=${tokenNum === 1 ? tokenIdMap[0].id : tokenIdMap | ||
| .map((token) => token.id) | ||
| .join('%2C')}&vs_currencies=usd` | ||
| : '' | ||
| return [url, tokenIdMap] | ||
| } |
@@ -10,2 +10,4 @@ "use strict"; | ||
| var _providers = require("@ethersproject/providers"); | ||
| var _ethScan = require("@mycrypto/eth-scan"); | ||
@@ -32,3 +34,3 @@ | ||
| const nodeUrl = (0, _stakerFreenodes.getNodeURL)(chainId); | ||
| const nodeUrl = new _providers.JsonRpcProvider((0, _stakerFreenodes.getNodeURL)(chainId)); | ||
| const contractAddress = _stakerContracts.ETHSCAN_CONTRACT[chainId]; | ||
@@ -35,0 +37,0 @@ const tokenSymbol = _stakerContracts.CHAIN_BASETOKEN[chainId]; |
@@ -10,2 +10,4 @@ "use strict"; | ||
| var _providers = require("@ethersproject/providers"); | ||
| var _ethScan = require("@mycrypto/eth-scan"); | ||
@@ -32,3 +34,3 @@ | ||
| const nodeUrl = (0, _stakerFreenodes.getNodeURL)(chainId); | ||
| const nodeUrl = new _providers.JsonRpcProvider((0, _stakerFreenodes.getNodeURL)(chainId)); | ||
| const contractAddress = _stakerContracts.ETHSCAN_CONTRACT[chainId]; | ||
@@ -35,0 +37,0 @@ const tokens = Array.isArray(tokenMap) && tokenMap.length > 0 ? tokenMap : _stakerContracts.TOKEN_CONTRACTS[chainId]; |
@@ -10,7 +10,5 @@ "use strict"; | ||
| var _toLower2 = _interopRequireDefault(require("lodash/toLower")); | ||
| var _react2 = _interopRequireDefault(require("fast-deep-equal/react")); | ||
| var _coingecko_token_map = _interopRequireDefault(require("./coingecko_token_map.json")); | ||
| var _tokensPrice = require("./tokensPrice"); | ||
@@ -30,15 +28,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| tokensRef.current = tokens; | ||
| } | ||
| } // return [url, tokenIdMap] | ||
| const coingGeckoSimplePriceAPI = (0, _react.useCallback)(() => { | ||
| // console.log('tokens %O', TOKEN_MAP) | ||
| const tokenIdMap = tokens.map(symbol => _coingecko_token_map.default.find(entry => entry.symbol === (0, _toLower2.default)(symbol))).filter(entry => entry !== undefined); // console.log('tokenIdMap %O', tokenIdMap) | ||
| const tokenNum = tokenIdMap.length; | ||
| const url = tokenNum > 0 ? `https://api.coingecko.com/api/v3/simple/price?ids=${tokenNum === 1 ? tokenIdMap[0].id : tokenIdMap.map(token => token.id).join('%2C')}&vs_currencies=usd` : ''; | ||
| return [url, tokenIdMap]; | ||
| const getSimplePriceAPI = (0, _react.useCallback)(() => { | ||
| return (0, _tokensPrice.getTokenPriceQueryUrl)(tokensRef.current); | ||
| }, [tokensRef.current]); | ||
| (0, _react.useEffect)(() => { | ||
| async function getPrices() { | ||
| const [url, tokenIdMap] = coingGeckoSimplePriceAPI(tokens); | ||
| const [url, tokenIdMap] = getSimplePriceAPI(tokens); | ||
@@ -45,0 +39,0 @@ if (url) { |
+5
-4
| { | ||
| "name": "staker-hooks", | ||
| "version": "0.46.1", | ||
| "version": "0.47.0", | ||
| "description": "React Hooks for Ethereum and compatible chains", | ||
@@ -30,6 +30,7 @@ "files": [ | ||
| "dependencies": { | ||
| "@ethersproject/providers": "^5.1.2", | ||
| "@mycrypto/eth-scan": "^3.4.3", | ||
| "fast-deep-equal": "^3.1.3", | ||
| "staker-contracts": "^0.46.1", | ||
| "staker-freenodes": "^0.46.0" | ||
| "staker-contracts": "^0.47.0", | ||
| "staker-freenodes": "^0.47.0" | ||
| }, | ||
@@ -52,3 +53,3 @@ "peerDependencies": { | ||
| }, | ||
| "gitHead": "48d10661d6d128a8c645291e58929417dc065d15" | ||
| "gitHead": "d8a038726f0c543310abbf8e206cde4afd59c63f" | ||
| } |
| /* eslint-disable require-jsdoc */ | ||
| import {useEffect, useRef, useState} from 'react'; | ||
| import {JsonRpcProvider} from '@ethersproject/providers'; | ||
| import {getEtherBalances} from '@mycrypto/eth-scan'; | ||
@@ -18,3 +19,3 @@ import {getNodeURL, CHAIN_ETHEREUM} from 'staker-freenodes'; | ||
| const nodeUrl = getNodeURL(chainId); | ||
| const nodeUrl = new JsonRpcProvider(getNodeURL(chainId)); | ||
| const contractAddress = ETHSCAN_CONTRACT[chainId]; | ||
@@ -21,0 +22,0 @@ const tokenSymbol = CHAIN_BASETOKEN[chainId]; |
| /* eslint-disable require-jsdoc */ | ||
| import {useEffect, useRef, useState} from 'react'; | ||
| import {JsonRpcProvider} from '@ethersproject/providers'; | ||
| import {getTokensBalances} from '@mycrypto/eth-scan'; | ||
@@ -18,3 +19,3 @@ import {getNodeURL, CHAIN_ETHEREUM} from 'staker-freenodes' | ||
| const nodeUrl = getNodeURL(chainId); | ||
| const nodeUrl = new JsonRpcProvider(getNodeURL(chainId)); | ||
| const contractAddress = ETHSCAN_CONTRACT[chainId]; | ||
@@ -21,0 +22,0 @@ const tokens = Array.isArray(tokenMap) && tokenMap.length > 0 |
| import React, { useState, useEffect, useCallback, useRef } from 'react' | ||
| import _toLower from 'lodash/toLower' | ||
| import isDeepEqual from 'fast-deep-equal/react'; | ||
| import TOKEN_MAP from './coingecko_token_map.json' | ||
| import {getTokenPriceQueryUrl} from './tokensPrice' | ||
@@ -16,17 +15,5 @@ export const useTokensPrice = (tokens = [], fetch) => { | ||
| const coingGeckoSimplePriceAPI = useCallback(() => { | ||
| // console.log('tokens %O', TOKEN_MAP) | ||
| const tokenIdMap = tokens | ||
| .map((symbol) => | ||
| TOKEN_MAP.find((entry) => entry.symbol === _toLower(symbol)) | ||
| ) | ||
| .filter((entry) => entry !== undefined) | ||
| // console.log('tokenIdMap %O', tokenIdMap) | ||
| const tokenNum = tokenIdMap.length | ||
| const url = tokenNum > 0 | ||
| ? `https://api.coingecko.com/api/v3/simple/price?ids=${tokenNum === 1 ? tokenIdMap[0].id : tokenIdMap | ||
| .map((token) => token.id) | ||
| .join('%2C')}&vs_currencies=usd` | ||
| : '' | ||
| return [url, tokenIdMap] | ||
| // return [url, tokenIdMap] | ||
| const getSimplePriceAPI = useCallback(() => { | ||
| return getTokenPriceQueryUrl(tokensRef.current) | ||
| }, [tokensRef.current]) | ||
@@ -36,3 +23,3 @@ | ||
| async function getPrices() { | ||
| const [url, tokenIdMap] = coingGeckoSimplePriceAPI(tokens) | ||
| const [url, tokenIdMap] = getSimplePriceAPI(tokens) | ||
| if (url) { | ||
@@ -39,0 +26,0 @@ const data = await fetch(url, { |
769598
0.16%15
15.38%3254
0.84%6
20%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated
Updated