Skip to content

Commit

Permalink
fix: crashing charting data
Browse files Browse the repository at this point in the history
  • Loading branch information
grinry committed Oct 22, 2024
1 parent f35a832 commit 7c9aad9
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/controllers/main-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,17 @@ router.get(
req.query,
);

const timeframeMinutes = TIMEFRAMES[timeframe];
const start = ceilDate(dayjs.unix(startTimestamp).toDate(), timeframeMinutes);
const end = ceilDate(dayjs.unix(endTimestamp).toDate(), timeframeMinutes);
const start = dayjs.unix(startTimestamp).toDate();
const end = dayjs.unix(endTimestamp).toDate();

return await maybeCacheResponse(
res,
`chart/${chainId}/${baseTokenAddress}/${quoteTokenAddress}/${start.getTime()}/${end.getTime()}/${timeframe}`,
async () => {
const intervals = await getPrices(chainId, baseTokenAddress, quoteTokenAddress, start, end, timeframe);
const candlesticks = await constructCandlesticks(intervals, TIMEFRAMES[timeframe]);
return candlesticks;
},
DEFAULT_CACHE_TTL,
).then((data) => res.json(toResponse(data)));
try {
const intervals = await getPrices(chainId, baseTokenAddress, quoteTokenAddress, start, end, timeframe);
const data = await constructCandlesticks(intervals, TIMEFRAMES[timeframe]);

return res.json(toResponse(data));
} catch (e) {
return res.json(toResponse([]));
}
}),
);

Expand Down

0 comments on commit 7c9aad9

Please sign in to comment.