Skip to content

fix: remove orphaned, mainnet-hardcoded useStellarAccount hook#33

Merged
abayomicornelius merged 8 commits into
StellarSend:mainfrom
Temi-suwa18:fix/remove-orphaned-usestellaraccount-hook
Jul 17, 2026
Merged

fix: remove orphaned, mainnet-hardcoded useStellarAccount hook#33
abayomicornelius merged 8 commits into
StellarSend:mainfrom
Temi-suwa18:fix/remove-orphaned-usestellaraccount-hook

Conversation

@Temi-suwa18

@Temi-suwa18 Temi-suwa18 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #21.

src/hooks/useStellarAccount.ts hardcoded https://horizon.stellar.org (mainnet) with no way to target testnet, unlike WalletContext's network-aware fetchAccountFromHorizon(publicKey, network). For a testnet-only address, calling it would always 404 ("Account not found") even though the account genuinely exists on testnet — a confusing false negative.

Per the issue's own suggested resolution, I checked for call sites before deciding between "fix in place" vs. "remove":

$ grep -rn "useStellarAccount" --include="*.ts" --include="*.tsx" src/
src/hooks/useStellarAccount.ts:9:export function useStellarAccount() {

Zero call sites anywhere in the app — it's dead code. It also duplicated functionality that already exists, correctly, network-aware, in useWallet's account state (backed by fetchAccountFromHorizon), and its local AccountInfo shape ({ address, balance, sequence }) was a narrower ad-hoc duplicate of the real AccountInfo type in src/types (missing thresholds, flags, non-XLM balances).

Since nothing imports it and a correct, network-aware equivalent already exists, this removes the hook entirely rather than threading network-awareness into unused code and maintaining two parallel account-fetching implementations.

The issue's "Testing strategy" section asked for a test asserting request-host selection by network. Since that logic lives correctly in horizonUrl/fetchAccountFromHorizon (which had zero test coverage despite being exactly the code this whole issue is about), I added coverage there instead of testing the deleted hook: testnet/mainnet host selection, 404 and generic-error handling, and full AccountInfo field mapping (thresholds/flags/multi-asset balances — the exact gap useStellarAccount's narrower shape had).

Test plan

  • grep -rn "useStellarAccount" confirms no remaining references after removal
  • npm run lint — clean
  • npx tsc --noEmit — clean
  • npx vitest run — 66/66 passing (7 new tests in src/lib/api.test.ts)
  • npm run build — succeeds

useStellarAccount hardcoded https://horizon.stellar.org (mainnet)
regardless of the user's selected network, unlike WalletContext's
network-aware fetchAccountFromHorizon(publicKey, network). It also had
zero call sites anywhere in the app and returned a narrower ad-hoc
{ address, balance, sequence } shape that duplicates the real
AccountInfo type in src/types.

Per the issue's own suggested resolution, deleting a dead,
network-unaware duplicate is preferable to fixing it in place and
maintaining two parallel account-fetching implementations —
useWallet's account state (backed by fetchAccountFromHorizon) already
covers this correctly.
The network-selection bug in StellarSend#21 lived in a hook that duplicated this
exact logic without testing or reusing it. horizonUrl is the real,
correct implementation everything should route through — give it
coverage so a future regression here is caught directly.
This is the request path that useStellarAccount should have delegated
to instead of hardcoding the mainnet host. Assert the request URL
actually varies with the network argument, mocking global fetch.
Confirms a missing account (the exact symptom this issue's testnet
addresses hit against the wrong, hardcoded mainnet host) surfaces as a
readable 'Account not found on Stellar network' error.
Non-404 failures (rate limiting, Horizon downtime, etc.) should still
surface a readable message rather than an unhandled rejection.
One of StellarSend#21's complaints about useStellarAccount was that it only
surfaced the native XLM balance and none of an account's thresholds/
flags/other-asset balances. Assert fetchAccountFromHorizon — the
implementation everything should use instead — actually returns the
full AccountInfo shape, not just a subset.
… network-aware path

Leaves a pointer at the source of truth so a future ad-hoc Horizon
call reaches for this instead of re-hardcoding a host the way
useStellarAccount did (StellarSend#21).
@Temi-suwa18

Copy link
Copy Markdown
Contributor Author

please review all 4 checks has passed

@abayomicornelius
abayomicornelius merged commit 9519011 into StellarSend:main Jul 17, 2026
4 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

Development

Successfully merging this pull request may close these issues.

useStellarAccount hardcodes mainnet Horizon regardless of the user's selected network, and duplicates useWallet's account fetching

2 participants