UNPKG

@safe-global/safe-react-hooks

Version:

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

26 lines 1.29 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'; /** * Hook to get all executed transactions 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 executed transactions. */ export function useTransactions(params = {}) { const [config] = useConfig({ config: params.config }); const { data: address } = useAddress({ config: params.config }); const safeClient = usePublicClient({ config: params.config }); const getTransactions = useCallback(async () => { if (!safeClient || !address) { throw new Error('SafeClient not initialized'); } const response = await safeClient.apiKit.getAllTransactions(address); return response.results; }, [safeClient, address]); return useQuery({ queryKey: [QueryKey.Transactions, config], queryFn: getTransactions }); } //# sourceMappingURL=useTransactions.js.map