Nicolas Cantu 3000872dbc refactoring
- **Motivations :** Assurer passage du lint strict et clarifier la logique paiements/publications.

- **Root causes :** Fonctions trop longues, promesses non gérées et typages WebLN/Nostr incomplets.

- **Correctifs :** Refactor PaymentModal (handlers void), extraction helpers articlePublisher, simplification polling sponsoring/zap, corrections curly et awaits.

- **Evolutions :** Nouveau module articlePublisherHelpers pour présentation/aiguillage contenu privé.

- **Page affectées :** components/PaymentModal.tsx, lib/articlePublisher.ts, lib/articlePublisherHelpers.ts, lib/paymentPolling.ts, lib/sponsoring.ts, lib/nostrZapVerification.ts et dépendances liées.
2025-12-22 17:56:00 +01:00

80 lines
2.0 KiB
TypeScript

import type { Article } from '@/types/nostr'
import { useNostrConnect } from '@/hooks/useNostrConnect'
import { useArticlePayment } from '@/hooks/useArticlePayment'
import { ArticlePreview } from './ArticlePreview'
import { PaymentModal } from './PaymentModal'
interface ArticleCardProps {
article: Article
onUnlock?: (article: Article) => void
}
function ArticleMeta({
article,
error,
paymentInvoice,
onClose,
onPaymentComplete,
}: {
article: Article
error: string | null
paymentInvoice: ReturnType<typeof useArticlePayment>['paymentInvoice']
onClose: () => void
onPaymentComplete: () => void
}) {
return (
<>
{error && <p className="text-sm text-red-600 mt-2">{error}</p>}
<div className="text-xs text-gray-400 mt-4">
Published {new Date(article.createdAt * 1000).toLocaleDateString()}
</div>
{paymentInvoice && (
<PaymentModal
invoice={paymentInvoice}
onClose={onClose}
onPaymentComplete={onPaymentComplete}
/>
)}
</>
)
}
export function ArticleCard({ article, onUnlock }: ArticleCardProps) {
const { connected, pubkey } = useNostrConnect()
const {
loading,
error,
paymentInvoice,
handleUnlock,
handlePaymentComplete,
handleCloseModal,
} = useArticlePayment(article, pubkey ?? null, () => {
onUnlock?.(article)
})
return (
<article className="border rounded-lg p-6 shadow-sm hover:shadow-md transition-shadow">
<h2 className="text-2xl font-bold mb-2">{article.title}</h2>
<div className="text-gray-600 mb-4">
<ArticlePreview
article={article}
connected={connected}
loading={loading}
onUnlock={() => {
void handleUnlock()
}}
/>
</div>
<ArticleMeta
article={article}
error={error}
paymentInvoice={paymentInvoice}
onClose={handleCloseModal}
onPaymentComplete={() => {
void handlePaymentComplete()
}}
/>
</article>
)
}