Skip to content

Commit

Permalink
Only add uids to overloaded functions
Browse files Browse the repository at this point in the history
  • Loading branch information
portdeveloper committed Mar 14, 2024
1 parent 5bc6506 commit d841651
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions packages/nextjs/components/scaffold-eth/Contract/ContractUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, AbiFunction[]> = {};
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();

/**
Expand All @@ -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 => {
Expand Down

0 comments on commit d841651

Please sign in to comment.