- Création lib/platformCommissions.ts : configuration centralisée des commissions - Articles : 800 sats (700 auteur, 100 plateforme) - Avis : 70 sats (49 lecteur, 21 plateforme) - Sponsoring : 0.046 BTC (0.042 auteur, 0.004 plateforme) - Validation des montants à chaque étape : - Publication : vérification du montant avant publication - Paiement : vérification du montant avant acceptation - Erreurs explicites si montant incorrect - Tracking des commissions sur Nostr : - Tags author_amount et platform_commission dans événements - Interface ContentDeliveryTracking étendue - Traçabilité complète pour audit - Logs structurés avec informations de commission - Documentation complète du système Les commissions sont maintenant systématiques, validées et traçables.
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { useEffect, useState, useMemo } from 'react'
|
|
import type { NostrProfile } from '@/types/nostr'
|
|
import { nostrService } from '@/lib/nostr'
|
|
|
|
interface AuthorProfile extends NostrProfile {
|
|
pubkey: string
|
|
}
|
|
|
|
export function useAuthorsProfiles(authorPubkeys: string[]): {
|
|
profiles: Map<string, AuthorProfile>
|
|
loading: boolean
|
|
} {
|
|
const [profiles, setProfiles] = useState<Map<string, AuthorProfile>>(new Map())
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
const pubkeysKey = useMemo(() => [...authorPubkeys].sort().join(','), [authorPubkeys])
|
|
|
|
useEffect(() => {
|
|
if (authorPubkeys.length === 0) {
|
|
setProfiles(new Map())
|
|
setLoading(false)
|
|
return
|
|
}
|
|
|
|
const loadProfiles = async () => {
|
|
setLoading(true)
|
|
const profilesMap = new Map<string, AuthorProfile>()
|
|
|
|
const profilePromises = authorPubkeys.map(async (pubkey) => {
|
|
try {
|
|
const profile = await nostrService.getProfile(pubkey)
|
|
return {
|
|
pubkey,
|
|
profile: profile ?? { pubkey },
|
|
}
|
|
} catch (error) {
|
|
console.error(`Error loading profile for ${pubkey}:`, error)
|
|
return {
|
|
pubkey,
|
|
profile: { pubkey },
|
|
}
|
|
}
|
|
})
|
|
|
|
const results = await Promise.all(profilePromises)
|
|
results.forEach(({ pubkey, profile }) => {
|
|
profilesMap.set(pubkey, profile)
|
|
})
|
|
|
|
setProfiles(profilesMap)
|
|
setLoading(false)
|
|
}
|
|
|
|
void loadProfiles()
|
|
}, [pubkeysKey])
|
|
|
|
return { profiles, loading }
|
|
}
|