Browse Source

nip05: fix identifier format in profile editor

Changelog-Fixed: Fixed nip05 identifier format in profile editor
post-button-style
William Casarin 2 years ago
parent
commit
1d1e0c553b
  1. 21
      damus/Views/EditMetadataView.swift

21
damus/Views/EditMetadataView.swift

@ -15,6 +15,11 @@ func isHttpsUrl(_ string: String) -> Bool {
return urlTest.evaluate(with: string) return urlTest.evaluate(with: string)
} }
struct NIP05 {
let username: String
let host: String
}
func isImage(_ urlString: String) -> Bool { func isImage(_ urlString: String) -> Bool {
let imageTypes = ["image/jpg", "image/jpeg", "image/png", "image/gif", "image/tiff", "image/bmp", "image/webp"] let imageTypes = ["image/jpg", "image/jpeg", "image/png", "image/gif", "image/tiff", "image/bmp", "image/webp"]
@ -95,6 +100,14 @@ struct EditMetadataView: View {
} }
} }
var nip05_parts: NIP05? {
let parts = nip05.split(separator: "@")
guard parts.count == 2 else {
return nil
}
return NIP05(username: String(parts[0]), host: String(parts[1]))
}
var body: some View { var body: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
HStack { HStack {
@ -149,13 +162,17 @@ struct EditMetadataView: View {
} }
Section(content: { Section(content: {
TextField("example.com", text: $nip05) TextField("jb55@jb55.com", text: $nip05)
.autocorrectionDisabled(true) .autocorrectionDisabled(true)
.textInputAutocapitalization(.never) .textInputAutocapitalization(.never)
}, header: { }, header: {
Text("NIP-05 Verification") Text("NIP-05 Verification")
}, footer: { }, footer: {
Text("\(name)@\(nip05) will be used for verification") if let parts = nip05_parts {
Text("'\(parts.username)' at '\(parts.host)' will be used for verification")
} else {
Text("'\(nip05)' is an invalid nip05 identifier. It should look like an email.")
}
}) })
Button("Save") { Button("Save") {

Loading…
Cancel
Save