@@ -15,6 +15,7 @@ import deployedContracts from "~~/contracts/deployedContracts";
1515import predeployedContracts from "~~/contracts/predeployedContracts" ;
1616import configExternalContracts from "~~/contracts/configExternalContracts" ;
1717import { deepMergeContracts } from "~~/utils/scaffold-stark/contract" ;
18+ import { EMITTED_EVENT } from "@starknet-io/types-js" ;
1819
1920export interface EventData {
2021 blockHash : string ;
@@ -428,12 +429,13 @@ export function useFetchEvents(
428429
429430 if ( eventResponse . events ) {
430431 // Sort events by block number and event index (newest first)
431- const sortedEvents = eventResponse . events . sort ( ( a , b ) => {
432- if ( a . block_number !== b . block_number ) {
433- return b . block_number - a . block_number ;
434- }
435- return ( b as any ) . event_index - ( a as any ) . event_index ;
436- } ) ;
432+ const sortedEvents = ( eventResponse . events as EMITTED_EVENT [ ] ) . sort (
433+ ( a , b ) => {
434+ const blockA = a . block_number ?? 0 ;
435+ const blockB = b . block_number ?? 0 ;
436+ return blockB - blockA ;
437+ } ,
438+ ) ;
437439
438440 // Apply pagination
439441 const startIndex = ( page - 1 ) * pageSize ;
@@ -459,8 +461,8 @@ export function useFetchEvents(
459461
460462 // Initialize event data
461463 const eventData : EventData = {
462- blockHash : event . block_hash ,
463- blockNumber : event . block_number ,
464+ blockHash : event . block_hash ?? "" ,
465+ blockNumber : event . block_number ?? 0 ,
464466 transactionHash : event . transaction_hash ,
465467 eventName : "Event" ,
466468 contractAddress : event . from_address ,
@@ -530,8 +532,8 @@ export function useFetchEvents(
530532 } catch ( error ) {
531533 console . warn ( "Failed to process event:" , error ) ;
532534 return {
533- blockHash : event . block_hash ,
534- blockNumber : event . block_number ,
535+ blockHash : event . block_hash ?? "" ,
536+ blockNumber : event . block_number ?? 0 ,
535537 transactionHash : event . transaction_hash ,
536538 eventName : "Unknown" ,
537539 contractAddress : event . from_address ,
0 commit comments