diff --git a/src/app_sweep.cpp b/src/app_sweep.cpp index 760ca69..fb182bc 100644 --- a/src/app_sweep.cpp +++ b/src/app_sweep.cpp @@ -14,6 +14,7 @@ #include "app.h" #include "config/settings.h" +#include "data/address_book.h" #include "ui/schema/skin_manager.h" #include "ui/notifications.h" #include "ui/sidebar.h" @@ -90,6 +91,29 @@ const char* kDemoMnemonic = const char* kDemoZAddr = "zs1demoseedwalletreceiveaddressforuisweepcaptures00000000000000000000000000"; const char* kDemoTxid = "b647077c471fdd2877d35c9d8b70e3c785547fae618458b4068d913ee3d1dc4f"; + +// Contacts-view sweep: seed a few demo contacts (Z + T types, some global) so the Cards/List/Table +// modes render with data, and restore the real book afterward. Uses sweepSetEntries (no disk write), +// so the user's persisted address book is never touched even if the sweep is interrupted. +std::vector s_contactsSweepBackup; +void seedSweepContacts(App& a) +{ + s_contactsSweepBackup = a.addressBook().entries(); + data::AddressBookEntry e1("drgx pool payout address", kDemoZAddr, "mining pool payouts"); // Z, global + data::AddressBookEntry e2("exchange deposit", "t1DemoTransparentAddressForUiSweep00000", ""); // T + // Scope to the active wallet so it's visible (the tab hides contacts not in the active wallet); + // non-empty hash also keeps it non-global -> no globe badge, so the list shows a global/non-global mix. + e2.scope = a.activeWalletIdentityHash(); + data::AddressBookEntry e3("cold savings", + "zs1sweepdemocoldsavingsaddressforuicapture0000000000000000000000000000", "long-term storage"); // Z, global + a.addressBook().sweepSetEntries({ e1, e2, e3 }); +} +void restoreSweepContacts(App& a) +{ + a.addressBook().sweepSetEntries(s_contactsSweepBackup); + s_contactsSweepBackup.clear(); + if (a.settings()) a.settings()->setContactsViewMode(0); +} } // namespace std::string App::screenshotDir() const @@ -373,6 +397,16 @@ void App::buildSweepCatalog() add("modal-key-export", ui::NavPage::Overview, [](App&) { ui::KeyExportDialog::show(kDemoZAddr, ui::KeyExportDialog::KeyType::Private); }, [](App&) { ui::KeyExportDialog::hide(); }); + // Contacts address-list view modes, each seeded with demo contacts (restored after; no disk write). + add("contacts-cards", ui::NavPage::Contacts, + [](App& a) { seedSweepContacts(a); if (a.settings()) a.settings()->setContactsViewMode(0); }, + [](App& a) { restoreSweepContacts(a); }); + add("contacts-list", ui::NavPage::Contacts, + [](App& a) { seedSweepContacts(a); if (a.settings()) a.settings()->setContactsViewMode(1); }, + [](App& a) { restoreSweepContacts(a); }); + add("contacts-table", ui::NavPage::Contacts, + [](App& a) { seedSweepContacts(a); if (a.settings()) a.settings()->setContactsViewMode(2); }, + [](App& a) { restoreSweepContacts(a); }); add("modal-about", ui::NavPage::Overview, [](App& a) { a.show_about_ = true; }, [](App& a) { a.show_about_ = false; }); add("modal-settings", ui::NavPage::Settings, diff --git a/src/data/address_book.h b/src/data/address_book.h index 01e5cdf..afaab5e 100644 --- a/src/data/address_book.h +++ b/src/data/address_book.h @@ -109,6 +109,12 @@ public: */ size_t size() const { return entries_.size(); } + /** + * @brief UI-sweep ONLY: replace the in-memory entries WITHOUT persisting to disk, so the sweep can + * seed demo contacts and restore the real book without a disk write. Do not use outside the sweep. + */ + void sweepSetEntries(std::vector e) { entries_ = std::move(e); } + /** * @brief Check if empty */