Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default function Content({
positionId,
degenMode,
revertPrice,
getZapRoute,
} = useZapState();
const {
pool,
Expand Down Expand Up @@ -311,6 +312,11 @@ export default function Content({
if (tickLower === null && tickUpper === null && pool) selectPriceRange(0.2);
}, [pool, selectPriceRange, tickLower, tickUpper]);

const onDismissPreview = useCallback(() => {
setSnapshotState(null);
getZapRoute?.();
}, [getZapRoute]);

return (
<>
{loadPoolError && (
Expand All @@ -328,13 +334,13 @@ export default function Content({
</Modal>
)}
{snapshotState && (
<Modal isOpen onClick={() => setSnapshotState(null)}>
<Modal isOpen onClick={onDismissPreview}>
<div className="flex justify-between text-xl font-medium">
<div>{positionId ? "Increase" : "Add"} Liquidity via Zap</div>
<div
className="cursor-pointer"
role="button"
onClick={() => setSnapshotState(null)}
onClick={onDismissPreview}
>
<X />
</div>
Expand All @@ -344,9 +350,7 @@ export default function Content({
onTxSubmit={onTxSubmit}
checkNftApproval={checkNftApproval}
zapState={snapshotState}
onDismiss={() => {
setSnapshotState(null);
}}
onDismiss={onDismissPreview}
/>
</Modal>
)}
Expand Down
11 changes: 9 additions & 2 deletions packages/pancake-liquidity-widgets/src/hooks/useZapInState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const ZapContext = createContext<{
positionId?: string;
marketPrice: number | undefined | null;
source: string;
getZapRoute: () => void;
}>({
revertPrice: false,
tickLower: null,
Expand All @@ -86,6 +87,7 @@ const ZapContext = createContext<{
setDegenMode: () => {},
marketPrice: undefined,
source: "",
getZapRoute: () => {},
});

export const ZapContextProvider = ({
Expand Down Expand Up @@ -371,8 +373,7 @@ export const ZapContextProvider = ({
});
}, [chainId, pool]);

// get zap route
useEffect(() => {
const getZapRoute = useCallback(() => {
if (
debounceTickLower !== null &&
debounceTickUpper !== null &&
Expand Down Expand Up @@ -499,6 +500,11 @@ export const ZapContextProvider = ({
poolType,
]);

// get zap route
useEffect(() => {
getZapRoute();
}, [getZapRoute]);

return (
<ZapContext.Provider
value={{
Expand Down Expand Up @@ -527,6 +533,7 @@ export const ZapContextProvider = ({
setDegenMode,
marketPrice,
source,
getZapRoute,
}}
>
{children}
Expand Down
Loading