Skip to content

Commit

Permalink
Improve exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Oct 29, 2024
1 parent 6a63e2a commit 62ebee0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 38 deletions.
8 changes: 2 additions & 6 deletions src/hooks/useConfirmSafeOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@ export function useConfirmSafeOperation(
...params,
mutationKey: [MutationKey.ConfirmSafeOperation],
mutationSafeClientFn: async (signerClient, { safeOperationHash }) => {
if (!config?.safeOperationOptions)
throw new Error('SafeOperationOptions are not specified in SafeConfig')

if (!signerClient.confirmSafeOperation) {
throw new Error('You should add safeOperationOptions to the SafeConfig')
}
if (!config?.safeOperationOptions || !signerClient.confirmSafeOperation)
throw new Error('Property safeOperationOptions are not specified in SafeConfig')

const result = await signerClient.confirmSafeOperation({
safeOperationHash
Expand Down
8 changes: 2 additions & 6 deletions src/hooks/usePendingSafeOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ export function usePendingSafeOperations(
throw new Error('Safe is not deployed')
}

if (!config?.safeOperationOptions)
throw new Error('SafeOperationOptions are not specified in SafeConfig')

if (!safeClient.getPendingSafeOperations) {
throw new Error('You should add safeOperationOptions to the SafeConfig')
}
if (!config?.safeOperationOptions || !safeClient.getPendingSafeOperations)
throw new Error('Property safeOperationOptions are not specified in SafeConfig')

const pendingSafeOperations = await safeClient.getPendingSafeOperations({
limit: params.limit,
Expand Down
41 changes: 15 additions & 26 deletions src/hooks/useSendSafeOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,22 @@ export function useSendSafeOperation(
...params,
mutationKey: [MutationKey.SendSafeOperation],
mutationSafeClientFn: async (signerClient, { transactions = [], ...paymasterSendOptions }) => {
if (!config?.safeOperationOptions)
throw new Error('SafeOperationOptions are not specified in SafeConfig')

try {
console.log('sendSafeOperation', { transactions, ...paymasterSendOptions })

if (!signerClient.sendSafeOperation) {
throw new Error('You should add safeOperationOptions to the SafeConfig')
}

const result = await signerClient.sendSafeOperation({
transactions,
...paymasterSendOptions
})
console.log('result', result)

if (result.safeOperations?.userOperationHash) {
invalidateQueries([QueryKey.SafeOperations, QueryKey.SafeInfo])
} else if (result.safeOperations?.safeOperationHash) {
invalidateQueries([QueryKey.PendingSafeOperations])
}

return result
} catch (error) {
console.error('error', error)
throw new Error("Couldn't send SafeOperation")
if (!config?.safeOperationOptions || !signerClient.sendSafeOperation)
throw new Error('Property safeOperationOptions are not specified in SafeConfig')

const result = await signerClient.sendSafeOperation({
transactions,
...paymasterSendOptions
})
console.log('result', result)

if (result.safeOperations?.userOperationHash) {
invalidateQueries([QueryKey.SafeOperations, QueryKey.SafeInfo])
} else if (result.safeOperations?.safeOperationHash) {
invalidateQueries([QueryKey.PendingSafeOperations])
}

return result
}
})

Expand Down

0 comments on commit 62ebee0

Please sign in to comment.