import { useState } from 'react'; import { Link } from 'react-router-dom'; import { nip19 } from 'nostr-tools'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useAuthor } from '@/hooks/useAuthor'; import { useToast } from '@/hooks/useToast'; import { useTraderRecommendations, useMyRecommendation, useRecommendationActions, } from '@/hooks/useTraderRecommendations'; import { genUserName } from '@/lib/genUserName'; import { ShieldCheck, Loader2 } from 'lucide-react'; import { useTranslation } from '@/contexts/language'; function Recommender({ pubkey }: { pubkey: string }) { const author = useAuthor(pubkey); const name = author.data?.metadata?.name ?? genUserName(pubkey); return ( {name.slice(0, 2).toUpperCase()} {name} ); } /** * Trusted-trader recommendations for a profile (kind 31873). Shows who vouches * for this trader, and lets a logged-in viewer add their own recommendation. */ export function TradeRecommendationsCard({ pubkey, className }: { pubkey: string; className?: string }) { const { t } = useTranslation(); const { user } = useCurrentUser(); const { data: recs, isLoading } = useTraderRecommendations(pubkey); const { data: mine } = useMyRecommendation(pubkey); const { recommend } = useRecommendationActions(); const { toast } = useToast(); const [busy, setBusy] = useState(false); const isSelf = user?.pubkey === pubkey; const count = recs?.length ?? 0; // Don't flash an empty "No recommendations yet." card while the query is still // loading (it then vanishes for a self/empty view) — render nothing until we // know, and only show the card when there's something (or the viewer can add). if (count === 0 && (isLoading || !user || isSelf)) return null; const handleRecommend = async () => { setBusy(true); try { await recommend(pubkey); toast({ title: t('marketUi.recommendations.published'), description: t('marketUi.recommendations.publishedBody') }); } catch (e) { toast({ title: t('marketUi.recommendations.failed'), description: e instanceof Error ? e.message : t('marketUi.recommendations.somethingWrong'), variant: 'destructive', }); } finally { setBusy(false); } }; return ( {t('marketUi.recommendations.title')}

{count > 0 ? ( <> {t('marketUi.recommendations.recommendedBy')} {count} {count === 1 ? t('marketUi.recommendations.skaterOne') : t('marketUi.recommendations.skaterMany')}. ) : ( t('marketUi.recommendations.none') )}

{count > 0 && (
{recs!.slice(0, 8).map((r) => ( ))}
)} {user && !isSelf && ( mine ? (

{t('marketUi.recommendations.youRecommend')}

) : ( ) )}
); }