Skip to content

Commit

Permalink
feat: add prepare error and loading variables to contract write hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aramalipoor committed Oct 3, 2022
1 parent d862f3f commit 31b1c0b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/react/src/common/hooks/useContractWriteAndWait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ export const useContractWriteAndWait = <ArgsType extends any[] = any[]>({
const { isConnected } = useAccount();
const { chain } = useNetwork();

const { config, data } = usePrepareContractWrite({
const {
config,
data: prepareData,
error: prepareError,
isError: prepareIsError,
isLoading: prepareLoading,
} = usePrepareContractWrite({
addressOrName: contractAddress as string,
contractInterface,
functionName,
Expand Down Expand Up @@ -107,15 +113,15 @@ export const useContractWriteAndWait = <ArgsType extends any[] = any[]>({

return {
data: {
...data,
...prepareData,
txResponse: responseData,
txReceipt: receiptData,
},
error: responseError || receiptError,
error: prepareError || responseError || receiptError,
isIdle: responseIsIdle && receiptIsIdle,
isLoading: responseIsLoading || receiptIsLoading,
isLoading: prepareLoading || responseIsLoading || receiptIsLoading,
isSuccess: responseIsSuccess && receiptIsSuccess,
isError: responseIsError || receiptIsError,
isError: prepareIsError || responseIsError || receiptIsError,
writeAndWait: doWrite ? writeAndWait : undefined,
} as const;
};

0 comments on commit 31b1c0b

Please sign in to comment.