GraphemeNFT / rarible-scaffold

MIT License
0 stars 0 forks source link

emit event on claim #45

Closed dcsan closed 2 years ago

dcsan commented 2 years ago

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?

keepRunning commented 2 years ago

sure. I will add a CLAIMED event with the tokenId argument

dcsan commented 2 years ago

can you help find how to listen for these events? I don't currently know... in order to trigger a UI update...

keepRunning commented 2 years ago

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.

keepRunning commented 2 years ago

or we can bind the UI state to isClaimed() method output itself?

dcsan commented 2 years ago

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...

dcsan commented 2 years ago

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...

tomosaigon commented 2 years ago

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.

tomosaigon commented 2 years ago

The contract has code to emit a Claim event.

The remainder is explained by #70