Skip to content

fix(network): validate custom network inputs before saving (#39) - #49

Open
produckq-boop wants to merge 1 commit into
octraban:mainfrom
produckq-boop:fix/validate-custom-network-inputs-39
Open

produckq-boop wants to merge 1 commit into
octraban:mainfrom
produckq-boop:fix/validate-custom-network-inputs-39

Conversation

@produckq-boop

Copy link
Copy Markdown

Closes #39

Summary

Validates custom network entries in NetworkSwitcher before persisting them so invalid names, malformed URLs, or missing passphrases cannot be saved into active network state.

What Changed

  • URL & form validation (src/config/network.ts, src/components/NetworkSwitcher.tsx):
    • Added isValidHttpUrl to require well-formed http: or https: URLs with valid hostnames and no internal whitespace.
    • Added validateCustomNetworkForm to require non-empty name, rpcUrl, and passphrase, validate rpcUrl (and horizonUrl when provided) as http(s) URLs, and reject duplicate network names case-insensitively against both built-in (Testnet, Mainnet, Futurenet) and saved custom networks.
  • Inline errors, disabled Save, & input trimming (src/components/NetworkSwitcher.tsx, src/contexts/NetworkContext.tsx):
    • Rendered field-level inline error alerts (role="alert", aria-invalid, aria-describedby) on field interaction/blur or submit, and kept Save & switch disabled until all fields are valid.
    • Trimmed name, rpcUrl, horizonUrl, and passphrase before validation and persistence, and guarded NetworkContext against malformed localStorage entries.
  • Non-blocking RPC reachability check (src/components/NetworkSwitcher.tsx):
    • Added debounced (300ms) and on-demand (Check RPC) JSON-RPC getHealth probing with AbortController cleanup and a 4s timeout, surfacing reachability status (role="status") without blocking save when an endpoint is offline or unreachable.
  • Tests (test/NetworkSwitcher.test.tsx):
    • Added 14 unit and component tests covering isValidHttpUrl, validateCustomNetworkForm, malformed RPC URLs, blank/whitespace required fields, optional Horizon URL validation, case-insensitive duplicate name checks, trimmed persistence and network re-selection, non-blocking RPC reachability states, form cancellation, and malformed localStorage filtering.

Verification

  • npm run lint
  • npx prettier --check src/config/network.ts src/contexts/NetworkContext.tsx src/components/NetworkSwitcher.tsx test/NetworkSwitcher.test.tsx
  • npx tsc --noEmit
  • npm run build
  • npm test (21/21 test files, 179/179 tests passing)

- Validate required name, RPC URL, and passphrase fields, and require well-formed http(s) URLs for RPC and optional Horizon endpoints
- Render field-level inline validation errors and disable Save until the form is valid
- Trim inputs before saving, reject duplicate network names case-insensitively across built-in and saved custom networks, and guard persisted entries in NetworkContext
- Surface non-blocking RPC reachability status without preventing valid networks from being saved
- Add unit and component tests covering validation, duplicate prevention, trimming, reachability probing, and network selection
@vercel

vercel Bot commented Nov 3, 2026

Copy link
Copy Markdown

@produckq-boop is attempting to deploy a commit to the Prisca's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Validate custom network inputs before saving in the network switcher

1 participant