diff --git a/src/store.ts b/src/store.ts index aaf20b8..ceda385 100644 --- a/src/store.ts +++ b/src/store.ts @@ -4,12 +4,16 @@ import { persist } from 'zustand/middleware'; interface AppStore { slippage: number; setSlippage: (slippage: number) => void; + forceLiquidityHub: boolean; + setForceLiquidityHub: (forceLiquidityHub: boolean) => void; } export const useAppState = create( persist( (set) => ({ slippage: 0.5, setSlippage: (slippage: number) => set({ slippage }), + forceLiquidityHub: false, + setForceLiquidityHub: (forceLiquidityHub: boolean) => set({ forceLiquidityHub }), }), { name: 'main-store', diff --git a/src/trade/liquidity-hub/context.tsx b/src/trade/liquidity-hub/context.tsx index 019810b..b0530b1 100644 --- a/src/trade/liquidity-hub/context.tsx +++ b/src/trade/liquidity-hub/context.tsx @@ -13,7 +13,6 @@ const initialState: State = { acceptedQuote: undefined, acceptedOptimalRate: undefined, liquidityHubDisabled: false, - forceLiquidityHub: false, confirmationModalOpen: false, proceedWithLiquidityHub: false, }; @@ -24,7 +23,6 @@ interface State { inputAmount: string; acceptedQuote: Quote | undefined; liquidityHubDisabled: boolean; - forceLiquidityHub: boolean; signature?: string; confirmationModalOpen: boolean; proceedWithLiquidityHub: boolean; @@ -88,13 +86,6 @@ export const LiquidityHubSwapProvider = ({ children }: { children: ReactNode }) const sdk = useMemo(() => constructSDK({ partner: 'widget', chainId }), [chainId]); - useEffect(() => { - const params = new URLSearchParams(window.location.search); - const lh = params.get('lh'); - if (lh) { - updateState({ forceLiquidityHub: true }); - } - }, [updateState]); return ( { const { - state: { liquidityHubDisabled, proceedWithLiquidityHub, forceLiquidityHub }, + state: { liquidityHubDisabled, proceedWithLiquidityHub }, } = useLiquidityHubSwapContext(); + const {forceLiquidityHub} = useAppState() const liquidityHubQuote = useLiquidityHubQuote().data; const paraswapMinAmountOut = useParaswapMinAmountOut(); diff --git a/src/trade/liquidity-hub/useLiquidityHubSwapCallback.ts b/src/trade/liquidity-hub/useLiquidityHubSwapCallback.ts index 6262ebf..a1f2c9e 100644 --- a/src/trade/liquidity-hub/useLiquidityHubSwapCallback.ts +++ b/src/trade/liquidity-hub/useLiquidityHubSwapCallback.ts @@ -18,6 +18,12 @@ import { useLiquidityHubSwapContext } from "./useLiquidityHubSwapContext"; import { useOptimalRate, useLiquidityHubApproval } from "./hooks"; import { useLiquidityHubQuote } from "./useLiquidityHubQuote"; +export const isRejectedError = (error: any) => { + const message = error.message?.toLowerCase(); + return message?.includes('rejected') || message?.includes('denied'); +}; + + export function useLiquidityHubSwapCallback( updateSwapProgressState: (values: Partial) => void ) { @@ -118,6 +124,7 @@ export function useLiquidityHubSwapCallback( updateState({ signature }); } catch (error) { liquidityHub.analytics.onSignatureFailed((error as Error).message); + throw error; } // Pass the liquidity provider txData if possible @@ -150,9 +157,13 @@ export function useLiquidityHubSwapCallback( console.log("Swapped"); updateSwapProgressState({ swapStatus: SwapStatus.SUCCESS }); } catch (error) { - updateSwapProgressState({ swapStatus: SwapStatus.FAILED }); + if(isRejectedError(error)) { + updateSwapProgressState({ swapStatus: undefined }); + }else{ + updateSwapProgressState({ swapStatus: SwapStatus.FAILED }); + throw error; + } - throw error; } }, }); diff --git a/src/trade/settings.tsx b/src/trade/settings.tsx index 7f93379..ce9c99a 100644 --- a/src/trade/settings.tsx +++ b/src/trade/settings.tsx @@ -1,16 +1,13 @@ -import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; -import { - Popover, - PopoverContent, - PopoverTrigger, -} from "@/components/ui/popover"; -import { useAppState } from "@/store"; -import { SettingsIcon } from "lucide-react"; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; +import { Switch } from '@/components/ui/switch'; +import { useAppState } from '@/store'; +import { SettingsIcon } from 'lucide-react'; export const Settings = () => { - const { slippage, setSlippage } = useAppState(); + const { slippage, setSlippage, forceLiquidityHub, setForceLiquidityHub } = useAppState(); return (
@@ -35,6 +32,15 @@ export const Settings = () => {
%
+
+ +
+ setForceLiquidityHub(!forceLiquidityHub)} + /> +
+