Created
April 21, 2020 20:05
-
-
Save caseyjkey/b1488d34016197889ab84d9e33ab388a to your computer and use it in GitHub Desktop.
Access mapping from address to Struct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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