Skip to content

Instantly share code, notes, and snippets.

@caseyjkey
Created April 21, 2020 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caseyjkey/b1488d34016197889ab84d9e33ab388a to your computer and use it in GitHub Desktop.
Save caseyjkey/b1488d34016197889ab84d9e33ab388a to your computer and use it in GitHub Desktop.
Access mapping from address to Struct
import React, { useEffect, useState, useContext } from "react";
import { DrizzleContext } from "@drizzle/react-plugin";
export default () => {
const drizzleContext = useContext(DrizzleContext.Context);
const [dataKey, setDataKey] = useState(null);
const [group, setGroup] = useState(null);
const account = drizzleContext.drizzleState.accounts[0];
const web3 = drizzleContext.drizzle.web3;
useEffect(() => {
if (drizzleContext.initialized) {
const contract = drizzleContext.drizzle.contracts.ComplexStorage;
const dataKey = contract.methods["userToGroup"].cacheCall(account);
setDataKey(dataKey);
console.log(dataKey);
}
}, [drizzleContext.initialized]);
useEffect(() => {
if (dataKey) {
const ContractStore = drizzleContext.drizzleState.contracts.ComplexStorage;
// Use the saved 'dataKey' to get the return value from earlier.
setGroup(ContractStore.userToGroup[dataKey].value)
console.log(group);
}
}, [drizzleContext.drizzleState]);
return (
<div className="navbar">
<h2>{account}'s Group: {group && group.name}</h2>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment