fix: processing gift wraps and notifications #193
@ -27,6 +27,8 @@ import {
|
|||||||
import { useAppSelector } from '../hooks'
|
import { useAppSelector } from '../hooks'
|
||||||
import styles from './style.module.scss'
|
import styles from './style.module.scss'
|
||||||
|
|
||||||
|
const UPDATE_INTERVAL_MS = 120000
|
||||||
|
|
||||||
export const MainLayout = () => {
|
export const MainLayout = () => {
|
||||||
const dispatch: Dispatch = useDispatch()
|
const dispatch: Dispatch = useDispatch()
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
@ -35,7 +37,7 @@ export const MainLayout = () => {
|
|||||||
const usersAppData = useAppSelector((state) => state.userAppData)
|
const usersAppData = useAppSelector((state) => state.userAppData)
|
||||||
|
|
||||||
// Ref to track if `subscribeForSigits` has been called
|
// Ref to track if `subscribeForSigits` has been called
|
||||||
const hasSubscribed = useRef(false)
|
const hasSubscribed = useRef<number | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const metadataController = new MetadataController()
|
const metadataController = new MetadataController()
|
||||||
@ -109,10 +111,27 @@ export const MainLayout = () => {
|
|||||||
|
|
||||||
if (pubkey && !hasSubscribed.current) {
|
if (pubkey && !hasSubscribed.current) {
|
||||||
// Call `subscribeForSigits` only if it hasn't been called before
|
// Call `subscribeForSigits` only if it hasn't been called before
|
||||||
|
// #193 disabled websocket subscribtion, keep updating the sigits on UPDATE_INTERVAL_MS until #194 is done
|
||||||
|
// Set up the update sigit loop, use setTimeout to make sure times between updates are consistent
|
||||||
|
// (not affected by execution duration of subscribeForSigits call)
|
||||||
|
const loop = () => {
|
||||||
|
hasSubscribed.current = window.setTimeout(async () => {
|
||||||
|
await subscribeForSigits(pubkey)
|
||||||
|
loop()
|
||||||
|
}, UPDATE_INTERVAL_MS)
|
||||||
|
}
|
||||||
subscribeForSigits(pubkey)
|
subscribeForSigits(pubkey)
|
||||||
|
loop()
|
||||||
|
|
||||||
// Mark `subscribeForSigits` as called
|
// Mark `subscribeForSigits` as called
|
||||||
hasSubscribed.current = true
|
//hasSubscribed.current = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (hasSubscribed.current) {
|
||||||
|
window.clearTimeout(hasSubscribed.current)
|
||||||
|
hasSubscribed.current = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [authState, usersAppData])
|
}, [authState, usersAppData])
|
||||||
|
@ -859,9 +859,16 @@ export const subscribeForSigits = async (pubkey: string) => {
|
|||||||
'#p': [pubkey]
|
'#p': [pubkey]
|
||||||
}
|
}
|
||||||
|
|
||||||
relayController.subscribeForEvents(filter, relaySet.read, (event) => {
|
// Process the received event synchronously
|
||||||
processReceivedEvent(event) // Process the received event
|
const events = await relayController.fetchEvents(filter, relaySet.read)
|
||||||
})
|
for (const e of events) {
|
||||||
|
await processReceivedEvent(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Async processing of the events has a race condition
|
||||||
|
// relayController.subscribeForEvents(filter, relaySet.read, (event) => {
|
||||||
|
// processReceivedEvent(event)
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
|
const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
|
||||||
@ -907,7 +914,7 @@ const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
|
|||||||
|
|
||||||
if (!meta) return
|
if (!meta) return
|
||||||
|
|
||||||
updateUsersAppData(meta)
|
await updateUsersAppData(meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user