diff --git a/apps/app/components/Swap/Atomic/index.tsx b/apps/app/components/Swap/Atomic/index.tsx index ba7e1b0..cf0043c 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 "@/context/query"; import useWallet from "@/hooks/useWallet"; import { SwapQuote } from "@/lib/trainApiClient"; -import { dynamicWithRetries } from "@/lib/dynamicWithRetries"; import { useAtomicState } from "@/context/atomicContext"; import VaulDrawer from "../../Modal/vaulModal"; import { Widget } from "../../Widget/Index"; @@ -22,18 +21,6 @@ import { NetworkContractType } from "@/Models/Network"; import { HTLCStatus } from "@/Models/HTLCStatus"; import { usePulsatingCircles } from "@/stores/pulsatingCirclesStore"; -const AtomicPage = dynamicWithRetries( - () => import("../AtomicChat") as unknown as Promise<{ default: React.ComponentType }>, -
-
-
-
-
-
-
-
-
-) export default function Form() { const formikRef = useRef>(null); diff --git a/apps/app/components/Swap/AtomicChat/Actions/UserActions.tsx b/apps/app/components/Swap/AtomicChat/Actions/UserActions.tsx index ef15065..d7c5298 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 {