damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | LICENSE

commit a417da6089b727dd7a9760b98cb3a34ee9b86a93
parent ae68d8a7e333530459fbf55daf39e787c363dfcb
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 18 Jun 2022 10:35:46 -0700

Add logout button, and show account keys

Changelog-Added: Show logout button and account keys in config
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Util/Notifications.swift | 6++++++
Mdamus/Views/ConfigView.swift | 38++++++++++++++++++++++++++++++++++++++
Mdamus/damusApp.swift | 3+++
3 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/damus/Util/Notifications.swift b/damus/Util/Notifications.swift @@ -128,6 +128,12 @@ extension Notification.Name { } extension Notification.Name { + static var logout: Notification.Name { + return Notification.Name("logout") + } +} + +extension Notification.Name { static var followed: Notification.Name { return Notification.Name("followed") } diff --git a/damus/Views/ConfigView.swift b/damus/Views/ConfigView.swift @@ -6,11 +6,13 @@ // import SwiftUI +import AVFoundation struct ConfigView: View { let state: DamusState @Environment(\.dismiss) var dismiss @State var show_add_relay: Bool = false + @State var confirm_logout: Bool = false @State var new_relay: String = "" func Relay(_ ev: NostrEvent, relay: String) -> some View { @@ -45,6 +47,32 @@ struct ConfigView: View { } } + + Section("Public Account ID") { + Text(state.keypair.pubkey_bech32) + .textSelection(.enabled) + .onTapGesture { + UIPasteboard.general.string = state.keypair.pubkey_bech32 + AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate)) + } + } + + if let sec = state.keypair.privkey_bech32 { + Section("Secret Account Login Key") { + Text(sec) + .textSelection(.enabled) + .onTapGesture { + UIPasteboard.general.string = sec + AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate)) + } + } + } + + Section("Reset") { + Button("Logout") { + confirm_logout = true + } + } } VStack { @@ -63,6 +91,16 @@ struct ConfigView: View { } .navigationTitle("Settings") .navigationBarTitleDisplayMode(.large) + .alert("Logout", isPresented: $confirm_logout) { + Button("Logout") { + notify(.logout, ()) + } + Button("Cancel") { + confirm_logout = false + } + } message: { + Text("Make sure your nsec account key is saved before you logout or you will lose access to this account") + } .sheet(isPresented: $show_add_relay) { AddRelayView(show_add_relay: $show_add_relay, relay: $new_relay) { _ in guard let url = URL(string: new_relay) else { diff --git a/damus/damusApp.swift b/damus/damusApp.swift @@ -35,6 +35,9 @@ struct MainView: View { } } } + .onReceive(handle_notify(.logout)) { _ in + keypair = nil + } .onAppear { keypair = get_saved_keypair() }