Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gem/Scenes/RootScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct RootScene: View {
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.

.alertSheet($model.updateVersionAlertMessage)
} else {
OnboardingScene(
Expand Down
8 changes: 7 additions & 1 deletion Gem/ViewModels/MainTabViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
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.


var isMarketEnabled: Bool {
false //TODO: Disabled. Preferences.standard.isDeveloperEnabled && wallet.type == .multicoin
}
Expand Down
1 change: 1 addition & 0 deletions Gem/Views/MainTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ struct MainTabView: View {
}
.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.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Primitives

public struct TransactionsCountRequest: DatabaseQueryable {

private let walletId: WalletId
public var walletId: WalletId
private let state: TransactionState

public init(
Expand Down