Skip to content

Commit eb5fb88

Browse files
tuphan-dnjxom
andauthored
fix: clearTimeout in waitForUserOperationReceipt (#4058)
* fix: clearTimeout in waitForUserOperationReceipt * chore: add changeset * Update clever-buttons-cut.md --------- Co-authored-by: jxom <7336481+jxom@users.noreply.github.com>
1 parent 2bfa29e commit eb5fb88

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

.changeset/clever-buttons-cut.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"viem": patch
3+
---
4+
5+
Fixed a bug where the timeout in `waitForUserOperationReceipt` was not properly cleared after the receipt was returned.

src/account-abstraction/actions/bundler/waitForUserOperationReceipt.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,26 @@ export function waitForUserOperationReceipt(
9292
unobserve()
9393
}
9494

95+
const timeoutId = timeout ? setTimeout(
96+
() =>
97+
done(() =>
98+
emit.reject(
99+
new WaitForUserOperationReceiptTimeoutError({ hash }),
100+
),
101+
),
102+
timeout,
103+
) : undefined
104+
95105
const unpoll = poll(
96106
async () => {
97-
if (retryCount && count >= retryCount)
107+
if (retryCount && count >= retryCount) {
108+
clearTimeout(timeoutId)
98109
done(() =>
99110
emit.reject(
100111
new WaitForUserOperationReceiptTimeoutError({ hash }),
101112
),
102113
)
114+
}
103115

104116
try {
105117
const receipt = await getAction(
@@ -112,6 +124,8 @@ export function waitForUserOperationReceipt(
112124
const error = err as GetUserOperationReceiptErrorType
113125
if (error.name !== 'UserOperationReceiptNotFoundError')
114126
done(() => emit.reject(error))
127+
} finally {
128+
clearTimeout(timeoutId)
115129
}
116130

117131
count++
@@ -122,17 +136,6 @@ export function waitForUserOperationReceipt(
122136
},
123137
)
124138

125-
if (timeout)
126-
setTimeout(
127-
() =>
128-
done(() =>
129-
emit.reject(
130-
new WaitForUserOperationReceiptTimeoutError({ hash }),
131-
),
132-
),
133-
timeout,
134-
)
135-
136139
return unpoll
137140
})
138141
})

0 commit comments

Comments
 (0)