Skip to content

UI DX: make MetaMask connect + network switching more reliable#22

Merged
snissn merged 1 commit into
masterfrom
feat/ui-metamask-dx
Feb 5, 2026
Merged

UI DX: make MetaMask connect + network switching more reliable#22
snissn merged 1 commit into
masterfrom
feat/ui-metamask-dx

Conversation

@snissn

@snissn snissn commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Problem

Generated UIs can fail to switch networks in MetaMask with a vague message like:

Wrong network… (An error occurred when attempting to switch chain.)

This is especially common when the user is currently on a non-local chain (e.g. chainId 314159) and the app expects Anvil (31337).

Fix

Improve the wallet connect + network switch flow:

  • Connect first (eth_requestAccounts) before attempting a network switch. Some wallets behave more reliably when already connected.
  • Best-effort add + switch fallback: if wallet_switchEthereumChain fails, attempt wallet_addEthereumChain and retry switching.
  • Actionable errors:
    • Detect user-rejected requests and tell them to approve the prompt.
    • When possible, include the expected chain name/id and the RPC URL to add in MetaMask.

How to test

  1. Run pnpm th dev apps/example/job-board.schema.json.
  2. In MetaMask, switch to another network (e.g. a testnet).
  3. In the UI, try creating a record.
  4. Expected: the UI connects the wallet, then prompts to add/switch to Anvil (31337); errors are now actionable if rejected.

@snissn snissn merged commit 2b35582 into master Feb 5, 2026
1 check passed
@snissn snissn deleted the feat/ui-metamask-dx branch February 5, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant