feat(react, actions): Generate a combined simulate-write-wait hook (e.g., swwContractName, useSwwContractName) #4862
Unanswered
thanhhoa214
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
First off, I want to say thank you for the incredible work on Wagmi CLI. The
reactandactionsplugins are a massive developer experience win and save an enormous amount of my time, I'm using it as a go-to for all my wagmi project.Problem
The current plugins generate
useWriteContractNameFunctionmutation hooks, which is fantastic. However, in practice, I've found that I never use this hook directly.My typical workflow for any contract write operation involves a three-step process by redefining using
useMutation:simulateContractNameto prepare the transaction and, most importantly, check for simulation errors before prompting the user.writeContractNamewith the reused params fromsimulatecall in step 1.waitForTransactionReceiptto get the final confirmation and handle the complete loading state for the user.Proposed Solution
I'd like to propose an enhancement: automatically generate a higher-order hook that encapsulates this entire simulate-write-wait (sww) flow.
Following the existing naming convention, if the CLI generates
useWriteErc20Approve, it would also generate a hook nameduseSwwErc20Approve.Code Example: Current vs. Expected
Here is a practical example of the boilerplate required today versus the ideal experience with this new feature.
👎 Current Verbose Workflow
To wire up a single "Approve" button, I need to combine three hooks and manage all their states manually.
👍 Expected Simplified Workflow
Why This Is Useful
This would apply to the actions plugin as well, perhaps by generating an async
swwContractNamefunction that takes the simulation args and returns a promise that resolves with the transaction receipt.Please upvote if you get the same usage pattern.
Beta Was this translation helpful? Give feedback.
All reactions