Skip to content

useBalances conflates "account not found" with generic/offline network failures #643

Description

@K1NGD4VID

Category: Functional Edge Case

Repository location: apps/web/hooks/useBalances.ts (lines ~50-56)

Problem
The 404 (account-not-found) detection duck-types the Horizon SDK error shape (err.response.status === 404) rather than using a typed error class. If the actual error is different — e.g. a network-level failure while offline (TypeError: Failed to fetch) — the account-not-found branch is skipped and the raw error propagates through the same generic error path, so the UI cannot distinguish "you're offline" from "this account doesn't exist on-chain yet," and there's no explicit offline-handling UI anywhere in useWallet/WalletConnect for this case.

Evidence

catch (err: unknown) {
  if (err instanceof Error && "response" in err) {
    const resp = (err as { response?: { status: number } }).response;
    if (resp?.status === 404) {
      return { usdc: null, xlm: "0" };
    }
  }
  captureError(err);
  throw err;
}

Suggested implementation
Use a more robust check (the Horizon SDK's typed NotFoundError class if exported) and add a distinct branch/message for network-level failures (e.g. TypeError/fetch failures) so the UI can show an explicit "you appear to be offline" state.

Acceptance criteria

  • A simulated 404 from Horizon still returns { usdc: null, xlm: "0" }.
  • A simulated network failure (e.g. TypeError: Failed to fetch) surfaces a distinguishable offline error rather than being treated identically to "account not found."

Difficulty: Medium

Expected impact: Gives users accurate feedback instead of a misleading "no balance" state when they're actually offline.


Filed as part of the second repository-wide audit (deeper refinements following the first cleanup pass).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingfrontendNext.js Web Application

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions