Skip to content

[Error Handling] WalletScreen silently swallows refreshBalance errors — user sees stale/zero balance #84

Description

@cybermax4200

Why this matters now: WalletScreen.tsx:18 calls refreshBalance().finally(() => setLoading(false)). If refreshBalance throws (Horizon network failure, rate limiting, account not found), the error is silently consumed. The user sees their old balance (or zero) with no indication that the data is stale. For a financial dApp, showing wrong balance data is worse than showing an error.

Problem / What: src/screens/WalletScreen.tsx:17-19refreshBalance().finally(() => setLoading(false)) — no .catch(), no error state. The useStellarWallet hook's refreshBalance (line 205-210) calls stellar.getBalance() which catches errors and returns '0' — so the error is double-swallowed: once in stellar.ts:40-42 (returns '0'), and once in WalletScreen (no error handling).

Key Challenges:

  • stellar.getBalance() currently returns '0' on error (line 40-42). This is wrong for network failures — it should distinguish between "account not found" (legitimately '0') and "network error" (should propagate).
  • Add error state to WalletScreen to display a "Failed to refresh balance" message.
  • Add a retry mechanism (pull-to-refresh or retry button).
  • Consider showing a "stale data" indicator when the last refresh failed.

Acceptance Criteria:

  • stellar.getBalance() distinguishes "account not found" from network errors.
  • WalletScreen displays an error message when balance refresh fails.
  • User can retry the balance refresh.
  • Stale balance data is visually indicated.
  • Tests verify error state display and retry.

Relevant files/functions:

  • src/screens/WalletScreen.tsx:17-19
  • src/hooks/useStellarWallet.ts:205-210
  • src/services/stellar.ts:35-43

Out of scope: Offline balance caching, background balance refresh.

Labels: error-handling, intermediate, wallet

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions