diff --git a/damus/Components/NIP05Badge.swift b/damus/Components/NIP05Badge.swift index 7d0ccd11..759b733e 100644 --- a/damus/Components/NIP05Badge.swift +++ b/damus/Components/NIP05Badge.swift @@ -12,14 +12,16 @@ struct NIP05Badge: View { let pubkey: String let contacts: Contacts let show_domain: Bool - + let profiles: Profiles + @Environment(\.openURL) var openURL - init(nip05: NIP05, pubkey: String, contacts: Contacts, show_domain: Bool) { + init(nip05: NIP05, pubkey: String, contacts: Contacts, show_domain: Bool, profiles: Profiles) { self.nip05 = nip05 self.pubkey = pubkey self.contacts = contacts self.show_domain = show_domain + self.profiles = profiles } var nip05_color: Bool { @@ -42,8 +44,18 @@ struct NIP05Badge: View { } } + var username_matches_nip05: Bool { + guard let profile = profiles.lookup(id: pubkey), + let name = profile.name + else { + return false + } + + return name.lowercased() == nip05.username.lowercased() + } + var nip05_string: String { - if nip05.username == "_" { + if nip05.username == "_" || username_matches_nip05 { return nip05.host } else { return "\(nip05.username)@\(nip05.host)" @@ -87,13 +99,13 @@ 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) + NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, profiles: test_state.profiles) - NIP05Badge(nip05: NIP05(username: "_", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true) + NIP05Badge(nip05: NIP05(username: "_", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, profiles: test_state.profiles) - NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true) + NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, profiles: test_state.profiles) - NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: Contacts(our_pubkey: "sdkfjsdf"), show_domain: true) + NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: Contacts(our_pubkey: "sdkfjsdf"), show_domain: true, profiles: test_state.profiles) } } } diff --git a/damus/Views/Profile/ProfileName.swift b/damus/Views/Profile/ProfileName.swift index 6c28510a..5a756094 100644 --- a/damus/Views/Profile/ProfileName.swift +++ b/damus/Views/Profile/ProfileName.swift @@ -85,7 +85,7 @@ struct ProfileName: View { .font(.body) .fontWeight(prefix == "@" ? .none : .bold) if let nip05 = current_nip05 { - NIP05Badge(nip05: nip05, pubkey: pubkey, contacts: damus_state.contacts, show_domain: show_nip5_domain) + NIP05Badge(nip05: nip05, pubkey: pubkey, contacts: damus_state.contacts, show_domain: show_nip5_domain, profiles: damus_state.profiles) } if let friend = friend_type, current_nip05 == nil { FriendIcon(friend: friend)