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.77 kB
import { useSendSafeOperation } from '../hooks/useSendSafeOperation.js'; import { useSendTransaction } from '../hooks/useSendTransaction.js'; import { useConfig } from '../hooks/useConfig.js'; import { useSignerClientMutation } from '../hooks/useSignerClientMutation.js'; import { MutationKey } from '../constants.js'; /** * Hook to update the threshold of the connected Safe. It sends or (if the current threshold is > 1) proposes * a transaction to update the threshold of the Safe account and returns the transaction result. * @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 function to update the threshold. */ export function useUpdateThreshold(params = {}) { const [config] = useConfig({ config: params.config }); const { sendSafeOperationAsync } = useSendSafeOperation(params); const { sendTransactionAsync } = useSendTransaction(params); const { mutate, mutateAsync, ...result } = useSignerClientMutation({ ...params, mutationKey: [MutationKey.UpdateThreshold], mutationSafeClientFn: async (signerClient, updateThresholdParams) => { const updateThresholdTx = await signerClient.createChangeThresholdTransaction(updateThresholdParams); const isSafeOperation = !!config.safeOperationOptions; return isSafeOperation ? sendSafeOperationAsync({ transactions: [updateThresholdTx] }) : sendTransactionAsync({ transactions: [updateThresholdTx] }); } }); return { ...result, updateThreshold: mutate, updateThresholdAsync: mutateAsync }; } //# sourceMappingURL=useUpdateThreshold.js.map