From c8263cc2c830c497c128bb73abbb98d400355399 Mon Sep 17 00:00:00 2001 From: Keith Date: Sat, 4 Nov 2023 16:03:43 +0900 Subject: [PATCH] fix: fix frozen avg-block-time chart The data of each item is an array of string, but it's asserted to be a string while the exception is not handled properly. --- .../StatisticsChart/block/AverageBlockTime.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/StatisticsChart/block/AverageBlockTime.tsx b/src/pages/StatisticsChart/block/AverageBlockTime.tsx index 91cbca489..962413640 100644 --- a/src/pages/StatisticsChart/block/AverageBlockTime.tsx +++ b/src/pages/StatisticsChart/block/AverageBlockTime.tsx @@ -2,7 +2,7 @@ import { useTranslation } from 'react-i18next' import { parseDateNoTime, parseSimpleDate, parseSimpleDateNoSecond } from '../../../utils/date' import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common' import { localeNumberString } from '../../../utils/number' -import { DATA_ZOOM_CONFIG, assertIsArray, assertSerialsDataIsString, assertSerialsItem } from '../../../utils/chart' +import { DATA_ZOOM_CONFIG, assertIsArray, assertSerialsItem } from '../../../utils/chart' import { ChartItem, explorerService } from '../../../services/ExplorerService' import { ChartCachedKeys } from '../../../constants/cache' import { useCurrentLanguage } from '../../../utils/i18n' @@ -41,13 +41,13 @@ const useOption = ( const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 180 : 100) - const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: string }): string => { - if (seriesName === t('statistic.daily_moving_average')) { + const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data?: string[] }): string => { + if (seriesName === t('statistic.daily_moving_average') && data?.[1]) { return `
${tooltipColor(color)}${widthSpan(t('statistic.daily_moving_average'))} ${localeNumberString( data[1], )}
` } - if (seriesName === t('statistic.weekly_moving_average')) { + if (seriesName === t('statistic.weekly_moving_average') && data?.[2]) { return `
${tooltipColor(color)}${widthSpan(t('statistic.weekly_moving_average'))} ${localeNumberString( data[2], )}
` @@ -68,8 +68,7 @@ const useOption = ( )}` dataList.forEach(data => { assertSerialsItem(data) - assertSerialsDataIsString(data) - result += parseTooltip(data) + result += parseTooltip({ ...data }) }) return result }, @@ -88,7 +87,8 @@ const useOption = ( } : undefined, grid: isThumbnail ? gridThumbnail : grid, - dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG, + /* Selection starts from 1% because the average block time is extremely high on launch */ + dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG.map(zoom => ({ ...zoom, start: 1 })), xAxis: [ { name: isMobile || isThumbnail ? '' : t('statistic.date'),