fix: stringify contentJson for CopyableJsonViewer and support 'about' field

- Fix React error 31: CopyableJsonViewer expects string, not object
- Add JSON.stringify() with pretty printing for metadata display
- Support both 'description' and 'about' fields in content JSON (common in kind 0)
- Add tests for 'about' field handling
This commit is contained in:
Claude
2026-01-05 09:27:06 +00:00
parent 583dfd9786
commit 45c9ca7a2b
3 changed files with 25 additions and 3 deletions

View File

@@ -196,7 +196,7 @@ export function ApplicationHandlerDetailRenderer({
{contentJson && Object.keys(contentJson).length > 0 && (
<div className="flex flex-col gap-3">
<h2 className="text-xl font-semibold">Metadata</h2>
<CopyableJsonViewer json={contentJson} />
<CopyableJsonViewer json={JSON.stringify(contentJson, null, 2)} />
</div>
)}

View File

@@ -91,6 +91,23 @@ describe("Kind 31990 (Application Handler) Helpers", () => {
expect(getAppDescription(event)).toBe("A great app");
});
it("should extract about field as fallback", () => {
const event = createHandlerEvent({
content: JSON.stringify({ about: "An awesome app" }),
});
expect(getAppDescription(event)).toBe("An awesome app");
});
it("should prefer description over about", () => {
const event = createHandlerEvent({
content: JSON.stringify({
description: "Description text",
about: "About text",
}),
});
expect(getAppDescription(event)).toBe("Description text");
});
it("should return undefined if no content", () => {
const event = createHandlerEvent({ content: "" });
expect(getAppDescription(event)).toBeUndefined();

View File

@@ -47,14 +47,19 @@ export function getAppName(event: NostrEvent): string {
/**
* Extract app description from kind 31990 event content JSON
* Checks both 'description' and 'about' fields
*/
export function getAppDescription(event: NostrEvent): string | undefined {
if (event.kind !== 31990 || !event.content) return undefined;
try {
const metadata = JSON.parse(event.content);
if (metadata && typeof metadata === "object" && metadata.description && typeof metadata.description === "string") {
return metadata.description;
if (metadata && typeof metadata === "object") {
// Check description first, then about (common in kind 0 profile format)
const desc = metadata.description || metadata.about;
if (desc && typeof desc === "string") {
return desc;
}
}
} catch {
// Invalid JSON