Skip to content

Conversation

@praveenperera
Copy link
Contributor

@praveenperera praveenperera commented Jan 23, 2026

  • Extract loadState and transactions once to avoid evaluating the when expression twice for overscroll handling
  • Add AmountDisplay helper composable to eliminate repeated if/else-if/else pattern for hidden/amount/loading states in WalletBalanceHeaderView

Summary by CodeRabbit

  • Refactor
    • Improved consistency in how wallet balances and transaction lists are computed and displayed.
    • Streamlined loading state handling across balance and transaction views for more predictable UI behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Two Android UI components are refactored for improved code reusability. SelectedWalletScreen extracts transaction computation and load state logic into derived variables, while WalletBalanceHeaderView introduces a new private AmountDisplay composable to centralize amount rendering across hidden, loaded, and loading states.

Changes

Cohort / File(s) Summary
Transaction and Load State Refactoring
android/app/src/main/java/org/bitcoinppl/cove/flows/SelectedWalletFlow/SelectedWalletScreen.kt
Introduces local loadState variable and derived transactions list (with empty list fallback) to replace multiple inline loadState.txns checks. Adds hasTransactions flag derived from transactions or unsignedTransactions. Updates conditional rendering in when expression and TransactionsCardView invocations to use centralized transactions source.
Amount Display Composable
android/app/src/main/java/org/bitcoinppl/cove/flows/SelectedWalletFlow/WalletBalanceHeaderView.kt
Extracts new private AmountDisplay composable to centralize conditional rendering logic for hidden, loaded, and available amount states. Replaces explicit conditional blocks with unified composable accepting amount, isHidden, and two composable lambdas (textContent and loadingContent) for flexible content rendering.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

android

Poem

🐰 Through composables new, a pattern takes flight,
Reusable components that glimmer so bright,
Load states extracted, amounts on display,
The code hops much cleaner this very fine day! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring objectives: eliminating duplicated logic in SelectedWalletScreen and implementing DRY principles for balance display through the new AmountDisplay composable.

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

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

- Extract loadState and transactions once to avoid evaluating the when
  expression twice for overscroll handling
- Add AmountDisplay helper composable to eliminate repeated if/else-if/else
  pattern for hidden/amount/loading states in WalletBalanceHeaderView
@praveenperera
Copy link
Contributor Author

@greptile-apps review pr

@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Overview

Greptile Summary

This PR refactors two key components to eliminate code duplication and improve performance. In SelectedWalletScreen, the loadState and transactions are now extracted once and reused throughout the component, avoiding duplicate evaluation of the when expression during overscroll handling. In WalletBalanceHeaderView, a new AmountDisplay helper composable was introduced to consolidate the repeated if/else-if/else pattern for handling hidden/amount/loading states.

Key Changes:

  • Extracted loadState and transactions once in SelectedWalletScreen to avoid re-evaluating the when expression
  • Created reusable AmountDisplay composable to handle three states: hidden (shows "••••••"), amount available (displays value), and loading (shows spinner)
  • Both refactorings maintain identical behavior while improving code maintainability and reducing duplication

Confidence Score: 5/5

  • This PR is safe to merge with no identified risks
  • The refactoring is straightforward and maintains identical behavior to the original code. The changes improve code quality through DRY principles without introducing any new logic or side effects. Both files show clear improvements in maintainability and performance optimization.
  • No files require special attention

Important Files Changed

Filename Overview
android/app/src/main/java/org/bitcoinppl/cove/flows/SelectedWalletFlow/SelectedWalletScreen.kt Extracted loadState and transactions once to avoid duplicate evaluation of when expression, improving performance and code clarity
android/app/src/main/java/org/bitcoinppl/cove/flows/SelectedWalletFlow/WalletBalanceHeaderView.kt Added AmountDisplay helper composable to eliminate repeated if/else-if/else pattern for hidden/amount/loading states, improving code reusability

Sequence Diagram

sequenceDiagram
    participant User
    participant SelectedWalletScreen
    participant WalletManager
    participant BalanceWidget
    participant AmountDisplay

    User->>SelectedWalletScreen: View wallet
    SelectedWalletScreen->>WalletManager: Get loadState
    WalletManager-->>SelectedWalletScreen: Return loadState (LOADING/SCANNING/LOADED)
    
    Note over SelectedWalletScreen: Extract loadState once
    Note over SelectedWalletScreen: Compute transactions from loadState
    
    alt loadState is SCANNING
        SelectedWalletScreen->>SelectedWalletScreen: Use loadState.txns as transactions
    else loadState is LOADED
        SelectedWalletScreen->>SelectedWalletScreen: Use loadState.txns as transactions
    else loadState is LOADING or null
        SelectedWalletScreen->>SelectedWalletScreen: Use emptyList() as transactions
    end
    
    SelectedWalletScreen->>BalanceWidget: Display balance (primaryAmount, secondaryAmount, isHidden)
    
    BalanceWidget->>AmountDisplay: Render secondary amount
    Note over AmountDisplay: Check isHidden → amount → loading states
    AmountDisplay-->>BalanceWidget: Display text or spinner
    
    BalanceWidget->>AmountDisplay: Render primary amount
    Note over AmountDisplay: Check isHidden → amount → loading states
    AmountDisplay-->>BalanceWidget: Display text or spinner
    
    BalanceWidget-->>User: Show balance UI
    
    Note over SelectedWalletScreen: Reuse transactions for<br/>TransactionsCardView rendering
    SelectedWalletScreen->>User: Display transactions using pre-computed list
Loading

@praveenperera praveenperera merged commit ee4eb48 into master Jan 23, 2026
10 checks passed
@praveenperera praveenperera deleted the android-code-cleanup branch January 23, 2026 21:25
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.

2 participants