debug: add debug logs to trace NIP-19 parsing and profile resolution

- Add logs to useProfileLabels hook
- Add logs to useMarkdownToHTML hook
- Add logs to RichContent component
- Add logs to extractNostrUris function
- Add error handling with fallbacks
This commit is contained in:
Gigi
2025-11-02 20:04:01 +01:00
parent b7cda7a351
commit 056da1ad23
4 changed files with 85 additions and 28 deletions

View File

@@ -12,14 +12,31 @@ const { getPubkeyFromDecodeResult, encodeDecodeResult } = Helpers
export function useProfileLabels(content: string): Map<string, string> {
// Extract profile pointers (npub and nprofile) using applesauce helpers
const profileData = useMemo(() => {
const pointers = getContentPointers(content)
return pointers
.filter(p => p.type === 'npub' || p.type === 'nprofile')
.map(pointer => ({
pubkey: getPubkeyFromDecodeResult(pointer),
encoded: encodeDecodeResult(pointer)
}))
.filter(p => p.pubkey)
console.log('[useProfileLabels] Processing content, length:', content?.length || 0)
try {
const pointers = getContentPointers(content)
console.log('[useProfileLabels] Found pointers:', pointers.length, 'types:', pointers.map(p => p.type))
const filtered = pointers.filter(p => p.type === 'npub' || p.type === 'nprofile')
console.log('[useProfileLabels] Profile pointers:', filtered.length)
const result = filtered
.map(pointer => {
try {
return {
pubkey: getPubkeyFromDecodeResult(pointer),
encoded: encodeDecodeResult(pointer)
}
} catch (err) {
console.error('[useProfileLabels] Error processing pointer:', err, pointer)
return null
}
})
.filter((p): p is { pubkey: string; encoded: string } => p !== null && !!p.pubkey)
console.log('[useProfileLabels] Profile data after filtering:', result.length)
return result
} catch (err) {
console.error('[useProfileLabels] Error extracting pointers:', err)
return []
}
}, [content])
// Fetch profiles for all found pubkeys (progressive loading)
@@ -30,15 +47,18 @@ export function useProfileLabels(content: string): Map<string, string> {
// Build profile labels map that updates reactively as profiles load
return useMemo(() => {
const labels = new Map<string, string>()
console.log('[useProfileLabels] Building labels map, profileData:', profileData.length, 'profiles:', profiles.length)
profileData.forEach(({ encoded }, index) => {
const profile = profiles[index]
if (profile) {
const displayName = profile.name || profile.display_name || profile.nip05
if (displayName) {
labels.set(encoded, `@${displayName}`)
console.log('[useProfileLabels] Set label:', encoded, '->', displayName)
}
}
})
console.log('[useProfileLabels] Final labels map size:', labels.size)
return labels
}, [profileData, profiles])
}