Skip to content

Friendly error for network passphrase mismatch#285

Open
githoboman wants to merge 6 commits into
ezedike-evan:mainfrom
githoboman:friendly-error-for-network-passphrase-mismatch
Open

Friendly error for network passphrase mismatch#285
githoboman wants to merge 6 commits into
ezedike-evan:mainfrom
githoboman:friendly-error-for-network-passphrase-mismatch

Conversation

@githoboman
Copy link
Copy Markdown
Contributor

Summary
Freighter throws an opaque error when its selected network doesn't match the network the anchor's SEP-10 challenge is for. I added a pre-sign guard that detects this and surfaces actionable guidance.
Closes #26

lib/stellar/sep10.ts
NetworkMismatchError — a new typed error (extending the existing WalletError hierarchy) carrying both the expected and the wallet's current network, with a message that starts "Switch network in Freighter to …" and names the exact network.
networkNameForPassphrase() — maps a raw passphrase to a friendly name (Mainnet (Public), Testnet, Futurenet, or the passphrase itself as fallback).
signChallenge() — now reads Freighter's network via getNetwork() before calling signTransaction. On a confirmed mismatch it throws NetworkMismatchError and never attempts the sign. If the network can't be read (extension hiccup, missing API), it falls through and lets signing proceed — so this guard can't itself break the happy path.
components/offramp/ExecuteDrawer.tsx
The catch block now branches on err instanceof NetworkMismatchError first, rendering the dedicated switch-network message via the existing error UI (with a "Try Again" button) before any generic handling.
Acceptance criteria
✅ Mismatch surfaces specific guidance (exact network name) without attempting the sign (signTransaction is asserted not-called).
✅ No uncaught exception reaches the UI boundary — the typed error flows through ExecuteDrawer's existing catch into the rendered error state.
Tests
Added coverage in tests/lib/sep10.test.ts (mismatch throws without signing, both networks named in the message, graceful fall-through when the network can't be read) and tests/components/ExecuteDrawer.test.tsx (dedicated guidance renders). All sep10 tests pass (12/12); my new component test passes.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

@githoboman is attempting to deploy a commit to the ezedikeevan's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Owner

@ezedike-evan ezedike-evan left a comment

Choose a reason for hiding this comment

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

Thanks @githoboman — the core fix for #26 (NetworkMismatchError, networkNameForPassphrase, the pre-sign guard in signChallenge, and the ExecuteDrawer catch branch) is correct and well-tested. However, I cannot merge this PR as-is because it violates the "one logical change per PR" rule.

What's in scope for #26 (2 files):

  • lib/stellar/sep10.ts — the mismatch guard
  • components/offramp/ExecuteDrawer.tsx — the UI catch branch
  • tests/lib/sep10.test.ts — mismatch tests
  • tests/components/ExecuteDrawer.test.tsx — UI guidance test

What's bundled in that belongs to different tickets:

  1. lib/stellar/rates-engine.ts + tests/rates-dedupe.spec.ts — this is the dedupe primitive for #175. It has its own PR (#284) open right now.
  2. tests/sep38-auth.spec.ts — SEP-38 JWT auth test suite. Not related to network mismatch; belongs in a separate PR covering sep38 auth work.
  3. app/globals.css — mobile bottom-sheet swipe-to-dismiss styles. Unrelated to network errors; belongs with whichever PR ships the swipe feature.
  4. types/index.ts (quoteId field on AnchorRate) — belongs with the dedupe/sep38 work, not this PR.

How to fix:

  1. Create a clean branch from main containing only the 4 files scoped to #26.
  2. Split the remaining changes into their appropriate PRs (or they land via #284 once that's cleaned up).
  3. Re-open a focused PR against main for #26.

The mismatch logic itself is solid — happy to fast-track review once the scope is trimmed.

@ezedike-evan
Copy link
Copy Markdown
Owner

Still bundling three unrelated changesets. The network-mismatch fix in sep10.ts + ExecuteDrawer.tsx is the ticket scope — but this PR also adds the swipe-to-dismiss bottom sheet (app/globals.css, the drag-offset state, scroll-lock effect, and touch handlers in ExecuteDrawer.tsx), the rates-engine.ts dedupe module with its 117-line test suite, the sep38-auth.spec.ts (243 lines for a different feature entirely), and a types/index.ts quoteId field that belongs with the dedupe work. Please strip everything except NetworkMismatchError, networkNameForPassphrase, the guard in signChallenge, the ExecuteDrawer catch branch, and the two targeted test files; the swipe sheet, dedupe, and SEP-38 auth work should land in their own PRs.

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.

[#026] friendly error for network passphrase mismatch

2 participants