Skip to content

Freighter network mismatch detection — block all contract calls when wrong network is active #22

Description

@prodbycorne

Problem

StellarWalletContext connects Freighter and stores the public key, but it never checks which Stellar network Freighter is currently set to. If a user has Freighter pointing at Mainnet (PUBLIC) while the app is configured for TESTNET, any deposit or unlock transaction will be built against the wrong network passphrase and either fail with a cryptographic error or — worse — be silently routed to the wrong network.

Expected Behaviour

After a successful Freighter connection (and on every subsequent page focus), the app reads Freighter's active network and compares it against NEXT_PUBLIC_STELLAR_NETWORK. If they differ, a persistent dismissible banner warns the user and all contract-interaction buttons (Deposit, Unlock, Boost) are disabled until the user switches networks inside Freighter.

Acceptance Criteria

  • StellarWalletContext calls freighter.getNetworkDetails() immediately after getAddress() succeeds and stores the result as networkName: string | null
  • isNetworkMismatch: boolean is derived and exposed from the context: true when networkName !== NEXT_PUBLIC_STELLAR_NETWORK
  • A NetworkMismatchBanner component renders a sticky top alert (Chakra Alert status='warning') with the message "Freighter is set to {networkName}. Switch to {expected} to use SmartDrop."
  • document.addEventListener('visibilitychange', ...) re-checks the Freighter network when the tab regains focus so if the user switches network in Freighter and returns, the banner clears automatically within 1 second
  • All three action buttons read isNetworkMismatch from context and pass it into their disabled prop
  • Unit test mocks freighter.getNetworkDetails returning a mismatched network and asserts the banner text is visible and action buttons are disabled

Relevant Files

  • src/context/StellarWalletContext.tsx — add networkName, isNetworkMismatch
  • src/components/AppShell/AppShell.tsx — render NetworkMismatchBanner
  • src/app/farm/page.tsx — consume isNetworkMismatch to gate buttons
  • src/config/index.tsstellarNetwork for comparison

Metadata

Metadata

Assignees

Labels

Official CampaignCampaign: Official CampaignhardRequires deep domain knowledge — Soroban, Stellar SDK, or complex statesecuritySecurity, signing safety, or wallet interaction hardeningwalletFreighter wallet integration, session, and network switching

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions