-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(types): better types and autocomplete for custom contract hooks #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
330ae38 to
6bc50ad
Compare
|
Hey! Is this pr updates #147? Why didn't you add last changes there? |
Yes, this builds off of those changes, but when I created this PR, I wasn't added to the repo yet, so couldn't push to that other branch. |
|
Thanks, @sverps love the clean-up looks a lot better and more sync with main 🙌 Some of my thoughts on TODO(Source of truth for chain id) : 1. Keep the chain in
|
|
I'm on it 👍 |
07b9184 to
a26b2f7
Compare
|
More conflicts, sorry :/
Anything else? I'll do a full review when ready! Thanks |
|
On it 👍 |
|
Making progress on this, but found a small issue that is a bit tricky to resolve. Currently, typescript doesn't show any error when you pick a functionName that needs arguments in the read or write hook, but don't provide them. useScaffoldContractWrite("YourContract", "setGreeting"); // Doesn't show TS errorI think it would be nice if typescript tells the user that he's missing the arguments. This became a bit tricky to resolve (especially due to the optional config in the read hook and the optional value param in the write hook, and the missing optional config for the write hook). Here are a couple of options on how to proceed: fix/116-type-inference-option-1
fix/116-type-inference-option-2
So please check out those two branches and look at the Personally, I like option 2 the most. It's the least complex in implementation, and has the best type error messages, which make for the best DX. |
|
I like second too. What do you think about the third parameter being like so it should be much easier to configure types in hooks and you'll not need params like |
|
Will review it later today. Just wanted to un-draft it to see if the GH Actions worked. It did! :D |
++ My thoughts :I actually like how our current useScaffoldContractRead("YourContract", "testRead", [BigNumber.from(1)])But looking fix/116-type-inference-option-1, I agree with pt 2, 3 which @sverps mentioned #202 (comment) Also, it might cause confusion : I really liked fix/116-type-inference-option-2 !! Since it shows a nice verbose error for the args. But I think passing My Suggestion :I would love if we could make hook signature something like this : useScaffoldContractRead({
contractName: "YourContract",
functionName: "greeting",
args: [BigNumber.from(1)],
enabled: false,
});Wherein we are passing an object as the first argument itself, similar to Reason: I think now it will be more intuitive to pass in args, because before you wanted open PS : It's great we are having this discussion, love it !! because |
|
This is looking really good. Great job @sverps !! Great reviews & hindsight @technophile-04 @rin-st <3 I feel that what Shiv is suggesting is the way to go if all the type hinting / auto-completions / errors work. Basically the same as using wagmi hooks but with some extra magic :) |
|
Thanks for the suggestion @technophile-04, I like this option even more 👍 One thing I'm still a bit unsure about is whether or not the Maybe that's the reason why |
|
Even I am confused a bit, although I tend to like the current state where we are doing union with But would love to hear @carletex and @rin-st thoughts on this, I have also created |
|
This looks great, good job everyone. Merged some conflicts from #248 and pushed a couple of tiny tweaks. I've been testing it, and everything looks great. I'm going to merge, let's keep building and fix any issue that we might encounter. Something that we need to figure out at some point
I'll create an issue for this. |
|
Just read your last comment @technophile-04 , sorry!
I agree!
Thanks!!! I'll take a look. Stil going to merge, so we can start testing. I have a couple of builds lined up and can't wait to use the new hooks :) Using them would be the best way to see if need to make some tweaks. |

Fixes #116
Implemented types throughout all the hooks.
useScaffoldEventSubscriber
autocompletes contractName and eventName
infers correct type for event inputs in the callback
useScaffoldContractWrite
autocompletes contractName and function name (only allows write functions)
useScaffoldContractRead
autocompletes contractName and function name (only allows read functions)
proper return types
useDeployedContractInfo
autocompletes contractName
Returns typed abi and address
TODO
Source of truth for chain id
@carletex @rin-st @technophile-04