From 0e5d371d0b2c57821165cf61434c637180c324dd Mon Sep 17 00:00:00 2001 From: Nadai2010 Date: Tue, 15 Oct 2024 23:11:39 +0100 Subject: [PATCH] The new changes in useScaffoldWriteContract give me error if I don't add the `args: []` --- packages/nextjs/app/token-vendor/page.tsx | 1 - .../nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts | 2 +- .../nextjs/hooks/scaffold-stark/useScaffoldWriteContract.ts | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/nextjs/app/token-vendor/page.tsx b/packages/nextjs/app/token-vendor/page.tsx index 61f46c9e..c5de52b5 100644 --- a/packages/nextjs/app/token-vendor/page.tsx +++ b/packages/nextjs/app/token-vendor/page.tsx @@ -47,7 +47,6 @@ const TokenVendor: NextPage = () => { const { data: tokensPerEth } = useScaffoldReadContract({ contractName: "Vendor", functionName: "tokens_per_eth", - args: [], }); const { sendAsync: transferTokens } = useScaffoldWriteContract({ diff --git a/packages/nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts b/packages/nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts index 511b2c94..fae3d663 100644 --- a/packages/nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts @@ -29,7 +29,7 @@ export const useScaffoldReadContract = < address: deployedContract?.address, abi: deployedContract?.abi, watch: true, - args, + args: args || [], enabled: args && (!Array.isArray(args) || !args.some((arg) => arg === undefined)), blockIdentifier: "pending" as BlockNumber, diff --git a/packages/nextjs/hooks/scaffold-stark/useScaffoldWriteContract.ts b/packages/nextjs/hooks/scaffold-stark/useScaffoldWriteContract.ts index 1c082912..9fce2ee5 100644 --- a/packages/nextjs/hooks/scaffold-stark/useScaffoldWriteContract.ts +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldWriteContract.ts @@ -76,7 +76,7 @@ export const useScaffoldWriteContract = < }) => { // if no args supplied, use the one supplied from hook let newArgs = params?.args; - if (!newArgs) { + if (Object.keys(newArgs || {}).length <= 0) { newArgs = args; } @@ -100,7 +100,7 @@ export const useScaffoldWriteContract = < ? parseFunctionParams({ abiFunction, abi: deployedContractData.abi, - inputs: args as any[], + inputs: newArgs as any[], isRead: false, isReadArgsParsing: false, }).flat(Infinity)