Skip to content

Commit

Permalink
force LH + fix swap flow
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhsinghcodes committed Dec 3, 2024
1 parent f996f5d commit c4b38a8
Show file tree
Hide file tree
Showing 5 changed files with 3,493 additions and 427 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/trade/liquidity-hub/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const initialState: State = {
acceptedQuote: undefined,
acceptedOptimalRate: undefined,
liquidityHubDisabled: false,
forceLiquidityHub: false,
forceLiquidityHub: true,
confirmationModalOpen: false,
proceedWithLiquidityHub: false,
};
Expand Down Expand Up @@ -65,6 +65,7 @@ interface ContextType {
}

const Context = createContext({} as ContextType);
// eslint-disable-next-line react-refresh/only-export-components
export const useLiquidityHubSwapContext = () => {
return useContext(Context);
};
Expand Down Expand Up @@ -108,7 +109,7 @@ export const LiquidityHubSwapProvider = ({
if(chainId) {
resetState();
}
}, [chainId])
}, [chainId, resetState])



Expand Down
13 changes: 6 additions & 7 deletions src/trade/liquidity-hub/useIsLiquidityHubTrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import BN from "bignumber.js";

export const useIsLiquidityHubTrade = () => {
const {
state: { liquidityHubDisabled, proceedWithLiquidityHub },
state: { liquidityHubDisabled, proceedWithLiquidityHub, forceLiquidityHub },
} = useLiquidityHubSwapContext();
const liquidityHubQuote = useLiquidityHubQuote().data;
const paraswapMinAmountOut = useParaswapMinAmountOut();

return useMemo(() => {
if (forceLiquidityHub) {
return true;
}

// Choose between liquidity hub and dex swap based on the min amount out
if (proceedWithLiquidityHub) {
return true;
Expand All @@ -21,10 +25,5 @@ export const useIsLiquidityHubTrade = () => {
return BN(liquidityHubQuote?.minAmountOut || 0).gt(
paraswapMinAmountOut || 0
);
}, [
liquidityHubDisabled,
liquidityHubQuote?.minAmountOut,
paraswapMinAmountOut,
proceedWithLiquidityHub,
]);
}, [forceLiquidityHub, liquidityHubDisabled, liquidityHubQuote?.minAmountOut, paraswapMinAmountOut, proceedWithLiquidityHub]);
};
5 changes: 2 additions & 3 deletions src/trade/liquidity-hub/useLiquidityHubSwapCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function useLiquidityHubSwapCallback(
if (steps.includes(SwapSteps.Wrap)) {
updateSwapProgressState({ currentStep: SwapSteps.Wrap });
try {
liquidityHub.analytics.onWrapRequest;
liquidityHub.analytics.onWrapRequest();
await wrap(quote.inAmount);
liquidityHub.analytics.onWrapSuccess();
} catch (error) {
Expand All @@ -88,7 +88,6 @@ export function useLiquidityHubSwapCallback(
amount: quote.inAmount,
});
liquidityHub.analytics.onApprovalSuccess(txHash);
return txHash;
} catch (error) {
liquidityHub.analytics.onApprovalFailed((error as Error).message);
throw error;
Expand Down Expand Up @@ -178,7 +177,7 @@ const useSign = () => {
);

const signature = await promiseWithTimeout<string>(
(signTypedDataAsync as any)(payload),
(signTypedDataAsync)(payload),
40_000
);

Expand Down
Loading

0 comments on commit c4b38a8

Please sign in to comment.