scaffold-eth / scaffold-eth-2

Open source forkable Ethereum dev stack
https://scaffoldeth.io
MIT License
1.41k stars 887 forks source link

useScaffoldEventHistory uses data from old fetch with different filters #903

Closed phaitonican closed 2 months ago

phaitonican commented 3 months ago

Is there an existing issue for this?

Which method was used to setup Scaffold-ETH 2 ?

git clone

Current Behavior

I use useScaffoldEventHistory twice on a single page with different filters. It fetches right data. I run again and the old data does not change, it use overrides the data with first run of useScaffoldEventHistory (even the constants have a differnt name). Any ideas??

This:

<PostCardList key="-1" filters={{ _post_hash: postHash }} />
<PostCardList key="-2" filters={{ _parent_post_hash: postHash }} />

and PostCardList.tsx:

export const PostCardList = ({ filters }: PostCardListProps) => {

const { data: postCreatedEvents, isLoading } = useScaffoldEventHistory({
    contractName: "PostCreator",
    eventName: "PostCreated",
    fromBlock: 0n,
    watch: true,
    filters: filters 
  });
...

But the second One gets overridden with contents of first one?? Both solidity parameters are indexed. And I also put a key inside my looped list items (unique hash)

Expected Behavior

No response

Steps To Reproduce

Use useScaffoldEventHistory on same page with different filters

Anything else?

No response

technophile-04 commented 3 months ago

Thanks @phaitonican! Would appreciate if you could share an link to minimal reproducible repo with example simple contract and using the hook on same page causing problem.

phaitonican commented 3 months ago

Hello. Here is the minimal reproduciable repo https://github.com/phaitonican/scuffold-eth-2-event-history-test

Just have open http://localhost:3000/test site. It call component with useScaffoldEventHistory twice on same Page (test/page.tsx). Just Simple smart contract with counter function which emit signal (Test.sol), run twice inside deployement script

rin-st commented 3 months ago

@phaitonican thank you for your example! Please add changes from suggested pr and check if it works for you

phaitonican commented 2 months ago

It does work thanks very much