mobile-wallet icon indicating copy to clipboard operation
mobile-wallet copied to clipboard

fix(savedcards): refresh card list after delete and wire pull-to-refresh

Open bhuvan-somisetty opened this issue 6 months ago • 1 comments

Deleting a saved card left the list showing the deleted entry until you navigated away and back. The root cause was that cardState was built directly from a one-shot API flow: once it emitted and completed, there was nothing to trigger a re-fetch after a delete.

The fix introduces a MutableSharedFlow<Unit> as a refresh trigger (seeded with an initial emission so the first load still happens automatically). The cardState flow now uses flatMapLatest on that trigger, so every tryEmit(Unit) restarts the underlying getSavedCards call and the list updates immediately.

Two places now emit to the trigger:

  • After a successful delete, so the removed card disappears right away
  • When CardAction.RefreshCards is dispatched, which the screen sends on pull-to-refresh

The isPullRefreshEnabled property was already defined on ViewState but the scaffold was never wired up to it. This PR connects it via rememberMifosPullToRefreshState, so users can also manually refresh the list by pulling down.

The known-issue comment on CardsScreen is removed since the underlying problem is resolved.

Tested manually: deleting a card now removes it from the list without any navigation, and pull-to-refresh re-fetches correctly.

Summary by CodeRabbit

  • New Features
    • Pull-to-refresh support added to saved cards screen—swipe down to manually refresh your card list.
    • Saved cards automatically refresh after successful deletion.

Review Change Stack

bhuvan-somisetty avatar May 15 '26 18:05 bhuvan-somisetty

[!WARNING]

Review limit reached

@bhuvan-somisetty, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1997b28d-ff63-425a-bf47-cf9a560f6d71

📥 Commits

Reviewing files that changed from the base of the PR and between 7e69208492425277d5f17c770aac3770811e7264 and f29ff45362f5087a1e3a02b6926ba614f5b32fc3.

📒 Files selected for processing (2)
  • feature/savedcards/src/commonMain/kotlin/org/mifospay/feature/savedcards/CardsScreen.kt
  • feature/savedcards/src/commonMain/kotlin/org/mifospay/feature/savedcards/CardsScreenViewModel.kt
📝 Walkthrough

Walkthrough

Pull-to-refresh functionality is added to the saved cards feature. The ViewModel introduces a refresh trigger that re-fetches cards on explicit refresh or after deletion. The UI wires the scaffold to enable pull-to-refresh and dispatch the refresh action.

Changes

Pull-to-Refresh for Saved Cards

Layer / File(s) Summary
Refresh trigger mechanism and action contract
feature/savedcards/src/commonMain/kotlin/org/mifospay/feature/savedcards/CardsScreenViewModel.kt
CardAction.RefreshCards is added as a new action. A private refreshTrigger MutableSharedFlow<Unit> is introduced, and cardState is refactored to use flatMapLatest to re-subscribe to the repository on each trigger emission. The refresh action is handled by emitting to the trigger.
Refresh on card deletion
feature/savedcards/src/commonMain/kotlin/org/mifospay/feature/savedcards/CardsScreenViewModel.kt
After successful card deletion, the ViewModel emits to refreshTrigger to reload the saved cards.
UI scaffold pull-to-refresh wiring
feature/savedcards/src/commonMain/kotlin/org/mifospay/feature/savedcards/CardsScreen.kt
rememberMifosPullToRefreshState is imported and wired into MifosScaffold with refresh enabled based on state.isPullRefreshEnabled and callback routed to CardAction.RefreshCards. A stale "Known Issue" comment is removed.

Sequence Diagram

sequenceDiagram
  participant User
  participant CardsScreen
  participant CardsScreenViewModel
  participant Repository
  User->>CardsScreen: Pull to refresh
  CardsScreen->>CardsScreenViewModel: CardAction.RefreshCards
  CardsScreenViewModel->>CardsScreenViewModel: emit to refreshTrigger
  CardsScreenViewModel->>Repository: getSavedCards()
  Repository-->>CardsScreenViewModel: cards
  CardsScreenViewModel-->>CardsScreen: cardState updated
  CardsScreen-->>User: Display refreshed cards

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A flutter of cards in the breeze, Pull down to refresh with ease, The trigger now flows through the state, No stale data, we refresh first-rate! 🐰 Deletion too gets the refresh call, Pull-to-refresh handles it all!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: fixing stale card list state after deletion and implementing pull-to-refresh functionality.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar May 15 '26 18:05 coderabbitai[bot]

Rebased on latest dev and pushed a fix for the CodeRabbit finding: both refresh call sites now go through a requestRefresh() helper that uses the suspending emit instead of tryEmit, so a refresh event can no longer be silently dropped under backpressure.

bhuvan-somisetty avatar Jul 05 '26 05:07 bhuvan-somisetty