Skip to content

Gate play on Base Sepolia and offer one-click network switch - #67

Merged
aichannode merged 2 commits into
mainfrom
fix/base-sepolia-network-gate
Jul 25, 2026
Merged

Gate play on Base Sepolia and offer one-click network switch#67
aichannode merged 2 commits into
mainfrom
fix/base-sepolia-network-gate

Conversation

@heyradcode

Copy link
Copy Markdown
Collaborator

Why

A wallet on any network other than Base Sepolia left the app in a dead state
with no way out:

  • The network switcher returned null whenever useAccount().chain was
    undefined, which is exactly the state an unsupported network puts it in. The
    one control that could switch back was hidden.
  • Native balance reads failed for the same reason: useBalance({ address })
    targeted a chain wagmi had no transport for.
  • Hardhat Local sat first in CHAINS, and wagmi treats chains[0] as its
    default, so hosted builds fell back to http://localhost:8545 for RPC reads
    before a wallet reported a usable chain.

MetaMask defaults to Ethereum Mainnet, so a new player hit all three at once.

What changed

Chain list (constants/chains/ethereum.ts)

  • Base Sepolia first, so the default RPC target is the chain we deploy to.
  • Hardhat Local only under import.meta.env.DEV.
  • Removed Arbitrum, Optimism, and Base mainnet. None have contracts, so
    offering them let a player switch to a network where every read silently
    fails.
  • Added TARGET_CHAIN_ID (from VITE_EVM_CHAIN_ID, default 84532) and
    isSupportedChain(). Declared VITE_EVM_CHAIN_ID in vite-env.d.ts, where
    it was already being read but undeclared.

Network switcher

  • Keyed off chainId (raw, defined whenever connected) instead of chain
    (only set for configured chains), so it stays visible and reads
    "Wrong network".
  • Dropped the mainnet/testnet toggle, which had nothing left to toggle.

New NetworkGate

  • Banner under the top bar with a single "Switch to Base Sepolia" action.
  • switchChain sends wallet_switchEthereumChain; wagmi's injected connector
    retries with wallet_addEthereumChain on MetaMask error 4902, so a player who
    has never added Base Sepolia gets the add prompt from the same button.
  • Falls back to Dynamic's primaryWallet.switchNetwork() when the wagmi bridge
    isn't connected yet.
  • Translates error 4001 into a readable message instead of a raw wallet error.
  • Renders nothing unless an EVM wallet is connected, so Solana-only players
    never see it.

Testing

pnpm --filter frontend lint:check, test, and build all pass
(42 files / 281 tests).

Two existing test files covered the changed API and were updated; 11 tests were
failing against the old getChainsByType helpers and chain mock. Added a
regression test that the switcher stays visible on an unsupported chain, plus
six tests for the gate covering the Dynamic fallback and the rejection path.

@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
do-not-stop-frontend Ready Ready Preview, Comment Jul 25, 2026 3:04pm
do-not-stop-website Ready Ready Preview, Comment Jul 25, 2026 3:04pm

@github-actions

Copy link
Copy Markdown

🧪 Coverage

Package Statements Branches Functions Lines Overall
backend 81.44% (869/1067) 75.13% (405/539) 83.41% (181/217) 82.88% (809/976) 80.89% (2264/2799)
frontend 67.00% (1245/1858) 67.57% (1038/1536) 63.00% (298/473) 67.55% (1135/1680) 66.99% (3716/5547)
shared 59.35% (1491/2512) 58.10% (900/1549) 59.07% (267/452) 62.31% (1379/2213) 60.02% (4037/6726)

@heyradcode
heyradcode marked this pull request as ready for review July 25, 2026 15:06

@aichannode aichannode left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thank you 👍

@aichannode
aichannode merged commit defcbc2 into main Jul 25, 2026
4 checks passed
@aichannode
aichannode deleted the fix/base-sepolia-network-gate branch July 25, 2026 15:07
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.

2 participants