Skip to content

Commit

Permalink
add better structs to ReadOnlyFunctionForm too
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 committed Feb 10, 2024
1 parent df3fd3e commit 1394397
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 21 additions & 1 deletion packages/hardhat/contracts/YourContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,27 @@ contract YourContract {
sData = _nestedStruct; // Assigns the entire struct. For dynamic arrays, you might need more complex logic.
}

// Function to get the current data
// Read function which accepts _nestedStruct
function totalPassedStruct(
NestedStruct calldata _nestedStruct
) public pure returns (uint totalA, uint totalX, uint totalY) {
totalA = _nestedStruct.a;
uint totalXSum = 0;
uint totalYSum = 0;

for (uint i = 0; i < _nestedStruct.b.length; i++) {
for (uint j = 0; j < _nestedStruct.b[i].length; j++) {
for (uint k = 0; k < _nestedStruct.b[i][j].length; k++) {
totalXSum += _nestedStruct.b[i][j][k].x;
totalYSum += _nestedStruct.b[i][j][k].y;
}
}
}

return (totalA, totalXSum, totalYSum);
}

// Function to get the current datahe current data
function geAllSData() public view returns (NestedStruct memory) {
return (sData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getFunctionInputKey,
getInitialFormState,
getParsedContractFunctionArgs,
transformAbiFunction,
} from "~~/app/debug/_components/contract";
import { getParsedError, notification } from "~~/utils/scaffold-eth";

Expand Down Expand Up @@ -42,7 +43,8 @@ export const ReadOnlyFunctionForm = ({
},
});

const inputElements = abiFunction.inputs.map((input, inputIndex) => {
const transformedFunction = transformAbiFunction(abiFunction);
const inputElements = transformedFunction.inputs.map((input, inputIndex) => {
const key = getFunctionInputKey(abiFunction.name, input, inputIndex);
return (
<ContractInput
Expand Down

0 comments on commit 1394397

Please sign in to comment.