switch to buttons for copying keys
This commit is contained in:
@@ -13,12 +13,29 @@ struct ConfigView: View {
|
||||
@State var show_add_relay: Bool = false
|
||||
@State var confirm_logout: Bool = false
|
||||
@State var new_relay: String = ""
|
||||
@State var showPrivateKey: Bool = false
|
||||
@State var privateKey: String
|
||||
@State var show_privkey: Bool = false
|
||||
@State var privkey: String
|
||||
@State var privkey_copied: Bool = false
|
||||
@State var pubkey_copied: Bool = false
|
||||
|
||||
let generator = UIImpactFeedbackGenerator(style: .light)
|
||||
|
||||
init(state: DamusState) {
|
||||
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 {
|
||||
@@ -35,43 +52,29 @@ struct ConfigView: View {
|
||||
}
|
||||
|
||||
Section("Public Account ID") {
|
||||
HStack {
|
||||
Text(state.keypair.pubkey_bech32)
|
||||
.textSelection(.enabled)
|
||||
.onTapGesture {
|
||||
UIPasteboard.general.string = state.keypair.pubkey_bech32
|
||||
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
|
||||
|
||||
CopyButton(is_pk: true)
|
||||
}
|
||||
.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 {
|
||||
Section("Secret Account Login Key") {
|
||||
if showPrivateKey == false {
|
||||
SecureField("PrivateKey", text: $privateKey)
|
||||
HStack {
|
||||
if show_privkey == false {
|
||||
SecureField("PrivateKey", text: $privkey)
|
||||
.disabled(true)
|
||||
} else {
|
||||
Text(sec)
|
||||
.textSelection(.enabled)
|
||||
.onTapGesture {
|
||||
UIPasteboard.general.string = sec
|
||||
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
|
||||
}
|
||||
.clipShape(RoundedRectangle(cornerRadius: 5))
|
||||
.gesture(
|
||||
LongPressGesture(minimumDuration: 1.0)
|
||||
.onEnded { _ in
|
||||
UIPasteboard.general.string = sec
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Toggle("Show PrivateKey", isOn: $showPrivateKey)
|
||||
CopyButton(is_pk: false)
|
||||
}
|
||||
|
||||
Toggle("Show", isOn: $show_privkey)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user