Skip to content

Comments

Update ObservableQuery dynamically#1736

Open
DRadmir wants to merge 1 commit intomainfrom
remove-main-tab-view-id
Open

Update ObservableQuery dynamically#1736
DRadmir wants to merge 1 commit intomainfrom
remove-main-tab-view-id

Conversation

@DRadmir
Copy link
Contributor

@DRadmir DRadmir commented Feb 24, 2026

Update ObservableQuery dynamically via onChangeWallet instead of recreating the entire tab view.

@DRadmir DRadmir self-assigned this Feb 24, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @DRadmir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors how the application handles wallet changes within the main tab view. Instead of destroying and recreating the entire view hierarchy when the active wallet changes, the system now dynamically updates the relevant view model and its associated observable queries. This change aims to improve performance and provide a smoother user experience by avoiding costly view re-initializations.

Highlights

  • Dynamic Wallet Updates: The MainTabViewModel now dynamically updates its wallet property and the associated transactionsQuery when the currentWallet changes, instead of forcing the entire MainTabView to be recreated.
  • View Recreation Prevention: The explicit .id(currentWallet.walletId) modifier was removed from MainTabView in RootScene.swift to prevent unnecessary view recreation when the wallet changes.
  • Observable Query Modification: The walletId property within TransactionsCountRequest was changed to public var to allow the MainTabViewModel to modify it directly when the wallet changes, enabling dynamic data fetching.
  • SwiftUI onChange Integration: An .onChange modifier was added to MainTabView to observe changes in walletService.currentWallet and trigger the new onChangeWallet method in the view model.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • Gem/Scenes/RootScene.swift
    • Removed the .id(currentWallet.walletId) modifier from MainTabView.
  • Gem/ViewModels/MainTabViewModel.swift
    • Changed the wallet property from a constant (let) to a variable (var).
    • Added the onChangeWallet method to update the wallet property and the walletId of the transactionsQuery.
  • Gem/Views/MainTabView.swift
    • Added an .onChange modifier to MainTabView to observe changes in walletService.currentWallet and trigger the model.onChangeWallet method.
  • Packages/Store/Sources/Requests/TransactionsCountRequest.swift
    • Changed the walletId property from private let to public var to allow external modification.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request effectively addresses the dynamic updating of ObservableQuery by removing the .id() modifier from MainTabView and introducing an onChangeWallet function in MainTabViewModel. This change prevents the entire tab view from being recreated, leading to a smoother user experience. The wallet property in MainTabViewModel is correctly changed to var to allow modification, and TransactionsCountRequest's walletId is made public var for external updates. The use of onChange(of: _, _:) in MainTabView correctly triggers the wallet update logic. Overall, the changes are well-implemented and improve the application's responsiveness.

VStack {
if let currentWallet = model.currentWallet {
MainTabView(model: .init(wallet: currentWallet))
.id(currentWallet.walletId)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Removing the .id(currentWallet.walletId) modifier is a good change. It prevents SwiftUI from recreating the entire MainTabView hierarchy when the currentWallet changes, which can lead to better performance and a smoother user experience. Instead, the onChange modifier is now used within MainTabView to update the MainTabViewModel dynamically.

Comment on lines +26 to +30
func onChangeWallet(_ _: Wallet?, _ newWallet: Wallet?) {
guard let newWallet else { return }
wallet = newWallet
transactionsQuery.request.walletId = newWallet.walletId
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The onChangeWallet function correctly updates both the wallet property and the walletId in transactionsQuery.request. This ensures that the ObservableQuery for transactions is updated with the new wallet's ID, triggering a re-fetch of transactions relevant to the newly selected wallet.

}
.toast(message: $model.isPresentingToastMessage)
.bindQuery(model.transactionsQuery)
.onChange(of: walletService.currentWallet, model.onChangeWallet)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Adding .onChange(of: walletService.currentWallet, model.onChangeWallet) is the correct way to observe changes in walletService.currentWallet and propagate them to the MainTabViewModel. This ensures that when the active wallet changes, the MainTabViewModel is notified and can update its internal state and queries accordingly.

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.

1 participant