From d841651135f84300e10b4fb975c33bbf35aaa688 Mon Sep 17 00:00:00 2001 From: port <108868128+portdeveloper@users.noreply.github.com> Date: Thu, 14 Mar 2024 09:12:24 +0300 Subject: [PATCH] Only add uids to overloaded functions --- .../scaffold-eth/Contract/ContractUI.tsx | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/packages/nextjs/components/scaffold-eth/Contract/ContractUI.tsx b/packages/nextjs/components/scaffold-eth/Contract/ContractUI.tsx index 9e29f587..592bab93 100644 --- a/packages/nextjs/components/scaffold-eth/Contract/ContractUI.tsx +++ b/packages/nextjs/components/scaffold-eth/Contract/ContractUI.tsx @@ -22,6 +22,39 @@ export interface AugmentedAbiFunction extends AbiFunction { uid: string; } +const augmentMethodsWithUid = (methods: AbiFunction[]): AugmentedAbiFunction[] => { + // Group methods by their name to identify overloaded functions + const methodsByName: Record = {}; + methods.forEach(method => { + if (!methodsByName[method.name]) { + methodsByName[method.name] = []; + } + methodsByName[method.name].push(method); + }); + + // Process each method, adding UID with index only for overloaded functions + const augmentedMethods: AugmentedAbiFunction[] = []; + Object.entries(methodsByName).forEach(([, group]) => { + if (group.length > 1) { + // overloaded methods + group.forEach((method, index) => { + augmentedMethods.push({ + ...method, + uid: `${method.name}_${index}`, + }); + }); + } else { + // regular methods + augmentedMethods.push({ + ...group[0], + uid: group[0].name, + }); + } + }); + + return augmentedMethods; +}; + const mainNetworks = getTargetNetworks(); /** @@ -47,13 +80,6 @@ export const ContractUI = ({ className = "", initialContractData }: ContractUIPr router.push({ pathname: newPath, query: currentQuery.toString() }, undefined, { shallow: true }); }; - const augmentMethodsWithUid = (methods: AbiFunction[]): AugmentedAbiFunction[] => { - return methods.map((method, index) => ({ - ...method, - uid: `${method.name}_${index}`, // Simple UID based on index - })); - }; - const readMethodsWithInputsAndWriteMethods = useMemo(() => { return augmentMethodsWithUid( initialContractData.abi.filter((method): method is AbiFunction => {