Created
February 20, 2022 12:49
-
-
Save zh/6f69f441483c067e316726548c782c4b to your computer and use it in GitHub Desktop.
refresh with events
This file contains 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
const setEventHandlers = () => { | |
if (!contract || !currentAccount) { | |
return; | |
} | |
console.log('add event contract handlers'); | |
try { | |
contract.on('DomainMinted', async () => { | |
console.log('event: domain minted'); | |
await fetchMints(); | |
}); | |
contract.on('MetadataUpdated', async () => { | |
console.log('event: metadata updated'); | |
await fetchMints(); | |
}); | |
} catch (error) { | |
console.log(error); | |
} | |
}; | |
useEffect(() => { | |
if (network === 'Polygon Mumbai Testnet') { | |
fetchMints(); | |
setEventHandlers(); | |
} | |
}, [!!contract, currentAccount]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment