Browse Source

switch to buttons for copying keys

post-button-style
William Casarin 2 years ago
parent
commit
49e683e10d
  1. 71
      damus/Views/ConfigView.swift

71
damus/Views/ConfigView.swift

@ -13,12 +13,29 @@ struct ConfigView: View {
@State var show_add_relay: Bool = false @State var show_add_relay: Bool = false
@State var confirm_logout: Bool = false @State var confirm_logout: Bool = false
@State var new_relay: String = "" @State var new_relay: String = ""
@State var showPrivateKey: Bool = false @State var show_privkey: Bool = false
@State var privateKey: String @State var privkey: String
@State var privkey_copied: Bool = false
@State var pubkey_copied: Bool = false
let generator = UIImpactFeedbackGenerator(style: .light)
init(state: DamusState) { init(state: DamusState) {
self.state = state self.state = state
_privateKey = State(initialValue: self.state.keypair.privkey_bech32 ?? "") _privkey = State(initialValue: self.state.keypair.privkey_bech32 ?? "")
}
// TODO: (jb55) could be more general but not gonna worry about it atm
func CopyButton(is_pk: Bool) -> some View {
return Button(action: {
UIPasteboard.general.string = is_pk ? self.state.keypair.pubkey_bech32 : self.privkey
self.privkey_copied = !is_pk
self.pubkey_copied = is_pk
generator.impactOccurred()
}) {
let copied = is_pk ? self.pubkey_copied : self.privkey_copied
Image(systemName: copied ? "checkmark.circle" : "doc.on.doc")
}
} }
var body: some View { var body: some View {
@ -35,43 +52,29 @@ struct ConfigView: View {
} }
Section("Public Account ID") { Section("Public Account ID") {
Text(state.keypair.pubkey_bech32) HStack {
.textSelection(.enabled) Text(state.keypair.pubkey_bech32)
.onTapGesture {
UIPasteboard.general.string = state.keypair.pubkey_bech32 CopyButton(is_pk: true)
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate)) }
} .clipShape(RoundedRectangle(cornerRadius: 5))
.clipShape(RoundedRectangle(cornerRadius: 5))
.gesture(
LongPressGesture(minimumDuration: 1.0)
.onEnded { _ in
UIPasteboard.general.string = state.keypair.pubkey_bech32
}
)
} }
if let sec = state.keypair.privkey_bech32 { if let sec = state.keypair.privkey_bech32 {
Section("Secret Account Login Key") { Section("Secret Account Login Key") {
if showPrivateKey == false { HStack {
SecureField("PrivateKey", text: $privateKey) if show_privkey == false {
.disabled(true) SecureField("PrivateKey", text: $privkey)
} else { .disabled(true)
Text(sec) } else {
.textSelection(.enabled) Text(sec)
.onTapGesture { .clipShape(RoundedRectangle(cornerRadius: 5))
UIPasteboard.general.string = sec }
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
} CopyButton(is_pk: false)
.clipShape(RoundedRectangle(cornerRadius: 5))
.gesture(
LongPressGesture(minimumDuration: 1.0)
.onEnded { _ in
UIPasteboard.general.string = sec
}
)
} }
Toggle("Show PrivateKey", isOn: $showPrivateKey) Toggle("Show", isOn: $show_privkey)
} }
} }

Loading…
Cancel
Save