@@ -215,8 +215,9 @@ const PoolSelectionGraph: React.FC<PoolSelectionGraphProps> = ({
215215 if ( Number . isNaN ( currentPrice ) ) {
216216 return 0 ;
217217 }
218- return priceToTick ( currentPrice ) ;
219- } , [ currentPrice ] ) ;
218+ const tick = priceToTick ( currentPrice ) ;
219+ return flip ? - tick : tick ;
220+ } , [ currentPrice , flip ] ) ;
220221
221222 const tooltipPosition = useMemo ( ( ) : FloatingPosition => {
222223 if ( position ) {
@@ -263,8 +264,16 @@ const PoolSelectionGraph: React.FC<PoolSelectionGraphProps> = ({
263264 const startPosition = selection [ 0 ] as number ;
264265 const endPosition = selection [ 1 ] as number ;
265266
266- const startPrice = tickToPrice ( Math . round ( scaleX . invert ( startPosition ) + graphMinTick ) ) ;
267- const endPrice = tickToPrice ( Math . round ( scaleX . invert ( endPosition ) + graphMinTick ) ) ;
267+ let startTick = Math . round ( scaleX . invert ( startPosition ) + graphMinTick ) ;
268+ let endTick = Math . round ( scaleX . invert ( endPosition ) + graphMinTick ) ;
269+
270+ if ( flip ) {
271+ startTick = - startTick ;
272+ endTick = - endTick ;
273+ }
274+
275+ const startPrice = tickToPrice ( startTick ) ;
276+ const endPrice = tickToPrice ( endTick ) ;
268277
269278 const startRate = currentPrice ? ( ( Number ( startPrice ) - currentPrice ) / currentPrice ) * 100 : 0 ;
270279 const endRate = currentPrice ? ( ( Number ( endPrice ) - currentPrice ) / currentPrice ) * 100 : 0 ;
@@ -386,7 +395,12 @@ const PoolSelectionGraph: React.FC<PoolSelectionGraphProps> = ({
386395 return 0 ;
387396 }
388397
389- const tick = Math . round ( ( tickWithOffset + graphMinTick ) / tickSpacing ) * tickSpacing ;
398+ let tick = Math . round ( ( tickWithOffset + graphMinTick ) / tickSpacing ) * tickSpacing ;
399+
400+ if ( flip ) {
401+ tick = - tick ;
402+ }
403+
390404 if ( tick <= swapFeeTierMaxPriceRange . minTick ) {
391405 return 0 ;
392406 }
@@ -398,8 +412,12 @@ const PoolSelectionGraph: React.FC<PoolSelectionGraphProps> = ({
398412 return tickToPrice ( tick ) ;
399413 }
400414
401- const minPrice = getPriceBy ( startPosition ) ;
402- const maxPrice = getPriceBy ( endPosition ) ;
415+ let minPrice = getPriceBy ( startPosition ) ;
416+ let maxPrice = getPriceBy ( endPosition ) ;
417+
418+ if ( minPrice > maxPrice ) {
419+ [ minPrice , maxPrice ] = [ maxPrice , minPrice ] ;
420+ }
403421
404422 setSelectionColor ( selectionColor ) ;
405423 setMinPrice ( minPrice ) ;
@@ -521,7 +539,15 @@ const PoolSelectionGraph: React.FC<PoolSelectionGraphProps> = ({
521539 const mouseXTick = scaleX . invert ( event . offsetX ) + graphMinTick ;
522540
523541 if ( minPrice && maxPrice ) {
524- if ( priceToTick ( minPrice ) < mouseXTick && priceToTick ( maxPrice ) > mouseXTick ) {
542+ let minTick = priceToTick ( minPrice ) ;
543+ let maxTick = priceToTick ( maxPrice ) ;
544+
545+ if ( flip ) {
546+ minTick = - minTick ;
547+ maxTick = - maxTick ;
548+ }
549+
550+ if ( minTick < mouseXTick && maxTick > mouseXTick ) {
525551 setTooltipInfo ( null ) ;
526552 setHoverBarIndex ( null ) ;
527553 return ;
@@ -547,7 +573,6 @@ const PoolSelectionGraph: React.FC<PoolSelectionGraphProps> = ({
547573 return ;
548574 }
549575
550- // To reduce the computation of scaleY, the Y-axis condition check is done separately.
551576 if ( mouseY < scaleY ( bin . height ) ) {
552577 setPositionX ( null ) ;
553578 setPositionX ( null ) ;
@@ -672,12 +697,19 @@ const PoolSelectionGraph: React.FC<PoolSelectionGraphProps> = ({
672697 if ( fullRange ) {
673698 brush . move ( brushElement , [ 0 , boundsWidth ] ) ;
674699 } else {
675- brush . move ( brushElement , [
676- scaleX ( priceToTick ( minPrice ) - graphMinTick ) ,
677- scaleX ( priceToTick ( maxPrice ) - graphMinTick ) ,
678- ] ) ;
700+ let minTick = flip ? - priceToTick ( maxPrice ) : priceToTick ( minPrice ) ;
701+ let maxTick = flip ? - priceToTick ( minPrice ) : priceToTick ( maxPrice ) ;
702+
703+ if ( minTick > maxTick ) {
704+ [ minTick , maxTick ] = [ maxTick , minTick ] ;
705+ }
706+
707+ const x0 = scaleX ( minTick - graphMinTick ) ;
708+ const x1 = scaleX ( maxTick - graphMinTick ) ;
709+
710+ brush . move ( brushElement , [ x0 , x1 ] ) ;
679711 }
680- } , [ minPrice , maxPrice , zoomLevel , shiftIndex , fullRange , displayBins ] ) ;
712+ } , [ minPrice , maxPrice , zoomLevel , shiftIndex , fullRange , displayBins , flip ] ) ;
681713
682714 useEffect ( ( ) => {
683715 if ( ! brushRef . current ) {
0 commit comments