Skip to content

refactor: enhance balance refresh logic in useStellarWallet and Walle… - #119

Merged
cybermax4200 merged 2 commits into
ecotask-network:mainfrom
D240021:main
Aug 25, 2026
Merged

refactor: enhance balance refresh logic in useStellarWallet and Walle…#119
cybermax4200 merged 2 commits into
ecotask-network:mainfrom
D240021:main

Conversation

@D240021

@D240021 D240021 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

fix(wallet): surface balance refresh errors on WalletScreen

Description

WalletScreen used to refresh the XLM balance without handling failure. A Horizon/network error was swallowed, so the user kept seeing a stale or zero balance with no way to tell the data was wrong. This change surfaces that failure, lets the user retry, and marks the last known balance as possibly out of date.

refreshBalance now returns true/false instead of swallowing the error. It still does not throw, so existing fire-and-forget call sites stay safe. stellar.getBalance() already distinguishes an unfunded account (NotFoundError'0') from a network failure (the error is rethrown); that contract is unchanged.

Closes #84

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that breaks existing functionality)
  • Documentation update
  • Chore (deps, tooling, refactoring)

How Has This Been Tested?

  • Unit tests added / updated
  • Integration tests added / updated
  • Manual testing on Android
  • Manual testing on iOS

Unit tests cover:

  • stellar.getBalance(): unfunded account → '0'; network failure → reject
  • useStellarWallet.refreshBalance(): keeps the last known balance on failure; returns false; clears the error after a successful retry
  • WalletScreen: shows Failed to refresh balance and May be out of date without replacing the last known balance; Retry and pull-to-refresh both re-fetch and clear the error on success

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my own code
  • I have commented on complex or non-obvious code
  • I have updated the documentation where needed
  • My changes generate no new warnings or lint errors
  • All existing and new tests pass

Screenshots

N/A — no visual assets attached. On refresh failure the wallet screen shows an error alert with a Retry button, the last known XLM amount, and a May be out of date warning. Pull-to-refresh is also available.

Additional Context

Completed from #84:

  • refreshBalance reports success/failure to the UI without wiping the stored balance
  • WalletScreen shows Failed to refresh balance, a retry control, and a stale-data indicator
  • Tests cover error display and retry (button + pull-to-refresh)

Already in the repo (not changed here): src/services/stellar.ts already distinguishes NotFoundError from network errors. stellarBalance.test.ts still covers that contract.

Out of scope (per the issue): offline balance caching and background balance refresh.

I remain open to any corrections or feedback you may have.

D240021 and others added 2 commits August 24, 2026 15:55
…tScreen

- Updated refreshBalance function to return a boolean indicating success or failure, allowing better error handling in UI.
- Improved WalletScreen to handle balance refresh with user feedback for errors and loading states, including a retry mechanism.
- Added visual indicators for balance freshness and error messages to enhance user experience.
@cybermax4200
cybermax4200 merged commit d45e863 into ecotask-network:main Aug 25, 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.

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

2 participants