Skip to content

Commit

Permalink
pass parameters reactively into createReadContract in createScaffoldR…
Browse files Browse the repository at this point in the history
…eadContract
  • Loading branch information
ByteAtATime committed Apr 16, 2024
1 parent 4e3b0df commit 40c38ea
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions packages/svelte/src/lib/runes/scaffoldReadContract.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,25 @@ export const createScaffoldReadContract = <
const targetNetwork = $derived.by(createTargetNetwork());

const result = $derived.by(
createReadContract({
chainId: targetNetwork.id,
functionName,
address: deployedContract?.address,
abi: deployedContract?.abi,
watch: true,
args: args,
value: value,
enabled: !Array.isArray(args) || !args.some(arg => arg === undefined),
...(readConfig as any),
}) as () => Omit<ReturnType<CreateReadContractReturnType>, "data" | "refetch"> & {
data: AbiFunctionReturnType<ContractAbi, TFunctionName> | undefined;
refetch: (
options?: RefetchOptions | undefined,
) => Promise<QueryObserverResult<AbiFunctionReturnType<ContractAbi, TFunctionName>, ReadContractErrorType>>;
},
createReadContract(
() =>
({
chainId: targetNetwork.id,
functionName,
address: deployedContract?.address,
abi: deployedContract?.abi,
watch: true,
args: args,
value: value,
enabled: !Array.isArray(args) || !args.some(arg => arg === undefined),
...(readConfig as any),
}) as () => Omit<ReturnType<CreateReadContractReturnType>, "data" | "refetch"> & {
data: AbiFunctionReturnType<ContractAbi, TFunctionName> | undefined;
refetch: (
options?: RefetchOptions | undefined,
) => Promise<QueryObserverResult<AbiFunctionReturnType<ContractAbi, TFunctionName>, ReadContractErrorType>>;
},
),
);

return () => result;
Expand Down

0 comments on commit 40c38ea

Please sign in to comment.