feat: remove 'npub1' prefix from shortened npub displays

- Show @derggg instead of @npub1derggg for truncated npubs
- Update getNostrUriLabel to skip first 5 chars ('npub1')
- Update NostrMentionLink fallback display to match
This commit is contained in:
Gigi
2025-11-02 20:40:12 +01:00
parent 68e6fcd3ac
commit 30c2ca5b85
2 changed files with 12 additions and 5 deletions

View File

@@ -50,11 +50,14 @@ const NostrMentionLink: React.FC<NostrMentionLinkProps> = ({
switch (decoded.type) {
case 'npub': {
const pk = decoded.data
const displayName = profile?.name || profile?.display_name || profile?.nip05 || `${pk.slice(0, 8)}...`
const npub = nip19.npubEncode(pk)
// Fallback: show npub without "npub1" prefix
const fallbackDisplay = `@${npub.slice(5, 12)}...`
const displayName = profile?.name || profile?.display_name || profile?.nip05 || fallbackDisplay
return (
<a
href={`/p/${nip19.npubEncode(pk)}`}
href={`/p/${npub}`}
className={className}
onClick={onClick}
>
@@ -64,8 +67,10 @@ const NostrMentionLink: React.FC<NostrMentionLinkProps> = ({
}
case 'nprofile': {
const { pubkey: pk } = decoded.data
const displayName = profile?.name || profile?.display_name || profile?.nip05 || `${pk.slice(0, 8)}...`
const npub = nip19.npubEncode(pk)
// Fallback: show npub without "npub1" prefix
const fallbackDisplay = `@${npub.slice(5, 12)}...`
const displayName = profile?.name || profile?.display_name || profile?.nip05 || fallbackDisplay
return (
<a

View File

@@ -91,10 +91,12 @@ export function getNostrUriLabel(encoded: string): string {
switch (decoded.type) {
case 'npub':
return `@${encoded.slice(0, 12)}...`
// Remove "npub1" prefix (5 chars) and show next 7 chars
return `@${encoded.slice(5, 12)}...`
case 'nprofile': {
const npub = npubEncode(decoded.data.pubkey)
return `@${npub.slice(0, 12)}...`
// Remove "npub1" prefix (5 chars) and show next 7 chars
return `@${npub.slice(5, 12)}...`
}
case 'note':
return `note:${encoded.slice(5, 12)}...`