Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add uids to overloaded methods #73

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading