From b344b04be82beb61d472d472d6a700eb1596335d Mon Sep 17 00:00:00 2001 From: jinoosss Date: Wed, 17 Jul 2024 18:02:08 +0900 Subject: [PATCH] fix: reset to default range --- .../SelectPriceRangeCustomPosition.tsx | 12 +++++++++--- .../SelectPriceRangeReposition.tsx | 3 +++ .../reposition-content/RepositionContent.tsx | 3 +++ .../RepositionSelectRange.tsx | 3 +++ .../reposition-container/RepositionContainer.tsx | 2 ++ .../src/hooks/reposition/use-reposition-handle.tsx | 7 +++++++ 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/web/src/components/common/select-price-range-custom/SelectPriceRangeCustomPosition.tsx b/packages/web/src/components/common/select-price-range-custom/SelectPriceRangeCustomPosition.tsx index ce749adfb..fcfd70fa0 100644 --- a/packages/web/src/components/common/select-price-range-custom/SelectPriceRangeCustomPosition.tsx +++ b/packages/web/src/components/common/select-price-range-custom/SelectPriceRangeCustomPosition.tsx @@ -33,6 +33,7 @@ export interface SelectPriceRangeCustomProps { showDim: boolean; defaultPrice: number | null; handleSwapValue: () => void; + resetRange?: () => void; isEmptyLiquidity: boolean; isKeepToken: boolean; } @@ -43,6 +44,7 @@ const SelectPriceRangeCustom: React.FC = ({ priceRangeType, selectPool, showDim, + resetRange, handleSwapValue, isKeepToken, }) => { @@ -234,7 +236,11 @@ const SelectPriceRangeCustom: React.FC = ({ } } - function resetRange(priceRangeType?: PriceRangeType | null) { + function onResetRange(priceRangeType?: PriceRangeType | null) { + if (resetRange) { + resetRange(); + return; + } selectPool.resetRange(); setShiftPosition(0); initPriceRange(priceRangeType); @@ -259,7 +265,7 @@ const SelectPriceRangeCustom: React.FC = ({ }, [tokenA]); useEffect(() => { - resetRange(priceRangeType); + onResetRange(priceRangeType); }, [ selectPool.poolPath, selectPool.feeTier, @@ -430,7 +436,7 @@ const SelectPriceRangeCustom: React.FC = ({
resetRange()} + onClick={() => onResetRange()} > Reset Range diff --git a/packages/web/src/components/common/select-price-range-reposition/SelectPriceRangeReposition.tsx b/packages/web/src/components/common/select-price-range-reposition/SelectPriceRangeReposition.tsx index 6ad031a90..649a96905 100644 --- a/packages/web/src/components/common/select-price-range-reposition/SelectPriceRangeReposition.tsx +++ b/packages/web/src/components/common/select-price-range-reposition/SelectPriceRangeReposition.tsx @@ -25,6 +25,7 @@ interface SelectPriceRangeProps { showDim: boolean; defaultPrice: number | null; handleSwapValue: () => void; + resetRange: () => void; isEmptyLiquidity: boolean; isKeepToken: boolean; } @@ -41,6 +42,7 @@ const SelectPriceRangeReposition: React.FC = ({ showDim, defaultPrice, handleSwapValue, + resetRange, isEmptyLiquidity, isKeepToken, }) => { @@ -78,6 +80,7 @@ const SelectPriceRangeReposition: React.FC = ({ priceRangeType={priceRange?.type || null} showDim={showDim} defaultPrice={defaultPrice} + resetRange={resetRange} handleSwapValue={handleSwapValue} isEmptyLiquidity={isEmptyLiquidity} isKeepToken={isKeepToken} diff --git a/packages/web/src/components/reposition/reposition-content/RepositionContent.tsx b/packages/web/src/components/reposition/reposition-content/RepositionContent.tsx index eee54454a..1cbafca41 100644 --- a/packages/web/src/components/reposition/reposition-content/RepositionContent.tsx +++ b/packages/web/src/components/reposition/reposition-content/RepositionContent.tsx @@ -38,6 +38,7 @@ interface RepositionContentProps { priceRanges: AddLiquidityPriceRage[]; priceRange: AddLiquidityPriceRage; changePriceRange: (priceRange: AddLiquidityPriceRage) => void; + resetRange: () => void; currentAmounts: { amountA: string; amountB: string } | null; repositionAmounts: { amountA: string | null; amountB: string | null } | null; selectedPosition: PoolPositionModel | null; @@ -59,6 +60,7 @@ const RepositionContent: React.FC = ({ priceRange, priceRanges, changePriceRange, + resetRange, currentAmounts, repositionAmounts, selectedPosition, @@ -128,6 +130,7 @@ const RepositionContent: React.FC = ({ priceRanges={priceRanges} priceRange={priceRange} changePriceRange={changePriceRange} + resetRange={resetRange} isLoadingPosition={isLoadingPosition} /> diff --git a/packages/web/src/components/reposition/reposition-select-range/RepositionSelectRange.tsx b/packages/web/src/components/reposition/reposition-select-range/RepositionSelectRange.tsx index 245ba073b..e5cd10843 100644 --- a/packages/web/src/components/reposition/reposition-select-range/RepositionSelectRange.tsx +++ b/packages/web/src/components/reposition/reposition-select-range/RepositionSelectRange.tsx @@ -24,6 +24,7 @@ export interface RepositionSelectRangeProps { priceRanges: AddLiquidityPriceRage[]; priceRange: AddLiquidityPriceRage; changePriceRange: (priceRange: AddLiquidityPriceRage) => void; + resetRange: () => void; isLoadingPosition: boolean; } @@ -40,6 +41,7 @@ const RepositionSelectRange: React.FC = ({ priceRange, priceRanges, changePriceRange, + resetRange, isLoadingPosition, }) => { const [openedPriceRange, setOpenedPriceRange] = useState(true); @@ -71,6 +73,7 @@ const RepositionSelectRange: React.FC = ({ changePriceRange={changePriceRange} changeStartingPrice={() => {}} selectPool={selectPool} + resetRange={resetRange} showDim={false} handleSwapValue={() => {}} isEmptyLiquidity={true} diff --git a/packages/web/src/containers/reposition-container/RepositionContainer.tsx b/packages/web/src/containers/reposition-container/RepositionContainer.tsx index 0e8b658bd..f3381629a 100644 --- a/packages/web/src/containers/reposition-container/RepositionContainer.tsx +++ b/packages/web/src/containers/reposition-container/RepositionContainer.tsx @@ -38,6 +38,7 @@ const RepositionContainer: React.FC = () => { removePosition, swapRemainToken, reposition, + resetRange, selectedPosition, isLoadingPosition, isSkipSwap, @@ -93,6 +94,7 @@ const RepositionContainer: React.FC = () => { selectPool={selectPool} priceRanges={PRICE_RANGES} changePriceRange={changePriceRange} + resetRange={resetRange} priceRange={priceRange} currentAmounts={currentAmounts} repositionAmounts={repositionAmounts} diff --git a/packages/web/src/hooks/reposition/use-reposition-handle.tsx b/packages/web/src/hooks/reposition/use-reposition-handle.tsx index b63c8414e..3f9f3d321 100644 --- a/packages/web/src/hooks/reposition/use-reposition-handle.tsx +++ b/packages/web/src/hooks/reposition/use-reposition-handle.tsx @@ -155,6 +155,12 @@ export const useRepositionHandle = () => { : RANGE_STATUS_OPTION.OUT; }, [selectedPosition, inRange]); + const resetRange = useCallback(() => { + selectPool.resetRange(); + selectPool.setMinPosition(defaultPositionMinPrice); + selectPool.setMaxPosition(defaultPositionMaxPrice); + }, [selectPool]); + useEffect(() => { if (initialized || selectPool.isLoading || !selectPool.poolPath) { return; @@ -768,6 +774,7 @@ export const useRepositionHandle = () => { removePosition, swapRemainToken, reposition, + resetRange, selectedPosition, isLoadingPosition, isErrorLiquidity,