Skip to content

Commit

Permalink
feat: filter contract logs for events (#300)
Browse files Browse the repository at this point in the history
* feat: filter contract logs for events

* chore: add changeset

* Cleanup setting events

Co-authored-by: Łukasz Stankiewicz <[email protected]>
  • Loading branch information
lcamargof and nezouse authored Aug 23, 2021
1 parent 0a98795 commit afe26a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-worms-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@usedapp/core': minor
---

Prevent crash when parsing transaction logs from contract call
11 changes: 5 additions & 6 deletions packages/core/src/hooks/useContractFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ export function useContractFunction(contract: Contract, functionName: string, op
async (...args: any[]) => {
const contractWithSigner = connectContractToSigner(contract, options, library)
const receipt = await promiseTransaction(contractWithSigner[functionName](...args))
if (receipt) {
if (receipt.logs && receipt.logs.length > 0) {
setEvents(receipt.logs.map((log) => contract.interface.parseLog(log)))
} else {
setEvents([])
}
if (receipt?.logs) {
const events = receipt.logs
.filter((log) => log.address === contract.address)
.map((log) => contract.interface.parseLog(log))
setEvents(events)
}
},
[contract, functionName, options, library]
Expand Down

0 comments on commit afe26a5

Please sign in to comment.