feat(settings): lite secret auto-wipe, import-key reveal/hint, seed-save caution (F012/F060/F059)

UX audit, Settings surface (batch 2) — Lite backup/keys:

- F012: a revealed Lite seed / private keys auto-wipes after ~60s on screen (with a
  live countdown) and when the user switches settings tabs. The 60s backstop also
  covers walking away, locking, or leaving the page (all stop re-rendering the block).
  Choice a.
- F060: the Lite "Import key" field gets a show/hide (eye) toggle and a length + key-type
  hint (viewing / spending / unrecognized) so a blind-pasted key is checkable.
- F059: a seed "Save to file" shows an inline "saved unencrypted — move it offline"
  caution and notes when it replaced an existing file. Choice a.

New strings (English). Build + tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 14:34:19 -06:00
co-authored by Claude Opus 4.8
parent e4f7cd0b40
commit 3c5f3b9d69
2 changed files with 71 additions and 3 deletions
+64 -3
View File
@@ -145,6 +145,9 @@ struct SettingsPageState {
bool lite_export_is_seed = false; // revealed secret is a seed (show birthday + save-to-file)
unsigned long long lite_export_birthday = 0; // seed birthday (shown with the seed)
char lite_import_key[512] = "";
bool lite_import_show = false; // reveal the import-key field (F060)
double lite_export_reveal_time = 0.0; // when the secret was revealed, for the ~60s auto-wipe (F012)
int last_tab = -1; // detect settings-tab switches to auto-wipe a revealed secret (F012)
std::string lite_backup_status;
// Encryption passphrase inputs (SECRET: zeroed right after each action). lite_enc_pass is
// reused for Encrypt (unencrypted wallet) and Unlock (locked wallet); lite_dec_pass for Decrypt.
@@ -807,6 +810,16 @@ void RenderSettingsPage(App* app) {
ImFont* body2 = Type().body2();
ImFont* sub1 = Type().subtitle1();
// F012: switching settings tabs wipes any revealed Lite secret (it only shows on the Backup tab).
if (s_settingsState.current_tab != s_settingsState.last_tab) {
if (!s_settingsState.lite_export_secret.empty()) {
wallet::secureWipeLiteSecret(s_settingsState.lite_export_secret);
s_settingsState.lite_export_label.clear();
s_settingsState.lite_export_is_seed = false;
}
s_settingsState.last_tab = s_settingsState.current_tab;
}
// ====================================================================
// APPEARANCE — two stacked cards: THEME & LANGUAGE (2x2 dropdown grid)
// then SCALE & EFFECTS (font scale + effect toggles + Advanced sliders).
@@ -2007,6 +2020,7 @@ void RenderSettingsPage(App* app) {
s_settingsState.lite_export_label = TR("lite_seed_warning");
s_settingsState.lite_export_is_seed = true;
s_settingsState.lite_export_birthday = r.birthday;
s_settingsState.lite_export_reveal_time = ImGui::GetTime(); // F012
s_settingsState.lite_backup_status.clear();
} else {
s_settingsState.lite_export_label.clear();
@@ -2024,6 +2038,7 @@ void RenderSettingsPage(App* app) {
if (r.ok) {
s_settingsState.lite_export_secret = r.privateKeysJson;
s_settingsState.lite_export_label = TR("lite_private_keys_warning");
s_settingsState.lite_export_reveal_time = ImGui::GetTime(); // F012
s_settingsState.lite_backup_status.clear();
} else {
s_settingsState.lite_export_label.clear();
@@ -2033,11 +2048,27 @@ void RenderSettingsPage(App* app) {
}
if (ImGui::IsItemHovered()) material::Tooltip("%s", TR("tt_lite_show_keys"));
// F012: auto-wipe a revealed secret after ~60s on screen — the backstop for walking
// away, locking the app, or leaving the page (all of which stop re-rendering here).
if (!s_settingsState.lite_export_secret.empty() &&
ImGui::GetTime() - s_settingsState.lite_export_reveal_time >= 60.0) {
wallet::secureWipeLiteSecret(s_settingsState.lite_export_secret);
s_settingsState.lite_export_label.clear();
s_settingsState.lite_export_is_seed = false;
}
// Revealed secret: shown read-only (no extra copies), with copy + wipe.
if (!s_settingsState.lite_export_secret.empty()) {
ImGui::SetCursorScreenPos(ImVec2(leftX, ImGui::GetCursorScreenPos().y));
Type().textColored(TypeStyle::Caption, OnSurfaceDisabled(),
s_settingsState.lite_export_label.c_str());
// Countdown to the auto-wipe. (F012)
{
int secsLeft = (int)std::ceil(60.0 - (ImGui::GetTime() - s_settingsState.lite_export_reveal_time));
if (secsLeft < 0) secsLeft = 0;
char cd[64]; snprintf(cd, sizeof(cd), TR("lite_autohide_countdown"), secsLeft);
ImGui::SetCursorScreenPos(ImVec2(leftX, ImGui::GetCursorScreenPos().y));
Type().textColored(TypeStyle::Caption, OnSurfaceDisabled(), cd);
}
ImGui::SetCursorScreenPos(ImVec2(leftX, ImGui::GetCursorScreenPos().y));
ImGui::PushTextWrapPos(0.0f);
ImGui::TextWrapped("%s", s_settingsState.lite_export_secret.c_str());
@@ -2050,6 +2081,13 @@ void RenderSettingsPage(App* app) {
ImGui::SetCursorScreenPos(ImVec2(leftX, ImGui::GetCursorScreenPos().y));
Type().textColored(TypeStyle::Caption, OnSurfaceMedium(), bday);
}
// F059: a seed saved to file is written unencrypted — say so plainly.
if (s_settingsState.lite_export_is_seed) {
ImGui::SetCursorScreenPos(ImVec2(leftX, ImGui::GetCursorScreenPos().y));
ImGui::PushTextWrapPos(0.0f);
Type().textColored(TypeStyle::Caption, material::Warning(), TR("lite_seed_save_caution"));
ImGui::PopTextWrapPos();
}
ImGui::SetCursorScreenPos(ImVec2(leftX, ImGui::GetCursorScreenPos().y));
if (TactileButton(TrId("lite_copy", "LiteExportCopy").c_str(), ImVec2(0, 0), S.resolveFont("button"))) {
app->copySecretToClipboard(s_settingsState.lite_export_secret);
@@ -2060,13 +2098,16 @@ void RenderSettingsPage(App* app) {
if (s_settingsState.lite_export_is_seed &&
TactileButton(TrId("lite_save_to_file", "LiteExportSave").c_str(), ImVec2(0, 0), S.resolveFont("button"))) {
std::string path = util::Platform::getConfigDir() + "/lite-seed-backup.txt";
std::error_code existEc;
const bool existed = std::filesystem::exists(path, existEc); // F059: overwrite notice
std::string content = s_settingsState.lite_export_secret + "\nBirthday: " +
std::to_string(s_settingsState.lite_export_birthday) + "\n";
const bool ok = util::Platform::writeFileAtomically(
path, content, /*restrictPermissions=*/true);
wallet::secureWipeLiteSecret(content);
s_settingsState.lite_backup_status = ok
? (std::string(TR("lite_saved_to")) + path)
? (std::string(TR("lite_saved_to")) + path +
(existed ? std::string(" ") + TR("lite_saved_overwrote") : std::string()))
: (std::string(TR("lite_could_not_write")) + path);
}
if (s_settingsState.lite_export_is_seed) {
@@ -2086,11 +2127,31 @@ void RenderSettingsPage(App* app) {
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted(TR("lite_import_key_label"));
ImGui::SameLine(leftX - sectionOrigin.x + liteLabelW);
ImGui::SetNextItemWidth(liteInputW);
const float liteEyeW = ImGui::GetFrameHeight();
ImGui::SetNextItemWidth(liteInputW - liteEyeW - 6.0f * Layout::dpiScale());
ImGui::InputText("##LiteImportKey", s_settingsState.lite_import_key,
sizeof(s_settingsState.lite_import_key),
ImGuiInputTextFlags_Password);
s_settingsState.lite_import_show ? 0 : ImGuiInputTextFlags_Password); // F060
if (ImGui::IsItemHovered()) material::Tooltip("%s", TR("tt_lite_import_key"));
ImGui::SameLine(0, 6.0f * Layout::dpiScale());
{
material::IconButtonStyle est;
est.tooltip = TR(s_settingsState.lite_import_show ? "hide_password" : "show_password");
if (material::IconButton("##LiteImportKeyEye",
s_settingsState.lite_import_show ? ICON_MD_VISIBILITY_OFF : ICON_MD_VISIBILITY,
material::Type().iconSmall(), ImVec2(liteEyeW, liteEyeW), est))
s_settingsState.lite_import_show = !s_settingsState.lite_import_show;
}
// Length + key-type hint so a blind-pasted key is at least sanity-checkable. (F060)
if (s_settingsState.lite_import_key[0] != '\0') {
std::string kk = dragonx::util::stripAllWhitespaceForKey(s_settingsState.lite_import_key);
const char* kt = kk.rfind("zxview", 0) == 0 ? TR("lite_key_type_viewing")
: kk.rfind("secret-", 0) == 0 ? TR("lite_key_type_spending")
: TR("lite_key_type_unknown");
char kh[96]; snprintf(kh, sizeof(kh), TR("lite_import_key_hint_fmt"), (int)kk.size(), kt);
ImGui::SetCursorScreenPos(ImVec2(leftX, ImGui::GetCursorScreenPos().y));
Type().textColored(TypeStyle::Caption, OnSurfaceDisabled(), kh);
}
ImGui::SetCursorScreenPos(ImVec2(leftX, ImGui::GetCursorScreenPos().y));
// Import / Encrypt / Remove encryption end in a backend save that waits on the scan lock (held for a
// whole scan): they run on the controller's wallet-op lane and are unavailable while a scan runs.
+7
View File
@@ -1135,6 +1135,13 @@ void I18n::loadBuiltinEnglish()
strings_["lite_copy"] = "Copy";
strings_["lite_save_to_file"] = "Save to file";
strings_["lite_saved_to"] = "Saved (plaintext, owner-only) to ";
strings_["lite_saved_overwrote"] = "(replaced the existing file)";
strings_["lite_seed_save_caution"] = "Saved unencrypted \xE2\x80\x94 move it offline and delete it from this machine.";
strings_["lite_autohide_countdown"] = "Hides automatically in %ds";
strings_["lite_import_key_hint_fmt"] = "%d chars \xC2\xB7 %s";
strings_["lite_key_type_viewing"] = "looks like a viewing key";
strings_["lite_key_type_spending"] = "looks like a spending key";
strings_["lite_key_type_unknown"] = "unrecognized key format";
strings_["lite_could_not_write"] = "Could not write ";
strings_["lite_hide_wipe"] = "Hide & wipe";
strings_["lite_import_key_label"] = "Import key";