1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

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 <katunanorbert@gmai.com>
This commit is contained in:
Norbi 2021-06-25 11:34:39 +03:00 committed by GitHub
parent 00bce63b8d
commit 31ee1aab98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -123,11 +123,10 @@ export default function Graph(): ReactElement {
const { price } = useAsset()
const [lastBlock, setLastBlock] = useState(0)
const [lastBlock, setLastBlock] = useState<number>(0)
const [priceHistory, setPriceHistory] = useState([])
const [liquidityHistory, setLiquidityHistory] = useState([])
const [timestamps, setTimestamps] = useState([])
const [isLoading, setIsLoading] = useState(true)
const [graphData, setGraphData] = useState<ChartData>()
@ -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])