From 29c2a201f804debd724d94af1a826ba14a26c20b Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:23:41 -0500 Subject: [PATCH 1/3] [feat] support callbacks --- src/hooks/L1/useWriteDepositERC20.ts | 77 +++++++++++------ src/hooks/L2/useWriteWithdrawERC20.ts | 84 ++++++++++++------- src/hooks/L2/useWriteWithdrawETH.ts | 92 +++++++++++++-------- src/types/UseWriteOPActionBaseReturnType.ts | 37 ++++++++- 4 files changed, 199 insertions(+), 91 deletions(-) diff --git a/src/hooks/L1/useWriteDepositERC20.ts b/src/hooks/L1/useWriteDepositERC20.ts index 24b5802..83e728c 100644 --- a/src/hooks/L1/useWriteDepositERC20.ts +++ b/src/hooks/L1/useWriteDepositERC20.ts @@ -1,7 +1,9 @@ import { l1StandardBridgeABI } from '@eth-optimism/contracts-ts' import { type Config } from '@wagmi/core' import { type WriteDepositERC20Parameters as WriteDepositERC20ActionParameters } from 'op-viem/actions' +import type { ContractFunctionArgs } from 'viem' import { useAccount, useWriteContract } from 'wagmi' +import type { WriteContractVariables } from 'wagmi/query' import type { OpConfig } from '../../types/OpConfig.js' import type { UseWriteOPActionBaseParameters } from '../../types/UseWriteOPActionBaseParameters.js' import type { UseWriteOPActionBaseReturnType } from '../../types/UseWriteOPActionBaseReturnType.js' @@ -43,18 +45,21 @@ export function useWriteDepositERC20 = {}, ): UseWriteDepositERC20ReturnType { const config = useOpConfig(args) - const { writeContract, writeContractAsync, ...writeReturn } = useWriteContract() + const { writeContract, writeContractAsync, ...writeReturn } = useWriteContract(args) const account = useAccount(args) - return { - writeDepositERC20: ({ l2ChainId, args, ...rest }: WriteDepositERC20Parameters) => { - const l2Chain = config.l2chains[l2ChainId] + const writeDepositERC20: UseWriteDepositERC20ReturnType['writeDepositERC20'] = ( + { l2ChainId, args, ...rest }, + options, + ) => { + const l2Chain = config.l2chains[l2ChainId] - if (!l2Chain) { - throw new Error('L2 chain not configured') - } + if (!l2Chain) { + throw new Error('L2 chain not configured') + } - return writeContract({ + return writeContract( + { chainId: l2Chain.l1ChainId, address: l2Chain.l1Addresses.l1StandardBridge.address, abi: ABI, @@ -62,25 +67,47 @@ export function useWriteDepositERC20 { - const l2Chain = config.l2chains[l2ChainId] + } as unknown as WriteContractVariables< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + config, + config['chains'][number]['id'] + >, + options, + ) + } - if (!l2Chain) { - throw new Error('L2 chain not configured') - } + const writeDepositERC20Async: UseWriteDepositERC20ReturnType['writeDepositERC20Async'] = ( + { l2ChainId, args, ...rest }, + options, + ) => { + const l2Chain = config.l2chains[l2ChainId] - return writeContractAsync({ - chainId: l2Chain.l1ChainId, - address: l2Chain.l1Addresses.l1StandardBridge.address, - abi: ABI, - functionName: FUNCTION, - args: [args.l1Token, args.l2Token, args.to, args.amount, args.minGasLimit ?? 0, args.extraData ?? '0x'], - account: account.address, - ...rest, - }) - }, + if (!l2Chain) { + throw new Error('L2 chain not configured') + } + + return writeContractAsync({ + chainId: l2Chain.l1ChainId, + address: l2Chain.l1Addresses.l1StandardBridge.address, + abi: ABI, + functionName: FUNCTION, + args: [args.l1Token, args.l2Token, args.to, args.amount, args.minGasLimit ?? 0, args.extraData ?? '0x'], + account: account.address, + ...rest, + } as unknown as WriteContractVariables< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + config, + config['chains'][number]['id'] + >, options) + } + + return { + writeDepositERC20, + writeDepositERC20Async, ...writeReturn, } as unknown as UseWriteDepositERC20ReturnType } diff --git a/src/hooks/L2/useWriteWithdrawERC20.ts b/src/hooks/L2/useWriteWithdrawERC20.ts index 689ab4f..baae4e3 100644 --- a/src/hooks/L2/useWriteWithdrawERC20.ts +++ b/src/hooks/L2/useWriteWithdrawERC20.ts @@ -1,7 +1,9 @@ import { l2StandardBridgeABI } from '@eth-optimism/contracts-ts' import { type Config } from '@wagmi/core' import { type WriteWithdrawERC20Parameters as WriteWithdrawERC20ActionParameters } from 'op-viem/actions' +import type { ContractFunctionArgs } from 'viem' import { useWriteContract } from 'wagmi' +import type { WriteContractVariables } from 'wagmi/query' import type { OpConfig } from '../../types/OpConfig.js' import type { UseWriteOPActionBaseParameters } from '../../types/UseWriteOPActionBaseParameters.js' import type { UseWriteOPActionBaseReturnType } from '../../types/UseWriteOPActionBaseReturnType.js' @@ -43,41 +45,63 @@ export function useWriteWithdrawERC20 = {}, ): UseWriteWithdrawERC20ReturnType { const config = useOpConfig(args) - const { writeContract, writeContractAsync, ...writeReturn } = useWriteContract() + const { writeContract, writeContractAsync, ...writeReturn } = useWriteContract(args) - return { - writeWithdrawERC20: ({ chainId, args, ...rest }: WriteWithdrawERC20Parameters) => { - const l2Chain = config.l2chains[chainId] + const writeWithdrawERC20: UseWriteWithdrawERC20ReturnType['writeWithdrawERC20'] = ( + { chainId, args, ...rest }, + options, + ) => { + const l2Chain = config.l2chains[chainId] + + if (!l2Chain) { + throw new Error('L2 chain not configured') + } + + return writeContract({ + chainId: l2Chain.chainId, + address: l2Chain.l2Addresses.l2StandardBridge.address, + abi: ABI, + functionName: FUNCTION, + args: [args.l2Token, args.to, args.amount, args.minGasLimit ?? 0, args.extraData || '0x'], + ...rest, + } as unknown as WriteContractVariables< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + config, + config['chains'][number]['id'] + >, options) + } - if (!l2Chain) { - throw new Error('L2 chain not configured') - } + const writeWithdrawERC20Async: UseWriteWithdrawERC20ReturnType['writeWithdrawERC20Async'] = ( + { chainId, args, ...rest }, + options, + ) => { + const l2Chain = config.l2chains[chainId] - return writeContract({ - chainId: l2Chain.chainId, - address: l2Chain.l2Addresses.l2StandardBridge.address, - abi: ABI, - functionName: FUNCTION, - args: [args.l2Token, args.to, args.amount, args.minGasLimit ?? 0, args.extraData || '0x'], - ...rest, - }) - }, - writeWithdrawERC20Async: ({ chainId, args, ...rest }: WriteWithdrawERC20Parameters) => { - const l2Chain = config.l2chains[chainId] + if (!l2Chain) { + throw new Error('L2 chain not configured') + } - if (!l2Chain) { - throw new Error('L2 chain not configured') - } + return writeContractAsync({ + chainId: l2Chain.chainId, + address: l2Chain.l2Addresses.l2StandardBridge.address, + abi: ABI, + functionName: FUNCTION, + args: [args.l2Token, args.to, args.amount, args.minGasLimit ?? 0, args.extraData || '0x'], + ...rest, + } as unknown as WriteContractVariables< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + config, + config['chains'][number]['id'] + >, options) + } - return writeContractAsync({ - chainId: l2Chain.chainId, - address: l2Chain.l2Addresses.l2StandardBridge.address, - abi: ABI, - functionName: FUNCTION, - args: [args.l2Token, args.to, args.amount, args.minGasLimit ?? 0, args.extraData || '0x'], - ...rest, - }) - }, + return { + writeWithdrawERC20, + writeWithdrawERC20Async, ...writeReturn, } as unknown as UseWriteWithdrawERC20ReturnType } diff --git a/src/hooks/L2/useWriteWithdrawETH.ts b/src/hooks/L2/useWriteWithdrawETH.ts index bfc48e6..4c860ef 100644 --- a/src/hooks/L2/useWriteWithdrawETH.ts +++ b/src/hooks/L2/useWriteWithdrawETH.ts @@ -1,7 +1,9 @@ import { l2StandardBridgeABI } from '@eth-optimism/contracts-ts' import { type Config } from '@wagmi/core' import { type WriteWithdrawETHParameters as WriteWithdrawETHActionParameters } from 'op-viem/actions' +import type { ContractFunctionArgs } from 'viem' import { useAccount, useWriteContract } from 'wagmi' +import type { WriteContractVariables } from 'wagmi/query' import type { OpConfig } from '../../types/OpConfig.js' import type { UseWriteOPActionBaseParameters } from '../../types/UseWriteOPActionBaseParameters.js' import type { UseWriteOPActionBaseReturnType } from '../../types/UseWriteOPActionBaseReturnType.js' @@ -44,46 +46,68 @@ export function useWriteWithdrawETH = {}, ): UseWriteWithdrawETHReturnType { const config = useOpConfig(args) - const { writeContract, writeContractAsync, ...writeReturn } = useWriteContract() + const { writeContract, writeContractAsync, ...writeReturn } = useWriteContract(args) const account = useAccount(args) - return { - writeWithdrawETH: ({ chainId, args, ...rest }: WriteWithdrawETHParameters) => { - const l2Chain = config.l2chains[chainId] + const writeWithdrawETH: UseWriteWithdrawETHReturnType['writeWithdrawETH'] = ( + { chainId, args, ...rest }, + options, + ) => { + const l2Chain = config.l2chains[chainId] + + if (!l2Chain) { + throw new Error('L2 chain not configured') + } + + return writeContract({ + chainId: l2Chain.chainId, + address: l2Chain.l2Addresses.l2StandardBridge.address, + abi: ABI, + functionName: FUNCTION, + args: [OVM_ETH, args.to, args.amount, args.minGasLimit ?? 0, args.extraData ?? '0x'], + value: args.amount, + account: account.address, + ...rest, + } as unknown as WriteContractVariables< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + config, + config['chains'][number]['id'] + >, options) + } - if (!l2Chain) { - throw new Error('L2 chain not configured') - } + const writeWithdrawETHAsync: UseWriteWithdrawETHReturnType['writeWithdrawETHAsync'] = ( + { chainId, args, ...rest }, + options, + ) => { + const l2Chain = config.l2chains[chainId] - return writeContract({ - chainId: l2Chain.chainId, - address: l2Chain.l2Addresses.l2StandardBridge.address, - abi: ABI, - functionName: FUNCTION, - args: [OVM_ETH, args.to, args.amount, args.minGasLimit ?? 0, args.extraData ?? '0x'], - value: args.amount, - account: account.address, - ...rest, - }) - }, - writeWithdrawETHAsync: ({ chainId, args, ...rest }: WriteWithdrawETHParameters) => { - const l2Chain = config.l2chains[chainId] + if (!l2Chain) { + throw new Error('L2 chain not configured') + } - if (!l2Chain) { - throw new Error('L2 chain not configured') - } + return writeContractAsync({ + chainId: l2Chain.chainId, + address: l2Chain.l2Addresses.l2StandardBridge.address, + abi: ABI, + functionName: FUNCTION, + args: [OVM_ETH, args.to, args.amount, args.minGasLimit ?? 0, args.extraData ?? '0x'], + value: args.amount, + account: account.address, + ...rest, + } as unknown as WriteContractVariables< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + config, + config['chains'][number]['id'] + >, options) + } - writeContractAsync({ - chainId: l2Chain.chainId, - address: l2Chain.l2Addresses.l2StandardBridge.address, - abi: ABI, - functionName: FUNCTION, - args: [OVM_ETH, args.to, args.amount, args.minGasLimit ?? 0, args.extraData ?? '0x'], - value: args.amount, - account: account.address, - ...rest, - }) - }, + return { + writeWithdrawETH, + writeWithdrawETHAsync, ...writeReturn, } as unknown as UseWriteWithdrawETHReturnType } diff --git a/src/types/UseWriteOPActionBaseReturnType.ts b/src/types/UseWriteOPActionBaseReturnType.ts index 1333e4e..d1e735f 100644 --- a/src/types/UseWriteOPActionBaseReturnType.ts +++ b/src/types/UseWriteOPActionBaseReturnType.ts @@ -1,5 +1,8 @@ -import type { WriteContractReturnType } from '@wagmi/core' +import type { MutateOptions } from '@tanstack/react-query' +import type { WriteContractErrorType, WriteContractReturnType } from '@wagmi/core' +import type { Abi } from 'viem' import type { Config, UseWriteContractReturnType } from 'wagmi' +import type { WriteContractData, WriteContractVariables } from 'wagmi/query' import type { OpConfig } from './OpConfig.js' export type UseWriteOPActionBaseReturnType< @@ -9,8 +12,38 @@ export type UseWriteOPActionBaseReturnType< > = & Omit, 'writeContract' | 'writeContractAsync'> & { - write: (args: args) => void + write: ( + args: args, + options?: + | MutateOptions< + WriteContractData, + WriteContractErrorType, + WriteContractVariables< + Abi, + string, + readonly unknown[], + config, + config['chains'][number]['id'] + >, + context + > + | undefined, + ) => void writeAsync: ( args: args, + options?: + | MutateOptions< + WriteContractData, + WriteContractErrorType, + WriteContractVariables< + Abi, + string, + readonly unknown[], + config, + config['chains'][number]['id'] + >, + context + > + | undefined, ) => Promise } From 2184a35b73b101a99d79be391eabf037957ee45e Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:43:35 -0500 Subject: [PATCH 2/3] docs --- docs/docs/hooks/L1/useWriteDepositERC20.md | 38 ++++++++++++++++++- docs/docs/hooks/L1/useWriteDepositETH.md | 38 ++++++++++++++++++- .../useWriteFinalizeWithdrawalTransaction.md | 38 ++++++++++++++++++- .../L1/useWriteProveWithdrawalTransaction.md | 38 ++++++++++++++++++- docs/docs/hooks/L2/useWriteWithdrawERC20.md | 38 ++++++++++++++++++- docs/docs/hooks/L2/useWriteWithdrawETH.md | 38 ++++++++++++++++++- 6 files changed, 216 insertions(+), 12 deletions(-) diff --git a/docs/docs/hooks/L1/useWriteDepositERC20.md b/docs/docs/hooks/L1/useWriteDepositERC20.md index a45a3de..1d6b0ce 100644 --- a/docs/docs/hooks/L1/useWriteDepositERC20.md +++ b/docs/docs/hooks/L1/useWriteDepositERC20.md @@ -37,7 +37,7 @@ Config to use instead of retrieving from the from nearest WagmiProvider. ### writeDepositERC20 -`(variables: WriteDepositERC20Parameters) => void` +`(variables: WriteDepositERC20Parameters, { onSuccess, onSettled, onError }) => void` The mutation function you can call with variables to trigger the deposit. @@ -79,9 +79,26 @@ The mutation function you can call with variables to trigger the deposit. The chain ID of the chain you want to deposit to. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteDepositERC20Parameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteDepositERC20Parameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteDepositERC20Parameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### writeDepositERC20Async -`(variables: WriteDepositERC20Parameters) => Promise` +`(variables: WriteDepositERC20Parameters, { onSuccess, onSettled, onError }) => Promise` Similar to writeDepositERC20 but returns a promise which can be awaited. @@ -123,4 +140,21 @@ Similar to writeDepositERC20 but returns a promise which can be awaited. The chain ID of the chain you want to deposit to. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteDepositERC20Parameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteDepositERC20Parameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteDepositERC20Parameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### The rest of wagmi's [useWriteContract return type](https://beta.wagmi.sh/react/api/hooks/useWrtieContract#return-type) (except `writeContract` and `writeContractAsync`). diff --git a/docs/docs/hooks/L1/useWriteDepositETH.md b/docs/docs/hooks/L1/useWriteDepositETH.md index b1c4c22..1ab7fdc 100644 --- a/docs/docs/hooks/L1/useWriteDepositETH.md +++ b/docs/docs/hooks/L1/useWriteDepositETH.md @@ -35,7 +35,7 @@ Config to use instead of retrieving from the from nearest WagmiProvider. ### writeDepositETH -`(variables: WriteDepositETHParameters) => void` +`(variables: WriteDepositETHParameters, { onSuccess, onSettled, onError }) => void` The mutation function you can call with variables to trigger the ETH deposit. @@ -67,9 +67,26 @@ The mutation function you can call with variables to trigger the ETH deposit. The chain ID of the chain you want to deposit to. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteDepositETHParameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteDepositETHParameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteDepositETHParameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### writeDepositETHAsync -`(variables: WriteDepositETHParameters) => Promise` +`(variables: WriteDepositETHParameters, { onSuccess, onSettled, onError }) => Promise` Similar to writeDepositETH but returns a promise which can be awaited. @@ -101,4 +118,21 @@ Similar to writeDepositETH but returns a promise which can be awaited. The chain ID of the chain you want to deposit to. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteDepositETHParameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteDepositETHParameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteDepositETHParameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### The rest of wagmi's [useWriteContract return type](https://beta.wagmi.sh/react/api/hooks/useWrtieContract#return-type) (except `writeContract` and `writeContractAsync`). diff --git a/docs/docs/hooks/L1/useWriteFinalizeWithdrawalTransaction.md b/docs/docs/hooks/L1/useWriteFinalizeWithdrawalTransaction.md index acd7ad2..f75f5c3 100644 --- a/docs/docs/hooks/L1/useWriteFinalizeWithdrawalTransaction.md +++ b/docs/docs/hooks/L1/useWriteFinalizeWithdrawalTransaction.md @@ -36,7 +36,7 @@ Config to use instead of retrieving from the from nearest WagmiProvider. ### writeFinalizeWithdrawalTransaction -`(variables: WriteFinalizeWithdrawalTransactionParameters) => void` +`(variables: WriteFinalizeWithdrawalTransactionParameters, { onSuccess, onSettled, onError }) => void` The mutation function you can call with variables to trigger finalizing the provided withdrawal. @@ -53,9 +53,26 @@ The mutation function you can call with variables to trigger finalizing the prov The chain ID of the chain you are withdrawing from. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteFinalizeWithdrawalTransactionParameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteFinalizeWithdrawalTransactionParameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteFinalizeWithdrawalTransactionParameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### writeFinalizeWithdrawalTransactionAsync -`(variables: WriteFinalizeWithdrawalTransactionParameters) => Promise` +`(variables: WriteFinalizeWithdrawalTransactionParameters, { onSuccess, onSettled, onError }) => Promise` Similar to writeFinalizeWithdrawalTransaction but returns a promise which can be awaited. @@ -72,4 +89,21 @@ Similar to writeFinalizeWithdrawalTransaction but returns a promise which can be The chain ID of the chain you are withdrawing from. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteFinalizeWithdrawalTransactionParameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteFinalizeWithdrawalTransactionParameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteFinalizeWithdrawalTransactionParameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### The rest of wagmi's [useWriteContract return type](https://beta.wagmi.sh/react/api/hooks/useWrtieContract#return-type) (except `writeContract` and `writeContractAsync`). diff --git a/docs/docs/hooks/L1/useWriteProveWithdrawalTransaction.md b/docs/docs/hooks/L1/useWriteProveWithdrawalTransaction.md index 181f8c0..a1d0510 100644 --- a/docs/docs/hooks/L1/useWriteProveWithdrawalTransaction.md +++ b/docs/docs/hooks/L1/useWriteProveWithdrawalTransaction.md @@ -35,7 +35,7 @@ Config to use instead of retrieving from the from nearest WagmiProvider. ### writeProveWithdrawalTransaction -`(variables: WriteProveWithdrawalTransactionParameters) => void` +`(variables: WriteProveWithdrawalTransactionParameters, { onSuccess, onSettled, onError }) => void` The mutation function you can call with variables to trigger proving the provided withdrawal. @@ -52,9 +52,26 @@ The mutation function you can call with variables to trigger proving the provide The chain ID of the chain you are withdrawing from. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteProveWithdrawalTransactionParameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteProveWithdrawalTransactionParameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteProveWithdrawalTransactionParameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### writeProveWithdrawalTransactionAsync -`(variables: WriteProveWithdrawalTransactionParameters) => Promise` +`(variables: WriteProveWithdrawalTransactionParameters, { onSuccess, onSettled, onError }) => Promise` Similar to writeProveWithdrawalTransaction but returns a promise which can be awaited. @@ -71,4 +88,21 @@ Similar to writeProveWithdrawalTransaction but returns a promise which can be aw The chain ID of the chain you are withdrawing from. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteProveWithdrawalTransactionParameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteProveWithdrawalTransactionParameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteProveWithdrawalTransactionParameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### The rest of wagmi's [useWriteContract return type](https://beta.wagmi.sh/react/api/hooks/useWrtieContract#return-type) (except `writeContract` and `writeContractAsync`). diff --git a/docs/docs/hooks/L2/useWriteWithdrawERC20.md b/docs/docs/hooks/L2/useWriteWithdrawERC20.md index 0061460..c7c5a03 100644 --- a/docs/docs/hooks/L2/useWriteWithdrawERC20.md +++ b/docs/docs/hooks/L2/useWriteWithdrawERC20.md @@ -36,7 +36,7 @@ Config to use instead of retrieving from the from nearest WagmiProvider. ### writeWithdrawERC20 -`(variables: WriteWithdrawERC20Parameters) => void` +`(variables: WriteWithdrawERC20Parameters, { onSuccess, onSettled, onError }) => void` The mutation function you can call with variables to trigger initiating the ERC20 withdrawal. @@ -73,9 +73,26 @@ The mutation function you can call with variables to trigger initiating the ERC2 The chain ID of the chain you want to withdraw from. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteWithdrawERC20Parameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteWithdrawERC20Parameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteWithdrawERC20Parameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### writeWithdrawERC20Async -`(variables: WriteWithdrawERC20Parameters) => Promise` +`(variables: WriteWithdrawERC20Parameters, { onSuccess, onSettled, onError }) => Promise` Similar to writeWithdrawERC20 but returns a promise which can be awaited. @@ -112,4 +129,21 @@ Similar to writeWithdrawERC20 but returns a promise which can be awaited. The chain ID of the chain you want to withdraw from. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteWithdrawERC20Parameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteWithdrawERC20Parameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteWithdrawERC20Parameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### The rest of wagmi's [useWriteContract return type](https://beta.wagmi.sh/react/api/hooks/useWrtieContract#return-type) (except `writeContract` and `writeContractAsync`). diff --git a/docs/docs/hooks/L2/useWriteWithdrawETH.md b/docs/docs/hooks/L2/useWriteWithdrawETH.md index f892a94..f85fe57 100644 --- a/docs/docs/hooks/L2/useWriteWithdrawETH.md +++ b/docs/docs/hooks/L2/useWriteWithdrawETH.md @@ -35,7 +35,7 @@ Config to use instead of retrieving from the from nearest WagmiProvider. ### writeWithdrawETH -`(variables: WriteWithdrawETHParameters) => void` +`(variables: WriteWithdrawETHParameters, { onSuccess, onSettled, onError }) => void` The mutation function you can call with variables to trigger initiating the ETH withdrawal. @@ -67,9 +67,26 @@ The mutation function you can call with variables to trigger initiating the ETH The chain ID of the chain you want to withdraw from. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteWithdrawETHParameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteWithdrawETHParameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteWithdrawETHParameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### writeWithdrawETHAsync -`(variables: WriteWithdrawETHParameters) => Promise` +`(variables: WriteWithdrawETHParameters, { onSuccess, onSettled, onError }) => Promise` Similar to writeWithdrawETH but returns a promise which can be awaited. @@ -101,4 +118,21 @@ Similar to writeWithdrawETH but returns a promise which can be awaited. The chain ID of the chain you want to withdraw from. +- #### options (optional) + - ##### onSuccess + `(data: WriteContractReturnType, variables: WriteWithdrawETHParameters, context: TContext) => void` + + This function will fire when the mutation is successful and will be passed the mutation's result. + + - ##### onError + `(error: WriteContractErrorType, variables: WriteWithdrawETHParameters, context: TContext | undefined) => void` + + This function will fire if the mutation encounters an error and will be passed the error. + + - ##### onSettled + `(data: WriteContractReturnType | undefined, error: WriteContractErrorType | null, variables: WriteWithdrawETHParameters, context: TContext | undefined) => void` + + - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error + - If you make multiple requests, onSuccess will fire only after the latest call you've made. + ### The rest of wagmi's [useWriteContract return type](https://beta.wagmi.sh/react/api/hooks/useWrtieContract#return-type) (except `writeContract` and `writeContractAsync`). From f32a28f9f5434f2622c70fb4546c6ede07edd441 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:48:10 -0500 Subject: [PATCH 3/3] changeset --- .changeset/twenty-snakes-move.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/twenty-snakes-move.md diff --git a/.changeset/twenty-snakes-move.md b/.changeset/twenty-snakes-move.md new file mode 100644 index 0000000..16f1b64 --- /dev/null +++ b/.changeset/twenty-snakes-move.md @@ -0,0 +1,6 @@ +--- +"@op-wagmi/docs": minor +"op-wagmi": minor +--- + +[feat] support writeContract callbacks