import { ChainTypeEnum, CoreEventTypeEnum } from '@bit-ui-libs/common'; import { useQuery } from '@tanstack/react-query'; import { useEffect } from 'react'; import { useChainTypeStore } from '../../../hooks/use-infer-chain-type'; import { useServicesStore } from '../../../stores'; export function useChainTypeFromEvent(eventId: string) { const setChainType = useChainTypeStore((s) => s.setType); const service = useServicesStore(s => s.coreEvents); const { data } = useQuery({ queryKey: ['chain-type', eventId], queryFn: async () => service.getEventById(eventId), select: (data) => data.eventTypeId === CoreEventTypeEnum.CHAIN_OBJECTS ? ChainTypeEnum.Objects : ChainTypeEnum.Services, }); useEffect(() => { if (!data) return; setChainType(data); }, [data]); return data; }