story-research-zapwall/lib/invoiceResolver.ts
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

25 lines
845 B
TypeScript

import type { Article } from '@/types/nostr'
import type { AlbyInvoice } from '@/types/alby'
/**
* Resolve invoice for article payment
* Uses invoice from event tags only
*/
export function resolveArticleInvoice(article: Article): Promise<AlbyInvoice> {
if (!article.invoice || !article.paymentHash) {
throw new Error('Article does not have an invoice. The author must create an invoice when publishing the article.')
}
// Parse invoice from event tags
// Note: We don't have expiresAt from tags, so we'll assume it's valid
// In production, you'd decode BOLT11 to get expiry
const invoice: AlbyInvoice = {
invoice: article.invoice,
paymentHash: article.paymentHash,
amount: article.zapAmount,
expiresAt: Math.floor(Date.now() / 1000) + 86400, // Assume 24h validity
}
return Promise.resolve(invoice)
}