fix: random exception on mentions
continuous-integration/drone/push Build is running Details

This commit is contained in:
Kieran 2023-11-17 21:50:12 +00:00
parent eba47f085d
commit 9721aa506a
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
4 changed files with 18 additions and 17 deletions

View File

@ -14,7 +14,7 @@ export default function Mention({ link }: { link: NostrLink }) {
return (
<>
<ProfileLink pubkey={link.id} user={profile} onClick={e => e.stopPropagation()}>
<ProfileLink pubkey={link.id} link={link} user={profile} onClick={e => e.stopPropagation()}>
<span ref={ref}>
@<DisplayName user={profile} pubkey={link.id} />
</span>

View File

@ -8,6 +8,10 @@ export default function NostrLink({ link, depth }: { link: string; depth?: numbe
const nav = tryParseNostrLink(link);
if (nav?.type === NostrPrefix.PublicKey || nav?.type === NostrPrefix.Profile) {
if(nav.id.startsWith("npub")){
// eslint-disable-next-line no-debugger
debugger;
}
return <Mention link={nav} />;
} else if (nav?.type === NostrPrefix.Note || nav?.type === NostrPrefix.Event || nav?.type === NostrPrefix.Address) {
if ((depth ?? 0) > 0) {

View File

@ -144,13 +144,9 @@ export function getPublicKey(privKey: string) {
}
export function bech32ToHex(str: string) {
try {
const nKey = bech32.decode(str, 1_000);
const buff = bech32.fromWords(nKey.words);
return utils.bytesToHex(Uint8Array.from(buff));
} catch (e) {
return str;
}
const nKey = bech32.decode(str, 1_000);
const buff = bech32.fromWords(nKey.words);
return utils.bytesToHex(Uint8Array.from(buff));
}
/**
@ -159,13 +155,9 @@ export function bech32ToHex(str: string) {
* @returns
*/
export function bech32ToText(str: string) {
try {
const decoded = bech32.decode(str, 1000);
const buf = bech32.fromWords(decoded.words);
return new TextDecoder().decode(Uint8Array.from(buf));
} catch {
return "";
}
const decoded = bech32.decode(str, 1000);
const buf = bech32.fromWords(decoded.words);
return new TextDecoder().decode(Uint8Array.from(buf));
}
export async function fetchNip05Pubkey(name: string, domain: string, timeout = 2_000): Promise<string | undefined> {

View File

@ -233,11 +233,16 @@ export function tryParseNostrLink(link: string, prefixHint?: NostrPrefix): Nostr
}
}
export function parseNostrLink(link: string, prefixHint?: NostrPrefix): NostrLink {
let entity = link.startsWith("web+nostr:") || link.startsWith("nostr:") ? link.split(":")[1] : link;
export function trimNostrLink(link: string) {
let entity = (link.startsWith("web+nostr:") || link.startsWith("nostr:")) ? link.split(":")[1] : link;
// trim any non-bech32 chars
entity = entity.match(/(n(?:pub|profile|event|ote|addr|req)1[acdefghjklmnpqrstuvwxyz023456789]+)/)?.[0] ?? entity;
return entity;
}
export function parseNostrLink(link: string, prefixHint?: NostrPrefix): NostrLink {
const entity = trimNostrLink(link);
const isPrefix = (prefix: NostrPrefix) => {
return entity.startsWith(prefix);