refactor(nip-66): extract supported NIPs display into reusable component

Create RelaySupportedNips component to show relay-supported NIPs in a
consistent format. Used in RelayDiscoveryDetailRenderer to reduce code
duplication and improve maintainability.
This commit is contained in:
Claude
2026-01-22 12:39:51 +00:00
parent 195ef3f62b
commit 34b2c8a1f4
2 changed files with 38 additions and 19 deletions

View File

@@ -0,0 +1,36 @@
import { Label } from "@/components/ui/label";
import { NIPBadge } from "@/components/NIPBadge";
interface RelaySupportedNipsProps {
nips: number[];
}
/**
* Relay Supported NIPs Display Component
* Shows supported Nostr Implementation Possibilities (NIPs) for a relay
* Used in both Relay Discovery and Monitor Announcement detail views
*/
export function RelaySupportedNips({ nips }: RelaySupportedNipsProps) {
if (nips.length === 0) {
return null;
}
return (
<div className="space-y-2">
<Label className="text-muted-foreground">
Supported NIPs ({nips.length})
</Label>
<div className="flex flex-wrap gap-1.5">
{nips.map((nip) => (
<NIPBadge
key={nip}
nipNumber={nip.toString().padStart(2, "0")}
showName={false}
showNIPPrefix={false}
className="text-xs"
/>
))}
</div>
</div>
);
}

View File

@@ -4,8 +4,8 @@ import { Badge } from "@/components/ui/badge";
import { Label } from "@/components/ui/label";
import { JsonViewer } from "@/components/JsonViewer";
import { UserName } from "../UserName";
import { NIPBadge } from "@/components/NIPBadge";
import { RelayKindsDisplay } from "../RelayKindsDisplay";
import { RelaySupportedNips } from "../RelaySupportedNips";
import {
getRelayUrl,
getRttMetrics,
@@ -221,24 +221,7 @@ export function RelayDiscoveryDetailRenderer({ event }: { event: NostrEvent }) {
)}
{/* Supported NIPs */}
{nips.length > 0 && (
<div className="space-y-2">
<Label className="text-muted-foreground">
Supported NIPs ({nips.length})
</Label>
<div className="flex flex-wrap gap-1.5">
{nips.map((nip) => (
<NIPBadge
key={nip}
nipNumber={nip.toString().padStart(2, "0")}
showName={false}
showNIPPrefix={false}
className="text-xs"
/>
))}
</div>
</div>
)}
<RelaySupportedNips nips={nips} />
{/* Relay Kinds */}
<RelayKindsDisplay accepted={kinds.accepted} rejected={kinds.rejected} />