fix: reset suggestions widget when re-added empty#1016
Conversation
Greptile SummaryThis PR fixes two follow-on bugs that appeared after all Suggestions widget cards are dismissed: re-adding the widget never showed cards again, and editing the home grid showed a blank placeholder. The suggestion-visibility logic is extracted from
Confidence Score: 4/5Safe to merge; the fix is well-scoped and the sequential coroutine ordering in addWidget() correctly guarantees the reset completes before the widget is persisted. The reset logic, flow extraction, and edit-mode fallback are all correct. The one gap is in the unit test for resetDismissedSuggestionsIfEmpty: it verifies that settingsStore.update() is called but never inspects the lambda argument, so a regression that calls update() with the wrong transform would go undetected. SuggestionsRepoTest.kt — the lambda-content assertion for the reset test is missing.
|
| Filename | Overview |
|---|---|
| app/src/main/java/to/bitkit/repositories/SuggestionsRepo.kt | New singleton repo extracting suggestion logic from HomeViewModel; adds resetDismissedSuggestionsIfEmpty() for the re-add fix. Logic faithfully mirrors the old inline code. |
| app/src/main/java/to/bitkit/ui/screens/wallets/HomeScreen.kt | Suggestions widget placeholder logic updated to show SuggestionsPreviewGrid in edit mode when suggestions are empty, using default previewSuggestions. Clean when-branch replacement. |
| app/src/main/java/to/bitkit/ui/screens/widgets/suggestions/SuggestionsViewModel.kt | addWidget() now calls resetDismissedSuggestionsIfEmpty() before addWidget; sequential ordering within the coroutine is correct. |
| app/src/test/java/to/bitkit/repositories/SuggestionsRepoTest.kt | Three tests covering reset-when-empty, no-op when visible, and dismissed-filtering. The reset test only verifies update() is called, not the content of the transform lambda. |
| changelog.d/next/1010.fixed.md | Changelog entry added for the fix. |
Sequence Diagram
sequenceDiagram
participant User
participant SuggestionsViewModel
participant SuggestionsRepo
participant SettingsStore
participant WidgetsRepo
participant HomeViewModel
User->>SuggestionsViewModel: addWidget()
SuggestionsViewModel->>SuggestionsRepo: resetDismissedSuggestionsIfEmpty()
SuggestionsRepo->>SuggestionsRepo: suggestionsFlow.first()
SuggestionsRepo->>SettingsStore: "update(dismissedSuggestions = [])"
Note over SuggestionsRepo,SettingsStore: Only if flow resolved empty
SuggestionsViewModel->>WidgetsRepo: addWidget(SUGGESTIONS)
SettingsStore-->>HomeViewModel: settingsStore.data emits updated settings
HomeViewModel-->>HomeViewModel: suggestionsFlow re-emits non-empty list
HomeViewModel-->>User: UI shows restored suggestion cards
Reviews (1): Last reviewed commit: "chore: rename changelog fragment" | Re-trigger Greptile
ovitrif
left a comment
There was a problem hiding this comment.
utAck
Great refactor too! 🙌🏻
Fixes #1010
This PR fixes the Suggestions widget disappearing after every card is dismissed, both when the widget is re-added and while editing the home grid. It is a port of the iOS fix in synonymdev/bitkit-ios#598.
Description
When every suggestion card is dismissed with the [x] button, the Suggestions widget hides from the home grid, which is expected. Two follow-on problems remained, both caused by the dismissed cards being persisted so the widget kept resolving to an empty set:
Re-adding the widget (after removing it in edit mode) never brought it back, because the suggestions stayed empty. Re-adding now clears the dismissed cards when the widget would otherwise show nothing, restoring the default set. This only runs when the suggestions are empty, so re-adding while some cards are still visible leaves those dismissals untouched.
With all cards dismissed, editing the home grid showed a blank placeholder for the widget. When editing an empty Suggestions widget it now falls back to the static preview set (the same cards shown in the widget preview), so it stays visible and removable.
The suggestion-visibility logic was extracted from the home screen into a new shared repository, so the home grid and the widget preview flow resolve the visible cards the same way.
Preview
Screen_recording_20260615_114634.webm
QA Notes
Manual Tests
regression:dismiss only some cards → remove and re-add the Suggestions widget: remaining cards stay as-is, dismissed ones are not restored.regression:some cards still visible → enter edit mode: live cards show as normal (no preview fallback).Automated Checks
app/src/test/java/to/bitkit/repositories/SuggestionsRepoTest.kt.just test,just compile, andjust lintpass.