Fix fetching Balance on every screen#3162
Conversation
WalkthroughReworked asynchronous flow composition in ChainTokensViewModel. Replaced onCompletion-based lifecycle with onEach for refreshing state management, introduced List.hasNullAccount() extension for account validation, moved error handling earlier in the chain, and reorganized data preparation sequencing. Changes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@app/src/main/java/com/vultisig/wallet/ui/models/ChainTokensViewModel.kt`:
- Around line 232-235: The current placement of .catch in ChainTokensViewModel
is before the second combine, so exceptions during the UI-state mapping pipeline
(the second combine block that builds the view state) bypass the catch and never
call updateRefreshing(false); move the .catch to after the second combine (i.e.,
after the mapping that constructs the UI state) or add an additional
catch/finally around the second combine/mapping so that updateRefreshing(false)
is always invoked on error; reference the combine/catch chain inside the Flow in
ChainTokensViewModel and ensure updateRefreshing(false) is called in every error
path.
🧹 Nitpick comments (1)
app/src/main/java/com/vultisig/wallet/ui/models/ChainTokensViewModel.kt (1)
398-400: Consider a more descriptive function name.The name
hasNullAccountsuggests checking for nullAccountobjects in the list, but it actually checks for accounts with nulltokenValueorfiatValue. A name likehasIncompleteAccount()orhasUnloadedBalances()would better convey the intent.✏️ Suggested rename
- private fun List<Account>.hasNullAccount() = any { + private fun List<Account>.hasIncompleteAccount() = any { it.tokenValue == null || it.fiatValue == null }And update the call site on line 227:
- updateRefreshing(it.accounts.hasNullAccount()) + updateRefreshing(it.accounts.hasIncompleteAccount())
Description
Please include a summary of the change and which issue is fixed.
Fixes #3148
Which feature is affected?
Checklist
Screenshots (if applicable):
Additional context
Summary by CodeRabbit
Refactor
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.