From 31ee1aab986d6fef61356d13b2671e5615aaf195 Mon Sep 17 00:00:00 2001 From: Norbi <37236152+KatunaNorbert@users.noreply.github.com> Date: Fri, 25 Jun 2021 11:34:39 +0300 Subject: [PATCH] Pool statistics graph shows two sets of data when switching tabs (#696) * removed compose previous data with new data * removed unused states * fix refetch multiple times for same block number Co-authored-by: Norbi --- src/components/organisms/AssetActions/Pool/Graph.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/organisms/AssetActions/Pool/Graph.tsx b/src/components/organisms/AssetActions/Pool/Graph.tsx index b13e1fc3d..a20275d26 100644 --- a/src/components/organisms/AssetActions/Pool/Graph.tsx +++ b/src/components/organisms/AssetActions/Pool/Graph.tsx @@ -123,11 +123,10 @@ export default function Graph(): ReactElement { const { price } = useAsset() - const [lastBlock, setLastBlock] = useState(0) + const [lastBlock, setLastBlock] = useState(0) const [priceHistory, setPriceHistory] = useState([]) const [liquidityHistory, setLiquidityHistory] = useState([]) const [timestamps, setTimestamps] = useState([]) - const [isLoading, setIsLoading] = useState(true) const [graphData, setGraphData] = useState() @@ -156,7 +155,6 @@ export default function Graph(): ReactElement { return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}` }) ] - setTimestamps(latestTimestamps) const latestLiquidtyHistory = [ @@ -170,17 +168,20 @@ export default function Graph(): ReactElement { ...priceHistory, ...data.poolTransactions.map((item) => item.spotPrice) ] + setPriceHistory(latestPriceHistory) if (data.poolTransactions.length > 0) { + const newBlock = + data.poolTransactions[data.poolTransactions.length - 1].block + if (newBlock === lastBlock) return setLastBlock( data.poolTransactions[data.poolTransactions.length - 1].block ) refetch() } else { - setIsLoading(false) setGraphData({ - labels: timestamps.slice(0), + labels: latestTimestamps.slice(0), datasets: [ { ...lineStyle, @@ -194,6 +195,7 @@ export default function Graph(): ReactElement { } ] }) + setIsLoading(false) } }, [data, graphType])