UNPKG

@safe-global/safe-react-hooks

Version:

A collection of React Hooks that facilitates the interaction of React apps with Safe Smart Accounts

30 lines 1.38 kB
import { useCallback } from 'react'; import { useQuery } from '@tanstack/react-query'; import { useConfig } from '../hooks/useConfig.js'; import { usePublicClient } from '../hooks/usePublicClient.js'; import { QueryKey } from '../constants.js'; import { useAddress } from '../hooks/useSafeInfo/useAddress.js'; /**s * Hook to get all Safe Operations for the connected Safe. * @param params Parameters to customize the hook behavior. * @param params.config SafeConfig to use instead of the one provided by `SafeProvider`. * @returns Query result object containing the list of Safe Operations. */ export function useSafeOperations(params = {}) { const [config] = useConfig({ config: params.config }); const { data: address } = useAddress({ config }); const safeClient = usePublicClient({ config }); const getSafeOperations = useCallback(async () => { if (!safeClient || !address) { throw new Error('SafeClient not initialized'); } const response = await safeClient.apiKit.getSafeOperationsByAddress(address, { limit: params.limit, offset: params.offset, ordering: params.ordering }); return response; }, [safeClient, address]); return useQuery({ queryKey: [QueryKey.SafeOperations, config], queryFn: getSafeOperations }); } //# sourceMappingURL=useSafeOperations.js.map