diff --git a/src/components/Tokens/TokenDetails/PriceChart.tsx b/src/components/Tokens/TokenDetails/PriceChart.tsx index 6ad7b8b5b1..09d590dc2d 100644 --- a/src/components/Tokens/TokenDetails/PriceChart.tsx +++ b/src/components/Tokens/TokenDetails/PriceChart.tsx @@ -25,16 +25,9 @@ import { } from 'utils/formatChartTimes' import LineChart from '../../Charts/LineChart' +import { DISPLAYS, ORDERED_TIMES } from '../TokenTable/TimeSelector' // TODO: This should be combined with the logic in TimeSelector. -const TIME_DISPLAYS: [TimePeriod, string][] = [ - [TimePeriod.HOUR, '1H'], - [TimePeriod.DAY, '1D'], - [TimePeriod.WEEK, '1W'], - [TimePeriod.MONTH, '1M'], - [TimePeriod.YEAR, '1Y'], - [TimePeriod.ALL, 'All'], -] type PricePoint = { value: number; timestamp: number } @@ -307,9 +300,9 @@ export function PriceChart({ width, height, token }: PriceChartProps) { - {TIME_DISPLAYS.map(([value, display]) => ( - setTimePeriod(value)}> - {display} + {ORDERED_TIMES.map((time) => ( + setTimePeriod(time)}> + {DISPLAYS[time]} ))} diff --git a/src/components/Tokens/TokenTable/TimeSelector.tsx b/src/components/Tokens/TokenTable/TimeSelector.tsx index 7751f439dc..837ad52636 100644 --- a/src/components/Tokens/TokenTable/TimeSelector.tsx +++ b/src/components/Tokens/TokenTable/TimeSelector.tsx @@ -10,15 +10,23 @@ import styled, { useTheme } from 'styled-components/macro' import { MOBILE_MEDIA_BREAKPOINT, SMALL_MEDIA_BREAKPOINT } from '../constants' import { filterTimeAtom } from '../state' -export const TIME_DISPLAYS: { [key: string]: string } = { - hour: '1H', - day: '1D', - week: '1W', - month: '1M', - year: '1Y', +export const DISPLAYS: Record = { + [TimePeriod.HOUR]: '1H', + [TimePeriod.DAY]: '1D', + [TimePeriod.WEEK]: '1W', + [TimePeriod.MONTH]: '1M', + [TimePeriod.YEAR]: '1Y', + [TimePeriod.ALL]: 'All', } -const TIMES = [TimePeriod.HOUR, TimePeriod.DAY, TimePeriod.WEEK, TimePeriod.MONTH, TimePeriod.YEAR] +export const ORDERED_TIMES = [ + TimePeriod.HOUR, + TimePeriod.DAY, + TimePeriod.WEEK, + TimePeriod.MONTH, + TimePeriod.YEAR, + TimePeriod.ALL, +] const InternalMenuItem = styled.div` flex: 1; @@ -136,7 +144,7 @@ export default function TimeSelector() { - {TIME_DISPLAYS[activeTime]} + {DISPLAYS[activeTime]} {open ? : } @@ -144,15 +152,15 @@ export default function TimeSelector() { {open && ( - {TIMES.map((time) => ( + {ORDERED_TIMES.map((time) => ( { setTime(time) toggleMenu() }} > -
{TIME_DISPLAYS[time]}
+
{DISPLAYS[time]}
{time === activeTime && }
))} diff --git a/src/components/Tokens/TokenTable/TokenRow.tsx b/src/components/Tokens/TokenTable/TokenRow.tsx index 5f1144105b..fb62f4532c 100644 --- a/src/components/Tokens/TokenTable/TokenRow.tsx +++ b/src/components/Tokens/TokenTable/TokenRow.tsx @@ -33,7 +33,7 @@ import { useToggleFavorite, } from '../state' import { Category, SortDirection } from '../types' -import { TIME_DISPLAYS } from './TimeSelector' +import { DISPLAYS } from './TimeSelector' const ArrowCell = styled.div` padding-left: 2px; @@ -294,7 +294,7 @@ const LogoContainer = styled.div` /* formatting for volume with timeframe header display */ function getHeaderDisplay(category: string, timeframe: TimePeriod): string { - if (category === Category.volume) return `${TIME_DISPLAYS[timeframe]} ${category}` + if (category === Category.volume) return `${DISPLAYS[timeframe]} ${category}` return category }