1
0
mirror of git://jb55.com/damus synced 2024-09-18 19:23:49 +00:00

nip05: show username and support _ usernames

Changelog-Added: Show nostr address username and support abbreviated _ usernames
This commit is contained in:
William Casarin 2023-07-17 11:01:57 -07:00
parent 0e55b08b6c
commit 080aaf2d1b

View File

@ -43,14 +43,24 @@ struct NIP05Badge: View {
}
}
}
var nip05_string: String {
if nip05.username == "_" {
return nip05.host
} else {
return "\(nip05.username)@\(nip05.host)"
}
}
var body: some View {
HStack(spacing: 2) {
Seal
if show_domain {
if clickable {
Text(nip05.host)
Text(nip05_string)
.nip05_colorized(gradient: nip05_color)
.onTapGesture {
if let nip5url = nip05.siteUrl {
@ -58,7 +68,7 @@ struct NIP05Badge: View {
}
}
} else {
Text(nip05.host)
Text(nip05_string)
.foregroundColor(.gray)
}
}
@ -86,6 +96,10 @@ struct NIP05Badge_Previews: PreviewProvider {
static var previews: some View {
let test_state = test_damus_state()
VStack {
NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, clickable: true)
NIP05Badge(nip05: NIP05(username: "_", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, clickable: true)
NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, clickable: false)
NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: Contacts(our_pubkey: "sdkfjsdf"), show_domain: true, clickable: false)