Repository navigation
Replies: 1 comment
|
A rejection in the wallet does make 1. The rejection is wrapped. The error you get is a viem import { BaseError, UserRejectedRequestError } from 'viem'
import { useSendCalls, useWaitForCallsStatus } from 'wagmi'
function isUserRejection(error: unknown) {
if (error instanceof BaseError)
return Boolean(
error.walk((e) => e instanceof UserRejectedRequestError || (e as { code?: unknown }).code === 4001),
)
return (error as { code?: unknown })?.code === 4001
}
function Batch() {
const { sendCalls, data } = useSendCalls({
mutation: {
onError(error) {
if (isUserRejection(error)) {
// user cancelled in the wallet -> reset your UI here
}
},
},
})
const { data: callsStatus } = useWaitForCallsStatus({ id: data?.id })
// callsStatus?.status === 'failure' -> the batch was sent but did not fully succeed
// ...
}( 2. With
I checked this against viem 2.57.13 with a mocked EIP-1193 provider (two calls):
|
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I'm in the process of replacing our approval/writeContract (
useSimulateContract/useWriteContract) flow with batched transactions usinguseSendCallsanduseWaitForCallsStatus. While the happy flow works great, I'm having difficulties to spot when a user cancels his signature in the wallet and thus ends up the process. I have tried to hook into the differentonErrorcallbacks fromuseSendCalls,useSendCallsSyncoruseWaitForCallsStatus, but it seems they are not triggered as I would expect.What is the best way to detect this situation in order to update the UI of my app?
All reactions