refactor: enhance balance refresh logic in useStellarWallet and Walle… - #119
Merged
Conversation
…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
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
refreshBalancenow returnstrue/falseinstead 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
How Has This Been Tested?
Unit tests cover:
stellar.getBalance(): unfunded account →'0'; network failure → rejectuseStellarWallet.refreshBalance(): keeps the last known balance on failure; returnsfalse; clears the error after a successful retryWalletScreen: 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 successChecklist
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:
refreshBalancereports success/failure to the UI without wiping the stored balanceAlready in the repo (not changed here):
src/services/stellar.tsalready distinguishesNotFoundErrorfrom network errors.stellarBalance.test.tsstill 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.