extract Nip05OrPubkeyLine into shared composable

Extract nip05 value calculation into helper
This commit is contained in:
davotoula
2026-05-06 16:28:47 +02:00
parent a34a5e0af7
commit 54c48bc5b7
6 changed files with 80 additions and 59 deletions
@@ -29,6 +29,13 @@ data class Nip05Id(
) {
fun toValue(): String = assemble(name, domain)
/**
* Renders the address for users to read. When [name] is `"_"`, NIP-05
* specifies the address should display as just the domain. Use this in UI;
* use [toValue] for network lookups and storage.
*/
fun toDisplayValue(): String = if (name == "_") domain else assemble(name, domain)
fun toUserUrl(): String = userUrl(name, domain)
fun toDomainUrl(): String = domainUrl(domain)
@@ -109,6 +109,20 @@ class Nip05Test {
assertEquals("https://$domain/.well-known/nostr.json", parsedNip05.toDomainUrl())
}
@Test
fun `toDisplayValue with regular name returns name@domain`() {
val nip05 = Nip05Id.parse("alice@example.com")
assertNotNull(nip05)
assertEquals("alice@example.com", nip05.toDisplayValue())
}
@Test
fun `toDisplayValue with underscore name returns domain only`() {
val nip05 = Nip05Id.parse("_@example.com")
assertNotNull(nip05)
assertEquals("example.com", nip05.toDisplayValue())
}
@Test
fun `test json parsing with relays`() {
val parsedNip05 = Nip05Id.parse("bob@test.com")