Skip to content

refactor: consolidate Stellar network config into a single source (#489) - #621

Merged
nonsobethel0-dev merged 2 commits into
Parashield-Protocol:mainfrom
alansamdev:fix/489-consolidate-network-config
Sep 23, 2026
Merged

nonsobethel0-dev merged 2 commits into
Parashield-Protocol:mainfrom
alansamdev:fix/489-consolidate-network-config

Conversation

@alansamdev

@alansamdev alansamdev commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #489
Closes #492
Closes #491
Closes #490

The issue points at hooks/useStellarNetwork.ts and lib/config.ts, but neither file exists in the repo. The duplication it describes is real, though. Five modules each worked out network config from STELLAR_NETWORK independently:

Location What it re-derived
src/lib/stellar.ts STELLAR_NETWORK === 'PUBLIC' ? WalletNetwork.PUBLIC : … for the expected passphrase
src/lib/contract.ts STELLAR_NETWORK === 'PUBLIC' ? Networks.PUBLIC : Networks.TESTNET
src/context/WalletContext.tsx hard-coded testnet/public passphrases, a local networkLabel() and APP_NETWORK_LABEL
src/components/NetworkBanner.tsx hard-coded public passphrase, plus a STELLAR_NETWORK === 'PUBLIC' check
src/components/TransactionLink.tsx its own ternary for the explorer URL

So there were several ways to answer "which network are we on?", and they could drift apart.

Changes

Commit 1: src/lib/constants.ts is now the single source of truth. Added these next to the existing STELLAR_NETWORK:

  • IS_MAINNET
  • NETWORK_PASSPHRASES (PUBLIC / TESTNET literals)
  • NETWORK_PASSPHRASE: the active network's passphrase
  • NETWORK_LABEL: 'Mainnet' / 'Testnet'
  • networkLabelForPassphrase(passphrase): a readable name for a passphrase a wallet reports
  • EXPLORER_TX_BASE_URL

SOROBAN_RPC_URL now uses IS_MAINNET too.

Commit 2: consumers import the shared values instead of deriving their own.

  • contract.ts drops its local NETWORK_PASSPHRASE and the unused Networks import.
  • stellar.ts keeps EXPECTED_NETWORK_PASSPHRASE as a re-export of NETWORK_PASSPHRASE, so existing callers and the test mocks still work.
  • WalletContext, NetworkBanner and TransactionLink drop their hard-coded passphrases, labels and URLs.

Behaviour

No runtime change. Each derived value is the same as before on both TESTNET and PUBLIC. The passphrase literals match the SDK's Networks.* values and WalletNetwork.*.

Testing

  • Checked that the two test files that partially mock @/lib/constants (usePolicies.test.ts and useOracle.test.ts) only use hooks that import interval constants. They don't load the modules changed here.
  • I couldn't install dependencies locally because of a network restriction, so tsc and vitest have not been run. CI should confirm.

🤖 Generated with Claude Code

Add IS_MAINNET, NETWORK_PASSPHRASES, NETWORK_PASSPHRASE, NETWORK_LABEL,
networkLabelForPassphrase and EXPLORER_TX_BASE_URL as the single source of
truth for everything derived from STELLAR_NETWORK.

Refs Parashield-Protocol#489
stellar.ts, contract.ts, WalletContext, NetworkBanner and TransactionLink
each re-checked STELLAR_NETWORK === 'PUBLIC' and hard-coded passphrases /
explorer URLs. They now import the shared values from lib/constants.
EXPECTED_NETWORK_PASSPHRASE is kept as a re-export for existing callers.

Closes Parashield-Protocol#489
@drips-wave

drips-wave Bot commented Sep 23, 2026

Copy link
Copy Markdown

@alansamdev 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

@netlify

netlify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for boisterous-sunshine-dd4c4c failed.

Name Link
🔨 Latest commit a331866
🔍 Latest deploy log https://app.netlify.com/projects/boisterous-sunshine-dd4c4c/deploys/6ab414c14821f50007c806fb

@nonsobethel0-dev
nonsobethel0-dev merged commit 700ff0e into Parashield-Protocol:main Sep 23, 2026
0 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants