Skip to content

Commit

Permalink
Make waitForUserOperationReceipt return non nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
plusminushalf committed Oct 19, 2023
1 parent b59d48e commit c344b77
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/actions/bundler/getUserOperationReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type GetUserOperationReceiptReturnType = {
address: Address
topics: Hex[]
}[]
} | null
}

/**
* Returns the user operation receipt from userOpHash
Expand All @@ -62,7 +62,10 @@ export type GetUserOperationReceiptReturnType = {
* getUserOperationReceipt(bundlerClient, {hash: userOpHash})
*
*/
export const getUserOperationReceipt = async (client: BundlerClient, { hash }: GetUserOperationReceiptParameters) => {
export const getUserOperationReceipt = async (
client: BundlerClient,
{ hash }: GetUserOperationReceiptParameters
): Promise<GetUserOperationReceiptReturnType | null> => {
const params: [Hash] = [hash]

const response = await client.request({
Expand Down
10 changes: 6 additions & 4 deletions src/actions/bundler/waitForUserOperationReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ export const waitForUserOperationReceipt = <TChain extends Chain | undefined>(
_unobserve()
}

const _userOperationReceipt = await getUserOperationReceipt(bundlerClient, { hash })

if (_userOperationReceipt !== null) {
userOperationReceipt = _userOperationReceipt
}

if (userOperationReceipt) {
done(() => emit.resolve(userOperationReceipt))
return
}

userOperationReceipt = await getUserOperationReceipt(bundlerClient, { hash })

if (!userOperationReceipt) return
}, pollingInterval)
})
})
Expand Down
4 changes: 3 additions & 1 deletion src/clients/decorators/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ export type BundlerActions = {
* await bundlerClient.getUserOperationReceipt({hash: userOpHash})
*
*/
getUserOperationReceipt: (args: GetUserOperationReceiptParameters) => Promise<GetUserOperationReceiptReturnType>
getUserOperationReceipt: (
args: GetUserOperationReceiptParameters
) => Promise<GetUserOperationReceiptReturnType | null>

/**
* Waits for the User Operation to be included on a [Block](https://viem.sh/docs/glossary/terms.html#block) (one confirmation), and then returns the [User Operation Receipt](https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationReceipt).
Expand Down
1 change: 0 additions & 1 deletion test/bundlerActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import dotenv from "dotenv"
import {
BundlerClient,
GetUserOperationReceiptReturnType,
UserOperation,
WaitForUserOperationReceiptTimeoutError,
createBundlerClient
} from "permissionless"
Expand Down

0 comments on commit c344b77

Please sign in to comment.