mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 03:33:53 +00:00
Clean up 'you' page code and offer a missing section
This commit is contained in:
parent
d9cf30dc7a
commit
5813237e0b
444
src/ui/you.rs
444
src/ui/you.rs
@ -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,209 +85,201 @@ 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
|
||||||
let key_security = GLOBALS.signer.blocking_read().key_security().unwrap();
|
.to_overlord
|
||||||
|
.send(ToOverlordMessage::UnlockKey(app.password.clone()));
|
||||||
ui.label(&*format!(
|
app.password.zeroize();
|
||||||
"Private Key security is {}",
|
app.password = "".to_owned();
|
||||||
match key_security {
|
}
|
||||||
KeySecurity::Weak => "weak",
|
}
|
||||||
KeySecurity::Medium => "medium",
|
|
||||||
}
|
fn show_priv_key_detail(_app: &mut GossipUi, ui: &mut Ui) {
|
||||||
));
|
let key_security = GLOBALS.signer.blocking_read().key_security().unwrap();
|
||||||
|
|
||||||
ui.add_space(10.0);
|
ui.label(&*format!(
|
||||||
|
"Private Key security is {}",
|
||||||
if let Some(epk) = GLOBALS.signer.blocking_read().encrypted_private_key() {
|
match key_security {
|
||||||
ui.horizontal(|ui| {
|
KeySecurity::Weak => "weak",
|
||||||
ui.label(&format!("Encrypted Private Key: {}", epk));
|
KeySecurity::Medium => "medium",
|
||||||
if ui.add(CopyButton {}).clicked() {
|
}
|
||||||
ui.output().copied_text = epk.to_string();
|
));
|
||||||
}
|
|
||||||
});
|
ui.add_space(10.0);
|
||||||
}
|
|
||||||
|
if let Some(epk) = GLOBALS.signer.blocking_read().encrypted_private_key() {
|
||||||
ui.add_space(10.0);
|
ui.horizontal(|ui| {
|
||||||
ui.separator();
|
ui.label(&format!("Encrypted Private Key: {}", epk));
|
||||||
ui.add_space(10.0);
|
if ui.add(CopyButton {}).clicked() {
|
||||||
ui.heading("Raw Export");
|
ui.output().copied_text = epk.to_string();
|
||||||
if key_security == KeySecurity::Medium {
|
}
|
||||||
ui.label("WARNING: This will downgrade your key security to WEAK");
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.add_space(10.0);
|
fn offer_export_priv_key(app: &mut GossipUi, ui: &mut Ui) {
|
||||||
ui.label("Enter Password To Export: ");
|
let key_security = GLOBALS.signer.blocking_read().key_security().unwrap();
|
||||||
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
|
||||||
});
|
ui.heading("Raw Export");
|
||||||
|
if key_security == KeySecurity::Medium {
|
||||||
if ui.button("Export Private Key as bech32").clicked() {
|
ui.label("WARNING: This will downgrade your key security to WEAK");
|
||||||
match GLOBALS
|
}
|
||||||
.signer
|
|
||||||
.blocking_write()
|
ui.horizontal(|ui| {
|
||||||
.export_private_key_bech32(&app.password)
|
ui.add_space(10.0);
|
||||||
{
|
ui.label("Enter Password To Export: ");
|
||||||
Ok(mut bech32) => {
|
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
||||||
println!("Exported private key (bech32): {}", bech32);
|
});
|
||||||
bech32.zeroize();
|
|
||||||
*GLOBALS.status_message.blocking_write() =
|
if ui.button("Export Private Key as bech32").clicked() {
|
||||||
"Exported key has been printed to the console standard output.".to_owned();
|
match GLOBALS
|
||||||
}
|
.signer
|
||||||
Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e),
|
.blocking_write()
|
||||||
}
|
.export_private_key_bech32(&app.password)
|
||||||
app.password.zeroize();
|
{
|
||||||
app.password = "".to_owned();
|
Ok(mut bech32) => {
|
||||||
}
|
println!("Exported private key (bech32): {}", bech32);
|
||||||
if ui.button("Export Private Key as hex").clicked() {
|
bech32.zeroize();
|
||||||
match GLOBALS
|
*GLOBALS.status_message.blocking_write() =
|
||||||
.signer
|
"Exported key has been printed to the console standard output.".to_owned();
|
||||||
.blocking_write()
|
}
|
||||||
.export_private_key_hex(&app.password)
|
Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e),
|
||||||
{
|
}
|
||||||
Ok(mut hex) => {
|
app.password.zeroize();
|
||||||
println!("Exported private key (hex): {}", hex);
|
app.password = "".to_owned();
|
||||||
hex.zeroize();
|
}
|
||||||
*GLOBALS.status_message.blocking_write() =
|
if ui.button("Export Private Key as hex").clicked() {
|
||||||
"Exported key has been printed to the console standard output.".to_owned();
|
match GLOBALS
|
||||||
}
|
.signer
|
||||||
Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e),
|
.blocking_write()
|
||||||
}
|
.export_private_key_hex(&app.password)
|
||||||
app.password.zeroize();
|
{
|
||||||
app.password = "".to_owned();
|
Ok(mut hex) => {
|
||||||
}
|
println!("Exported private key (hex): {}", hex);
|
||||||
|
hex.zeroize();
|
||||||
ui.add_space(10.0);
|
*GLOBALS.status_message.blocking_write() =
|
||||||
ui.separator();
|
"Exported key has been printed to the console standard output.".to_owned();
|
||||||
ui.add_space(10.0);
|
}
|
||||||
ui.heading("DELETE This Identity");
|
Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e),
|
||||||
|
}
|
||||||
ui.horizontal(|ui| {
|
app.password.zeroize();
|
||||||
ui.add_space(10.0);
|
app.password = "".to_owned();
|
||||||
ui.label("Enter Password To Delete: ");
|
}
|
||||||
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
}
|
||||||
});
|
|
||||||
|
fn offer_import_priv_key(app: &mut GossipUi, ui: &mut Ui) {
|
||||||
if ui.button("DELETE (Cannot be undone!)").clicked() {
|
ui.heading("Import a Private Key");
|
||||||
match GLOBALS
|
|
||||||
.signer
|
ui.horizontal(|ui| {
|
||||||
.blocking_write()
|
ui.label("Enter private key");
|
||||||
.delete_identity(&app.password)
|
ui.add(
|
||||||
{
|
TextEdit::singleline(&mut app.import_priv)
|
||||||
Ok(_) => *GLOBALS.status_message.blocking_write() = "Identity deleted.".to_string(),
|
.hint_text("nsec1 or hex")
|
||||||
Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e),
|
.password(true),
|
||||||
}
|
);
|
||||||
app.password.zeroize();
|
});
|
||||||
app.password = "".to_owned();
|
ui.horizontal(|ui| {
|
||||||
}
|
ui.label("Enter a password to keep it encrypted under");
|
||||||
} else if GLOBALS.signer.blocking_read().is_loaded() {
|
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
||||||
ui.heading("Password Needed");
|
});
|
||||||
|
if ui.button("import").clicked() {
|
||||||
ui.horizontal(|ui| {
|
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::ImportPriv(
|
||||||
ui.label("Password: ");
|
app.import_priv.clone(),
|
||||||
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
app.password.clone(),
|
||||||
});
|
));
|
||||||
|
app.import_priv.zeroize();
|
||||||
if ui.button("Unlock Private Key").clicked() {
|
app.import_priv = "".to_owned();
|
||||||
let _ = GLOBALS
|
app.password.zeroize();
|
||||||
.to_overlord
|
app.password = "".to_owned();
|
||||||
.send(ToOverlordMessage::UnlockKey(app.password.clone()));
|
}
|
||||||
app.password.zeroize();
|
}
|
||||||
app.password = "".to_owned();
|
|
||||||
}
|
fn offer_import_pub_key(app: &mut GossipUi, ui: &mut Ui) {
|
||||||
} else {
|
ui.heading("Import a Public Key");
|
||||||
ui.heading("Generate a Keypair");
|
ui.add_space(10.0);
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.label("This won't let you post or react to posts, but you can view other people's posts (and fetch your following list) with just a public key.");
|
||||||
ui.label("Enter a password to keep it encrypted under");
|
|
||||||
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
if let Some(pk) = GLOBALS.signer.blocking_read().public_key() {
|
||||||
});
|
let pkhex: PublicKeyHex = pk.into();
|
||||||
if ui.button("Generate Now").clicked() {
|
ui.horizontal(|ui| {
|
||||||
let _ = GLOBALS
|
ui.label(&format!("Public Key (Hex): {}", pkhex.0));
|
||||||
.to_overlord
|
if ui.add(CopyButton {}).clicked() {
|
||||||
.send(ToOverlordMessage::GeneratePrivateKey(app.password.clone()));
|
ui.output().copied_text = pkhex.0;
|
||||||
app.password.zeroize();
|
}
|
||||||
app.password = "".to_owned();
|
});
|
||||||
}
|
|
||||||
|
if let Ok(bech32) = pk.try_as_bech32_string() {
|
||||||
ui.add_space(10.0);
|
ui.horizontal(|ui| {
|
||||||
ui.separator();
|
ui.label(&format!("Public Key (bech32): {}", bech32));
|
||||||
ui.add_space(10.0);
|
if ui.add(CopyButton {}).clicked() {
|
||||||
|
ui.output().copied_text = bech32;
|
||||||
ui.heading("Import a Private Key");
|
}
|
||||||
|
});
|
||||||
ui.horizontal(|ui| {
|
}
|
||||||
ui.label("Enter private key");
|
|
||||||
ui.add(
|
if ui.button("Delete this public key").clicked() {
|
||||||
TextEdit::singleline(&mut app.import_priv)
|
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::DeletePub);
|
||||||
.hint_text("nsec1 or hex")
|
}
|
||||||
.password(true),
|
} else {
|
||||||
);
|
ui.horizontal_wrapped(|ui| {
|
||||||
});
|
ui.label("Enter your public key");
|
||||||
ui.horizontal(|ui| {
|
ui.add(TextEdit::singleline(&mut app.import_pub).hint_text("npub1 or hex"));
|
||||||
ui.label("Enter a password to keep it encrypted under");
|
if ui.button("Import a Public Key").clicked() {
|
||||||
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
let _ = GLOBALS
|
||||||
});
|
.to_overlord
|
||||||
if ui.button("import").clicked() {
|
.send(ToOverlordMessage::ImportPub(app.import_pub.clone()));
|
||||||
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::ImportPriv(
|
app.import_pub = "".to_owned();
|
||||||
app.import_priv.clone(),
|
}
|
||||||
app.password.clone(),
|
});
|
||||||
));
|
}
|
||||||
app.import_priv.zeroize();
|
}
|
||||||
app.import_priv = "".to_owned();
|
|
||||||
app.password.zeroize();
|
fn offer_delete(app: &mut GossipUi, ui: &mut Ui) {
|
||||||
app.password = "".to_owned();
|
ui.heading("DELETE This Identity");
|
||||||
}
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
ui.add_space(10.0);
|
ui.add_space(10.0);
|
||||||
ui.separator();
|
ui.label("Enter Password To Delete: ");
|
||||||
ui.add_space(10.0);
|
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
||||||
|
});
|
||||||
ui.heading("Import a Public Key");
|
|
||||||
ui.add_space(10.0);
|
if ui.button("DELETE (Cannot be undone!)").clicked() {
|
||||||
|
match GLOBALS
|
||||||
ui.label("This won't let you post or react to posts, but you can view other people's posts (and fetch your following list) with just a public key.");
|
.signer
|
||||||
|
.blocking_write()
|
||||||
if let Some(pk) = GLOBALS.signer.blocking_read().public_key() {
|
.delete_identity(&app.password)
|
||||||
let pkhex: PublicKeyHex = pk.into();
|
{
|
||||||
ui.horizontal(|ui| {
|
Ok(_) => *GLOBALS.status_message.blocking_write() = "Identity deleted.".to_string(),
|
||||||
ui.label(&format!("Public Key (Hex): {}", pkhex.0));
|
Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e),
|
||||||
if ui.add(CopyButton {}).clicked() {
|
}
|
||||||
ui.output().copied_text = pkhex.0;
|
app.password.zeroize();
|
||||||
}
|
app.password = "".to_owned();
|
||||||
});
|
}
|
||||||
|
}
|
||||||
if let Ok(bech32) = pk.try_as_bech32_string() {
|
|
||||||
ui.horizontal(|ui| {
|
fn offer_generate(app: &mut GossipUi, ui: &mut Ui) {
|
||||||
ui.label(&format!("Public Key (bech32): {}", bech32));
|
ui.heading("Generate a Keypair");
|
||||||
if ui.add(CopyButton {}).clicked() {
|
|
||||||
ui.output().copied_text = bech32;
|
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() {
|
||||||
if ui.button("Delete this public key").clicked() {
|
let _ = GLOBALS
|
||||||
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::DeletePub);
|
.to_overlord
|
||||||
}
|
.send(ToOverlordMessage::GeneratePrivateKey(app.password.clone()));
|
||||||
} else {
|
app.password.zeroize();
|
||||||
ui.horizontal_wrapped(|ui| {
|
app.password = "".to_owned();
|
||||||
ui.label("Enter your public key");
|
|
||||||
ui.add(TextEdit::singleline(&mut app.import_pub).hint_text("npub1 or hex"));
|
|
||||||
if ui.button("Import a Public Key").clicked() {
|
|
||||||
let _ = GLOBALS
|
|
||||||
.to_overlord
|
|
||||||
.send(ToOverlordMessage::ImportPub(app.import_pub.clone()));
|
|
||||||
app.import_pub = "".to_owned();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user