Closed dcsan closed 2 years ago
sure. I will add a CLAIMED event with the tokenId argument
can you help find how to listen for these events? I don't currently know... in order to trigger a UI update...
I think something like this is used in UI const transferEvents = useEventListener(readContracts, "YourCollectible", "Transfer", localProvider, 1);
I haven't used this enough. So not sure how to subscribe to it to know a state change.
or we can bind the UI state to isClaimed() method output itself?
yeah we could do that... i'll have to figure out how to trigger a UI update from that. usually its when a state variable changes further upstream. we could 'set' something...
i think this is what does it:
// keep track of a variable from the contract in the local React state:
const balance = useContractReader(readContracts, "YourCollectible", "balanceOf", [address]);
console.log("🤗 balance:", balance);
// 📟 Listen for broadcast events
const transferEvents = useEventListener(readContracts, "YourCollectible", "Transfer", localProvider, 1);
console.log("📟 Transfer events:", transferEvents);
//
// 🧠This effect will update yourCollectibles by polling when your balance changes
//
const yourBalance = balance && balance.toNumber && balance.toNumber();
const [yourCollectibles, setYourCollectibles] = useState();
so if there's a transfer balance will change and that updates collectibles...
It would be closer to the balanceOf example in that snippet.
Something like: const tokenIsClaimed = useContractReader(readContracts, "YourCollectible", "isClaimed", [tokenId]);
But made to work for dynamic tokenIds.
The contract has code to emit a Claim event.
The remainder is explained by #70
currently UI doesn't update on claim, i think the scaffold is listening for events as it updates in other places...
can you look into what to emit there?