Centralise the NIP-05 wildcard check (name != "_") on the data class itself.
This commit is contained in:
@@ -36,6 +36,12 @@ data class Nip05Id(
|
||||
*/
|
||||
fun toDisplayValue(): String = if (name == "_") domain else assemble(name, domain)
|
||||
|
||||
/**
|
||||
* False when [name] is the NIP-05 wildcard `"_"`; use to gate rendering of
|
||||
* the local part when name and domain are shown as separate widgets.
|
||||
*/
|
||||
fun hasLocalPart(): Boolean = name != "_"
|
||||
|
||||
fun toUserUrl(): String = userUrl(name, domain)
|
||||
|
||||
fun toDomainUrl(): String = domainUrl(domain)
|
||||
|
||||
+14
@@ -123,6 +123,20 @@ class Nip05Test {
|
||||
assertEquals("example.com", nip05.toDisplayValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `hasLocalPart is true for regular name`() {
|
||||
val nip05 = Nip05Id.parse("alice@example.com")
|
||||
assertNotNull(nip05)
|
||||
assertEquals(true, nip05.hasLocalPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `hasLocalPart is false for underscore name`() {
|
||||
val nip05 = Nip05Id.parse("_@example.com")
|
||||
assertNotNull(nip05)
|
||||
assertEquals(false, nip05.hasLocalPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test json parsing with relays`() {
|
||||
val parsedNip05 = Nip05Id.parse("bob@test.com")
|
||||
|
||||
Reference in New Issue
Block a user