feat(settings): migrate Backup Wallet modal to the reference design
Phase 1. Struct-form BlurFloat overlay (was the legacy positional overload); DialogWarningHeader care header; centered DialogActionFooter (Create Backup + Close) replacing the StyledButtons + separator; full i18n — title/destination/ button reuse existing backup_* keys, plus two new keys (backup_warn one-line care line, backup_overwrite_confirm) added in en + 8 langs. No change to backupWallet. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
66
src/app.cpp
66
src/app.cpp
@@ -3271,42 +3271,44 @@ void App::renderExportKeyDialog()
|
||||
|
||||
void App::renderBackupDialog()
|
||||
{
|
||||
auto dlg = ui::schema::UI().drawElement("inline-dialogs", "backup");
|
||||
auto dlgF = [&](const char* key, float fb) -> float {
|
||||
auto it = dlg.extraFloats.find(key);
|
||||
return it != dlg.extraFloats.end() ? it->second : fb;
|
||||
};
|
||||
int btnFont = (int)dlgF("button-font", 1);
|
||||
float btnW = dlgF("button-width", 120.0f);
|
||||
|
||||
if (!ui::material::BeginOverlayDialog("Backup Wallet", &show_backup_, dlgF("width", 500.0f), 0.94f)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::TextWrapped("Export all private keys to a file. Keep this file secure!");
|
||||
namespace m = ui::material;
|
||||
|
||||
m::OverlayDialogSpec ov;
|
||||
ov.title = TR("backup_title");
|
||||
ov.p_open = &show_backup_;
|
||||
ov.style = m::OverlayStyle::BlurFloat;
|
||||
ov.cardWidth = 560.0f;
|
||||
ov.idSuffix = "backup";
|
||||
if (!m::BeginOverlayDialog(ov)) return;
|
||||
|
||||
m::DialogWarningHeader(TR("backup_warn"));
|
||||
ImGui::Spacing();
|
||||
|
||||
ImGui::Text("Backup File Path:");
|
||||
|
||||
static char backup_path[512] = "dragonx-backup.txt";
|
||||
static bool s_backup_confirm_overwrite = false;
|
||||
ImGui::TextUnformatted(TR("backup_destination"));
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
if (ImGui::InputText("##backuppath", backup_path, sizeof(backup_path)))
|
||||
s_backup_confirm_overwrite = false; // path edited — re-check overwrite on next Save
|
||||
|
||||
ImGui::Spacing();
|
||||
|
||||
|
||||
if (!backup_status_.empty()) {
|
||||
if (backup_success_) {
|
||||
ImGui::TextColored(ui::material::SuccessVec4(), "%s", backup_status_.c_str());
|
||||
} else {
|
||||
ImGui::TextColored(ImVec4(0.8f, 0.3f, 0.3f, 1.0f), "%s", backup_status_.c_str());
|
||||
}
|
||||
ImGui::Spacing();
|
||||
ImGui::PushTextWrapPos(0.0f);
|
||||
ImGui::TextColored(backup_success_ ? m::SuccessVec4() : ImVec4(0.8f, 0.3f, 0.3f, 1.0f),
|
||||
"%s", backup_status_.c_str());
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
|
||||
if (ui::material::StyledButton("Save Backup", ImVec2(btnW, 0), ui::material::resolveButtonFont(btnFont))) {
|
||||
|
||||
bool doSave = false, doClose = false;
|
||||
m::DialogActionFooter(TR("backup_create"), true, TR("close"), doSave, doClose);
|
||||
if (doClose) {
|
||||
show_backup_ = false;
|
||||
backup_status_.clear();
|
||||
s_backup_confirm_overwrite = false;
|
||||
}
|
||||
if (doSave) {
|
||||
std::string path(backup_path);
|
||||
// Trim surrounding whitespace (a pasted path can carry a trailing newline).
|
||||
while (!path.empty() && (path.front()==' '||path.front()=='\t'||path.front()=='\n'||path.front()=='\r')) path.erase(path.begin());
|
||||
@@ -3317,7 +3319,7 @@ void App::renderBackupDialog()
|
||||
// Don't clobber an existing file (possibly a good earlier backup) without confirmation.
|
||||
s_backup_confirm_overwrite = true;
|
||||
backup_success_ = false;
|
||||
backup_status_ = "A file already exists there — click Save Backup again to overwrite it.";
|
||||
backup_status_ = TR("backup_overwrite_confirm");
|
||||
} else {
|
||||
s_backup_confirm_overwrite = false;
|
||||
backupWallet(path, [this](bool success, const std::string& msg) {
|
||||
@@ -3327,14 +3329,8 @@ void App::renderBackupDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ui::material::StyledButton("Close", ImVec2(btnW, 0), ui::material::resolveButtonFont(btnFont))) {
|
||||
show_backup_ = false;
|
||||
backup_status_.clear();
|
||||
s_backup_confirm_overwrite = false;
|
||||
}
|
||||
|
||||
ui::material::EndOverlayDialog();
|
||||
m::EndOverlayDialog();
|
||||
}
|
||||
|
||||
void App::maybeOfferDaemonUpdate()
|
||||
|
||||
@@ -1202,6 +1202,8 @@ void I18n::loadBuiltinEnglish()
|
||||
strings_["backup_created"] = "Wallet backup created";
|
||||
strings_["backup_description"] = "Create a backup of your wallet.dat file. This file contains all your private keys and transaction history. Store the backup in a secure location.";
|
||||
strings_["backup_destination"] = "Backup destination:";
|
||||
strings_["backup_warn"] = "This file holds all your private keys \xE2\x80\x94 keep it somewhere safe.";
|
||||
strings_["backup_overwrite_confirm"] = "A file already exists there \xE2\x80\x94 Save again to overwrite it.";
|
||||
strings_["backup_tip_external"] = "Store backups on external drives or cloud storage";
|
||||
strings_["backup_tip_multiple"] = "Create multiple backups in different locations";
|
||||
strings_["backup_tip_test"] = "Test restoring from backup periodically";
|
||||
|
||||
Reference in New Issue
Block a user