Skip to content

Commit

Permalink
fix: reset to default range
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Jul 17, 2024
1 parent 0cc07b6 commit b344b04
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface SelectPriceRangeCustomProps {
showDim: boolean;
defaultPrice: number | null;
handleSwapValue: () => void;
resetRange?: () => void;
isEmptyLiquidity: boolean;
isKeepToken: boolean;
}
Expand All @@ -43,6 +44,7 @@ const SelectPriceRangeCustom: React.FC<SelectPriceRangeCustomProps> = ({
priceRangeType,
selectPool,
showDim,
resetRange,
handleSwapValue,
isKeepToken,
}) => {
Expand Down Expand Up @@ -234,7 +236,11 @@ const SelectPriceRangeCustom: React.FC<SelectPriceRangeCustomProps> = ({
}
}

function resetRange(priceRangeType?: PriceRangeType | null) {
function onResetRange(priceRangeType?: PriceRangeType | null) {
if (resetRange) {
resetRange();
return;
}
selectPool.resetRange();
setShiftPosition(0);
initPriceRange(priceRangeType);
Expand All @@ -259,7 +265,7 @@ const SelectPriceRangeCustom: React.FC<SelectPriceRangeCustomProps> = ({
}, [tokenA]);

useEffect(() => {
resetRange(priceRangeType);
onResetRange(priceRangeType);
}, [
selectPool.poolPath,
selectPool.feeTier,
Expand Down Expand Up @@ -430,7 +436,7 @@ const SelectPriceRangeCustom: React.FC<SelectPriceRangeCustomProps> = ({
<div className="extra-wrapper">
<div
className="icon-button reset"
onClick={() => resetRange()}
onClick={() => onResetRange()}
>
<IconRefresh />
<span>Reset Range</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface SelectPriceRangeProps {
showDim: boolean;
defaultPrice: number | null;
handleSwapValue: () => void;
resetRange: () => void;
isEmptyLiquidity: boolean;
isKeepToken: boolean;
}
Expand All @@ -41,6 +42,7 @@ const SelectPriceRangeReposition: React.FC<SelectPriceRangeProps> = ({
showDim,
defaultPrice,
handleSwapValue,
resetRange,
isEmptyLiquidity,
isKeepToken,
}) => {
Expand Down Expand Up @@ -78,6 +80,7 @@ const SelectPriceRangeReposition: React.FC<SelectPriceRangeProps> = ({
priceRangeType={priceRange?.type || null}
showDim={showDim}
defaultPrice={defaultPrice}
resetRange={resetRange}
handleSwapValue={handleSwapValue}
isEmptyLiquidity={isEmptyLiquidity}
isKeepToken={isKeepToken}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,6 +60,7 @@ const RepositionContent: React.FC<RepositionContentProps> = ({
priceRange,
priceRanges,
changePriceRange,
resetRange,
currentAmounts,
repositionAmounts,
selectedPosition,
Expand Down Expand Up @@ -128,6 +130,7 @@ const RepositionContent: React.FC<RepositionContentProps> = ({
priceRanges={priceRanges}
priceRange={priceRange}
changePriceRange={changePriceRange}
resetRange={resetRange}
isLoadingPosition={isLoadingPosition}
/>
</article>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface RepositionSelectRangeProps {
priceRanges: AddLiquidityPriceRage[];
priceRange: AddLiquidityPriceRage;
changePriceRange: (priceRange: AddLiquidityPriceRage) => void;
resetRange: () => void;
isLoadingPosition: boolean;
}

Expand All @@ -40,6 +41,7 @@ const RepositionSelectRange: React.FC<RepositionSelectRangeProps> = ({
priceRange,
priceRanges,
changePriceRange,
resetRange,
isLoadingPosition,
}) => {
const [openedPriceRange, setOpenedPriceRange] = useState(true);
Expand Down Expand Up @@ -71,6 +73,7 @@ const RepositionSelectRange: React.FC<RepositionSelectRangeProps> = ({
changePriceRange={changePriceRange}
changeStartingPrice={() => {}}
selectPool={selectPool}
resetRange={resetRange}
showDim={false}
handleSwapValue={() => {}}
isEmptyLiquidity={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const RepositionContainer: React.FC = () => {
removePosition,
swapRemainToken,
reposition,
resetRange,
selectedPosition,
isLoadingPosition,
isSkipSwap,
Expand Down Expand Up @@ -93,6 +94,7 @@ const RepositionContainer: React.FC = () => {
selectPool={selectPool}
priceRanges={PRICE_RANGES}
changePriceRange={changePriceRange}
resetRange={resetRange}
priceRange={priceRange}
currentAmounts={currentAmounts}
repositionAmounts={repositionAmounts}
Expand Down
7 changes: 7 additions & 0 deletions packages/web/src/hooks/reposition/use-reposition-handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -768,6 +774,7 @@ export const useRepositionHandle = () => {
removePosition,
swapRemainToken,
reposition,
resetRange,
selectedPosition,
isLoadingPosition,
isErrorLiquidity,
Expand Down

0 comments on commit b344b04

Please sign in to comment.