Files
eranos/src/lib/parseProfileBadges.ts
T
Alex Gleason 29fd0c9a0f Remove unused exports and dead code
Aggressive cleanup of 359 exports across 153 files identified as
having zero importers outside their declaring module:

- 105 symbols deleted entirely (no internal uses either)
- 254 symbols un-exported (still referenced file-locally; dropped the
  `export` keyword to shrink the public surface)
- ~70 cascade cleanups of locals that became dead once their sole
  consumer was removed

Notable shrinkage:
- src/hooks/useShakespeare.ts: 626 \u2192 22 lines (unwired AI chat surface;
  only the ChatMessage type is consumed)
- src/hooks/useTrending.ts: only useEventStats survives; trending feed
  hooks were never wired up
- src/hooks/useTrustedCountryStats.ts: dead type re-exports removed
- src/lib/bitcoin.ts: PSBT helpers \u2014 unused wallet feature scaffolding
- src/lib/communityUtils.ts: unused NIP-72 moderation helpers
- src/lib/extraKinds.ts, src/lib/colorUtils.ts: unused helpers
- src/lib/logger.ts: bare debug/info/warn/error exports dropped;
  consumers use the `logger` object
- src/lib/aiChatSystemPrompt.ts: trimmed to the
  DEFAULT_SYSTEM_PROMPT_TEMPLATE constant
- src/components/music/MusicTrackRow.tsx: dead row component removed;
  only the skeleton is consumed

src/hooks/useNostr.ts (intentional decoy) and src/i18n.ts
(side-effect import) were preserved per their respective contracts.
2026-05-23 20:56:43 -05:00

59 lines
1.7 KiB
TypeScript

import type { NostrEvent } from '@nostrify/nostrify';
import { isProfileBadgesKind } from '@/lib/badgeUtils';
/** A parsed badge reference from a profile badges event. */
interface BadgeRef {
/** The `a` tag value referencing a kind 30009 badge definition. */
aTag: string;
/** The `e` tag value referencing a kind 8 badge award event. */
eTag?: string;
/** Parsed components from the `a` tag. */
kind: number;
pubkey: string;
identifier: string;
}
/** Parse a profile badges event (kind 10008 or legacy 30008) into badge references. */
export function parseProfileBadges(event: NostrEvent): BadgeRef[] {
if (!isProfileBadgesKind(event.kind)) return [];
// Legacy kind 30008 requires d=profile_badges; kind 10008 doesn't need it
if (event.kind === 30008) {
const dTag = event.tags.find(([n]) => n === 'd')?.[1];
if (dTag !== 'profile_badges') return [];
}
const refs: BadgeRef[] = [];
const tags = event.tags;
for (let i = 0; i < tags.length; i++) {
if (tags[i][0] === 'a' && tags[i][1]) {
const aTag = tags[i][1];
const parts = aTag.split(':');
if (parts.length < 3) continue;
const kind = parseInt(parts[0], 10);
if (kind !== 30009) continue;
const pubkey = parts[1];
const identifier = parts.slice(2).join(':');
// Look for the corresponding `e` tag immediately after
let eTag: string | undefined;
if (i + 1 < tags.length && tags[i + 1][0] === 'e') {
eTag = tags[i + 1][1];
}
refs.push({ aTag, eTag, kind, pubkey, identifier });
}
}
// Deduplicate by aTag -- keep first occurrence only
const seen = new Set<string>();
return refs.filter((r) => {
if (seen.has(r.aTag)) return false;
seen.add(r.aTag);
return true;
});
}