fix: random exception on mentions
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
This commit is contained in:
parent
eba47f085d
commit
9721aa506a
@ -14,7 +14,7 @@ export default function Mention({ link }: { link: NostrLink }) {
|
|||||||
|
|
||||||
return (
|
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}>
|
<span ref={ref}>
|
||||||
@<DisplayName user={profile} pubkey={link.id} />
|
@<DisplayName user={profile} pubkey={link.id} />
|
||||||
</span>
|
</span>
|
||||||
|
@ -8,6 +8,10 @@ export default function NostrLink({ link, depth }: { link: string; depth?: numbe
|
|||||||
const nav = tryParseNostrLink(link);
|
const nav = tryParseNostrLink(link);
|
||||||
|
|
||||||
if (nav?.type === NostrPrefix.PublicKey || nav?.type === NostrPrefix.Profile) {
|
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} />;
|
return <Mention link={nav} />;
|
||||||
} else if (nav?.type === NostrPrefix.Note || nav?.type === NostrPrefix.Event || nav?.type === NostrPrefix.Address) {
|
} else if (nav?.type === NostrPrefix.Note || nav?.type === NostrPrefix.Event || nav?.type === NostrPrefix.Address) {
|
||||||
if ((depth ?? 0) > 0) {
|
if ((depth ?? 0) > 0) {
|
||||||
|
@ -144,13 +144,9 @@ export function getPublicKey(privKey: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function bech32ToHex(str: string) {
|
export function bech32ToHex(str: string) {
|
||||||
try {
|
|
||||||
const nKey = bech32.decode(str, 1_000);
|
const nKey = bech32.decode(str, 1_000);
|
||||||
const buff = bech32.fromWords(nKey.words);
|
const buff = bech32.fromWords(nKey.words);
|
||||||
return utils.bytesToHex(Uint8Array.from(buff));
|
return utils.bytesToHex(Uint8Array.from(buff));
|
||||||
} catch (e) {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,13 +155,9 @@ export function bech32ToHex(str: string) {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function bech32ToText(str: string) {
|
export function bech32ToText(str: string) {
|
||||||
try {
|
|
||||||
const decoded = bech32.decode(str, 1000);
|
const decoded = bech32.decode(str, 1000);
|
||||||
const buf = bech32.fromWords(decoded.words);
|
const buf = bech32.fromWords(decoded.words);
|
||||||
return new TextDecoder().decode(Uint8Array.from(buf));
|
return new TextDecoder().decode(Uint8Array.from(buf));
|
||||||
} catch {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchNip05Pubkey(name: string, domain: string, timeout = 2_000): Promise<string | undefined> {
|
export async function fetchNip05Pubkey(name: string, domain: string, timeout = 2_000): Promise<string | undefined> {
|
||||||
|
@ -233,11 +233,16 @@ export function tryParseNostrLink(link: string, prefixHint?: NostrPrefix): Nostr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseNostrLink(link: string, prefixHint?: NostrPrefix): NostrLink {
|
export function trimNostrLink(link: string) {
|
||||||
let entity = link.startsWith("web+nostr:") || link.startsWith("nostr:") ? link.split(":")[1] : link;
|
let entity = (link.startsWith("web+nostr:") || link.startsWith("nostr:")) ? link.split(":")[1] : link;
|
||||||
|
|
||||||
// trim any non-bech32 chars
|
// trim any non-bech32 chars
|
||||||
entity = entity.match(/(n(?:pub|profile|event|ote|addr|req)1[acdefghjklmnpqrstuvwxyz023456789]+)/)?.[0] ?? entity;
|
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) => {
|
const isPrefix = (prefix: NostrPrefix) => {
|
||||||
return entity.startsWith(prefix);
|
return entity.startsWith(prefix);
|
||||||
|
Loading…
Reference in New Issue
Block a user