feat(receive): fix share truncation, memo-only requests, explorer leak + clearer labels

UX audit, Receive surface (batch 1):

- F002: build the "Copy request" text in a std::string so a long memo's URI is
  never silently truncated (was a 1024-char buffer).
- F008: build the payment URI / QR when an amount OR a memo is set, so a
  memo-only request isn't a bare address; Copy URI / Copy request follow suit.
- F009: when the QR fails to encode (usually an over-long memo) say so and point
  to Copy URI, instead of a bare "QR unavailable".
- F028: rename "Share" to "Copy request" and add tooltips distinguishing it
  (address + amount + link) from Copy URI (just the drgx: link).
- F049: hide Explorer for shielded addresses — a z-address shows nothing on an
  explorer and the click would leak your receiving address; keep it (with a
  tooltip) for transparent/mining addresses. Choice a.
- F050: replace the cryptic [Z]/[T] source tags with "Shielded"/"Mining"; TR the
  share "URI" label.
- F083: Clear now has a tooltip and a one-step Undo (restores the amount + memo
  in the same slot). Choice a.

New strings (English; locales fall back). Build + tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 20:18:31 -06:00
co-authored by Claude Opus 4.8
parent 684fb64f4b
commit c66031f94b
2 changed files with 84 additions and 38 deletions
+75 -38
View File
@@ -197,7 +197,7 @@ static void RenderAddressDropdown(App* app, float width) {
s_selected_address_idx < (int)state.addresses.size()) {
const auto& addr = state.addresses[s_selected_address_idx];
bool isZ = addr.type == "shielded";
const char* tag = isZ ? "[Z]" : "[T]";
const char* tag = TR(isZ ? "shielded_type" : "mining"); // words, not cryptic [Z]/[T] (F050)
// Reserve pixel room for the tag prefix and the trailing balance, then middle-truncate the
// address to whatever remains — measured with the combo's own Body2 font. Char-count
// truncation kept MORE chars as the column widened, so at 150% the scaled font overflowed
@@ -256,7 +256,7 @@ static void RenderAddressDropdown(App* app, float width) {
const auto& addr = state.addresses[i];
bool isCurrent = (s_selected_address_idx == static_cast<int>(i));
bool isZ = addr.type == "shielded";
const char* tag = isZ ? "[Z]" : "[T]";
const char* tag = TR(isZ ? "shielded_type" : "mining"); // words, not [Z]/[T] (F050)
// Check for NEW badge
bool isNew = false;
@@ -663,7 +663,7 @@ void RenderReceiveTab(App* app)
// Generate QR data — shielded only: a mining (transparent) address can't be paid, so it gets no QR.
std::string qr_data = isZ ? selected.address : std::string();
if (isZ && s_request_amount > 0) {
if (isZ && (s_request_amount > 0 || s_request_memo[0])) { // include a memo-only request (F008)
// Canonical, URL-encoded "drgx:" URI via the shared builder. The old inline code emitted an
// unparseable "dragonx:" scheme and appended the memo raw (spaces/&/= corrupted the QR).
qr_data = util::buildPaymentUri(selected.address, s_request_amount, "",
@@ -983,7 +983,8 @@ void RenderReceiveTab(App* app)
ImVec2 textPos(qrPanelMin.x + totalQrSize * 0.5f - S.drawElement("tabs.receive", "qr-unavailable-text-offset").size * cardDp,
qrPanelMin.y + totalQrSize * 0.5f);
dl->AddText(capFont, capFont->LegacySize, textPos,
OnSurfaceDisabled(), TR("qr_unavailable"));
OnSurfaceDisabled(), TR(!qr_data.empty() ? "qr_too_long" : "qr_unavailable"),
nullptr, qrSize); // qr_data non-empty but no texture ⇒ encode failed (too long)
}
ImGui::SetCursorScreenPos(qrPanelMin);
@@ -1038,74 +1039,110 @@ void RenderReceiveTab(App* app)
// fixed-width buttons from the left (which left a large dead gap on the right). Split innerW
// into equal shares over the live button count: 2 by default (Clear Request + Explorer),
// 4 when an amount is requested (+ Copy URI + Share).
int nBtns = (s_request_amount > 0 ? 2 : 0) + 2;
// Copy URI + Copy request appear with any request data (amount OR memo, F008); Explorer only for
// a transparent address (F049); Clear is always present.
const bool hasData = (s_request_amount > 0 || s_request_memo[0]);
int nBtns = (hasData ? 2 : 0) + 1 /*Clear*/ + (isZ ? 0 : 1) /*Explorer*/;
float otherBtnW = std::max(S.drawElement("tabs.receive", "action-btn-min-width").size,
(innerW - (nBtns - 1) * btnGap) / (float)nBtns);
bool firstBtn = true;
if (s_request_amount > 0) {
if (hasData) {
if (!firstBtn) ImGui::SameLine(0, btnGap);
firstBtn = false;
if (TactileButton(TrId("copy_uri", "recv").c_str(), ImVec2(otherBtnW, btnH), S.resolveFont("button"))) {
ImGui::SetClipboardText(s_cached_qr_data.c_str());
Notifications::instance().info(TR("payment_uri_copied"));
}
if (ImGui::IsItemHovered()) material::Tooltip("%s", TR("recv_copy_uri_tip")); // F028
}
if (s_request_amount > 0) {
if (hasData) {
if (!firstBtn) ImGui::SameLine(0, btnGap);
firstBtn = false;
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
ImGui::ColorConvertU32ToFloat4(IM_COL32(255, 255, 255, (int)S.drawElement("tabs.receive", "btn-hover-alpha").size)));
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::ColorConvertU32ToFloat4(PrimaryLight()));
if (TactileButton(TrId("share", "recv").c_str(), ImVec2(otherBtnW, btnH), S.resolveFont("button"))) {
char shareBuf[1024];
snprintf(shareBuf, sizeof(shareBuf),
"%s\n%s: %.8f %s\n%s: %s\nURI: %s",
TR("payment_request"), TR("amount"),
s_request_amount, DRAGONX_TICKER,
TR("address"), selected.address.c_str(),
s_cached_qr_data.c_str());
ImGui::SetClipboardText(shareBuf);
// "Copy request" (clearer than "Share", which suggested an OS share sheet). Build the text in
// a std::string so a long memo's URI is never silently truncated. (F002, F028)
if (TactileButton(TrId("copy_request", "recv").c_str(), ImVec2(otherBtnW, btnH), S.resolveFont("button"))) {
std::string share = std::string(TR("payment_request")) + "\n";
if (s_request_amount > 0) {
char amt[64];
snprintf(amt, sizeof(amt), "%.8f %s", s_request_amount, DRAGONX_TICKER);
share += std::string(TR("amount")) + ": " + amt + "\n";
}
share += std::string(TR("address")) + ": " + selected.address + "\n";
share += std::string(TR("recv_share_uri_label")) + ": " + s_cached_qr_data;
ImGui::SetClipboardText(share.c_str());
Notifications::instance().info(TR("payment_request_copied"));
}
ImGui::PopStyleColor(3);
if (ImGui::IsItemHovered()) material::Tooltip("%s", TR("recv_copy_request_tip")); // F028
}
{
bool hasData = (s_request_amount > 0 || s_request_memo[0]);
// Clear with a tooltip naming what it removes, and a one-step undo: right after a clear the
// same slot becomes "Undo", restoring the amount + memo (easy to lose a long memo). (F083)
static double s_recv_undo_amount = 0.0, s_recv_undo_usd = 0.0;
static std::string s_recv_undo_memo;
static bool s_recv_undo_has = false;
if (!firstBtn) ImGui::SameLine(0, btnGap);
firstBtn = false;
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
ImGui::ColorConvertU32ToFloat4(IM_COL32(255, 255, 255, (int)S.drawElement("tabs.receive", "clear-btn-hover-alpha").size)));
ImGui::PushStyleColor(ImGuiCol_Text,
ImGui::ColorConvertU32ToFloat4(hasData ? OnSurfaceMedium() : OnSurfaceDisabled()));
ImGui::BeginDisabled(!hasData);
if (TactileButton(TrId("clear_request", "recv").c_str(), ImVec2(otherBtnW, btnH), S.resolveFont("button"))) {
s_request_amount = 0.0;
s_request_usd_amount = 0.0;
s_request_memo[0] = '\0';
if (!hasData && s_recv_undo_has) {
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::ColorConvertU32ToFloat4(PrimaryLight()));
if (TactileButton(TrId("undo", "recv").c_str(), ImVec2(otherBtnW, btnH), S.resolveFont("button"))) {
s_request_amount = s_recv_undo_amount;
s_request_usd_amount = s_recv_undo_usd;
snprintf(s_request_memo, sizeof(s_request_memo), "%s", s_recv_undo_memo.c_str());
s_recv_undo_has = false;
}
if (ImGui::IsItemHovered()) material::Tooltip("%s", TR("recv_undo_tip"));
ImGui::PopStyleColor(1);
} else {
ImGui::PushStyleColor(ImGuiCol_Text,
ImGui::ColorConvertU32ToFloat4(hasData ? OnSurfaceMedium() : OnSurfaceDisabled()));
ImGui::BeginDisabled(!hasData);
if (TactileButton(TrId("clear_request", "recv").c_str(), ImVec2(otherBtnW, btnH), S.resolveFont("button"))) {
s_recv_undo_amount = s_request_amount;
s_recv_undo_usd = s_request_usd_amount;
s_recv_undo_memo = s_request_memo;
s_recv_undo_has = true;
s_request_amount = 0.0;
s_request_usd_amount = 0.0;
s_request_memo[0] = '\0';
}
ImGui::EndDisabled();
if (hasData && ImGui::IsItemHovered()) material::Tooltip("%s", TR("recv_clear_tip"));
ImGui::PopStyleColor(1);
}
ImGui::EndDisabled();
ImGui::PopStyleColor(3);
ImGui::PopStyleColor(2);
}
if (!firstBtn) ImGui::SameLine(0, btnGap);
firstBtn = false;
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
ImGui::ColorConvertU32ToFloat4(IM_COL32(255, 255, 255, (int)S.drawElement("tabs.receive", "btn-hover-alpha").size)));
ImGui::PushStyleColor(ImGuiCol_Border, ImGui::ColorConvertU32ToFloat4(OnSurfaceDisabled()));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, S.drawElement("tabs.receive", "explorer-btn-border-size").size);
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::ColorConvertU32ToFloat4(PrimaryLight()));
if (TactileButton(TrId("explorer", "recv").c_str(), ImVec2(otherBtnW, btnH), S.resolveFont("button"))) {
OpenExplorerURL(app, selected.address);
// Explorer only for a transparent (mining) address: a shielded z-address is private — an external
// explorer shows nothing for it and the click would leak your receiving address to a third-party
// site. So hide it entirely for shielded. (F049, choice a)
if (!isZ) {
if (!firstBtn) ImGui::SameLine(0, btnGap);
firstBtn = false;
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
ImGui::ColorConvertU32ToFloat4(IM_COL32(255, 255, 255, (int)S.drawElement("tabs.receive", "btn-hover-alpha").size)));
ImGui::PushStyleColor(ImGuiCol_Border, ImGui::ColorConvertU32ToFloat4(OnSurfaceDisabled()));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, S.drawElement("tabs.receive", "explorer-btn-border-size").size);
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::ColorConvertU32ToFloat4(PrimaryLight()));
if (TactileButton(TrId("explorer", "recv").c_str(), ImVec2(otherBtnW, btnH), S.resolveFont("button"))) {
OpenExplorerURL(app, selected.address);
}
ImGui::PopStyleVar(); // FrameBorderSize
ImGui::PopStyleColor(4);
if (ImGui::IsItemHovered()) material::Tooltip("%s", TR("recv_explorer_tip"));
}
ImGui::PopStyleVar(); // FrameBorderSize
ImGui::PopStyleColor(4);
}
+9
View File
@@ -1316,6 +1316,15 @@ void I18n::loadBuiltinEnglish()
strings_["addresses_appear_here"] = "Your receiving addresses will appear here once connected.";
strings_["loading_addresses"] = "Loading addresses...";
strings_["clear_request"] = "Clear Request";
strings_["copy_request"] = "Copy request";
strings_["undo"] = "Undo";
strings_["qr_too_long"] = "Request too long for a QR code \xE2\x80\x94 shorten the memo, or use Copy URI.";
strings_["recv_copy_uri_tip"] = "Copies only the drgx: payment link.";
strings_["recv_copy_request_tip"] = "Copies the address, amount and payment link as plain text.";
strings_["recv_share_uri_label"] = "URI";
strings_["recv_clear_tip"] = "Clears the amount and memo of this request.";
strings_["recv_undo_tip"] = "Restore the amount and memo you just cleared.";
strings_["recv_explorer_tip"] = "Opens this address on an external block explorer (a third-party website).";
strings_["copy_uri"] = "Copy URI";
strings_["qr_unavailable"] = "QR unavailable";
strings_["received_label"] = "Received";