Centralise the NIP-05 wildcard check (name != "_") on the data class itself.
This commit is contained in:
+2
-2
@@ -378,7 +378,7 @@ fun ObserveAndDisplayNIP05(
|
|||||||
) {
|
) {
|
||||||
val uri = LocalUriHandler.current
|
val uri = LocalUriHandler.current
|
||||||
|
|
||||||
if (nip05State.nip05.name != "_") {
|
if (nip05State.nip05.hasLocalPart()) {
|
||||||
Text(
|
Text(
|
||||||
text = remember(nip05State) { AnnotatedString(nip05State.nip05.name) },
|
text = remember(nip05State) { AnnotatedString(nip05State.nip05.name) },
|
||||||
fontSize = Font14SP,
|
fontSize = Font14SP,
|
||||||
@@ -407,7 +407,7 @@ fun DisplayNIP05(
|
|||||||
) {
|
) {
|
||||||
val uri = LocalUriHandler.current
|
val uri = LocalUriHandler.current
|
||||||
|
|
||||||
if (nip05State.nip05.name != "_") {
|
if (nip05State.nip05.hasLocalPart()) {
|
||||||
Text(
|
Text(
|
||||||
text = remember(nip05State) { AnnotatedString(nip05State.nip05.name) },
|
text = remember(nip05State) { AnnotatedString(nip05State.nip05.name) },
|
||||||
fontSize = Font14SP,
|
fontSize = Font14SP,
|
||||||
|
|||||||
+1
-1
@@ -188,7 +188,7 @@ private fun NonClickableObserveAndDisplayNIP05(
|
|||||||
nip05State: Nip05State.Exists,
|
nip05State: Nip05State.Exists,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
) {
|
) {
|
||||||
if (nip05State.nip05.name != "_") {
|
if (nip05State.nip05.hasLocalPart()) {
|
||||||
Text(
|
Text(
|
||||||
text = remember(nip05State) { AnnotatedString(nip05State.nip05.name) },
|
text = remember(nip05State) { AnnotatedString(nip05State.nip05.name) },
|
||||||
fontSize = Font14SP,
|
fontSize = Font14SP,
|
||||||
|
|||||||
+1
-1
@@ -490,7 +490,7 @@ private fun PubkeyNip05Row(
|
|||||||
|
|
||||||
when (val nip05State = nip05StateMetadata) {
|
when (val nip05State = nip05StateMetadata) {
|
||||||
is Nip05State.Exists -> {
|
is Nip05State.Exists -> {
|
||||||
if (nip05State.nip05.name != "_") {
|
if (nip05State.nip05.hasLocalPart()) {
|
||||||
Text(
|
Text(
|
||||||
text = remember(nip05State) { AnnotatedString(nip05State.nip05.name) },
|
text = remember(nip05State) { AnnotatedString(nip05State.nip05.name) },
|
||||||
fontSize = Font14SP,
|
fontSize = Font14SP,
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ data class Nip05Id(
|
|||||||
*/
|
*/
|
||||||
fun toDisplayValue(): String = if (name == "_") domain else assemble(name, domain)
|
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 toUserUrl(): String = userUrl(name, domain)
|
||||||
|
|
||||||
fun toDomainUrl(): String = domainUrl(domain)
|
fun toDomainUrl(): String = domainUrl(domain)
|
||||||
|
|||||||
+14
@@ -123,6 +123,20 @@ class Nip05Test {
|
|||||||
assertEquals("example.com", nip05.toDisplayValue())
|
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
|
@Test
|
||||||
fun `test json parsing with relays`() {
|
fun `test json parsing with relays`() {
|
||||||
val parsedNip05 = Nip05Id.parse("bob@test.com")
|
val parsedNip05 = Nip05Id.parse("bob@test.com")
|
||||||
|
|||||||
Reference in New Issue
Block a user