slymnoyann/hey-1 · error · Error

No active wallet connection found.

Error message

No active wallet connection found.

What it means

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.

Source

Thrown at src/hooks/useHandleWrongNetwork.tsx:16

import { useAccount, useSwitchChain } from "wagmi";
import { CHAIN } from "@/data/constants";

interface HandleWrongNetworkParams {
  chainId?: number;
}

const useHandleWrongNetwork = () => {
  const { chainId: activeChainId, isConnected } = useAccount();
  const { switchChainAsync } = useSwitchChain();

  const handleWrongNetwork = async (params?: HandleWrongNetworkParams) => {
    const chainId = params?.chainId ?? CHAIN.id;

    if (!isConnected) {
      throw new Error("No active wallet connection found.");
    }

    if (activeChainId !== chainId) {
      await switchChainAsync({ chainId });
    }
  };

  return handleWrongNetwork;
};

export default useHandleWrongNetwork;

View on GitHub (pinned to 88c8f9d553)

Solutions

  1. Ensure the user is connected before invoking: gate the button/action on isConnected from useAccount, or open the connect modal first
  2. If triggered right after page load, await wagmi's reconnection (useAccount IsReady / useReconnect) before calling chain-dependent logic
  3. Catch this error in the action handler and prompt a wallet reconnect, then retry the action
  4. Consider a fallback to wallet_switchEthereumChain via direct provider request if wagmi connection state is unreliable

Example fix

// before
await handleWrongNetwork();
await sendTransaction(...);

// after
if (!isConnected) {
  openConnectModal();
  return;
}
await handleWrongNetwork();
await sendTransaction(...);
Defensive patterns

Strategy: validation

Validate before calling

const { isConnected } = useAccount();
if (!isConnected) {
  openConnectModal();
  return;
}
await handleWrongNetwork();

Type guard

const hasActiveWallet = (account: { isConnected: boolean; isDisconnected?: boolean }): boolean =>
  account.isConnected && !account.isDisconnected;

Try / catch

try {
  await handleWrongNetwork({ chainId });
} catch (e) {
  if (e instanceof Error && e.message.includes("No active wallet connection")) {
    openConnectModal();
    return;
  }
  throw e; // chain-switch rejection (4001) etc.
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.


AI-assisted analysis of slymnoyann/hey-1@88c8f9d553 (2026-08-28). Data as JSON: /api/errors/79e270d0164cf3af. Report an issue: GitHub.