Skip to content

Commit

Permalink
fix up runes
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteAtATime committed Apr 18, 2024
1 parent 7881e34 commit 24f10f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
15 changes: 7 additions & 8 deletions packages/svelte/src/lib/runes/scaffoldReadContract.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type {
AbiFunctionReturnType,
ContractAbi,
ContractName,
CreateScaffoldReadConfig,
import {
resolveVal,
type AbiFunctionReturnType,
type ContractAbi,
type ContractName,
type CreateScaffoldReadConfig,
} from "$lib/utils/scaffold-eth/contract";
import type { ExtractAbiFunctionNames } from "abitype";
import { createDeployedContractInfo } from "./deployedContractInfo.svelte";
Expand All @@ -25,9 +26,7 @@ export const createScaffoldReadContract = <
>(
config: CreateScaffoldReadConfig<TContractName, TFunctionName>,
) => {
const { contractName, functionName, args, value, ...readConfig } = $derived(
config instanceof Function ? config() : config,
);
const { contractName, functionName, args, value, ...readConfig } = $derived(resolveVal(config));
const { data: deployedContract } = $derived.by(createDeployedContractInfo(contractName));
const targetNetwork = $derived.by(createTargetNetwork());

Expand Down
24 changes: 23 additions & 1 deletion packages/svelte/src/lib/utils/scaffold-eth/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export type FunctionNamesWithInputs<
}
>["name"];

type FuncOrValue<T> = () => T | T;
type FuncOrVal<T> = () => T | T;
export const resolveVal = <T>(val: FuncOrVal<T>) => (val instanceof Function ? val() : val);

type Expand<T> = T extends object ? (T extends infer O ? { [K in keyof O]: O[K] } : never) : T;

Expand All @@ -159,6 +160,7 @@ type UseScaffoldArgsParam<
TFunctionName extends ExtractAbiFunctionNames<ContractAbi<TContractName>>,
> =
TFunctionName extends FunctionNamesWithInputs<TContractName>
<<<<<<< HEAD
? {
args: FuncOrValue<
OptionalTupple<UnionToIntersection<AbiFunctionArguments<ContractAbi<TContractName>, TFunctionName>>>
Expand All @@ -173,19 +175,39 @@ type UseScaffoldArgsParam<
args?: never;
value?: never;
};
=======
? {
args: OptionalTupple<UnionToIntersection<AbiFunctionArguments<ContractAbi<TContractName>, TFunctionName>>>;
value?: ExtractAbiFunction<ContractAbi<TContractName>, TFunctionName>["stateMutability"] extends "payable"
? bigint | undefined
: undefined;
}
: {
args?: never;
value?: never;
};
>>>>>>> d95b17a (fix up createScaffoldReadContract types)

export type CreateScaffoldReadConfig<
TContractName extends ContractName,
TFunctionName extends ExtractAbiFunctionNames<ContractAbi<TContractName>, ReadAbiStateMutability>,
<<<<<<< HEAD
> = FuncOrValue<
=======
> = FuncOrVal<
>>>>>>> d95b17a (fix up createScaffoldReadContract types)
{
contractName: TContractName;
} & IsContractDeclarationMissing<
Partial<CreateReadContractParameters>,
{
functionName: TFunctionName;
} & UseScaffoldArgsParam<TContractName, TFunctionName> &
<<<<<<< HEAD
Omit<CreateReadContractParameters, "chainId" | "abi" | "address" | "functionName" | "args">
=======
Omit<CreateReadContractParameters, "chainId" | "abi" | "address" | "functionName" | "args">
>>>>>>> d95b17a (fix up createScaffoldReadContract types)
>
>;

Expand Down

0 comments on commit 24f10f4

Please sign in to comment.