From dfd8c432f8b98d448966f158d126e326b7fbe53c Mon Sep 17 00:00:00 2001 From: aldin4u Date: Tue, 3 Feb 2026 10:16:42 +0000 Subject: [PATCH 1/3] fix: use fallback HTTP transport in delegatedEoa mode --- src/apps/perps/hooks/useHyperliquid.ts | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/apps/perps/hooks/useHyperliquid.ts b/src/apps/perps/hooks/useHyperliquid.ts index 15046cdb..eeee393f 100644 --- a/src/apps/perps/hooks/useHyperliquid.ts +++ b/src/apps/perps/hooks/useHyperliquid.ts @@ -1,4 +1,4 @@ -import { useState, useCallback, useEffect } from 'react'; +import { useState, useCallback, useEffect, useMemo } from 'react'; import { useWalletClient } from 'wagmi'; import useTransactionKit from '../../../hooks/useTransactionKit'; import { @@ -26,7 +26,7 @@ import { } from '../lib/hyperliquid/math'; import { toast } from 'sonner'; import { getAgentAddress } from '../lib/hyperliquid/keystore'; -import { createWalletClient, custom } from 'viem'; +import { createWalletClient, custom, http } from 'viem'; import { arbitrum } from 'viem/chains'; type SetupStatus = 'unknown' | 'not-setup' | 'setup'; @@ -42,7 +42,16 @@ export function useHyperliquid() { const [address, setAddress] = useState(null); const [walletClient, setWalletClient] = useState(null); - const provider = kit.getProvider(); + // Safe provider access for delegatedEoa mode + const clientTransport = useMemo(() => { + try { + return custom(kit.getProvider()); + } catch (e) { + // In delegatedEoa mode, getProvider() might throw. + // We fallback to standard http transport for Arbitrum. + return http(); + } + }, [kit]); const checkSetupStatus = useCallback(async () => { // 1. Check for Imported Account (Priority) @@ -64,7 +73,7 @@ export function useHyperliquid() { client = createWalletClient({ account, chain: arbitrum, - transport: custom(provider as any), + transport: clientTransport, }); isImported = true; } else { @@ -78,7 +87,7 @@ export function useHyperliquid() { client = createWalletClient({ account: eoa as `0x${string}`, chain: arbitrum, - transport: custom(provider as any), + transport: clientTransport, }); } } @@ -196,13 +205,13 @@ export function useHyperliquid() { client = createWalletClient({ account, chain: arbitrum, - transport: custom(provider as any), + transport: clientTransport, }); } else { client = createWalletClient({ account: address as `0x${string}`, chain: arbitrum, - transport: custom(provider as any), + transport: clientTransport, }); } @@ -300,13 +309,13 @@ export function useHyperliquid() { client = createWalletClient({ account, chain: arbitrum, - transport: custom(provider as any), + transport: clientTransport, }); } else { client = createWalletClient({ account: address as `0x${string}`, chain: arbitrum, - transport: custom(provider as any), + transport: clientTransport, }); } const walletClient = client; From d54a6b23b03cfff588b9d46c9342ed84d3ad47d6 Mon Sep 17 00:00:00 2001 From: aldin4u Date: Tue, 3 Feb 2026 10:25:00 +0000 Subject: [PATCH 2/3] fix: refine transport logic for EOA safety --- src/apps/perps/hooks/useHyperliquid.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/apps/perps/hooks/useHyperliquid.ts b/src/apps/perps/hooks/useHyperliquid.ts index eeee393f..ef619451 100644 --- a/src/apps/perps/hooks/useHyperliquid.ts +++ b/src/apps/perps/hooks/useHyperliquid.ts @@ -48,8 +48,8 @@ export function useHyperliquid() { return custom(kit.getProvider()); } catch (e) { // In delegatedEoa mode, getProvider() might throw. - // We fallback to standard http transport for Arbitrum. - return http(); + console.debug('Provider not available (likely delegatedEoa mode).'); + return null; } }, [kit]); @@ -73,7 +73,7 @@ export function useHyperliquid() { client = createWalletClient({ account, chain: arbitrum, - transport: clientTransport, + transport: clientTransport ?? http(), }); isImported = true; } else { @@ -82,7 +82,7 @@ export function useHyperliquid() { const eoa = (await walletProvider.getSdk()).getEOAAddress() || null; console.log('DEBUG: Wallet Provider EOA:', eoa); - if (eoa) { + if (eoa && clientTransport) { targetAddress = eoa; client = createWalletClient({ account: eoa as `0x${string}`, @@ -205,9 +205,9 @@ export function useHyperliquid() { client = createWalletClient({ account, chain: arbitrum, - transport: clientTransport, + transport: clientTransport ?? http(), }); - } else { + } else if (clientTransport) { client = createWalletClient({ account: address as `0x${string}`, chain: arbitrum, @@ -309,9 +309,9 @@ export function useHyperliquid() { client = createWalletClient({ account, chain: arbitrum, - transport: clientTransport, + transport: clientTransport ?? http(), }); - } else { + } else if (clientTransport) { client = createWalletClient({ account: address as `0x${string}`, chain: arbitrum, From 9fa92577bd441959441aa75ecebc6eb5a71fa76e Mon Sep 17 00:00:00 2001 From: aldin4u Date: Tue, 3 Feb 2026 10:37:39 +0000 Subject: [PATCH 3/3] fix: update dependency arrays to include clientTransport --- src/apps/perps/hooks/useHyperliquid.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/perps/hooks/useHyperliquid.ts b/src/apps/perps/hooks/useHyperliquid.ts index ef619451..9793add8 100644 --- a/src/apps/perps/hooks/useHyperliquid.ts +++ b/src/apps/perps/hooks/useHyperliquid.ts @@ -191,7 +191,7 @@ export function useHyperliquid() { } finally { setIsLoading(false); } - }, []); + }, [clientTransport]); const setupHyperliquid = useCallback(async () => { // Check for Imported Account logic again to ensure valid signer @@ -242,7 +242,7 @@ export function useHyperliquid() { } finally { setIsLoading(false); } - }, [address, checkSetupStatus]); + }, [address, checkSetupStatus, clientTransport]); const loadBalance = useCallback(async () => { if (!address) return; @@ -392,7 +392,7 @@ export function useHyperliquid() { setIsLoading(false); } }, - [address, setupStatus, loadBalance] + [address, setupStatus, loadBalance, clientTransport] ); // Call checkSetupStatus on mount to initialize the address