Friendly error for network passphrase mismatch#285
Conversation
…o-dismiss bottom sheet functionality
…tion and automatic retry logic
…based on earliest timestamp
…w for withdrawal processes
|
@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. |
ezedike-evan
left a comment
There was a problem hiding this comment.
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 guardcomponents/offramp/ExecuteDrawer.tsx— the UI catch branchtests/lib/sep10.test.ts— mismatch teststests/components/ExecuteDrawer.test.tsx— UI guidance test
What's bundled in that belongs to different tickets:
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.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.app/globals.css— mobile bottom-sheet swipe-to-dismiss styles. Unrelated to network errors; belongs with whichever PR ships the swipe feature.types/index.ts(quoteIdfield onAnchorRate) — belongs with the dedupe/sep38 work, not this PR.
How to fix:
- Create a clean branch from
maincontaining only the 4 files scoped to #26. - Split the remaining changes into their appropriate PRs (or they land via #284 once that's cleaned up).
- Re-open a focused PR against
mainfor #26.
The mismatch logic itself is solid — happy to fast-track review once the scope is trimmed.
|
Still bundling three unrelated changesets. The network-mismatch fix in |
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.