Skip to content

refactor: simplify home view #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

rubensmachion
Copy link
Collaborator

@rubensmachion rubensmachion commented Apr 25, 2025

Description

This PR simplify HomeView by separating the Activity Header on side component

Screenshot 2025-04-24 at 21 12 20

Simulator Screenshot - iPhone 16 Pro - 2025-04-24 at 21 21 06 #2

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • UI changes tested on small, medium, and large devices to ensure layout consistency

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@rubensmachion rubensmachion requested a review from reez April 25, 2025 00:22
@reez
Copy link
Collaborator

reez commented Apr 28, 2025

Concept ACK

I mean this is totally good as-is, the only thing im noodling on is the datasource part in ActivityHomeHeaderView. Typically in the codebase I inject either a view model or just the properties, here you created a datasource struct to pass/inject. I dont actually think there's anything wrong with that at all, but I'm just trying to think of how to best keep it consistent with what the codebase does right now.

I think you're datasource struct makes sense, it encapsulates those 5 properties, but also at the call-site it still requires being explicit about those 5 properties. I'm not sure how well adding a corresponding view model for ActivityHomeHeaderView would work in the case that we need the functions like fullScanWithProgress to still be in the WalletViewModel (the ideal state is if they were just able to be in a ActivityHomeHeaderViewModel but I dont know that that's possible or not, I haven't fully walked down that road).

Let me keep thinking on this, and if you have an additional comments/thoughts/ideas let me know.

But if I haven't thought of any better way to do things in the next day or two I'll merge this because its definitely a nice refactor!

@rubensmachion
Copy link
Collaborator Author

Hi @reez, this evening I will study a better way to handle those five attributes to try to decouple these components.

@reez
Copy link
Collaborator

reez commented Apr 28, 2025

Hi @reez, this evening I will study a better way to handle those five attributes to try to decouple these components.

Sounds good. Dont spend too much time on it, this PR is mergeable as is, but if something better happens to come to us in the next day or so we can chat about it here and see what we think.

@rubensmachion
Copy link
Collaborator Author

In this last commit, I moved the role logic to WalletViewModel, and in ActivityHomeHeaderView, I created an enum to represent the view state.

@reez
Copy link
Collaborator

reez commented Apr 29, 2025

After looking at the State enum approach, I think we can achieve a cleaner separation by sticking closer to direct property injection, which keeps the view simpler and avoids mixing presentation logic into the WalletViewModel.

Here's why the direct property approach (with a small tweak to WalletViewModel) feels better to me:

  • Simpler View: ActivityHomeHeaderView just takes the raw data it needs (progress, state, etc.). The State enum made the view more complex internally, needing extra logic to unpack the state.
  • Cleaner ViewModel: WalletViewModel provides simple data. Adding a needsFullScan computed property hides the internal bdkClient detail from the caller (WalletView). The State enum approach mixed view-specific presentation logic into the WalletViewModel.
  • Less Coupled: The view stays dumb and reusable, only needing basic data types. The State enum created unnecessary coupling between the view's internal structure and the ViewModel.

I'll add code suggestions right now too

Copy link
Collaborator

@reez reez left a comment

Choose a reason for hiding this comment

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

can add this to WalletViewModel too to make the call-site for ActivityHomeHeaderView cleaner w my proposed changes:

    // Add computed property for needsFullScan
    var needsFullScan: Bool {
        bdkClient.needsFullScan()
    }
    ```

rubensmachion and others added 5 commits April 30, 2025 10:50
Co-authored-by: Matthew Ramsden <6657488+reez@users.noreply.github.com>
Co-authored-by: Matthew Ramsden <6657488+reez@users.noreply.github.com>
…github.com/rubensmachion/BDKSwiftExampleWallet into refactor/extract-activity-header-component

* 'refactor/extract-activity-header-component' of https://github.com/rubensmachion/BDKSwiftExampleWallet:
  Update BDKSwiftExampleWallet/View/WalletView.swift
  Update BDKSwiftExampleWallet/View/Home/ActivityHomeHeaderView.swift
@rubensmachion
Copy link
Collaborator Author

Good calls, @reez.

I just applied all your suggestions. To keep the var body: some View shorter, I created a new function to encapsulate the indicator image construction.

see in ActivityHomeHeaderView.syncImageIndicator()

@reez
Copy link
Collaborator

reez commented Apr 30, 2025

perfect! thanks for working on+thru this!

@reez reez merged commit dc057ad into bitcoindevkit:main Apr 30, 2025
1 check passed
@rubensmachion rubensmachion deleted the refactor/extract-activity-header-component branch April 30, 2025 14:18
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