From a1856d79a4e92d01218ad6a293577b8d4d300b01 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Fri, 10 Jun 2022 07:11:37 -0700 Subject: [PATCH] fix global stats (#1512) * fix global stats * switch graph schema to ropsten * minor fix --- package.json | 2 +- src/components/Footer/MarketStats/index.tsx | 35 +++++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index b64b82c96..1a9b95e7c 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "type-check": "tsc --noEmit", "deploy:s3": "bash scripts/deploy-s3.sh", "postinstall": "husky install", - "codegen:apollo": "apollo client:codegen --endpoint=https://v4.subgraph.rinkeby.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph --target typescript --tsFileExtension=d.ts --outputFlat src/@types/subgraph/", + "codegen:apollo": "apollo client:codegen --endpoint=https://v4.subgraph.ropsten.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph --target typescript --tsFileExtension=d.ts --outputFlat src/@types/subgraph/", "storybook": "cross-env NODE_ENV=test start-storybook -p 6006 --quiet", "storybook:build": "cross-env NODE_ENV=test build-storybook" }, diff --git a/src/components/Footer/MarketStats/index.tsx b/src/components/Footer/MarketStats/index.tsx index 10c050883..d50d8ff2b 100644 --- a/src/components/Footer/MarketStats/index.tsx +++ b/src/components/Footer/MarketStats/index.tsx @@ -61,7 +61,9 @@ export default function MarketStats(): ReactElement { // const getMarketStats = useCallback(async () => { if (!mainChainIds?.length) return - + const newData: { + [chainId: number]: FooterStatsValuesGlobalStatistics + } = {} for (const chainId of mainChainIds) { const context: OperationContext = { url: `${getSubgraphUri( @@ -73,15 +75,12 @@ export default function MarketStats(): ReactElement { try { const response = await fetchData(queryGlobalStatistics, null, context) if (!response?.data?.globalStatistics) return - - setData((prevState) => ({ - ...prevState, - [chainId]: response.data.globalStatistics[0] - })) + newData[chainId] = response.data.globalStatistics[0] } catch (error) { LoggerInstance.error('Error fetching global stats: ', error.message) } } + setData(newData) }, [mainChainIds]) // @@ -96,10 +95,12 @@ export default function MarketStats(): ReactElement { // useEffect(() => { if (!data || !mainChainIds?.length) return - const newTotal: StatsTotal = { ...initialTotal // always start calculating beginning from initial 0 values } + const newTVLInOcean: StatsValue = {} + const newTotalLiquidity: StatsValue = {} + const newPoolCount: StatsValue = {} for (const chainId of mainChainIds) { const baseTokenValue = data[chainId]?.totalLiquidity[0]?.value @@ -109,25 +110,15 @@ export default function MarketStats(): ReactElement { ? new Decimal(baseTokenValue).mul(2) : new Decimal(0) - setTotalValueLockedInOcean((prevState) => ({ - ...prevState, - [chainId]: `${totalValueLockedInOcean}` - })) + newTVLInOcean[chainId] = `${totalValueLockedInOcean}` const totalOceanLiquidity = Number(baseTokenValue) || 0 - setTotalOceanLiquidity((prevState) => ({ - ...prevState, - [chainId]: `${totalOceanLiquidity}` - })) + newTotalLiquidity[chainId] = `${totalOceanLiquidity}` const poolCount = data[chainId]?.poolCount || 0 - setPoolCount((prevState) => ({ - ...prevState, - [chainId]: `${poolCount}` - })) - + newPoolCount[chainId] = `${poolCount}` const nftCount = data[chainId]?.nftCount || 0 const datatokenCount = data[chainId]?.datatokenCount || 0 const orderCount = data[chainId]?.orderCount || 0 @@ -142,7 +133,9 @@ export default function MarketStats(): ReactElement { LoggerInstance.error('Error data manipulation: ', error.message) } } - + setTotalValueLockedInOcean(newTVLInOcean) + setTotalOceanLiquidity(newTotalLiquidity) + setPoolCount(newPoolCount) setTotal(newTotal) }, [data, mainChainIds, prices, currency])