From d2e04a6726eace4ecbc4f6d45a4b1b73fa8bf70d Mon Sep 17 00:00:00 2001 From: davotoula Date: Wed, 6 May 2026 17:08:50 +0200 Subject: [PATCH] Code review: exhaustive when on Nip05State in Nip05OrPubkeyLine memoize pubkey display in Nip05OrPubkeyLine --- .../commons/ui/components/Nip05OrPubkeyLine.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/ui/components/Nip05OrPubkeyLine.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/ui/components/Nip05OrPubkeyLine.kt index 87e8157d4..73c69da9c 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/ui/components/Nip05OrPubkeyLine.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/ui/components/Nip05OrPubkeyLine.kt @@ -24,24 +24,22 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.text.style.TextOverflow import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vitorpamplona.amethyst.commons.model.User import com.vitorpamplona.amethyst.commons.model.nip05DnsIdentifiers.Nip05State -/** - * Single-line bodySmall label for a user secondary identifier: shows the - * verified NIP-05 (formatted via [com.vitorpamplona.quartz.nip05DnsIdentifiers.Nip05Id.toDisplayValue]) - * when present, otherwise a shortened pubkey. - */ +/** Shows the verified NIP-05 if present, otherwise a shortened pubkey. */ @Composable fun Nip05OrPubkeyLine(user: User) { val nip05StateMetadata by user.nip05State().flow.collectAsStateWithLifecycle() + val pubkeyShort = remember(user.pubkeyHex) { user.pubkeyDisplayHex() } val text = when (val state = nip05StateMetadata) { is Nip05State.Exists -> state.nip05.toDisplayValue() - else -> user.pubkeyDisplayHex() + is Nip05State.NotFound -> pubkeyShort } Text(