Files
zeekay da79f9e711 feat: rename @blockscout to @luxfi, monochrome theme, horizontal blocks
- Rename all @blockscout/* npm packages to @luxfi/* aliases (150+ files)
- Override blue accent colors to gray for monochrome theme
- Fix dropdown/menu/popover fonts to use Geist Sans
- Change Latest Blocks to horizontal scrolling layout
- Show dashes instead of zeros for validator stats on error
- Fix GHA deploy step to use correct deployment name
2026-03-02 12:28:15 -08:00

62 lines
1.9 KiB
TypeScript

import React from 'react';
import type { LineChart, Resolution } from '@luxfi/stats-types';
import type { StatsIntervalIds } from 'types/client/stats';
import useApiQuery from 'lib/api/useApiQuery';
import { useAppContext } from 'lib/contexts/app';
import { STATS_INTERVALS } from 'ui/stats/constants';
import { formatDate } from './utils';
export default function useChartQuery(id: string, resolution: Resolution, interval: StatsIntervalIds, enabled = true) {
const { apiData } = useAppContext<'/stats/[id]'>();
const selectedInterval = STATS_INTERVALS[interval];
const endDate = selectedInterval.start ? formatDate(new Date()) : undefined;
const startDate = selectedInterval.start ? formatDate(selectedInterval.start) : undefined;
const [ info, setInfo ] = React.useState<LineChart['info']>(apiData || undefined);
const lineQuery = useApiQuery('stats:line', {
pathParams: { id },
queryParams: {
from: startDate,
to: endDate,
resolution,
},
queryOptions: {
enabled: enabled,
refetchOnMount: false,
placeholderData: {
info: {
title: 'Chart title placeholder',
description: 'Chart placeholder description chart placeholder description',
resolutions: [ 'DAY', 'WEEK', 'MONTH', 'YEAR' ],
id: 'placeholder',
units: undefined,
},
chart: [],
},
},
});
React.useEffect(() => {
if (!info && lineQuery.data?.info && !lineQuery.isPlaceholderData) {
// save info to keep title and description when change query params
setInfo(lineQuery.data?.info);
}
}, [ info, lineQuery.data?.info, lineQuery.isPlaceholderData ]);
const items = React.useMemo(() => lineQuery.data?.chart?.map((item) => {
return { date: new Date(item.date), date_to: new Date(item.date_to), value: Number(item.value), isApproximate: item.is_approximate };
}), [ lineQuery ]);
return {
items,
info,
lineQuery,
};
}