extract Nip05OrPubkeyLine into shared composable
Extract nip05 value calculation into helper
This commit is contained in:
@@ -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)
|
||||
|
||||
+14
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user