-
Notifications
You must be signed in to change notification settings - Fork 58
Update ObservableQuery dynamically #1736
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import Components | |
| @Observable | ||
| @MainActor | ||
| final class MainTabViewModel { | ||
| let wallet: Wallet | ||
| var wallet: Wallet | ||
| let transactionsQuery: ObservableQuery<TransactionsCountRequest> | ||
|
|
||
| var transactions: Int { transactionsQuery.value } | ||
|
|
@@ -23,6 +23,12 @@ final class MainTabViewModel { | |
|
|
||
| var walletId: WalletId { wallet.walletId } | ||
|
|
||
| func onChangeWallet(_ _: Wallet?, _ newWallet: Wallet?) { | ||
| guard let newWallet else { return } | ||
| wallet = newWallet | ||
| transactionsQuery.request.walletId = newWallet.walletId | ||
| } | ||
|
Comment on lines
+26
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| var isMarketEnabled: Bool { | ||
| false //TODO: Disabled. Preferences.standard.isDeveloperEnabled && wallet.type == .multicoin | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,7 @@ struct MainTabView: View { | |
| } | ||
| .toast(message: $model.isPresentingToastMessage) | ||
| .bindQuery(model.transactionsQuery) | ||
| .onChange(of: walletService.currentWallet, model.onChangeWallet) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the
.id(currentWallet.walletId)modifier is a good change. It prevents SwiftUI from recreating the entireMainTabViewhierarchy when thecurrentWalletchanges, which can lead to better performance and a smoother user experience. Instead, theonChangemodifier is now used withinMainTabViewto update theMainTabViewModeldynamically.