Closed LorenzoZaccagnini closed 4 years ago
Hi! Im having the same issue, I need to retrieve data from a method of my solidity contract and then call another method from my contract using the data output from the first method. The thing is that the first method outputs undefined, and the only way to make it work is to force it to update, did you find a solution for this ? please I need help :c
`const {drizzle, drizzleState} = props; const contract = drizzle.contracts.PepoCollectibles; const {PepoCollectibles} = drizzleState.contracts; const [currentAcc, setCurrentAcc] = useState(drizzleState.accounts[0]); const [balance, setBalance] = useState(null);
useEffect(() => {
getBalanceOf();
let last = getItemByIndex(balance - 1);
});
const getBalanceOf = () => {
const _dataKey = contract.methods["balanceOf"].cacheCall(currentAcc);
const res = PepoCollectibles.balanceOf[_dataKey];
let value = res && res.value;
setBalance(res && res.value);
}
const getItemByIndex = index => {
if(!index) return;
const _dataKey = contract.methods["tokenOfOwnerByIndex"].cacheCall(currentAcc, index);
const res = PepoCollectibles.tokenOfOwnerByIndex[_dataKey];
return res && res.value;
}`
Is there a fix/workaround yet?
Hi, I'm having problems with cacheCall (pragma 0.5 so no 0.6 compatibility issues), I set the dataKey but when I try to retrieve the value using
Devoleum.getMerchantInfo[dataKey]
It's undefined, the only thing that works is to force rerendering (the value comes out if I force the Devoleum.getMerchantInfo[dataKey] multiple times) but this causes many performance issues and it's not the correct practice.
This is my React snippet
This is the solidity function:
I've even integrated in my smart contract and frontend the tutorial read/set string part and it works correctly, I don't know what causes this issue with my getMerchantInfo function, maybe a racing condition.