diff --git a/packages/nextjs/hooks/scaffold-stark/useScaffoldMultiWriteContract.ts b/packages/nextjs/hooks/scaffold-stark/useScaffoldMultiWriteContract.ts index e6661477..a119737e 100644 --- a/packages/nextjs/hooks/scaffold-stark/useScaffoldMultiWriteContract.ts +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldMultiWriteContract.ts @@ -34,53 +34,53 @@ export const useScaffoldMultiWriteContract = < const { chain } = useNetwork(); const sendTxnWrapper = useTransactor(); - const parsedCalls = useMemo(() => { - if (calls) { - return calls.map((call) => { - const functionName = call.functionName; - const contractName = call.contractName; - const unParsedArgs = call.args as any[]; - const contract = contracts?.[targetNetwork.network]?.[ - contractName as ContractName - ] as Contract; + // TODO: commented out in case we need it again + // const parsedCalls = useMemo(() => { + // if (calls) { + // return calls.map((call) => { + // const functionName = call.functionName; + // const contractName = call.contractName; + // const unParsedArgs = call.args as any[]; + // const contract = contracts?.[targetNetwork.network]?.[ + // contractName as ContractName + // ] as Contract; - // TODO: see if we still need this - // const abiFunction = getFunctionsByStateMutability( - // contract?.abi || [], - // "external", - // ).find((fn) => fn.name === functionName); + // // TODO: see if we still need this + // // const abiFunction = getFunctionsByStateMutability( + // // contract?.abi || [], + // // "external", + // // ).find((fn) => fn.name === functionName); - // we convert to starknetjs contract instance here since deployed data may be undefined if contract is not deployed - const contractInstance = new StarknetJsContract( - contract.abi, - contract.address, - ); + // // we convert to starknetjs contract instance here since deployed data may be undefined if contract is not deployed + // const contractInstance = new StarknetJsContract( + // contract.abi, + // contract.address, + // ); - return { - ...contractInstance.populate(functionName, unParsedArgs as any[]), + // return { + // ...contractInstance.populate(functionName, unParsedArgs as any[]), - // TODO: see if we still need this - // calldata: - // abiFunction && unParsedArgs && contract - // ? parseFunctionParams({ - // abiFunction, - // isRead: false, - // inputs: unParsedArgs as any[], - // isReadArgsParsing: false, - // abi: contract.abi, - // }).flat() - // : [], - }; - }); - } else { - return []; - } - }, [calls, targetNetwork.network]); + // // TODO: see if we still need this + // // calldata: + // // abiFunction && unParsedArgs && contract + // // ? parseFunctionParams({ + // // abiFunction, + // // isRead: false, + // // inputs: unParsedArgs as any[], + // // isReadArgsParsing: false, + // // abi: contract.abi, + // // }).flat() + // // : [], + // }; + // }); + // } else { + // return []; + // } + // }, [calls, targetNetwork.network]); // TODO add custom options - const sendTransactionInstance = useSendTransaction({ - calls: parsedCalls, - }); + + const sendTransactionInstance = useSendTransaction({}); const sendContractWriteTx = async () => { if (!chain?.id) { @@ -94,8 +94,37 @@ export const useScaffoldMultiWriteContract = < if (sendTransactionInstance.sendAsync) { try { + // we just parse calldata here so that it will only parse on demand. + // use IIFE pattern + const parsedCalls = (() => { + if (calls) { + return calls.map((call) => { + const functionName = call.functionName; + const contractName = call.contractName; + const unParsedArgs = call.args as any[]; + const contract = contracts?.[targetNetwork.network]?.[ + contractName as ContractName + ] as Contract; + // we convert to starknetjs contract instance here since deployed data may be undefined if contract is not deployed + const contractInstance = new StarknetJsContract( + contract.abi, + contract.address, + ); + + return contractInstance.populate( + functionName, + unParsedArgs as any[], + ); + }); + } else { + return []; + } + })(); + // setIsMining(true); - return await sendTxnWrapper(() => sendTransactionInstance.sendAsync()); + return await sendTxnWrapper(() => + sendTransactionInstance.sendAsync(parsedCalls), + ); } catch (e: any) { throw e; } finally {