You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1015 B
29 lines
1015 B
import { EmbeddedMention, EmbeddedNote } from '@/components/Embedded' |
|
import { nip19 } from 'nostr-tools' |
|
import { ComponentProps, useMemo } from 'react' |
|
import { Components } from './types' |
|
|
|
export default function NostrNode({ rawText, bech32Id }: ComponentProps<Components['nostr']>) { |
|
const { type, id } = useMemo(() => { |
|
if (!bech32Id) return { type: 'invalid', id: '' } |
|
try { |
|
const { type } = nip19.decode(bech32Id) |
|
if (type === 'npub' || type === 'nprofile') { |
|
return { type: 'mention', id: bech32Id } |
|
} |
|
if (type === 'nevent' || type === 'naddr' || type === 'note') { |
|
return { type: 'note', id: bech32Id } |
|
} |
|
} catch (error) { |
|
console.error('Invalid bech32 ID:', bech32Id, error) |
|
} |
|
return { type: 'invalid', id: '' } |
|
}, [bech32Id]) |
|
|
|
if (type === 'invalid') return rawText |
|
|
|
if (type === 'mention') { |
|
return <EmbeddedMention userId={id} className="not-prose" /> |
|
} |
|
return <EmbeddedNote noteId={id} className="not-prose" /> |
|
}
|
|
|