UNPKG

@safe-global/safe-react-hooks

Version:

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

36 lines 1.72 kB
import { useSignerClientMutation } from '../hooks/useSignerClientMutation.js'; import { MutationKey, QueryKey } from '../constants.js'; import { invalidateQueries } from '../queryClient.js'; /** * Hook to send or propose Safe Operations. * @param params Parameters to customize the hook behavior. * @param params.config SafeConfig to use instead of the one provided by `SafeProvider`. * @returns Object containing the mutation state and the sendSafeOperation function. */ export function useSendSafeOperation(params = {}) { const { mutate, mutateAsync, ...result } = useSignerClientMutation({ ...params, mutationKey: [MutationKey.SendSafeOperation], mutationSafeClientFn: async (signerClient, { transactions = [], ...paymasterSendOptions }) => { if (!signerClient.sendSafeOperation) throw new Error('To use Safe Operations, you need to specify the safeOperationOptions in the SafeProvider configuration.'); const result = await signerClient.sendSafeOperation({ transactions, ...paymasterSendOptions }); if (result.safeOperations?.userOperationHash) { invalidateQueries([ QueryKey.SafeOperations, QueryKey.SafeInfo, QueryKey.PendingSafeOperations ]); } else if (result.safeOperations?.safeOperationHash) { invalidateQueries([QueryKey.PendingSafeOperations]); } return result; } }); return { ...result, sendSafeOperation: mutate, sendSafeOperationAsync: mutateAsync }; } //# sourceMappingURL=useSendSafeOperation.js.map