- **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.
61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
import { getAlbyService } from './alby'
|
|
import type { AlbyInvoice } from '@/types/alby'
|
|
import type { ArticleDraft } from './articlePublisher'
|
|
|
|
/**
|
|
* Create Lightning invoice for article
|
|
* Requires Alby/WebLN to be available and enabled
|
|
*/
|
|
export async function createArticleInvoice(draft: ArticleDraft): Promise<AlbyInvoice> {
|
|
const alby = getAlbyService()
|
|
await alby.enable() // Request permission
|
|
|
|
const invoice = await alby.createInvoice({
|
|
amount: draft.zapAmount,
|
|
description: `Payment for article: ${draft.title}`,
|
|
expiry: 86400, // 24 hours
|
|
})
|
|
|
|
return invoice
|
|
}
|
|
|
|
/**
|
|
* Create preview event with invoice tags
|
|
*/
|
|
export function createPreviewEvent(
|
|
draft: ArticleDraft,
|
|
invoice: AlbyInvoice,
|
|
authorPresentationId?: string
|
|
): {
|
|
kind: 1
|
|
created_at: number
|
|
tags: string[][]
|
|
content: string
|
|
} {
|
|
const tags: string[][] = [
|
|
['title', draft.title],
|
|
['preview', draft.preview],
|
|
['zap', draft.zapAmount.toString()],
|
|
['content-type', 'article'],
|
|
['invoice', invoice.invoice],
|
|
['payment_hash', invoice.paymentHash],
|
|
]
|
|
|
|
// Add category if specified
|
|
if (draft.category) {
|
|
tags.push(['category', draft.category])
|
|
}
|
|
|
|
// Add author presentation ID if provided
|
|
if (authorPresentationId) {
|
|
tags.push(['author_presentation_id', authorPresentationId])
|
|
}
|
|
|
|
return {
|
|
kind: 1 as const,
|
|
created_at: Math.floor(Date.now() / 1000),
|
|
tags,
|
|
content: draft.preview,
|
|
}
|
|
}
|