From 46db3ae22b1ad04fe08150957d9d2801d51e3332 Mon Sep 17 00:00:00 2001 From: shendel Date: Tue, 19 Sep 2023 14:16:59 +0300 Subject: [PATCH] show pools info --- src/state/pools/updater.ts | 218 ++++++++++--------------------- src/utils/bridge/getBalanceV2.ts | 5 +- 2 files changed, 72 insertions(+), 151 deletions(-) diff --git a/src/state/pools/updater.ts b/src/state/pools/updater.ts index 7a3f1d1c..8dbcabd6 100644 --- a/src/state/pools/updater.ts +++ b/src/state/pools/updater.ts @@ -1,163 +1,85 @@ +// @ts-nocheck import { useCallback } from 'react' import useInterval from '../../hooks/useInterval' // import { useDispatch } from 'react-redux' import { useDispatch } from 'react-redux' // import axios from 'axios' // import config from '../../config' -// import { useAppState } from '../../state/application/hooks' -import {poolLiquidity} from './actions' +import { useAppState } from '../../state/application/hooks' +import { poolLiquidity } from './actions' +import { getUrlData } from '../../utils/tools/axios' +import { getNodeTotalsupply, getBlandTs } from '../../utils/bridge/getBalanceV2' +import { useActiveWeb3React } from '../../hooks' export default function Updater(): null { const dispatch = useDispatch() - console.log('>>> call state/pools/update') - // const { apiAddress } = useAppState() + + const { apiAddress } = useAppState() const getPools = useCallback(() => { - /* - axios.get(`${apiAddress}/data/router/pools`).then(res => { - const {status, data } = res - if (status === 200) { - const testData = { - "1": { - "0xdac17f958d2ee523a2206206994597c13d831ec7": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "TetherUSD", - "symbol": "USDT", - "decimals": 6, - "anyToken": "0x22648c12acd87912ea1710357b1302c6a4154ebc", - "liquidity": "9009221334195" - } - }, - "56": { - "0x55d398326f99059ff775485246999027b3197955": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "TetherUSD", - "symbol": "USDT", - "decimals": 18, - "anyToken": "0xedf0c420bc3b92b961c6ec411cc810ca81f5f21a", - "liquidity": "5756135762036213167560" - } - }, - "66": { - "0x382bb369d343125bfb2117af9c149795c6c65c50": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "USDT", - "symbol": "USDT", - "decimals": 18, - "anyToken": "0x0dcb0cb0120d355cde1ce56040be57add0185baa", - "liquidity": "8358674931031277832025" - } - }, - "128": { - "0xa71edc38d189767582c38a3145b5873052c3e47a": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "Heco-Peg USDT Token", - "symbol": "USDT", - "decimals": 18, - "anyToken": "0xfea7a6a0b346362bf88a9e4a88416b77a57d6c2a", - "liquidity": "2210305595209176178171" - } - }, - "137": { - "0xc2132d05d31c914a87c6611c10748aeb04b58e8f": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "(PoS)TetherUSD", - "symbol": "USDT", - "decimals": 6, - "anyToken": "0xe3eeda11f06a656fcaee19de663e84c7e61d3cac", - "liquidity": "24406406214" - } - }, - "250": { - "0x049d68029688eabf473097a2fc38ef61633a3c7a": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "FrappedUSDT", - "symbol": "fUSDT", - "decimals": 6, - "anyToken": "0x2823d10da533d9ee873fed7b16f4a962b2b7f181", - "liquidity": "28719720236637" - } - } - } - dispatch(poolLiquidity({poolLiquidity: testData})) - } - }) - */ - /* - const testData = { - "1": { - "0xdac17f958d2ee523a2206206994597c13d831ec7": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "TetherUSD", - "symbol": "USDT", - "decimals": 6, - "anyToken": "0x22648c12acd87912ea1710357b1302c6a4154ebc", - "liquidity": "9009221334195" - } - }, - "56": { - "0x55d398326f99059ff775485246999027b3197955": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "TetherUSD", - "symbol": "USDT", - "decimals": 18, - "anyToken": "0xedf0c420bc3b92b961c6ec411cc810ca81f5f21a", - "liquidity": "5756135762036213167560" - } - }, - "97": { - "0x6e9c98a8a481BF038Ba7e1d669a0086547dd144E": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "TetherUSD", - "symbol": "USDT", - "decimals": 8, - "anyToken": "0xc0c3394781c23faa538a506b3c96fb59c050bed8", - "liquidity": "5756135762036213167560" - } - }, - "66": { - "0x382bb369d343125bfb2117af9c149795c6c65c50": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "USDT", - "symbol": "USDT", - "decimals": 18, - "anyToken": "0x0dcb0cb0120d355cde1ce56040be57add0185baa", - "liquidity": "8358674931031277832025" - } - }, - "128": { - "0xa71edc38d189767582c38a3145b5873052c3e47a": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "Heco-Peg USDT Token", - "symbol": "USDT", - "decimals": 18, - "anyToken": "0xfea7a6a0b346362bf88a9e4a88416b77a57d6c2a", - "liquidity": "2210305595209176178171" - } - }, - "137": { - "0xc2132d05d31c914a87c6611c10748aeb04b58e8f": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "(PoS)TetherUSD", - "symbol": "USDT", - "decimals": 6, - "anyToken": "0xe3eeda11f06a656fcaee19de663e84c7e61d3cac", - "liquidity": "24406406214" - } - }, - "250": { - "0x049d68029688eabf473097a2fc38ef61633a3c7a": { - "logoUrl": "https://assets.coingecko.com/coins/images/325/large/Tether-logo.png", - "name": "FrappedUSDT", - "symbol": "fUSDT", - "decimals": 6, - "anyToken": "0x2823d10da533d9ee873fed7b16f4a962b2b7f181", - "liquidity": "28719720236637" + const url = `${apiAddress}/config` + + getUrlData(url) + .then(async (tokenList: any) => { + if (tokenList.msg && tokenList.msg == 'Success' && tokenList.data && tokenList.data.length > 0) { + const callsByChainId = {} + const tokensByChainsMap = {} + + tokenList.data.forEach((tokenGroup) => { + tokenGroup.multichainTokens.forEach((mcToken) => { + //if (mcToken.chainId != 1229) { /* Dont fork for me without VPN - for dev skip it chain */ + callsByChainId[mcToken.chainId] = callsByChainId[mcToken.chainId] || [] + callsByChainId[mcToken.chainId].push({ + token: mcToken.anyswapToken.ContractAddress, + underlying: mcToken.anyswapToken.Underlying, + dec: mcToken.anyswapToken.Decimals + }) + + tokensByChainsMap[`${mcToken.chainId}:${mcToken.anyswapToken.ContractAddress}`] = { + name: mcToken.anyswapToken.TokenID, + symbol: mcToken.anyswapToken.TokenID, + decimals: mcToken.anyswapToken.Decimals, + anyToken: mcToken.anyswapToken.ContractAddress, + underlying: mcToken.anyswapToken.Underlying + } + //} + }) + }) + + const promiseList = Object.keys(callsByChainId).map((chainId) => { + return new Promise((resolve) => { + try { + getBlandTs(callsByChainId[chainId], chainId).then((res: any) => { + resolve({ + chainId, + data: res + }) + }) + } catch (err) { + console.log('>>> POOL ERROR', err) + } + }) + }) + Promise.all(promiseList).then((res) => { + const retData = {} + res.forEach(({ chainId, data }) => { + retData[chainId] = {} + Object.keys(data).forEach((anyAddress) => { + retData[chainId][tokensByChainsMap[`${chainId}:${anyAddress}`].underlying] = { + ...tokensByChainsMap[`${chainId}:${anyAddress}`], + liquidity: data[anyAddress].wei_ts + } + }) + }) + dispatch(poolLiquidity({poolLiquidity: retData})) + }) } - } - } -*/ - dispatch(poolLiquidity({poolLiquidity: {}/*testData*/})) + }) + .catch(error => { + console.log('Pool error', error) + }) + + dispatch(poolLiquidity({poolLiquidity: {} })) }, [dispatch]) useInterval(getPools, 1000 * 30) diff --git a/src/utils/bridge/getBalanceV2.ts b/src/utils/bridge/getBalanceV2.ts index 729ff703..591e1944 100644 --- a/src/utils/bridge/getBalanceV2.ts +++ b/src/utils/bridge/getBalanceV2.ts @@ -61,7 +61,7 @@ export function getNodeBalance(account?:any, token?:string, chainID?:any, dec?:a const SRCTOTALSUPPLY = 'SRCTOTALSUPPLY' -function getBlandTs(tokenList:any, chainId?:any, account?:string | null | undefined) { +export function getBlandTs(tokenList:any, chainId?:any, account?:string | null | undefined) { return new Promise(async(resolve) => { const len = tokenList.length const list:any = {} @@ -131,6 +131,7 @@ function getBlandTs(tokenList:any, chainId?:any, account?:string | null | undefi if (!list[arr[i].token]) list[arr[i].token] = {} list[arr[i].token][arr[i].key] = fromWei(balance, arr[i].dec) + list[arr[i].token][`wei_${arr[i].key}`] = balance.toString() } } } catch (error) { @@ -164,8 +165,6 @@ export function getNodeTotalsupply( } ] getBlandTs(tokenList, chainId, account).then((res: any) => { - // console.log(token) - // console.log(res) resolve(res) }) }