UNPKG

@safe-global/safe-react-hooks

Version:

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

25 lines 1.24 kB
import { useCallback } from 'react'; import { useMutation } from '@tanstack/react-query'; import { useConfig } from '../hooks/useConfig.js'; import { useSignerClient } from '../hooks/useSignerClient.js'; /** * Hook for sending a custom mutation via the SafeClient. * @param params Parameters to customize the hook behavior. * @param params.config SafeConfig to use instead of the one provided by `SafeProvider`. * @param params.mutationSafeClientFn Mutation function to be called with the SafeClient. * @param params.mutationKey Key to identify the mutation. * @returns Object containing the mutation result. */ export function useSignerClientMutation(params) { const { mutationSafeClientFn, mutationKey } = params; const [config] = useConfig({ config: params.config }); const signerClient = useSignerClient({ config: params.config }); const mutationFn = useCallback((params) => { if (!signerClient) { throw new Error('Signer client is not available'); } return mutationSafeClientFn(signerClient, params); }, [signerClient, mutationSafeClientFn]); return useMutation({ mutationKey: [...mutationKey, config], mutationFn }); } //# sourceMappingURL=useSignerClientMutation.js.map