feat: nip19/21 links

This commit is contained in:
2023-03-25 22:55:34 +00:00
parent 12f82372e5
commit 9b6e5090dc
21 changed files with 282 additions and 137 deletions

View File

@ -0,0 +1,27 @@
import { encodeTLV, NostrPrefix } from "@snort/nostr";
import { Link } from "react-router-dom";
import Mention from "Element/Mention";
import { parseNostrLink } from "Util";
export default function NostrLink({ link }: { link: string }) {
const nav = parseNostrLink(link);
if (nav?.type === NostrPrefix.PublicKey || nav?.type === NostrPrefix.Profile) {
return <Mention pubkey={nav.id} relays={nav.relays} />;
} else if (nav?.type === NostrPrefix.Note || nav?.type === NostrPrefix.Event) {
// translate all "event" links to nevent
const evLink = encodeTLV(nav.id, NostrPrefix.Event, nav.relays);
return (
<Link to={`/e/${evLink}`} onClick={e => e.stopPropagation()} state={{ from: location.pathname }}>
#{evLink.substring(0, 12)}
</Link>
);
} else {
return (
<a href={link} onClick={e => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">
{link}
</a>
);
}
}