Skip to content

Wallet state is copied into every screen instead of derived #833

Description

@DRadmir

Each screen keeps its own var wallet and updates it by hand from a separate .onChange observer. The rule for when a wallet change should re-scope the screen's queries versus just redraw it is rewritten in four view models, and all four versions differ:

// WalletSceneViewModel — diffs id, then value
if wallet.id != newWallet.id { refresh(for: newWallet) }
else if wallet != newWallet { wallet = newWallet }

// TransactionsViewModel — always full refresh
if let newWallet, wallet != newWallet { refresh(for: newWallet) }

// CollectionsViewable — value only, no id check
if let newWallet, wallet != newWallet {
    wallet = newWallet
    query.request = NFTRequest(walletId: newWallet.id, filter: .all)
}

// MainTabViewModel — no diff at all
wallet = newWallet
transactionsQuery.request.walletId = newWallet.id

The source they all read is only half observable, so renaming a wallet invalidates nothing:

var currentWallet: Wallet? {
    guard let currentWalletId else { return nil }           // observable
    return try? walletStore.getWallet(id: currentWalletId)  // plain read, not observed
}

A rename reaches the wallet tab only because closing the rename sheet happens to trigger a redraw that re-reads it.

Make the current wallet one derived value that screens read, so a rename propagates by itself and switching a wallet rebuilds the screen instead of being patched into it.

Entry points: onChangeWallet, refresh(for:), CollectionsViewable, WalletSessionService.currentWallet.

Metadata

Metadata

Assignees

Labels

Projects

Status
📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions