lint fix wip

This commit is contained in:
Nicolas Cantu 2026-01-06 22:13:46 +01:00
parent 91fe30a860
commit d01ecb7402
3 changed files with 114 additions and 43 deletions

View File

@ -76,10 +76,15 @@ function ProfileHeaderSection({
return ( return (
<> <>
<BackButton /> <BackButton />
{loadingProfile ? ( {(() => {
<ProfileLoading /> if (loadingProfile) {
) : profile !== null && profile !== undefined ? ( return <ProfileLoading />
<UserProfile profile={profile} pubkey={currentPubkey} articleCount={articleCount} /> }
if (profile !== null && profile !== undefined) {
return <UserProfile profile={profile} pubkey={currentPubkey} articleCount={articleCount} />
}
return null
})()}
) : null} ) : null}
</> </>
) )

View File

@ -43,11 +43,15 @@ class PlatformSyncService {
const { relaySessionManager } = await import('./relaySessionManager') const { relaySessionManager } = await import('./relaySessionManager')
const activeRelays = await relaySessionManager.getActiveRelays() const activeRelays = await relaySessionManager.getActiveRelays()
const initialRelay = activeRelays[0] ?? 'Connecting...' const initialRelay = activeRelays[0] ?? 'Connecting...'
syncProgressManager.setProgress({ currentStep: 0, totalSteps: 1, completed: false, currentRelay: initialRelay }) const totalRelays = activeRelays.length || 1
syncProgressManager.setProgress({ currentStep: 0, totalSteps: totalRelays, completed: false, currentRelay: initialRelay })
try { try {
await this.performSync(pool as unknown as SimplePoolWithSub) await this.performSync(pool as unknown as SimplePoolWithSub)
syncProgressManager.setProgress({ currentStep: 1, totalSteps: 1, completed: true, currentRelay: initialRelay })
// Mark as completed after all relays are processed
const finalRelay = activeRelays[activeRelays.length - 1] ?? initialRelay
syncProgressManager.setProgress({ currentStep: totalRelays, totalSteps: totalRelays, completed: true, currentRelay: finalRelay })
} catch (error) { } catch (error) {
console.error('Error in platform sync:', error) console.error('Error in platform sync:', error)
syncProgressManager.setProgress(null) syncProgressManager.setProgress(null)
@ -62,7 +66,7 @@ class PlatformSyncService {
/** /**
* Perform a sync operation * Perform a sync operation
* Scans all notes with service='zapwall.fr' tag * Scans all notes with service='zapwall.fr' tag from ALL active relays
*/ */
private async performSync(pool: SimplePoolWithSub): Promise<void> { private async performSync(pool: SimplePoolWithSub): Promise<void> {
const filters = [ const filters = [
@ -75,71 +79,109 @@ class PlatformSyncService {
}, },
] ]
// Use relay rotation for platform sync const { relaySessionManager } = await import('./relaySessionManager')
const { tryWithRelayRotation } = await import('./relayRotation')
const { syncProgressManager } = await import('./syncProgressManager') const { syncProgressManager } = await import('./syncProgressManager')
const activeRelays = await relaySessionManager.getActiveRelays()
return tryWithRelayRotation( if (activeRelays.length === 0) {
pool as unknown as import('nostr-tools').SimplePool, throw new Error('No active relays available')
async (relayUrl, poolWithSub) => { }
// Update progress with current relay
const currentProgress = syncProgressManager.getProgress() const allEvents: Event[] = []
if (currentProgress) { const processedEventIds = new Set<string>()
syncProgressManager.setProgress({
...currentProgress, // Synchronize from all active relays
currentRelay: relayUrl, for (let i = 0; i < activeRelays.length; i++) {
}) const relayUrl = activeRelays[i]
} if (!relayUrl) {
continue
}
// Update progress with current relay
syncProgressManager.setProgress({
currentStep: 0,
totalSteps: activeRelays.length,
completed: false,
currentRelay: relayUrl,
})
try {
console.log(`[PlatformSync] Synchronizing from relay ${i + 1}/${activeRelays.length}: ${relayUrl}`)
const { createSubscription } = require('@/types/nostr-tools-extended') const { createSubscription } = require('@/types/nostr-tools-extended')
const sub = createSubscription(poolWithSub, [relayUrl], filters) const sub = createSubscription(pool, [relayUrl], filters)
const events: Event[] = [] const relayEvents: Event[] = []
let resolved = false let resolved = false
const finalize = async (): Promise<void> => { const finalize = (): void => {
if (resolved) { if (resolved) {
return return
} }
resolved = true resolved = true
sub.unsub() sub.unsub()
this.syncSubscription = null
// Process all events and cache them // Deduplicate events by ID before adding to allEvents
await this.processAndCacheEvents(events) for (const event of relayEvents) {
if (!processedEventIds.has(event.id)) {
processedEventIds.add(event.id)
allEvents.push(event)
}
}
this.lastSyncTime = Date.now() console.log(`[PlatformSync] Relay ${relayUrl} completed, received ${relayEvents.length} events`)
} }
return new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
sub.on('event', (event: Event): void => { sub.on('event', (event: Event): void => {
// Only process events with service='zapwall.fr' // Only process events with service='zapwall.fr'
const tags = extractTagsFromEvent(event) const tags = extractTagsFromEvent(event)
if (tags.service === PLATFORM_SERVICE) { if (tags.service === PLATFORM_SERVICE) {
events.push(event) relayEvents.push(event)
} }
}) })
sub.on('eose', (): void => { sub.on('eose', (): void => {
void (async (): Promise<void> => { finalize()
await finalize() resolve()
resolve()
})()
}) })
// Timeout after SYNC_TIMEOUT_MS // Timeout after SYNC_TIMEOUT_MS
setTimeout((): void => { setTimeout((): void => {
void (async (): Promise<void> => { finalize()
await finalize() resolve()
resolve()
})()
}, this.SYNC_TIMEOUT_MS).unref?.() }, this.SYNC_TIMEOUT_MS).unref?.()
this.syncSubscription = sub this.syncSubscription = sub
}) })
},
30000 // 30 second timeout per relay // Update progress after each relay
) syncProgressManager.setProgress({
currentStep: i + 1,
totalSteps: activeRelays.length,
completed: false,
currentRelay: relayUrl,
})
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
console.warn(`[PlatformSync] Relay ${relayUrl} failed: ${errorMessage}`)
// Mark relay as failed but continue with next relay
relaySessionManager.markRelayFailed(relayUrl)
// Update progress even on failure
syncProgressManager.setProgress({
currentStep: i + 1,
totalSteps: activeRelays.length,
completed: false,
currentRelay: relayUrl,
})
}
}
// Process all collected events
await this.processAndCacheEvents(allEvents)
console.log(`[PlatformSync] Total events collected from all relays: ${allEvents.length}`)
this.lastSyncTime = Date.now()
} }
/** /**

View File

@ -6,7 +6,15 @@ import type { Article } from '@/types/nostr'
* These tags will be included in the zap receipt (kind 9735) by the Lightning wallet * These tags will be included in the zap receipt (kind 9735) by the Lightning wallet
*/ */
export function buildPurchaseZapRequestTags(article: Article): string[][] { export function buildPurchaseZapRequestTags(article: Article): string[][] {
const category = article.category === 'science-fiction' ? 'sciencefiction' : article.category === 'scientific-research' ? 'research' : 'sciencefiction' const category = (() => {
if (article.category === 'science-fiction') {
return 'sciencefiction'
}
if (article.category === 'scientific-research') {
return 'research'
}
return 'sciencefiction'
})()
return [ return [
['kind_type', 'purchase'], ['kind_type', 'purchase'],
@ -30,7 +38,15 @@ export function buildReviewTipZapRequestTags(params: {
seriesId?: string seriesId?: string
text?: string text?: string
}): string[][] { }): string[][] {
const category = params.category === 'science-fiction' ? 'sciencefiction' : params.category === 'scientific-research' ? 'research' : 'sciencefiction' const category = (() => {
if (params.category === 'science-fiction') {
return 'sciencefiction'
}
if (params.category === 'scientific-research') {
return 'research'
}
return 'sciencefiction'
})()
return [ return [
['kind_type', 'review_tip'], ['kind_type', 'review_tip'],
@ -55,7 +71,15 @@ export function buildSponsoringZapRequestTags(params: {
articleId?: string articleId?: string
text?: string text?: string
}): string[][] { }): string[][] {
const category = params.category === 'science-fiction' ? 'sciencefiction' : params.category === 'scientific-research' ? 'research' : 'sciencefiction' const category = (() => {
if (params.category === 'science-fiction') {
return 'sciencefiction'
}
if (params.category === 'scientific-research') {
return 'research'
}
return 'sciencefiction'
})()
return [ return [
['kind_type', 'sponsoring'], ['kind_type', 'sponsoring'],