{"record":{"id":"79e270d0164cf3af","repo":"slymnoyann/hey-1","slug":"no-active-wallet-connection-found","errorCode":null,"errorMessage":"No active wallet connection found.","messagePattern":"No active wallet connection found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/hooks/useHandleWrongNetwork.tsx","lineNumber":16,"sourceCode":"import { useAccount, useSwitchChain } from \"wagmi\";\nimport { CHAIN } from \"@/data/constants\";\n\ninterface HandleWrongNetworkParams {\n  chainId?: number;\n}\n\nconst useHandleWrongNetwork = () => {\n  const { chainId: activeChainId, isConnected } = useAccount();\n  const { switchChainAsync } = useSwitchChain();\n\n  const handleWrongNetwork = async (params?: HandleWrongNetworkParams) => {\n    const chainId = params?.chainId ?? CHAIN.id;\n\n    if (!isConnected) {\n      throw new Error(\"No active wallet connection found.\");\n    }\n\n    if (activeChainId !== chainId) {\n      await switchChainAsync({ chainId });\n    }\n  };\n\n  return handleWrongNetwork;\n};\n\nexport default useHandleWrongNetwork;\n","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/slymnoyann/hey-1/blob/88c8f9d55340d57a37846ff72f55c2c604e3a566/src/hooks/useHandleWrongNetwork.tsx#L1-L28","documentation":"Thrown by handleWrongNetwork in useHandleWrongNetwork.tsx when the wallet reports no active connection (isConnected from wagmi's useAccount is false). The hook's job is to switch the connected wallet to the app chain (CHAIN.id) before signing/sending a transaction, and that's meaningless without a connection.","triggerScenarios":"Calling handleWrongNetwork after the user disconnected or locked the wallet, on first render before wagmi re-hydrates a persisted connector, or after the connector's session expired — isConnected is false so switchChainAsync would be unsafe.","commonSituations":"Wallet disconnected mid-session (extension timeout), page refresh where wagmi hasn't finished reconnecting, MetaMask locked, or a stale connector id persisted in localStorage that fails to reconnect.","solutions":["Ensure the user is connected before invoking: gate the button/action on isConnected from useAccount, or open the connect modal first","If triggered right after page load, await wagmi's reconnection (useAccount IsReady / useReconnect) before calling chain-dependent logic","Catch this error in the action handler and prompt a wallet reconnect, then retry the action","Consider a fallback to wallet_switchEthereumChain via direct provider request if wagmi connection state is unreliable"],"exampleFix":"// before\nawait handleWrongNetwork();\nawait sendTransaction(...);\n\n// after\nif (!isConnected) {\n  openConnectModal();\n  return;\n}\nawait handleWrongNetwork();\nawait sendTransaction(...);","handlingStrategy":"validation","validationCode":"const { isConnected } = useAccount();\nif (!isConnected) {\n  openConnectModal();\n  return;\n}\nawait handleWrongNetwork();","typeGuard":"const hasActiveWallet = (account: { isConnected: boolean; isDisconnected?: boolean }): boolean =>\n  account.isConnected && !account.isDisconnected;","tryCatchPattern":"try {\n  await handleWrongNetwork({ chainId });\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"No active wallet connection\")) {\n    openConnectModal();\n    return;\n  }\n  throw e; // chain-switch rejection (4001) etc.\n}","preventionTips":["Gate all signing/tx actions behind isConnected from useAccount","Await wagmi rehydration after page refresh before chain-dependent calls","Handle wallet disconnect events globally to reset in-flight web3 flows"],"tags":["wallet","wagmi","chain-switch","web3"],"backgroundTag":"wallet-not-connected","analyzedSha":"88c8f9d55340d57a37846ff72f55c2c604e3a566","analyzedAt":"2026-08-28T16:20:43.640Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}