/
EventLink.tsx
41 lines (34 loc) 路 993 Bytes
/
EventLink.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Show, type Component } from 'solid-js';
import { Kind, nip19 } from 'nostr-tools';
const { noteEncode, neventEncode } = nip19;
type EventLinkProps = {
eventId: string;
kind?: Kind;
};
const tryEncodeNote = (eventId: string) => {
try {
return noteEncode(eventId);
} catch (err) {
console.error('failed to encode event id into Bech32 entity (NIP-19) but ignore', eventId, err);
return eventId;
}
};
const tryEncodeNevent = (eventId: string) => {
try {
return neventEncode({ id: eventId });
} catch (err) {
console.error('failed to encode event id into Bech32 entity (NIP-19) but ignore', eventId, err);
return eventId;
}
};
const EventLink: Component<EventLinkProps> = (props) => (
<button class="text-blue-500 underline">
<Show
when={props.kind == null || props.kind === Kind.Text}
fallback={tryEncodeNevent(props.eventId)}
>
{tryEncodeNote(props.eventId)}
</Show>
</button>
);
export default EventLink;