diff --git a/src/app_security.cpp b/src/app_security.cpp index cb8b4a3..a649bba 100644 --- a/src/app_security.cpp +++ b/src/app_security.cpp @@ -1239,9 +1239,9 @@ void App::renderLockScreen() { float startX = cardX + (cardW - totalW) * 0.5f; float textY = cy + (iconSize.y - textSize.y) * 0.5f; // vertically align text to icon dl->AddText(iconFont, iconFont->LegacySize, - ImVec2(startX, cy), IM_COL32(255,255,255,120), modeIcon); + ImVec2(startX, cy), ui::material::OnSurfaceMedium(), modeIcon); dl->AddText(captionFont, captionFont->LegacySize, - ImVec2(startX + iconSize.x, textY), IM_COL32(255,255,255,120), modeText); + ImVec2(startX + iconSize.x, textY), ui::material::OnSurfaceMedium(), modeText); cy += std::max(iconSize.y, textSize.y) + 8.0f * dp; // Switch link @@ -1530,7 +1530,7 @@ void App::renderEncryptWalletDialog() { int classes = (int)hasDigit + (int)hasLower + (int)hasUpper + (int)hasSymbol; const char* strengthLabel = TR("wiz_strength_weak"); - ImVec4 strengthCol(0.9f, 0.2f, 0.2f, 1.0f); + ImVec4 strengthCol = ui::material::ErrorVec4(); float strengthPct = 0.25f; int tier = 0; // 0=Weak, 1=Fair, 2=Good, 3=Strong if (len >= 16) tier = 3; @@ -1538,16 +1538,16 @@ void App::renderEncryptWalletDialog() { else if (len >= 8) tier = 1; // Downgrade one tier when only a single character class is used. if (classes <= 1 && tier > 0) tier -= 1; - if (tier == 3) { strengthLabel = TR("wiz_strength_strong"); strengthCol = ImVec4(0.3f,0.9f,0.5f,1); strengthPct = 1.0f; } - else if (tier == 2) { strengthLabel = TR("wiz_strength_good"); strengthCol = ImVec4(0.3f,0.9f,0.5f,1); strengthPct = 0.75f; } - else if (tier == 1) { strengthLabel = TR("wiz_strength_fair"); strengthCol = ImVec4(1,0.7f,0.3f,1); strengthPct = 0.5f; } + if (tier == 3) { strengthLabel = TR("wiz_strength_strong"); strengthCol = ui::material::SuccessVec4(); strengthPct = 1.0f; } + else if (tier == 2) { strengthLabel = TR("wiz_strength_good"); strengthCol = ui::material::SuccessVec4(); strengthPct = 0.75f; } + else if (tier == 1) { strengthLabel = TR("wiz_strength_fair"); strengthCol = ui::material::WarningVec4(); strengthPct = 0.5f; } float barW = ImGui::GetContentRegionAvail().x; float barH = 4.0f * ui::Layout::dpiScale(); ImVec2 p = ImGui::GetCursorScreenPos(); ImDrawList* dl = ImGui::GetWindowDrawList(); dl->AddRectFilled(p, ImVec2(p.x + barW, p.y + barH), - IM_COL32(255,255,255,30), 2.0f); + ImGui::GetColorU32(ImGuiCol_FrameBg), 2.0f); if (len > 0) dl->AddRectFilled(p, ImVec2(p.x + barW * strengthPct, p.y + barH), ImGui::ColorConvertFloat4ToU32(strengthCol), 2.0f); @@ -1562,10 +1562,18 @@ void App::renderEncryptWalletDialog() { ImGui::Spacing(); const size_t encPassLen = strlen(encrypt_pass_buf_); const bool encMatch = strcmp(encrypt_pass_buf_, encrypt_confirm_buf_) == 0; - bool valid = encPassLen >= 8 && encMatch; + // Leading/trailing space or tab: block (matches the wizard). Silently trimming would change + // the passphrase the user believes they set and lock them out on the next unlock. + bool encEdgeSpace = false; + if (encPassLen > 0) { + const char a = encrypt_pass_buf_[0], b = encrypt_pass_buf_[encPassLen - 1]; + encEdgeSpace = (a == ' ' || a == '\t' || b == ' ' || b == '\t'); + } + bool valid = encPassLen >= 8 && encMatch && !encEdgeSpace; // Say WHY the button is disabled, once the user has started typing (was silent before). if (!valid && (encPassLen > 0 || strlen(encrypt_confirm_buf_) > 0)) { - const char* why = (encPassLen < 8) ? TR("enc_min_len") + const char* why = encEdgeSpace ? TR("wiz_pass_spaces") + : (encPassLen < 8) ? TR("enc_min_len") : (!encMatch ? TR("enc_mismatch") : ""); if (*why) ImGui::TextColored(ui::material::WarningVec4(), "%s", why); } @@ -1604,7 +1612,7 @@ void App::renderEncryptWalletDialog() { ImVec2 p = ImGui::GetCursorScreenPos(); ImDrawList* dl = ImGui::GetWindowDrawList(); dl->AddRectFilled(p, ImVec2(p.x + barW, p.y + barH), - IM_COL32(255,255,255,25), 3.0f); + ImGui::GetColorU32(ImGuiCol_FrameBg), 3.0f); float t = (float)ImGui::GetTime(); float pulse = 0.5f + 0.5f * sinf(t * 2.0f); float segW = barW * 0.3f; @@ -1616,11 +1624,11 @@ void App::renderEncryptWalletDialog() { } if (!encrypt_status_.empty()) { - ImGui::TextColored(ImVec4(1, 1, 1, 0.6f), "%s", encrypt_status_.c_str()); + ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(ui::material::OnSurfaceMedium()), "%s", encrypt_status_.c_str()); } ImGui::Spacing(); - ImGui::TextColored(ImVec4(1,1,1,0.4f), "%s", TR("enc_wait")); + ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(ui::material::OnSurfaceDisabled()), "%s", TR("enc_wait")); // Transition to PIN phase when encryption finishes successfully if (!encrypt_in_progress_ && encrypt_dialog_phase_ == EncryptDialogPhase::Encrypting) { @@ -1629,7 +1637,7 @@ void App::renderEncryptWalletDialog() { // ---- Phase 3: PIN setup (after successful encryption) ---- } else if (encrypt_dialog_phase_ == EncryptDialogPhase::PinSetup) { - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.3f, 0.9f, 0.5f, 1)); + ImGui::PushStyleColor(ImGuiCol_Text, ui::material::SuccessVec4()); ImGui::Text(ICON_MD_CHECK_CIRCLE " %s", TR("enc_success")); ImGui::PopStyleColor(); ImGui::Spacing(); @@ -1750,32 +1758,53 @@ void App::renderEncryptWalletDialog() { ImGui::Spacing(); } + static bool s_showChgPass = false; + const ImGuiInputTextFlags chgPwFlags = s_showChgPass ? 0 : ImGuiInputTextFlags_Password; + ImGui::TextUnformatted(TR("change_pass_current")); ImGui::PushItemWidth(-1); ImGui::InputText("##chg_old", change_old_pass_buf_, sizeof(change_old_pass_buf_), - ImGuiInputTextFlags_Password); + chgPwFlags); ImGui::PopItemWidth(); ImGui::TextUnformatted(TR("change_pass_new")); ImGui::PushItemWidth(-1); ImGui::InputText("##chg_new", change_new_pass_buf_, sizeof(change_new_pass_buf_), - ImGuiInputTextFlags_Password); + chgPwFlags); ImGui::PopItemWidth(); ImGui::TextUnformatted(TR("change_pass_confirm")); ImGui::PushItemWidth(-1); ImGui::InputText("##chg_confirm", change_confirm_buf_, sizeof(change_confirm_buf_), - ImGuiInputTextFlags_Password); + chgPwFlags); ImGui::PopItemWidth(); + ImGui::Checkbox(TR("enc_show_pass"), &s_showChgPass); if (!encrypt_status_.empty()) { ImGui::TextColored(ui::material::WarningVec4(), "%s", encrypt_status_.c_str()); } ImGui::Spacing(); - bool valid = strlen(change_old_pass_buf_) > 0 && - strlen(change_new_pass_buf_) >= 8 && - strcmp(change_new_pass_buf_, change_confirm_buf_) == 0; + const size_t chgNewLen = strlen(change_new_pass_buf_); + const bool chgHasOld = strlen(change_old_pass_buf_) > 0; + const bool chgMatch = strcmp(change_new_pass_buf_, change_confirm_buf_) == 0; + const bool chgSame = chgHasOld && chgNewLen > 0 && + strcmp(change_old_pass_buf_, change_new_pass_buf_) == 0; + bool chgEdgeSpace = false; + if (chgNewLen > 0) { + const char a = change_new_pass_buf_[0], b = change_new_pass_buf_[chgNewLen - 1]; + chgEdgeSpace = (a == ' ' || a == '\t' || b == ' ' || b == '\t'); + } + bool valid = chgHasOld && chgNewLen >= 8 && chgMatch && !chgEdgeSpace && !chgSame; + // Say WHY the primary button is disabled once the user has started typing. + if (!valid && (chgNewLen > 0 || strlen(change_confirm_buf_) > 0)) { + const char* why = chgEdgeSpace ? TR("wiz_pass_spaces") + : (chgNewLen < 8) ? TR("enc_min_len") + : chgSame ? TR("change_pass_same") + : !chgMatch ? TR("enc_mismatch") + : (!chgHasOld ? TR("change_pass_need_current") : ""); + if (*why) ImGui::TextColored(ui::material::WarningVec4(), "%s", why); + } // Two-button footer (primary + Cancel) to match the encrypt/decrypt siblings. float btnW = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f; @@ -2102,10 +2131,14 @@ void App::renderDecryptWalletDialog() { } else if (i == services::WalletSecurityWorkflow::stepIndex(decryptState.step)) { // In progress - animate float alpha = 0.5f + 0.5f * sinf((float)ImGui::GetTime() * 4.0f); - ImGui::TextColored(ImVec4(1.0f, 0.85f, 0.0f, alpha), ICON_MD_PENDING); + { + ImVec4 pendCol = ui::material::WarningVec4(); + pendCol.w = alpha; + ImGui::TextColored(pendCol, ICON_MD_PENDING); + } } else { // Not started - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 0.5f), ICON_MD_RADIO_BUTTON_UNCHECKED); + ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(ui::material::OnSurfaceDisabled()), ICON_MD_RADIO_BUTTON_UNCHECKED); } ImGui::PopFont(); ImGui::SameLine(); @@ -2115,15 +2148,15 @@ void App::renderDecryptWalletDialog() { int mins = (int)(stepElapsed / 60); int secs = (int)(stepElapsed % 60); if (mins > 0) { - ImGui::TextColored(ImVec4(1.0f, 0.9f, 0.6f, 1.0f), + ImGui::TextColored(ui::material::WarningVec4(), "%s... (%dm %02ds)", stepLabels[i], mins, secs); } else { - ImGui::TextColored(ImVec4(1.0f, 0.9f, 0.6f, 1.0f), + ImGui::TextColored(ui::material::WarningVec4(), "%s... (%ds)", stepLabels[i], secs); } } else if (services::WalletSecurityWorkflow::stepIsComplete(decryptState.step, services::WalletSecurityWorkflow::stepFromIndex(i))) { - ImGui::TextColored(ImVec4(0.6f, 0.8f, 0.6f, 1.0f), "%s", stepLabels[i]); + ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(ui::material::OnSurfaceMedium()), "%s", stepLabels[i]); } else { ImGui::TextDisabled("%s", stepLabels[i]); } @@ -2140,7 +2173,7 @@ void App::renderDecryptWalletDialog() { ImVec2 p = ImGui::GetCursorScreenPos(); ImDrawList* dl = ImGui::GetWindowDrawList(); dl->AddRectFilled(p, ImVec2(p.x + barW, p.y + barH), - IM_COL32(255, 255, 255, 25), 3.0f); + ImGui::GetColorU32(ImGuiCol_FrameBg), 3.0f); float t = (float)ImGui::GetTime(); float segW = barW * 0.3f; float x0 = p.x + (barW + segW) * (0.5f + 0.5f * sinf(t * 2.0f)) - segW; @@ -2149,7 +2182,7 @@ void App::renderDecryptWalletDialog() { x1 = std::min(x1, p.x + barW); if (x1 > x0) { dl->AddRectFilled(ImVec2(x0, p.y), ImVec2(x1, p.y + barH), - IM_COL32(255, 218, 0, 200), 3.0f); + ui::material::Primary(), 3.0f); } ImGui::Dummy(ImVec2(barW, barH)); } @@ -2174,10 +2207,10 @@ void App::renderDecryptWalletDialog() { // ---- Phase 2: Success ---- } else if (decryptState.phase == DecryptPhase::Success) { ImGui::PushFont(Type().iconLarge()); - ImGui::TextColored(ImVec4(0.3f, 1.0f, 0.5f, 1.0f), ICON_MD_CHECK_CIRCLE); + ImGui::TextColored(ui::material::SuccessVec4(), ICON_MD_CHECK_CIRCLE); ImGui::PopFont(); ImGui::SameLine(); - ImGui::TextColored(ImVec4(0.3f, 1.0f, 0.5f, 1.0f), "%s", TR("decrypt_success_title")); + ImGui::TextColored(ui::material::SuccessVec4(), "%s", TR("decrypt_success_title")); ImGui::Spacing(); ImGui::TextWrapped("%s", TR("decrypt_success_desc")); @@ -2190,10 +2223,10 @@ void App::renderDecryptWalletDialog() { // ---- Phase 3: Error ---- } else if (decryptState.phase == DecryptPhase::Error) { ImGui::PushFont(Type().iconLarge()); - ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f), ICON_MD_ERROR); + ImGui::TextColored(ui::material::ErrorVec4(), ICON_MD_ERROR); ImGui::PopFont(); ImGui::SameLine(); - ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f), "%s", TR("decrypt_error_title")); + ImGui::TextColored(ui::material::ErrorVec4(), "%s", TR("decrypt_error_title")); ImGui::Spacing(); ImGui::TextWrapped("%s", decryptState.status.c_str()); diff --git a/src/app_wizard.cpp b/src/app_wizard.cpp index 3a8cfd0..95c5cfd 100644 --- a/src/app_wizard.cpp +++ b/src/app_wizard.cpp @@ -1264,13 +1264,37 @@ void App::renderFirstRunWizard() { dl->AddText(captionFont, captionFont->LegacySize, ImVec2(cx, cy), dimCol, TR("wiz_passphrase")); cy += captionFont->LegacySize + 4.0f * dp; + // Reveal toggle state + armed-skip state live for this step only: if the step was not + // rendered on the previous frame (user left and came back), start masked / disarmed. + static bool s_wizShowPass = false; + static bool s_wizSkipArmed = false; + static int s_wizLastFrame = -10; + if (ImGui::GetFrameCount() != s_wizLastFrame + 1) { + s_wizShowPass = false; + s_wizSkipArmed = false; + } + s_wizLastFrame = ImGui::GetFrameCount(); + const ImGuiInputTextFlags wizPwFlags = s_wizShowPass ? 0 : ImGuiInputTextFlags_Password; + ImGui::SetCursorScreenPos(ImVec2(cx, cy)); - ImGui::PushItemWidth(contentW); + const float wizEyeSz = ImGui::GetFrameHeight(); + const float wizEyeGap = 6.0f * dp; + ImGui::PushItemWidth(contentW - wizEyeSz - wizEyeGap); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 6.0f * dp); - ImGui::InputText("##wiz_pass", encrypt_pass_buf_, sizeof(encrypt_pass_buf_), - ImGuiInputTextFlags_Password); + ImGui::InputText("##wiz_pass", encrypt_pass_buf_, sizeof(encrypt_pass_buf_), wizPwFlags); ImGui::PopStyleVar(); ImGui::PopItemWidth(); + ImGui::SameLine(0, wizEyeGap); + { + ui::material::IconButtonStyle eyeSt; + eyeSt.hoverBg = ui::material::WithAlpha(ui::material::OnSurface(), 30); + eyeSt.bgRounding = 4.0f * dp; + eyeSt.tooltip = TR("enc_show_pass"); + if (ui::material::IconButton("##wiz_reveal", + s_wizShowPass ? ICON_MD_VISIBILITY_OFF : ICON_MD_VISIBILITY, + ui::material::Type().iconSmall(), ImVec2(wizEyeSz, wizEyeSz), eyeSt)) + s_wizShowPass = !s_wizShowPass; + } cy += 36.0f * dp + 6.0f * dp; dl->AddText(captionFont, captionFont->LegacySize, ImVec2(cx, cy), dimCol, TR("wiz_confirm")); @@ -1280,7 +1304,7 @@ void App::renderFirstRunWizard() { ImGui::PushItemWidth(contentW); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 6.0f * dp); ImGui::InputText("##wiz_confirm", encrypt_confirm_buf_, sizeof(encrypt_confirm_buf_), - ImGuiInputTextFlags_Password); + wizPwFlags); ImGui::PopStyleVar(); ImGui::PopItemWidth(); cy += 36.0f * dp + 6.0f * dp; @@ -1292,11 +1316,27 @@ void App::renderFirstRunWizard() { ImU32 strengthCol = ui::material::Error(); float strengthPct = 0.25f; - if (len >= 16) { + // Character-class diversity (matches the Settings Encrypt dialog): an all-digit or + // single-class passphrase scores one tier lower than a mixed one of the same length. + bool hasDigit = false, hasLower = false, hasUpper = false, hasSymbol = false; + for (const char* c = encrypt_pass_buf_; *c; ++c) { + unsigned char uc = static_cast(*c); + if (uc >= '0' && uc <= '9') hasDigit = true; + else if (uc >= 'a' && uc <= 'z') hasLower = true; + else if (uc >= 'A' && uc <= 'Z') hasUpper = true; + else hasSymbol = true; + } + const int classes = (int)hasDigit + (int)hasLower + (int)hasUpper + (int)hasSymbol; + int tier = 0; // 0=Weak, 1=Fair, 2=Good, 3=Strong + if (len >= 16) tier = 3; + else if (len >= 12) tier = 2; + else if (len >= 8) tier = 1; + if (classes <= 1 && tier > 0) tier -= 1; + if (tier == 3) { strengthLabel = TR("wiz_strength_strong"); strengthCol = ui::material::Secondary(); strengthPct = 1.0f; - } else if (len >= 12) { + } else if (tier == 2) { strengthLabel = TR("wiz_strength_good"); strengthCol = ui::material::Secondary(); strengthPct = 0.75f; - } else if (len >= 8) { + } else if (tier == 1) { strengthLabel = TR("wiz_strength_fair"); strengthCol = ui::material::Warning(); strengthPct = 0.5f; } @@ -1309,26 +1349,30 @@ void App::renderFirstRunWizard() { } cy += sBarH + 4.0f * dp; - char slabel[64]; + char slabel[256]; snprintf(slabel, sizeof(slabel), TR("wiz_strength"), strengthLabel); - dl->AddText(captionFont, captionFont->LegacySize, ImVec2(cx, cy), dimCol, slabel); - cy += captionFont->LegacySize + 10.0f * dp; + ImVec2 slSize = captionFont->CalcTextSizeA(captionFont->LegacySize, FLT_MAX, contentW, slabel); + dl->AddText(captionFont, captionFont->LegacySize, ImVec2(cx, cy), dimCol, slabel, nullptr, contentW); + cy += slSize.y + 10.0f * dp; } // Feedback on why Encrypt is disabled { size_t pLen = strlen(encrypt_pass_buf_); if (pLen > 0 && pLen < 8) { - char fb[80]; + char fb[256]; snprintf(fb, sizeof(fb), TR("wiz_pass_too_short"), pLen); + ImVec2 fbSize = captionFont->CalcTextSizeA(captionFont->LegacySize, FLT_MAX, contentW, fb); dl->AddText(captionFont, captionFont->LegacySize, ImVec2(cx, cy), - ui::material::Error(), fb); - cy += captionFont->LegacySize + 6.0f * dp; + ui::material::Error(), fb, nullptr, contentW); + cy += fbSize.y + 6.0f * dp; } else if (pLen >= 8 && strlen(encrypt_confirm_buf_) > 0 && strcmp(encrypt_pass_buf_, encrypt_confirm_buf_) != 0) { + const char* mm = TR("wiz_pass_mismatch"); + ImVec2 mmSize = captionFont->CalcTextSizeA(captionFont->LegacySize, FLT_MAX, contentW, mm); dl->AddText(captionFont, captionFont->LegacySize, ImVec2(cx, cy), - ui::material::Error(), TR("wiz_pass_mismatch")); - cy += captionFont->LegacySize + 6.0f * dp; + ui::material::Error(), mm, nullptr, contentW); + cy += mmSize.y + 6.0f * dp; } } @@ -1385,9 +1429,10 @@ void App::renderFirstRunWizard() { // Status if (!encrypt_status_.empty()) { + ImVec2 stSize = captionFont->CalcTextSizeA(captionFont->LegacySize, FLT_MAX, contentW, encrypt_status_.c_str()); dl->AddText(captionFont, captionFont->LegacySize, ImVec2(cx, cy), - ui::material::Warning(), encrypt_status_.c_str()); - cy += captionFont->LegacySize + 6.0f * dp; + ui::material::Warning(), encrypt_status_.c_str(), nullptr, contentW); + cy += stSize.y + 6.0f * dp; } // Warn + block if the passphrase has leading/trailing whitespace. Silently trimming it would @@ -1417,7 +1462,8 @@ void App::renderFirstRunWizard() { bool canEncrypt = passValid && pinOk && !encrypt_in_progress_; float encBtnW = 180.0f * dp; - float skipW2 = 80.0f * dp; + const char* skipLabel = s_wizSkipArmed ? TR("wiz_skip_anyway") : TR("wiz_skip"); + float skipW2 = std::max(80.0f * dp, ImGui::CalcTextSize(skipLabel).x + 32.0f * dp); float btnH2 = 40.0f * dp; float totalBW = encBtnW + 12.0f * dp + skipW2; float bx = rightX + (colW - totalBW) * 0.5f; @@ -1440,6 +1486,8 @@ void App::renderFirstRunWizard() { settings_->setEncryptionPending(true); // Clear sensitive buffers + s_wizShowPass = false; + s_wizSkipArmed = false; memset(encrypt_pass_buf_, 0, sizeof(encrypt_pass_buf_)); memset(encrypt_confirm_buf_, 0, sizeof(encrypt_confirm_buf_)); memset(wizard_pin_buf_, 0, sizeof(wizard_pin_buf_)); @@ -1465,14 +1513,28 @@ void App::renderFirstRunWizard() { ImGui::SetCursorScreenPos(ImVec2(bx + encBtnW + 12.0f * dp, cy)); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 8.0f * dp); - if (ui::material::TactileButton(TR("wiz_skip"), ImVec2(skipW2, btnH2))) { - static bool s_skipEncConfirm = false; - if (!s_skipEncConfirm) { + if (s_wizSkipArmed) { + ImGui::PushStyleColor(ImGuiCol_Button, ImGui::ColorConvertU32ToFloat4(ui::material::Error())); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::ColorConvertU32ToFloat4(ui::material::Error())); + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::ColorConvertU32ToFloat4(ui::material::OnPrimary())); + } + const bool skipClicked = ui::material::TactileButton(skipLabel, ImVec2(skipW2, btnH2)); + const bool skipHovered = ImGui::IsItemHovered(); + if (s_wizSkipArmed) ImGui::PopStyleColor(3); + // Disarm when the user clicks anywhere else (a click on Skip is handled below). + if (s_wizSkipArmed && !skipClicked && !skipHovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { + s_wizSkipArmed = false; + if (encrypt_status_ == TR("wiz_skip_confirm")) encrypt_status_.clear(); + } + if (skipClicked) { + if (!s_wizSkipArmed) { // Skipping stores private keys UNENCRYPTED — require a confirming second click. - s_skipEncConfirm = true; + s_wizSkipArmed = true; encrypt_status_ = TR("wiz_skip_confirm"); } else { - s_skipEncConfirm = false; + s_wizSkipArmed = false; + s_wizShowPass = false; + encrypt_status_.clear(); // Skipping leaves the wallet UNENCRYPTED — wipe the passphrase/PIN the user may have // typed so it doesn't linger in these process-lifetime buffers (only the Encrypt // path cleared them before). (L-07) diff --git a/src/ui/windows/export_all_keys_dialog.cpp b/src/ui/windows/export_all_keys_dialog.cpp index c72e878..a30c9df 100644 --- a/src/ui/windows/export_all_keys_dialog.cpp +++ b/src/ui/windows/export_all_keys_dialog.cpp @@ -19,6 +19,7 @@ #include "../../embedded/IconsMaterialDesign.h" #include "imgui.h" +#include #include #include #include @@ -36,7 +37,8 @@ static std::string s_status; // error / partial message (non-empty => red static std::string s_saved_path; // full path on full success (=> green check + copy field) static std::string s_exported_keys; static int s_total_addresses = 0; -static int s_exported_count = 0; +static std::atomic s_exported_count{0}; // incremented per address by the worker thread, read by the UI +static bool s_file_written = false; // a plaintext key file now exists on disk (full or partial export) static bool s_include_z = true; static bool s_include_t = true; static char s_filename[256] = ""; @@ -50,6 +52,7 @@ void ExportAllKeysDialog::show() s_exported_keys.clear(); s_total_addresses = 0; s_exported_count = 0; + s_file_written = false; s_include_z = true; s_include_t = true; @@ -104,7 +107,7 @@ void ExportAllKeysDialog::render(App* app) if (s_exporting) { ImGui::Spacing(); ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(m::Primary()), TR("export_keys_progress"), - s_exported_count, s_total_addresses); + s_exported_count.load(), s_total_addresses); ImGui::SameLine(0, 0); ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(m::Primary()), "%s", m::LoadingDots()); } else if (!s_saved_path.empty()) { @@ -115,27 +118,57 @@ void ExportAllKeysDialog::render(App* app) ImGui::SameLine(0, 4.0f * Layout::dpiScale()); ImGui::TextColored(m::SuccessVec4(), "%s", TR("export_keys_success")); widgets::AddressCopyField("##exportedkeyspath", s_saved_path); + ImGui::Spacing(); + ImGui::PushStyleColor(ImGuiCol_Text, m::Warning()); + ImGui::TextWrapped("%s", TR("lite_seed_save_caution")); + ImGui::PopStyleColor(); } else if (!s_status.empty()) { ImGui::Spacing(); ImGui::PushTextWrapPos(0.0f); ImGui::TextColored(material::ErrorVec4(), "%s", s_status.c_str()); ImGui::PopTextWrapPos(); + if (s_file_written) { + // Partial export still left a plaintext key file on disk. + ImGui::Spacing(); + ImGui::PushStyleColor(ImGuiCol_Text, m::Warning()); + ImGui::TextWrapped("%s", TR("lite_seed_save_caution")); + ImGui::PopStyleColor(); + } } ImGui::Spacing(); + // Pre-flight: a locked wallet can't yield keys. Say so up front and offer Unlock instead of + // letting the user run a doomed export. + const bool walletLocked = app->getWalletState().isLocked(); + if (walletLocked && !s_exporting) { + ImGui::Spacing(); + ImGui::PushStyleColor(ImGuiCol_Text, m::Warning()); + ImGui::TextWrapped("%s", TR("export_keys_unlock_first")); + ImGui::PopStyleColor(); + ImGui::Spacing(); + if (m::TactileButton(TR("lite_unlock"))) { + if (app->liteWallet()) app->requestLiteUnlock(); + else s_open = false; // full node: closing reveals the lock screen already shown while locked + } + } + bool doExport = false, doClose = false; - m::DialogActionFooter(TR("export_keys_btn"), !s_exporting, TR("close"), doExport, doClose); + m::DialogActionFooter(TR("export_keys_btn"), !s_exporting && !walletLocked, TR("close"), doExport, doClose); if (doClose) s_open = false; if (doExport) { if (!s_include_z && !s_include_t) { Notifications::instance().warning(TR("export_keys_select_type")); } else if (!app->rpc() || !app->rpc()->isConnected()) { Notifications::instance().error(TR("export_keys_not_connected")); + } else if (app->getWalletState().isLocked()) { + // Defense in depth: locked between the footer render and the click. + Notifications::instance().warning(TR("export_keys_unlock_first")); } else { s_exporting = true; s_exported_keys.clear(); s_exported_count = 0; + s_file_written = false; s_status.clear(); s_saved_path.clear(); @@ -192,6 +225,7 @@ void ExportAllKeysDialog::render(App* app) keys += "# Address: " + addr + "\n"; keys += k + "\n\n"; exported++; // count only real successes (locked/failed keys don't count) + s_exported_count.store(exported); // live progress for the UI thread if (!k.empty()) sodium_memzero(&k[0], k.size()); // wipe the transient copy } catch (...) {} // non-string / locked key → skip (not counted) } @@ -207,6 +241,7 @@ void ExportAllKeysDialog::render(App* app) keys += "# Address: " + addr + "\n"; keys += k + "\n\n"; exported++; // count only real successes (locked/failed keys don't count) + s_exported_count.store(exported); // live progress for the UI thread if (!k.empty()) sodium_memzero(&k[0], k.size()); // wipe the transient copy } catch (...) {} // non-string / locked key → skip (not counted) } @@ -229,6 +264,7 @@ void ExportAllKeysDialog::render(App* app) return [exported, total, filepath, writeOk]() { s_exported_count = exported; s_exporting = false; + s_file_written = (exported > 0 && writeOk); char buf[320]; if (exported == 0) { snprintf(buf, sizeof(buf), TR("export_keys_none_result"), total); diff --git a/src/ui/windows/key_export_dialog.cpp b/src/ui/windows/key_export_dialog.cpp index f2f93fc..2ce6c34 100644 --- a/src/ui/windows/key_export_dialog.cpp +++ b/src/ui/windows/key_export_dialog.cpp @@ -35,6 +35,15 @@ std::string KeyExportDialog::s_address; std::string KeyExportDialog::s_key; std::string KeyExportDialog::s_error; +namespace { +// Auto-hide: seconds of inactivity before a revealed key is wiped (mirrors settings F012 lite secret auto-wipe). +constexpr double kKeyAutoHideSecs = 60.0; +double s_revealTime = 0.0; // ImGui time of last reveal/interaction; 0 = no key on screen +// Retry re-dispatch: frame number on which the Reveal path should fire as if the button were clicked (-1 = none). +// Frame-stamped so a stale request can never auto-fire a later reveal. +int s_retryFrame = -1; +} // namespace + void KeyExportDialog::releaseQr() { if (s_qr_tex) { FreeQRTexture(s_qr_tex); s_qr_tex = 0; } @@ -52,6 +61,8 @@ void KeyExportDialog::show(const std::string& address, KeyType type) s_address = address; wallet::secureWipeLiteSecret(s_key); // zero any prior secret before reuse s_error.clear(); + s_revealTime = 0.0; + s_retryFrame = -1; } bool KeyExportDialog::isOpen() @@ -67,6 +78,8 @@ void KeyExportDialog::hide() s_show_key = false; s_error.clear(); releaseQr(); + s_revealTime = 0.0; + s_retryFrame = -1; } void KeyExportDialog::render(App* app) @@ -97,7 +110,7 @@ void KeyExportDialog::render(App* app) const float addrBoxW = ImGui::CalcTextSize(chunkedAddr.c_str()).x + addrPadX * 2.0f + 2.0f; // The BlurFloat overlay card insets content by 28px per side (draw_helpers BeginOverlayDialog); add // that (+ a little slack) so the address box fits on one line under its label instead of wrapping. - const float wantW = addrBoxW + 28.0f * 2.0f + 12.0f; + const float wantW = addrBoxW + (28.0f * 2.0f + 12.0f) * Layout::dpiScale(); const float maxW = 0.85f * ImGui::GetMainViewport()->Size.x; const float cardW = (wantW < maxW ? wantW : maxW) / Layout::dpiScale(); material::OverlayDialogSpec ov; @@ -116,6 +129,21 @@ void KeyExportDialog::render(App* app) ImGui::Spacing(); + // Auto-hide: stamp the moment a key appears, and wipe it (key + QR) after kKeyAutoHideSecs of + // inactivity. Toggling Show/Hide or copying counts as activity and restarts the timer. + if (s_key.empty()) { + s_revealTime = 0.0; + } else { + const double nowT = ImGui::GetTime(); + if (s_revealTime <= 0.0) s_revealTime = nowT; + if (nowT - s_revealTime >= kKeyAutoHideSecs) { + wallet::secureWipeLiteSecret(s_key); + s_show_key = false; + releaseQr(); + s_revealTime = 0.0; + } + } + // Key display section const char* key_label = (s_key_type == KeyType::Private) ? TR("key_export_private_key") : TR("key_export_viewing_key"); ImGui::Text("%s", key_label); @@ -124,10 +152,12 @@ void KeyExportDialog::render(App* app) ImGui::TextColored(material::WarningVec4(), "%s%s", TR("key_export_fetching_base"), material::LoadingDots()); } else if (!s_error.empty()) { ImGui::TextColored(material::ErrorVec4(), TR("error_format"), s_error.c_str()); - // Not a dead-end: clearing the error falls back through to the Reveal button next frame. + // Not a dead-end: Retry clears the error AND re-dispatches the fetch on the next frame + // (the Reveal branch below honours s_retryFrame), so no second click is needed. ImGui::Spacing(); if (material::TactileButton(TR("retry"), ImVec2(revealBtn.width, 0), S.resolveFont(revealBtn.font))) { s_error.clear(); + s_retryFrame = ImGui::GetFrameCount() + 1; } } else if (s_key.empty() && s_address.length() < 26) { // Guard against an empty/blatantly-malformed address before dispatching a doomed reveal. @@ -145,7 +175,10 @@ void KeyExportDialog::render(App* app) } } else if (s_key.empty()) { // Show button to fetch key - if (material::TactileButton(TR("key_export_reveal"), ImVec2(revealBtn.width, 0), S.resolveFont(revealBtn.font))) { + const bool revealClicked = material::TactileButton(TR("key_export_reveal"), ImVec2(revealBtn.width, 0), S.resolveFont(revealBtn.font)); + const bool retryFire = (s_retryFrame == ImGui::GetFrameCount()); + if (retryFire) s_retryFrame = -1; + if (revealClicked || retryFire) { s_fetching = true; // Check if z-address or t-address @@ -282,11 +315,23 @@ void KeyExportDialog::render(App* app) ImGui::BeginGroup(); if (widgets::CopyField("##keycopy", keyText, keyW, 0.0f, /*center=*/true)) { app->copySecretToClipboard(s_key); // auto-clearing clipboard + s_revealTime = ImGui::GetTime(); // activity: restart the auto-hide timer } ImGui::Spacing(); if (material::TactileButton(s_show_key ? TR("hide") : TR("show"), ImVec2(0, 0), material::Type().subtitle1())) { s_show_key = !s_show_key; + s_revealTime = ImGui::GetTime(); // activity: restart the auto-hide timer + } + // Countdown to the auto-hide (reuses the lite secret auto-wipe string). + { + int secsLeft = (int)std::ceil(kKeyAutoHideSecs - (ImGui::GetTime() - s_revealTime)); + if (secsLeft < 0) secsLeft = 0; + char cd[64]; + snprintf(cd, sizeof(cd), TR("lite_autohide_countdown"), secsLeft); + ImGui::PushStyleColor(ImGuiCol_Text, material::OnSurfaceDisabled()); + ImGui::TextUnformatted(cd); + ImGui::PopStyleColor(); } ImGui::EndGroup(); diff --git a/src/ui/windows/validate_address_dialog.cpp b/src/ui/windows/validate_address_dialog.cpp index da7c33e..e50b6c3 100644 --- a/src/ui/windows/validate_address_dialog.cpp +++ b/src/ui/windows/validate_address_dialog.cpp @@ -99,7 +99,13 @@ void ValidateAddressDialog::render(App* app) ImGui::BeginDisabled(); } - if (material::TactileButton(TR("validate_btn"), ImVec2(valBtn.width, 0), S.resolveFont(valBtn.font)) || (enter_pressed && can_validate)) { + // Set by the Paste button (below) so a pasted address is validated on the next frame through the + // exact same handler the Validate button runs (single code path, no duplicated validation logic). + static bool s_paste_validate = false; + const bool auto_validate = s_paste_validate && can_validate; + s_paste_validate = false; + + if (material::TactileButton(TR("validate_btn"), ImVec2(valBtn.width, 0), S.resolveFont(valBtn.font)) || (enter_pressed && can_validate) || auto_validate) { s_validating = true; s_validated = false; s_error_message.clear(); @@ -154,7 +160,7 @@ void ValidateAddressDialog::render(App* app) s_address_type = TR(mining ? "validate_mining_type" : "validate_shielded_type"); s_is_mining = mining; } else { - s_error_message = error; + s_error_message = util::friendlyRpcError(error); s_is_valid = false; } s_validated = true; @@ -175,9 +181,12 @@ void ValidateAddressDialog::render(App* app) if (material::TactileButton(TR("paste"), ImVec2(pasteBtn.width, 0), S.resolveFont(pasteBtn.font))) { const char* clipboard = ImGui::GetClipboardText(); if (clipboard) { - strncpy(s_address_input, clipboard, sizeof(s_address_input) - 1); - s_address_input[sizeof(s_address_input) - 1] = '\0'; + // Strip ASCII + Unicode/CJK/zero-width whitespace so the field shows exactly what gets validated. + const std::string cleaned = dragonx::util::stripAllWhitespaceForKey(clipboard); + snprintf(s_address_input, sizeof(s_address_input), "%s", cleaned.c_str()); s_validated = false; + s_error_message.clear(); + s_paste_validate = !cleaned.empty(); } } diff --git a/src/util/i18n.cpp b/src/util/i18n.cpp index c99d088..e95330a 100644 --- a/src/util/i18n.cpp +++ b/src/util/i18n.cpp @@ -800,6 +800,7 @@ void I18n::loadBuiltinEnglish() strings_["wiz_bootstrap"] = "Bootstrap"; strings_["wiz_bootstrap_desc"] = "Download a blockchain bootstrap to dramatically speed up initial sync.\n\nYour existing wallet.dat will NOT be modified or replaced."; strings_["wiz_skip"] = "Skip"; + strings_["wiz_skip_anyway"] = "Skip anyway (unencrypted)"; strings_["wiz_bootstrap_failed"] = "Bootstrap failed"; strings_["bootstrap_try_mirror"] = "Try mirror"; strings_["wiz_download_failed"] = "Download Failed"; @@ -833,6 +834,8 @@ void I18n::loadBuiltinEnglish() strings_["enc_pin_skipped"] = "PIN skipped. You can set one later in Settings."; strings_["change_pass_title"] = "Change Passphrase"; strings_["change_pass_current"] = "Current Passphrase:"; + strings_["change_pass_same"] = "The new passphrase must differ from the current one."; + strings_["change_pass_need_current"] = "Enter your current passphrase."; strings_["change_pass_new"] = "New Passphrase:"; strings_["change_pass_confirm"] = "Confirm New:"; strings_["change_pass_pin_note"] = "This wallet has a quick-unlock PIN. After the change it will be out of date: remove the PIN in Settings and set it again."; @@ -2273,6 +2276,7 @@ void I18n::loadBuiltinEnglish() // --- Export All Keys Dialog --- strings_["export_keys_btn"] = "Export Keys"; + strings_["export_keys_unlock_first"] = "Unlock your wallet first, then export the keys."; strings_["export_keys_danger"] = "DANGER: This will export ALL private keys from your wallet! Anyone with access to this file can steal your funds. Store it securely and delete after use."; strings_["export_keys_include_t"] = "Include T-addresses (transparent)"; strings_["export_keys_include_z"] = "Include Z-addresses (shielded)";