diff --git a/damus/Util/Notifications.swift b/damus/Util/Notifications.swift index 8c88b07..756f71f 100644 --- a/damus/Util/Notifications.swift +++ b/damus/Util/Notifications.swift @@ -127,6 +127,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 index 0b115e1..b78495a 100644 --- 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 index 5121bc4..cca4ba2 100644 --- 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() }