From 94a97aa4745c31551b3017a3a7b5dd0efff9d28a Mon Sep 17 00:00:00 2001 From: yasha-meursault Date: Fri, 27 Feb 2026 17:04:14 +0400 Subject: [PATCH 1/2] Add missing error handlings for provider and client creation in UserActions and EvmHTLCClient --- .../Swap/AtomicChat/Actions/UserActions.tsx | 3 + apps/app/context/atomicContext.tsx | 4 +- packages/sdk/src/htlc-clients/evm/client.ts | 61 ++++++++++++------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/apps/app/components/Swap/AtomicChat/Actions/UserActions.tsx b/apps/app/components/Swap/AtomicChat/Actions/UserActions.tsx index 4927791..b02adf9 100644 --- a/apps/app/components/Swap/AtomicChat/Actions/UserActions.tsx +++ b/apps/app/components/Swap/AtomicChat/Actions/UserActions.tsx @@ -55,6 +55,9 @@ export const UserCommitAction: FC = ({ quote, type }) => if (!destination_asset) { throw new Error("No destination asset") } + if (!provider) { + throw new Error("No source_provider") + } if (!atomicContract) { throw new Error("No atomic contract") } diff --git a/apps/app/context/atomicContext.tsx b/apps/app/context/atomicContext.tsx index 6eceb0c..1483e23 100644 --- a/apps/app/context/atomicContext.tsx +++ b/apps/app/context/atomicContext.tsx @@ -175,13 +175,13 @@ export function AtomicProvider({ children }) { const sourceClient = useMemo(() => { if (!source_network) return undefined try { return createHTLCClient(source_network, getEffectiveRpcUrls) } - catch { return undefined } + catch (e) { console.error('Error creating source HTLC client:', e); return undefined } }, [source_network, getEffectiveRpcUrls]) const destinationClient = useMemo(() => { if (!destination_network) return undefined try { return createHTLCClient(destination_network, getEffectiveRpcUrls) } - catch { return undefined } + catch (e) { console.error('Error creating destination HTLC client:', e); return undefined } }, [destination_network, getEffectiveRpcUrls]) const handleUserLockSuccess = useCallback((details: LockDetails) => { diff --git a/packages/sdk/src/htlc-clients/evm/client.ts b/packages/sdk/src/htlc-clients/evm/client.ts index 834cebe..e57841e 100644 --- a/packages/sdk/src/htlc-clients/evm/client.ts +++ b/packages/sdk/src/htlc-clients/evm/client.ts @@ -128,10 +128,15 @@ export class EvmHTLCClient implements IHTLCClient { simulationData.value = parsedAmount; } - const { request } = await this.publicClient.simulateContract(simulationData); - const hash = await this.walletClient.writeContract(request as any); - - return { hash, hashlock, nonce: timestamp }; + try { + const { request } = await this.publicClient.simulateContract(simulationData); + const hash = await this.walletClient.writeContract(request as any); + + return { hash, hashlock, nonce: timestamp }; + } catch (error) { + console.error('Error in createHTLC:', error); + throw error; + } } async getUserLockDetails(params: LockParams): Promise { @@ -273,16 +278,21 @@ export class EvmHTLCClient implements IHTLCClient { if (!this.walletClient) throw new Error('WalletClient required for refund'); const { id, contractAddress } = params; - const { request } = await this.publicClient.simulateContract({ - account: this.walletClient.account?.address as `0x${string}`, - abi: HTLCAbi, - address: contractAddress as `0x${string}`, - functionName: 'refundUser', - args: [id], - chain: this.publicClient.chain, - }); + try { + const { request } = await this.publicClient.simulateContract({ + account: this.walletClient.account?.address as `0x${string}`, + abi: HTLCAbi, + address: contractAddress as `0x${string}`, + functionName: 'refundUser', + args: [id], + chain: this.publicClient.chain, + }); - return await this.walletClient.writeContract(request as any); + return await this.walletClient.writeContract(request as any); + } catch (error) { + console.error('Error in refund:', error); + throw error; + } } async claim(params: ClaimParams): Promise { @@ -291,16 +301,21 @@ export class EvmHTLCClient implements IHTLCClient { const account = (destinationAddress ?? this.walletClient.account?.address) as `0x${string}`; - const { request } = await this.publicClient.simulateContract({ - account, - abi: HTLCAbi, - address: contractAddress as `0x${string}`, - functionName: 'redeemSolver', - args: [id, 1, BigInt(secret)], - chain: this.publicClient.chain, - }); - - return await this.walletClient.writeContract(request as any); + try { + const { request } = await this.publicClient.simulateContract({ + account, + abi: HTLCAbi, + address: contractAddress as `0x${string}`, + functionName: 'redeemSolver', + args: [id, 1, BigInt(secret)], + chain: this.publicClient.chain, + }); + + return await this.walletClient.writeContract(request as any); + } catch (error) { + console.error('Error in claim:', error); + throw error; + } } async recoverSwap(txHash: `0x${string}`): Promise { From 600aa4708ec127fc6e9994b45ece4570c0961674 Mon Sep 17 00:00:00 2001 From: yasha-meursault Date: Fri, 27 Feb 2026 18:29:01 +0400 Subject: [PATCH 2/2] Refactor AtomicPage import to use static import instead of dynamic loading --- apps/app/components/Swap/Atomic/index.tsx | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/apps/app/components/Swap/Atomic/index.tsx b/apps/app/components/Swap/Atomic/index.tsx index 968cbc0..23e8452 100644 --- a/apps/app/components/Swap/Atomic/index.tsx +++ b/apps/app/components/Swap/Atomic/index.tsx @@ -8,7 +8,6 @@ import { NextRouter, useRouter } from "next/router"; import { useQueryState } from "@/apps/app/context/query"; import useWallet from "@/apps/app/hooks/useWallet"; import { SwapQuote } from "@/apps/app/lib/trainApiClient"; -import { dynamicWithRetries } from "@/apps/app/lib/dynamicWithRetries"; import { useAtomicState } from "@/apps/app/context/atomicContext"; import VaulDrawer from "../../Modal/vaulModal"; import { Widget } from "../../Widget/Index"; @@ -21,19 +20,7 @@ import { formatUnits } from "viem"; import { NetworkContractType } from "@/apps/app/Models/Network"; import { HTLCStatus } from "@/apps/app/Models/HTLCStatus"; import { usePulsatingCircles } from "@/apps/app/stores/pulsatingCirclesStore"; - -const AtomicPage = dynamicWithRetries( - () => import("../AtomicChat") as unknown as Promise<{ default: React.ComponentType }>, -
-
-
-
-
-
-
-
-
-) +import AtomicPage from "../AtomicChat"; export default function Form() { const formikRef = useRef>(null);