refactor(data): make AddressBook an App-owned shared instance
Phase 0a of the Contacts/Chat plan. The address book was a file-scoped singleton (`s_address_book` + `getAddressBook()`) trapped inside address_book_dialog.cpp, reachable only from that TU. Promote it to an App-owned member so the upcoming Contacts tab, the Send contact picker, and a future Chat roster all read one source of truth. - app.h: add `data::AddressBook address_book_;` + `App::addressBook()` accessors, next to the other owned data models. - app.cpp: load it once in App::init() (idempotent; missing file is fine; purely local, no daemon dependency). - address_book_dialog.cpp: delete the singleton + getAddressBook(); read through the App* the dialog already carries (dropping the dead `(void)app;`). show() is static so it can't reach the App — drop its per-open reload (the book is authoritative for the app lifetime and self-saves on mutation). Drop the now-unused <memory> include. No behavior change; groundwork for the Contacts tab. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <unordered_set>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include "data/transaction_history_cache.h"
|
||||
#include "data/address_book.h"
|
||||
#include "data/wallet_state.h"
|
||||
#include "rpc/connection.h"
|
||||
#include "services/network_refresh_service.h"
|
||||
@@ -175,6 +176,10 @@ public:
|
||||
WalletState& state() { return state_; }
|
||||
const WalletState& state() const { return state_; }
|
||||
const WalletState& getWalletState() const { return state_; }
|
||||
// Shared contact store (Contacts tab / Send picker / future Chat roster). App-owned so
|
||||
// every surface reads one source of truth instead of a per-dialog singleton.
|
||||
data::AddressBook& addressBook() { return address_book_; }
|
||||
const data::AddressBook& addressBook() const { return address_book_; }
|
||||
|
||||
// Connection state (convenience wrappers)
|
||||
bool isConnected() const { return state_.connected; }
|
||||
@@ -814,6 +819,7 @@ private:
|
||||
// PIN vault
|
||||
std::unique_ptr<util::SecureVault> vault_;
|
||||
data::TransactionHistoryCache transaction_history_cache_;
|
||||
data::AddressBook address_book_; // shared contact store; loaded once in init(), self-saves on mutation
|
||||
std::string pending_transaction_history_cache_passphrase_;
|
||||
bool transaction_history_cache_loaded_ = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user