diff --git a/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx b/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx index c8d184e2a..e77bde50b 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx @@ -5,6 +5,7 @@ import { ContractName, GenericContract, InheritedFunctions, + getFunctionsByStateMutability, } from "~~/utils/scaffold-stark/contract"; import { ReadOnlyFunctionForm } from "./ReadOnlyFunctionForm"; @@ -17,36 +18,19 @@ export const ContractReadMethods = ({ return null; } - const functionsToDisplay = ((deployedContractData.abi || []) as Abi) - .reduce((acc, part) => { - if (part.type === "function") { - acc.push(part); - } else if (part.type === "interface" && Array.isArray(part.items)) { - part.items.forEach((item) => { - if (item.type === "function") { - acc.push(item); - } - }); - } - return acc; - }, [] as AbiFunction[]) + const functionsToDisplay = getFunctionsByStateMutability( + (deployedContractData.abi || []) as Abi, + "view", + ) .filter((fn) => { - const isQueryableWithParams = - fn.state_mutability === "view" && fn.inputs.length > 0; + const isQueryableWithParams = fn.inputs.length > 0; return isQueryableWithParams; }) .map((fn) => { return { fn, - // inheritedFrom: ( - // (deployedContractData as GenericContract) - // ?.inheritedFunctions as InheritedFunctions - // )?.[fn.name], }; }); - // .sort((a, b) => - // b.inheritedFrom ? b.inheritedFrom.localeCompare(a.inheritedFrom) : 1 - // ); if (!functionsToDisplay.length) { return <>No read methods; } @@ -58,7 +42,6 @@ export const ContractReadMethods = ({ contractAddress={deployedContractData.address} abiFunction={fn} key={fn.name} - // inheritedFrom={inheritedFrom} /> ))} diff --git a/packages/nextjs/app/debug/_components/contract/ContractVariables.tsx b/packages/nextjs/app/debug/_components/contract/ContractVariables.tsx index 3c2013b30..f3fc73465 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractVariables.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractVariables.tsx @@ -5,6 +5,7 @@ import { ContractName, GenericContract, InheritedFunctions, + getFunctionsByStateMutability, } from "~~/utils/scaffold-stark/contract"; import { DisplayVariable } from "./DisplayVariable"; @@ -19,37 +20,19 @@ export const ContractVariables = ({ return null; } - const functionsToDisplay = ((deployedContractData.abi || []) as Abi) - .reduce((acc, part) => { - if (part.type === "function") { - acc.push(part); - } else if (part.type === "interface" && Array.isArray(part.items)) { - part.items.forEach((item) => { - if (item.type === "function") { - acc.push(item); - } - }); - } - return acc; - }, [] as AbiFunction[]) + const functionsToDisplay = getFunctionsByStateMutability( + (deployedContractData.abi || []) as Abi, + "view", + ) .filter((fn) => { - const isQueryableWithNoParams = - fn.state_mutability === "view" && fn.inputs.length === 0; - return isQueryableWithNoParams; + const isQueryableWithParams = fn.inputs.length === 0; + return isQueryableWithParams; }) .map((fn) => { return { fn, - // inheritedFrom: ( - // (deployedContractData as GenericContract) - // ?.inheritedFunctions as InheritedFunctions - // )?.[fn.name], }; }); - // .sort((a, b) => - // b.inheritedFrom ? b.inheritedFrom.localeCompare(a.inheritedFrom) : 1 - // ); - if (!functionsToDisplay.length) { return <>No contract variables; } diff --git a/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx b/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx index aa076d5be..f124110e6 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx @@ -6,6 +6,7 @@ import { ContractName, GenericContract, InheritedFunctions, + getFunctionsByStateMutability, } from "~~/utils/scaffold-stark/contract"; export const ContractWriteMethods = ({ @@ -19,35 +20,14 @@ export const ContractWriteMethods = ({ return null; } - const functionsToDisplay = ((deployedContractData.abi || []) as Abi) - .reduce((acc, part) => { - if (part.type === "function") { - acc.push(part); - } else if (part.type === "interface" && Array.isArray(part.items)) { - part.items.forEach((item) => { - if (item.type === "function") { - acc.push(item); - } - }); - } - return acc; - }, [] as AbiFunction[]) - .filter((fn) => { - const isWriteableFunction = fn.state_mutability == "external"; - return isWriteableFunction; - }) - .map((fn) => { - return { - fn, - // inheritedFrom: ( - // (deployedContractData as GenericContract) - // ?.inheritedFunctions as InheritedFunctions - // )?.[fn.name], - }; - }); - // .sort((a, b) => - // b.inheritedFrom ? b.inheritedFrom.localeCompare(a.inheritedFrom) : 1 - // ); + const functionsToDisplay = getFunctionsByStateMutability( + (deployedContractData.abi || []) as Abi, + "external", + ).map((fn) => { + return { + fn, + }; + }); if (!functionsToDisplay.length) { return <>No write methods; diff --git a/packages/nextjs/app/debug/_components/contract/DisplayVariable.tsx b/packages/nextjs/app/debug/_components/contract/DisplayVariable.tsx index 0e2a04d66..43d338324 100644 --- a/packages/nextjs/app/debug/_components/contract/DisplayVariable.tsx +++ b/packages/nextjs/app/debug/_components/contract/DisplayVariable.tsx @@ -27,6 +27,7 @@ export const DisplayVariable = ({ }: DisplayVariableProps) => { const { data: result, + isLoading, isFetching, refetch, } = useContractRead({ @@ -52,7 +53,7 @@ export const DisplayVariable = ({ className="btn btn-ghost btn-xs" onClick={async () => await refetch()} > - {isFetching ? ( + {!isLoading && isFetching ? ( ) : ( >(() => getInitialFormState(abiFunction), ); - const [result, setResult] = useState(); + const [inputValue, setInputValue] = useState(); - const { isLoading, isFetching, refetch } = useContractRead({ + const { isLoading, isFetching, data } = useContractRead({ address: contractAddress, functionName: abiFunction.name, abi: [...abi], - args: getParsedContractFunctionArgs(form), + args: inputValue, enabled: false, // TODO : notify when failed - add error blockIdentifier: "pending" as BlockNumber, }); @@ -49,7 +49,7 @@ export const ReadOnlyFunctionForm = ({ { - setResult(undefined); + setInputValue(undefined); setForm(updatedFormValue); }} form={form} @@ -68,11 +68,11 @@ export const ReadOnlyFunctionForm = ({ {inputElements}
- {result !== null && result !== undefined && ( + {data !== null && data !== undefined && (

Result:

-                {displayTxResult(result, false, abiFunction?.outputs)}
+                {displayTxResult(data, false, abiFunction?.outputs)}
               
)} @@ -80,8 +80,7 @@ export const ReadOnlyFunctionForm = ({