From e0ae8045c276bfe504908c789bfc2e7fd3e10ea2 Mon Sep 17 00:00:00 2001 From: DanS Date: Fri, 20 Nov 2026 13:10:32 -0600 Subject: [PATCH] feat(contacts): Message + Send-to as row icons, toolbar buttons, and menu (F020) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UX audit, Contacts surface — discoverability (choice a): - "Message" (open a chat) was reachable only from the right-click menu. It now also appears as a per-row hover icon and a toolbar button, disabled with a "needs a shielded (z) address" tooltip when the contact is transparent. - New "Send to" action (per-row icon, toolbar button, context menu) prefills the Send tab's recipient with the contact and switches there. Backed by a new PrefillSendRecipient() that fills only the recipient (amount/memo left to the user), distinct from the demo-only SweepSetSendRecipient. - The per-row action cluster is refactored to id-based dispatch so the two new actions slot in without positional-index fragility; width is reserved for the full cluster so the address text doesn't shift on hover. New string (English). Build + tests green. Co-Authored-By: Claude Opus 4.8 --- src/ui/windows/contacts_tab.cpp | 100 ++++++++++++++++++++++++-------- src/ui/windows/send_tab.cpp | 8 +++ src/ui/windows/send_tab.h | 2 + src/util/i18n.cpp | 1 + 4 files changed, 88 insertions(+), 23 deletions(-) diff --git a/src/ui/windows/contacts_tab.cpp b/src/ui/windows/contacts_tab.cpp index 0d803ce..6867dfb 100644 --- a/src/ui/windows/contacts_tab.cpp +++ b/src/ui/windows/contacts_tab.cpp @@ -20,6 +20,7 @@ #include "image_picker.h" #include "transactions_tab.h" #include "chat_tab.h" // OpenChatNewConversation — Contacts "Message" action +#include "send_tab.h" // PrefillSendRecipient — Contacts "Send to" action #include "../sidebar.h" #include "../layout.h" #include "imgui.h" @@ -549,6 +550,13 @@ void RenderContactsTab(App* app) OpenChatNewConversation(e.address); app->setCurrentPage(ui::NavPage::Chat); }; + // Send to — prefill the Send tab's recipient with this contact and switch there. (F020) + auto doSendTo = [&]() { + if (!selValid()) return; + ui::PrefillSendRecipient(app, book.entries()[s_selected_index].address.c_str()); + Notifications::instance().info(TR("send_recipient_prefilled")); + app->setCurrentPage(ui::NavPage::Send); + }; // Add/edit form — a modal popup layered over the tab, with a live contact preview and an avatar // picker (default Z/T badge, a Material icon, or a custom image via the in-app image picker). @@ -1120,6 +1128,28 @@ void RenderContactsTab(App* app) if (!has_selection && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) material::Tooltip("%s", TR("contacts_select_first")); // (F043) + ImGui::SameLine(); + + // Send to — prefill the Send tab with this contact (previously no toolbar/row affordance). (F020) + if (toolbarBtn("##ab_sendto", ICON_MD_SEND, TR("contacts_send_to"), false)) + doSendTo(); + if (!has_selection && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) + material::Tooltip("%s", TR("contacts_select_first")); + +#if DRAGONX_ENABLE_CHAT + ImGui::SameLine(); + // Message — needs a shielded (z) contact; was reachable only from the right-click menu. (F020) + const bool msgEnabled = has_selection && isShieldedAddr(book.entries()[s_selected_index].address); + if (!msgEnabled) ImGui::BeginDisabled(); + if (toolbarBtn("##ab_msg", ICON_MD_FORUM, TR("contacts_message"), false)) + doMessage(); + if (!msgEnabled) ImGui::EndDisabled(); + if (has_selection && !msgEnabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) + material::Tooltip("%s", TR("contacts_message_needs_z")); + else if (!has_selection && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) + material::Tooltip("%s", TR("contacts_select_first")); +#endif + if (!has_selection) ImGui::EndDisabled(); // Address-list view toggle (Cards / List / Table) — right-aligned on the toolbar row; persisted. @@ -1458,7 +1488,15 @@ void RenderContactsTab(App* app) // Label (line 1) + muted address (line 2) — reserve trailing room for the globe + actions. const float actHit = icoF->LegacySize + 8.0f * dp; // per-action square hit area const float globeW = entry.isGlobal() ? (icoF->LegacySize + 8.0f * dp) : 0.0f; - const float trailW = 4.0f * actHit + 8.0f * dp + globeW; // copy / view-tx / edit / delete + // Trailing action cluster width (reserved even when idle so the address doesn't shift on + // hover): copy / view-tx / send-to [/ message] / edit / delete. (F020) + const int kRowActs = +#if DRAGONX_ENABLE_CHAT + 6; +#else + 5; +#endif + const float trailW = kRowActs * actHit + 8.0f * dp + globeW; const float cy = mn.y + rowH * 0.5f; const float tx = (s_contactsShape == 2) ? (mn.x + tabW + pad) : (mn.x + pad + avR * 2.0f + pad); @@ -1490,41 +1528,56 @@ void RenderContactsTab(App* app) rightX -= gs.x + 8.0f * dp; } if (rowHovered || selected) { - // Order (left->right): copy, view-transactions, edit, delete. Drawn right-to-left. - const char* actGlyph[4] = { ICON_MD_CONTENT_COPY, ICON_MD_RECEIPT_LONG, ICON_MD_EDIT, ICON_MD_DELETE }; - const char* actTip[4] = { TR("copy_address"), TR("view_transactions"), TR("edit"), TR("delete") }; + // Row actions (drawn right-to-left): copy, view-tx, send-to [, message], edit, delete. (F020) + struct RowAct { const char* glyph; const char* tip; int id; bool enabled; bool isDelete; }; + RowAct acts[6]; + int nAct = 0; + acts[nAct++] = { ICON_MD_CONTENT_COPY, TR("copy_address"), 0, true, false }; + acts[nAct++] = { ICON_MD_RECEIPT_LONG, TR("view_transactions"), 1, true, false }; + acts[nAct++] = { ICON_MD_SEND, TR("contacts_send_to"), 2, true, false }; +#if DRAGONX_ENABLE_CHAT + acts[nAct++] = { ICON_MD_FORUM, + shielded ? TR("contacts_message") : TR("contacts_message_needs_z"), + 3, shielded, false }; +#endif + acts[nAct++] = { ICON_MD_EDIT, TR("edit"), 4, true, false }; + acts[nAct++] = { ICON_MD_DELETE, TR("delete"), 5, true, true }; float ax = rightX - actHit; // rightmost action (delete), just left of the globe - for (int a = 3; a >= 0; --a) { + for (int k = nAct - 1; k >= 0; --k) { + const RowAct& A = acts[k]; ImGui::SetCursorScreenPos(ImVec2(ax, cy - actHit * 0.5f)); - ImGui::PushID(a + 100); + ImGui::PushID(A.id + 100); const bool aClk = ImGui::InvisibleButton("##act", ImVec2(actHit, actHit)); const bool aHov = ImGui::IsItemHovered(); if (aHov) { ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); - // While the delete action is armed, name the consequence at the point of action - // instead of leaving the tooltip on "Delete". (F006) - if (a == 3 && s_confirm_delete_idx == static_cast(i)) + // Armed delete names the consequence at the point of action, not just "Delete". (F006) + if (A.isDelete && s_confirm_delete_idx == static_cast(i)) material::Tooltip(TR("contacts_delete_armed_tip"), entry.label.c_str()); else - material::Tooltip("%s", actTip[a]); + material::Tooltip("%s", A.tip); } - if (aClk) { + if (aClk && A.enabled) { s_selected_index = static_cast(i); - if (a == 0) doCopy(); - else if (a == 1) doViewTransactions(); - else if (a == 2) openEdit(); - // Delete mutates book.entries() (removeEntry -> erase) — deferring it past the - // row loop avoids iterating a vector we shrink mid-loop (OOB on later rows). - else rowDeleteRequested = true; + switch (A.id) { + case 0: doCopy(); break; + case 1: doViewTransactions(); break; + case 2: doSendTo(); break; + case 3: doMessage(); break; + case 4: openEdit(); break; + // Delete mutates book.entries() — defer past the row loop (OOB on later rows). + default: rowDeleteRequested = true; break; + } } - const bool armedDel = (a == 3 && s_confirm_delete_idx == static_cast(i)); - const ImU32 acol = armedDel ? material::ReadableError() - : aHov ? material::OnSurface() - : material::OnSurfaceMedium(); - const ImVec2 gsz = icoF->CalcTextSizeA(icoF->LegacySize, FLT_MAX, 0, actGlyph[a]); + const bool armedDel = (A.isDelete && s_confirm_delete_idx == static_cast(i)); + const ImU32 acol = !A.enabled ? material::OnSurfaceDisabled() + : armedDel ? material::ReadableError() + : aHov ? material::OnSurface() + : material::OnSurfaceMedium(); + const ImVec2 gsz = icoF->CalcTextSizeA(icoF->LegacySize, FLT_MAX, 0, A.glyph); dl->AddText(icoF, icoF->LegacySize, ImVec2(ax + (actHit - gsz.x) * 0.5f, cy - gsz.y * 0.5f), - acol, actGlyph[a]); + acol, A.glyph); ImGui::PopID(); ax -= actHit + 2.0f * dp; } @@ -1557,6 +1610,7 @@ void RenderContactsTab(App* app) if (ImGui::BeginPopup("##contactCtx")) { if (ImGui::MenuItem(TR("copy_address"))) doCopy(); if (ImGui::MenuItem(TR("view_transactions"))) doViewTransactions(); + if (ImGui::MenuItem(TR("contacts_send_to"))) doSendTo(); // (F020) #if DRAGONX_ENABLE_CHAT { const bool canMsg = selValid() && isShieldedAddr(book.entries()[s_selected_index].address); diff --git a/src/ui/windows/send_tab.cpp b/src/ui/windows/send_tab.cpp index daf981d..d802a57 100644 --- a/src/ui/windows/send_tab.cpp +++ b/src/ui/windows/send_tab.cpp @@ -752,6 +752,14 @@ void SweepSetSendRecipient(App* app, const char* to) { s_amount = to ? 1.0 : 0.0; } +// Fill ONLY the compose form's recipient (e.g. a contact's "Send to" from another tab), leaving the +// amount/memo/source for the user. Mirrors the in-tab "Send again" prefill. (F020) +void PrefillSendRecipient(App* app, const char* to) { + (void)app; + strncpy(s_to_address, to ? to : "", sizeof(s_to_address) - 1); + s_to_address[sizeof(s_to_address) - 1] = '\0'; +} + void SweepShowSendConfirm(App* app, bool show) { (void)app; if (show) { diff --git a/src/ui/windows/send_tab.h b/src/ui/windows/send_tab.h index c034e96..8500ec1 100644 --- a/src/ui/windows/send_tab.h +++ b/src/ui/windows/send_tab.h @@ -32,6 +32,8 @@ void RenderSendConfirmPopup(App* app); void SweepShowSendConfirm(App* app, bool show); // UI sweep: put `to` (nullptr: clear) in the recipient field, e.g. a mining address to show it can't be paid. void SweepSetSendRecipient(App* app, const char* to); +// Fill only the recipient field (e.g. a contact's "Send to"); amount/memo/source are left for the user. (F020) +void PrefillSendRecipient(App* app, const char* to); /** * @brief Pre-fill the "from" address in the send tab diff --git a/src/util/i18n.cpp b/src/util/i18n.cpp index 8fb1c76..79b7dd5 100644 --- a/src/util/i18n.cpp +++ b/src/util/i18n.cpp @@ -2051,6 +2051,7 @@ void I18n::loadBuiltinEnglish() strings_["clear_search"] = "Clear search"; strings_["contacts_sort_name"] = "Sort: name (click for recently added)"; strings_["contacts_sort_recent"] = "Sort: recently added (click for name)"; + strings_["contacts_send_to"] = "Send to"; strings_["address_book_count_one"] = "%zu address saved"; strings_["address_book_deleted"] = "Entry deleted"; strings_["address_book_edit"] = "Edit Address";