Clean up 'you' page code and offer a missing section

This commit is contained in:
Mike Dilger 2023-01-08 19:27:13 +13:00
parent d9cf30dc7a
commit 5813237e0b

View File

@ -16,6 +16,56 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.separator(); ui.separator();
ui.add_space(10.0); ui.add_space(10.0);
show_pub_key_detail(app, ui);
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
if GLOBALS.signer.blocking_read().is_ready() {
ui.heading("Ready to sign events");
ui.add_space(10.0);
show_priv_key_detail(app, ui);
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
offer_export_priv_key(app, ui);
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
offer_delete(app, ui);
} else if GLOBALS.signer.blocking_read().is_loaded() {
offer_unlock_priv_key(app, ui);
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
offer_delete(app, ui);
} else {
offer_generate(app, ui);
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
offer_import_priv_key(app, ui);
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
offer_import_pub_key(app, ui);
}
}
fn show_pub_key_detail(_app: &mut GossipUi, ui: &mut Ui) {
// Render public key if available // Render public key if available
if let Some(public_key) = GLOBALS.signer.blocking_read().public_key() { if let Some(public_key) = GLOBALS.signer.blocking_read().public_key() {
let pkhex: PublicKeyHex = public_key.into(); let pkhex: PublicKeyHex = public_key.into();
@ -35,16 +85,26 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
}); });
} }
} }
}
ui.add_space(10.0); fn offer_unlock_priv_key(app: &mut GossipUi, ui: &mut Ui) {
ui.separator(); ui.heading("Password Needed");
ui.add_space(10.0);
if GLOBALS.signer.blocking_read().is_ready() { ui.horizontal(|ui| {
ui.heading("Ready to sign events"); ui.label("Password: ");
ui.add(TextEdit::singleline(&mut app.password).password(true));
});
ui.add_space(10.0); if ui.button("Unlock Private Key").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UnlockKey(app.password.clone()));
app.password.zeroize();
app.password = "".to_owned();
}
}
fn show_priv_key_detail(_app: &mut GossipUi, ui: &mut Ui) {
let key_security = GLOBALS.signer.blocking_read().key_security().unwrap(); let key_security = GLOBALS.signer.blocking_read().key_security().unwrap();
ui.label(&*format!( ui.label(&*format!(
@ -65,10 +125,11 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
} }
}); });
} }
}
fn offer_export_priv_key(app: &mut GossipUi, ui: &mut Ui) {
let key_security = GLOBALS.signer.blocking_read().key_security().unwrap();
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
ui.heading("Raw Export"); ui.heading("Raw Export");
if key_security == KeySecurity::Medium { if key_security == KeySecurity::Medium {
ui.label("WARNING: This will downgrade your key security to WEAK"); ui.label("WARNING: This will downgrade your key security to WEAK");
@ -114,64 +175,9 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
app.password.zeroize(); app.password.zeroize();
app.password = "".to_owned(); app.password = "".to_owned();
} }
}
ui.add_space(10.0); fn offer_import_priv_key(app: &mut GossipUi, ui: &mut Ui) {
ui.separator();
ui.add_space(10.0);
ui.heading("DELETE This Identity");
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.label("Enter Password To Delete: ");
ui.add(TextEdit::singleline(&mut app.password).password(true));
});
if ui.button("DELETE (Cannot be undone!)").clicked() {
match GLOBALS
.signer
.blocking_write()
.delete_identity(&app.password)
{
Ok(_) => *GLOBALS.status_message.blocking_write() = "Identity deleted.".to_string(),
Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e),
}
app.password.zeroize();
app.password = "".to_owned();
}
} else if GLOBALS.signer.blocking_read().is_loaded() {
ui.heading("Password Needed");
ui.horizontal(|ui| {
ui.label("Password: ");
ui.add(TextEdit::singleline(&mut app.password).password(true));
});
if ui.button("Unlock Private Key").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UnlockKey(app.password.clone()));
app.password.zeroize();
app.password = "".to_owned();
}
} else {
ui.heading("Generate a Keypair");
ui.horizontal(|ui| {
ui.label("Enter a password to keep it encrypted under");
ui.add(TextEdit::singleline(&mut app.password).password(true));
});
if ui.button("Generate Now").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::GeneratePrivateKey(app.password.clone()));
app.password.zeroize();
app.password = "".to_owned();
}
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
ui.heading("Import a Private Key"); ui.heading("Import a Private Key");
ui.horizontal(|ui| { ui.horizontal(|ui| {
@ -196,11 +202,9 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
app.password.zeroize(); app.password.zeroize();
app.password = "".to_owned(); app.password = "".to_owned();
} }
}
ui.add_space(10.0); fn offer_import_pub_key(app: &mut GossipUi, ui: &mut Ui) {
ui.separator();
ui.add_space(10.0);
ui.heading("Import a Public Key"); ui.heading("Import a Public Key");
ui.add_space(10.0); ui.add_space(10.0);
@ -239,5 +243,43 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
} }
}); });
} }
}
fn offer_delete(app: &mut GossipUi, ui: &mut Ui) {
ui.heading("DELETE This Identity");
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.label("Enter Password To Delete: ");
ui.add(TextEdit::singleline(&mut app.password).password(true));
});
if ui.button("DELETE (Cannot be undone!)").clicked() {
match GLOBALS
.signer
.blocking_write()
.delete_identity(&app.password)
{
Ok(_) => *GLOBALS.status_message.blocking_write() = "Identity deleted.".to_string(),
Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e),
}
app.password.zeroize();
app.password = "".to_owned();
}
}
fn offer_generate(app: &mut GossipUi, ui: &mut Ui) {
ui.heading("Generate a Keypair");
ui.horizontal(|ui| {
ui.label("Enter a password to keep it encrypted under");
ui.add(TextEdit::singleline(&mut app.password).password(true));
});
if ui.button("Generate Now").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::GeneratePrivateKey(app.password.clone()));
app.password.zeroize();
app.password = "".to_owned();
} }
} }