add try catch for recent trades

This commit is contained in:
tjs 2022-09-28 12:45:38 -04:00
parent a14431ac2e
commit f68cbbc4d2
1 changed files with 14 additions and 10 deletions

View File

@ -30,17 +30,21 @@ const RecentTrades = () => {
const fetchTradesForChart = useCallback(async () => {
if (!selectedMarketPk) return
const response = await fetch(
`https://event-history-api-candles.herokuapp.com/trades/address/${selectedMarketPk}`
)
const parsedResp = await response.json()
const newTrades = parsedResp.data
if (!newTrades) return null
try {
const response = await fetch(
`https://event-history-api-candles.herokuapp.com/trades/address/${selectedMarketPk}`
)
const parsedResp = await response.json()
const newTrades = parsedResp.data
if (!newTrades) return null
if (newTrades.length && trades.length === 0) {
setTrades(newTrades)
} else if (newTrades?.length && !isEqual(newTrades[0], trades[0])) {
setTrades(newTrades)
if (newTrades.length && trades.length === 0) {
setTrades(newTrades)
} else if (newTrades?.length && !isEqual(newTrades[0], trades[0])) {
setTrades(newTrades)
}
} catch (e) {
console.error('Unable to fetch recent trades', e)
}
}, [selectedMarketPk, trades])