Skip to content

Commit

Permalink
Update useScaffoldWrite and useScaffoldRead
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadai2010 committed Oct 15, 2024
1 parent db48a88 commit e6982ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions packages/nextjs/components/stake/StakeContractInteraction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,18 @@ export const StakeContractInteraction = ({ address }: { address?: string }) => {
const { data: threshold } = useScaffoldReadContract({
contractName: "Staker",
functionName: "threshold",
args: [],
watch: true,
});

const { data: timeLeft } = useScaffoldReadContract({
contractName: "Staker",
functionName: "time_left",
args: [],
watch: true,
});

const { data: isStakingCompleted } = useScaffoldReadContract({
contractName: "Staker",
functionName: "completed",
args: [],
watch: true,
});

Expand All @@ -65,10 +62,11 @@ export const StakeContractInteraction = ({ address }: { address?: string }) => {
contractName: "Staker",
functionName: "execute",
});

const { sendAsync: withdrawETH } = useScaffoldWriteContract({
contractName: "Staker",
functionName: "withdraw",
args: [],
args: []
});

const { sendAsync: stakeEth } = useScaffoldMultiWriteContract({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ 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,
...(readConfig as any),
}) as Omit<ReturnType<typeof useReadContract>, "data"> & {
data: AbiFunctionOutputs<ContractAbi, TFunctionName> | undefined;
};
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down Expand Up @@ -134,4 +134,4 @@ export const useScaffoldWriteContract = <
...sendTransactionInstance,
sendAsync: sendContractWriteTx,
};
};
};

0 comments on commit e6982ee

Please sign in to comment.