From c3fa10f26f015516e377f2860565e0d9a195f796 Mon Sep 17 00:00:00 2001 From: saml33 Date: Tue, 30 Aug 2022 13:44:27 +1000 Subject: [PATCH] show high/low on trade chart --- components/SideNav.tsx | 2 +- components/swap/SwapTokenChart.tsx | 36 ++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/components/SideNav.tsx b/components/SideNav.tsx index 70fc154e..fc45c1df 100644 --- a/components/SideNav.tsx +++ b/components/SideNav.tsx @@ -171,7 +171,7 @@ const MenuItem = ({ return ( diff --git a/components/swap/SwapTokenChart.tsx b/components/swap/SwapTokenChart.tsx index 313f9a57..ee71511c 100644 --- a/components/swap/SwapTokenChart.tsx +++ b/components/swap/SwapTokenChart.tsx @@ -1,4 +1,10 @@ -import { FunctionComponent, useCallback, useEffect, useState } from 'react' +import { + FunctionComponent, + useCallback, + useEffect, + useMemo, + useState, +} from 'react' import dayjs from 'dayjs' import relativeTime from 'dayjs/plugin/relativeTime' import { @@ -18,7 +24,6 @@ import { formatFixedDecimals } from '../../utils/numbers' import SheenLoader from '../shared/SheenLoader' import { COLORS } from '../../styles/colors' import { useTheme } from 'next-themes' -import { SwitchHorizontalIcon } from '@heroicons/react/solid' dayjs.extend(relativeTime) @@ -89,6 +94,32 @@ const SwapTokenChart: FunctionComponent = ({ const [daysToShow, setDaysToShow] = useState(1) const { theme } = useTheme() + const [min, max] = useMemo(() => { + if (chartData.length) { + const prices = chartData.map((d: any) => d.price) + return [Math.min(...prices), Math.max(...prices)] + } + return ['', ''] + }, [chartData]) + + const CustomizedLabel = (props: any) => { + const { x, y, value } = props + if (value === min || value === max) { + return ( + + {value} + + ) + } else return
+ } + const handleMouseMove = (coords: any) => { if (coords.activePayload) { setMouseData(coords.activePayload[0].payload) @@ -363,6 +394,7 @@ const SwapTokenChart: FunctionComponent = ({ } strokeWidth={1.5} fill="url(#gradientArea)" + label={} />