Skip to content

feat: add wallet network selection (testnet/mainnet/custom) (#889) - #951

Open
adenueltech wants to merge 1 commit into
Stellar-split:mainfrom
adenueltech:feat/issue-889-network-selection
Open

adenueltech wants to merge 1 commit into
Stellar-split:mainfrom
adenueltech:feat/issue-889-network-selection

Conversation

@adenueltech

Copy link
Copy Markdown

Closes #889

What changed

Before this PR, the network was fixed at build time through NEXT_PUBLIC_STELLAR_NETWORK and read in about 20 separate places. Users can now switch between Testnet, Mainnet and a Custom network in the app.

Network switching logic and stored preference: src/lib/networks.ts

  • Presets for testnet and mainnet (passphrase, RPC, Horizon, contract ID, USDC, explorer), plus user-defined custom networks.
  • The user's choice is saved in localStorage (stellarsplit_network). getActiveNetwork() returns the saved choice in the browser and the build default otherwise, including on the server.
  • Switching reloads the page so every module-level constant and the splitClient are rebuilt for the new network. No stale RPC or contract client can leak across.

Endpoints correct per network

  • config.ts, stellar.ts and freighter.ts now resolve RPC, Horizon, passphrase, contract ID and USDC from the active network. Existing exports (RPC_URL, NETWORK_PASSPHRASE, USDC_CONTRACT_ID, …) are unchanged, so callers keep working.
  • Replaced the hard-coded NEXT_PUBLIC_STELLAR_NETWORK / NEXT_PUBLIC_RPC_URL ternaries in the client components and hooks (explorer links, Horizon polling, invoice stream, debugger, etc.). /payments previously always linked to the testnet explorer.
  • New optional env vars NEXT_PUBLIC_{TESTNET,MAINNET}_{CONTRACT_ID,RPC_URL,HORIZON_URL,USDC_ADDRESS} (documented in .env.example). The un-prefixed vars apply only to the default network, so a testnet contract ID is never reused on mainnet.

Validate network compatibility

  • A preset with no contract configured is shown as "Not configured for this deployment" and can't be selected.
  • Custom networks are validated: https only (http allowed for localhost), passphrase required, contract addresses checked with StrKey. They must also pass a live getNetwork RPC call that reports the same passphrase before the switch is allowed.
  • If Freighter is connected on a different network than the app, a warning banner says so (via getNetworkDetails).

Current network always visible, no accidental mainnet/testnet confusion

  • New NetworkSelector badge in the navbar, now shown at every breakpoint. The old static badge was hidden below sm. It is colour-coded and opens the switch dialog.
  • Switching to Mainnet requires ticking "I understand Mainnet uses real funds…".
  • "Reset to default" clears the stored preference.
  • NetworkStatus keeps the RPC health dot and now checks the active network's RPC.

Notes

  • API routes (server) still use the env default network. The user's choice lives in the browser.

How I tested

  • src/__tests__/networks.test.ts: presets, stored preference (including corrupt values), custom network validation and resolution, RPC passphrase check (match, mismatch, HTTP error, unreachable) and explorer URLs.
  • npx tsc --noEmit: 0 errors. next lint on all changed files: clean.
  • Full vitest run: 2141 passed, 5 failed. The 5 failures (ErrorBoundary, InvoiceExportButton, SubscriptionCard, brandTools, contractEvents) also fail or are flaky on unmodified main and are unrelated to this change.

🤖 Generated with Claude Code

…tellar-split#889)

- Add src/lib/networks.ts: presets, custom networks, stored preference,
  validation, live RPC passphrase check and explorer URL helpers
- Resolve RPC, Horizon, passphrase, contract ID and USDC address from the
  active network in config/stellar/freighter and the components that
  hard-coded them, so endpoints are correct per network
- Add NetworkSelector: always-visible badge in the navbar plus a dialog to
  switch; Mainnet needs explicit confirmation, custom networks must pass a
  getNetwork check, unconfigured presets are disabled
- Warn when the Freighter wallet is on a different network than the app
- Remove the static badge from NetworkStatus (now only RPC health)
- Document optional per-network env vars in .env.example

Closes Stellar-split#889

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 17, 2026

Copy link
Copy Markdown

@adenueltech is attempting to deploy a commit to the kingsman-99's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@adenueltech Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

This branch has not been deployed

No deployments
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.

Add wallet network selection (testnet/mainnet/custom)

1 participant