1

Greetings to the one reading this issue. My project uses:

  1. Ganache - Deployment
  2. Solidity - Smart Contract
  3. React - Frontend
  4. Metamask - Wallet

Here is the screenshot of the problem. I am unable to access the array of type string [ ] [ ]

Application interface

snippet of 100th line

I am working on a project which basically stores medical records of a patient on the blockchain. There can be insurance companies who can request a patient to share their medical records. And the patient can choose to accept these requests or not. This is one of the functionality that i am stuck implementing.

I want: To display the requests in a 3 columned Table, (Insurance Company name, Accept, Reject)

Code from Smart Contract:

function getaccessRequestedList() public view returns (string[][] memory) {
    // require(bytes(patients[msg.sender].user.name).length != 0, "You are not a patient");

    address[] memory requestedUsers = accessRequestedUserList[msg.sender];
    string[][] memory result = new string[][](requestedUsers.length);

    for (uint i = 0; i < requestedUsers.length; i++) {
        result[i] = new string[](2); // Each inner array has 2 elements
        result[i][0] = addressToString(requestedUsers[i]); // Convert address to string
        result[i][1] = users[requestedUsers[i]].name;
    }

    return result;
}

So Basically this is the function that is returning the requests from the Insurance companies to the patients in a String[ ][ ] format.

Firstly, [0] : 'InsCompany_Address' (I need the address to be passed as value if 'Grant' button is selected)

Next element, 1 : 'InsCompany_Name'

Frontend React Code:

async function getaccessRequestedList() {
if (typeof window.ethereum !== "undefined") {
  try {
    const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    const contract = new ethers.Contract(contractAddress, abi, provider);
    const accessRequestedList = await contract.getaccessRequestedList();
    setAccessRequest(accessRequestedList);
    console.log(accessRequestedList);
  } catch (error) {
    alert(error);
    console.log(error);
  }
} else {
  alert("Metamask not installed");
}} 

// Rest of the frontend code and Finally

return (
<div style={tableStyle}>
  <div style={{ display: "flex" }}>
    <Link to="/patientprofile" style={buttonLinkStyle}>
      <button style={buttonStyle}>Back to Patient Profile</button>
    </Link>
  </div>
  <h1 style={headingStyle}>Pending Access Requests</h1>
  {accessRequest == "" ? (
    <div>You have no request pending</div>
  ) : (
    <div style={{ width: "100%" }}>
      <div style={tableHeadStyle}>
        <div style={firstCellStyle}>
          <p>Name</p>
        </div>
        <div style={acceptCellStyle}>
          <p>Accept</p>
        </div>
        <div style={deleteCellStyle}>
          <p>Delete</p>
        </div>
      </div>
      {accessRequest.map((request, index) => {
        return (
          <div style={tableRowStyle} key={index}>
            <div style={firstCellStyle}>
              <p>{request[1]}</p>
            </div>
            <div style={acceptCellStyle}>
              <p>
                <TiTick style={{ cursor: "pointer" }} onClick={() => grantAccess(request[0])} size={25} />
              </p>
            </div>
            <div style={deleteCellStyle}>
              <p>
                <AiFillDelete />
              </p>
            </div>
          </div>
        );
      })}
    </div>
  )}
</div>);

Now you might feel its a problem of the Backend but no, it is of the frontend as you can see, I can get the exact results here.

Remix IDE debug

I've been at it for more than 2 days, It would be of great help if you could help me out over here. Thank you.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.