@@ -36,26 +36,26 @@ export function useSubscription(
3636 pollInterval = 5000 ,
3737) {
3838 const id = `${ contractId } :${ topic } `
39- paging [ id ] = paging [ id ] || { }
39+ if ( ! paging [ id ] ) paging [ id ] = { }
40+ const page = paging [ id ]
4041
4142 React . useEffect ( ( ) => {
4243 let timeoutId : NodeJS . Timeout | null = null
4344 let stop = false
4445
4546 async function pollEvents ( ) : Promise < void > {
4647 try {
47- if ( ! paging [ id ] . lastLedgerStart ) {
48+ if ( ! page . lastLedgerStart ) {
4849 const latestLedgerState = await server . getLatestLedger ( )
49- paging [ id ] . lastLedgerStart = latestLedgerState . sequence
50+ page . lastLedgerStart = latestLedgerState . sequence
5051 }
5152
52- // lastLedgerStart is now guaranteed to be a number
53- const lastLedger = paging [ id ] . lastLedgerStart
53+ const lastLedger = page . lastLedgerStart
5454
5555 const response = await server . getEvents (
56- paging [ id ] . pagingToken
56+ page . pagingToken
5757 ? {
58- cursor : paging [ id ] . pagingToken ,
58+ cursor : page . pagingToken ,
5959 filters : [
6060 {
6161 contractIds : [ contractId ] ,
@@ -79,9 +79,9 @@ export function useSubscription(
7979 } ,
8080 )
8181
82- paging [ id ] . pagingToken = undefined
82+ page . pagingToken = undefined
8383 if ( response . latestLedger ) {
84- paging [ id ] . lastLedgerStart = response . latestLedger
84+ page . lastLedgerStart = response . latestLedger
8585 }
8686 if ( response . events && response . events . length > 0 ) {
8787 response . events . forEach ( ( event ) => {
@@ -94,9 +94,8 @@ export function useSubscription(
9494 )
9595 }
9696 } )
97- // Store the cursor from the response for pagination
9897 if ( response . cursor ) {
99- paging [ id ] . pagingToken = response . cursor
98+ page . pagingToken = response . cursor
10099 }
101100 }
102101 } catch ( error ) {
0 commit comments