Skip to content

fix: reset suggestions widget when re-added empty#1016

Merged
ovitrif merged 4 commits into
masterfrom
fix/reset-suggestions-when-empty
Jun 16, 2026
Merged

fix: reset suggestions widget when re-added empty#1016
ovitrif merged 4 commits into
masterfrom
fix/reset-suggestions-when-empty

Conversation

@jvsena42

@jvsena42 jvsena42 commented Jun 15, 2026

Copy link
Copy Markdown
Member

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:

  1. 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.

  2. 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

  • 1. Home → dismiss every Suggestions card with [x]: widget hides once the last card is dismissed.
  • 2. edit mode → remove the Suggestions widget → re-add via Widgets list → Suggestions → Save: widget reappears showing the default suggestion cards.
  • 3. dismiss every card (do not remove widget) → enter edit mode: widget shows the static preview set and can be reordered/removed, instead of a blank placeholder.
  • 4a. regression: dismiss only some cards → remove and re-add the Suggestions widget: remaining cards stay as-is, dismissed ones are not restored.
    • 4b. regression: some cards still visible → enter edit mode: live cards show as normal (no preview fallback).

Automated Checks

  • Unit tests added: cover the reset-when-empty behaviour and dismissed filtering in app/src/test/java/to/bitkit/repositories/SuggestionsRepoTest.kt.
  • Local: just test, just compile, and just lint pass.
  • CI: standard compile, unit test, and detekt checks run by the PR bot.

@jvsena42 jvsena42 self-assigned this Jun 15, 2026
@greptile-apps

greptile-apps Bot commented Jun 15, 2026

Copy link
Copy Markdown

Greptile Summary

This 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 HomeViewModel into a new SuggestionsRepo singleton so both the home grid and the widget-preview flow share one source of truth.

  • SuggestionsRepo is a new singleton that owns suggestionsFlow and exposes resetDismissedSuggestionsIfEmpty(), which clears persisted dismissals only when the resolved suggestion list would otherwise be empty.
  • SuggestionsViewModel.addWidget calls resetDismissedSuggestionsIfEmpty() before adding the widget, restoring default cards on re-add without touching dismissals when some cards are still visible.
  • HomeScreen now falls back to SuggestionsPreviewGrid (the same static set shown in the widget-picker preview) instead of a blank placeholder when editing with all suggestions dismissed.

Confidence Score: 4/5

Safe 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.

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "chore: rename changelog fragment" | Re-trigger Greptile

Comment thread app/src/test/java/to/bitkit/repositories/SuggestionsRepoTest.kt Outdated
@jvsena42
jvsena42 requested a review from ovitrif June 16, 2026 09:16

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

@jvsena42 jvsena42 added this to the 2.4.0 milestone Jun 16, 2026

@ovitrif ovitrif left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utAck

Great refactor too! 🙌🏻

@ovitrif
ovitrif merged commit 29a99f1 into master Jun 16, 2026
29 of 31 checks passed
@ovitrif
ovitrif deleted the fix/reset-suggestions-when-empty branch June 16, 2026 10:27
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.

Suggestion widget bug when empty and re-adding

3 participants