From c10c5b13faad4bee30bc2cd61fe77ed38a233adf Mon Sep 17 00:00:00 2001 From: yjin Date: Sun, 5 Jan 2025 14:10:06 +0900 Subject: [PATCH] fix: [GSW-2033] TokenSwapChart Mobile Hover UI --- .../swap-token-info/SwapTokenChart.tsx | 33 ++++++++++++++++--- .../swap-token-info/SwapTokenInfo.tsx | 4 +++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/web/src/layouts/swap/components/swap-info-chart/swap-token-info/SwapTokenChart.tsx b/packages/web/src/layouts/swap/components/swap-info-chart/swap-token-info/SwapTokenChart.tsx index 0906a125c..2ff2db331 100644 --- a/packages/web/src/layouts/swap/components/swap-info-chart/swap-token-info/SwapTokenChart.tsx +++ b/packages/web/src/layouts/swap/components/swap-info-chart/swap-token-info/SwapTokenChart.tsx @@ -12,11 +12,23 @@ interface SwapTokenChartProps { data: IPriceResponse[]; isLoading: boolean; isFetched: boolean; + isChartHovered: boolean; onMouseMove: (data?: LineGraphData) => void; onMouseOut: () => void; + onMouseHover: () => void; + onMouseLeave: () => void; } -const SwapTokenChart = ({ data = [], isLoading, isFetched, onMouseMove, onMouseOut }: SwapTokenChartProps) => { +const SwapTokenChart = ({ + data = [], + isLoading, + isFetched, + isChartHovered, + onMouseMove, + onMouseOut, + onMouseHover, + onMouseLeave, +}: SwapTokenChartProps) => { const hasData = isFetched && data && data.length > 0; const isNoData = isFetched && !isLoading && !data; @@ -32,8 +44,21 @@ const SwapTokenChart = ({ data = [], isLoading, isFetched, onMouseMove, onMouseO .reverse(); }, [hasData, data]); + const handleMouseMove = React.useCallback( + (data?: LineGraphData) => { + onMouseMove(data); + }, + [onMouseMove], + ); + + const handleMouseOut = React.useCallback(() => { + if (!isChartHovered) { + onMouseOut(); + } + }, [onMouseOut, isChartHovered]); + return ( - + {isLoading && ( @@ -53,8 +78,8 @@ const SwapTokenChart = ({ data = [], isLoading, isFetched, onMouseMove, onMouseO hasNoLabel={true} cursor isShowTooltip={false} - onMouseMove={onMouseMove} - onMouseOut={onMouseOut} + onMouseMove={handleMouseMove} + onMouseOut={handleMouseOut} /> )} diff --git a/packages/web/src/layouts/swap/components/swap-info-chart/swap-token-info/SwapTokenInfo.tsx b/packages/web/src/layouts/swap/components/swap-info-chart/swap-token-info/SwapTokenInfo.tsx index ac17e0271..8d6e82ceb 100644 --- a/packages/web/src/layouts/swap/components/swap-info-chart/swap-token-info/SwapTokenInfo.tsx +++ b/packages/web/src/layouts/swap/components/swap-info-chart/swap-token-info/SwapTokenInfo.tsx @@ -16,6 +16,7 @@ interface SwapTokenInfoProps { const SwapTokenInfo = ({ token }: SwapTokenInfoProps) => { const { isMobile, breakpoint } = useWindowSize(); const [chartData, setChartData] = React.useState(); + const [isChartHovered, setIsChartHovered] = React.useState(false); const tokenData = React.useMemo( () => ({ @@ -69,8 +70,11 @@ const SwapTokenInfo = ({ token }: SwapTokenInfoProps) => { data={prices7d} isLoading={isLoading} isFetched={isFetched} + isChartHovered={isChartHovered} onMouseMove={handleMouseMove} onMouseOut={handleMouseOut} + onMouseHover={() => setIsChartHovered(true)} + onMouseLeave={() => setIsChartHovered(false)} /> );