damus

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

commit 42ea150d45a260c21fe7128ed4ab53ac14973723
parent 85f86ee31fc167587d8ef6b49fe4f85552876783
Author: Swift <scoder1747@gmail.com>
Date:   Tue,  7 Mar 2023 17:58:10 -0500

Show error on invalid lightning tip address

Changelog-Changed: Show error on invalid lightning tip address
Closes: #752

Diffstat:
Mdamus/Views/EditMetadataView.swift | 20++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/damus/Views/EditMetadataView.swift b/damus/Views/EditMetadataView.swift @@ -65,6 +65,8 @@ struct EditMetadataView: View { @Environment(\.dismiss) var dismiss @Environment(\.colorScheme) var colorScheme + + @State var confirm_ln_address: Bool = false init (damus_state: DamusState) { self.damus_state = damus_state @@ -103,6 +105,10 @@ struct EditMetadataView: View { damus_state.pool.send(.event(metadata_ev)) } } + + func is_ln_valid(ln: String) -> Bool { + return ln.contains("@") || ln.lowercased().starts(with: "lnurl") + } var nip05_parts: NIP05? { return NIP05.parse(nip05) @@ -201,8 +207,18 @@ struct EditMetadataView: View { }) Button(NSLocalizedString("Save", comment: "Button for saving profile.")) { - save() - dismiss() + if !ln.isEmpty && !is_ln_valid(ln: ln) { + confirm_ln_address = true + } else { + save() + dismiss() + } + } + .alert(NSLocalizedString("Invalid Tip Address", comment: "Title of alerting as invalid tip address."), isPresented: $confirm_ln_address) { + Button(NSLocalizedString("Ok", comment: "Button to dismiss the alert.")) { + } + } message: { + Text("The address should either begin with LNURL or should look like an email address.", comment: "Giving the description of the alert message.") } } }