Skip to content
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

feat: add useSendUserOperation and useDropAndReplaceUserOperation hooks #581

Conversation

avasisht23
Copy link
Contributor

@avasisht23 avasisht23 commented Apr 16, 2024

Pull Request Checklist


PR-Codex overview

This PR adds new hooks useSendUserOperation and useDropAndReplaceUserOperation for interacting with Alchemy smart accounts in React components.

Detailed summary

  • Updated error message in NoAlchemyAccountContextError class
  • Added useSendUserOperation and useDropAndReplaceUserOperation hooks
  • Created corresponding components for each hook
  • Updated sidebar links
  • Updated exports in alchemy/src/react/index.ts
  • Added meta information for new hooks in documentation pages

The following files were skipped due to too many changes: packages/alchemy/src/react/hooks/useSendUserOperation.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@avasisht23 avasisht23 changed the base branch from main to ajv/add_sign_messages_and_typeddata_hooks April 16, 2024 05:41
@avasisht23 avasisht23 force-pushed the 04-12-feat_add_useSendUserOperation_and_useDropAndReplaceUserOperation_hooks branch 2 times, most recently from 2e793e0 to de3c028 Compare April 16, 2024 05:52
@avasisht23 avasisht23 changed the title 04 12 feat add use send user operation and use drop and replace user operation hooks feat: add useSendUserOperation and useDropAndReplaceUserOperation hooks Apr 16, 2024
Comment on lines 69 to 71
if (!client) {
throw new ClientUndefinedError("useDropAndReplaceUserOperation");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto comment made in another hook pr:

or all out hooks, we should check from AlchemyAccountContext which state the user/account is in, and throw informative error messages instead of just throwing null exceptions or other generic error messages

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in the use client actions hook about this. I don't think this is a generic error. There's nothing to check in the account context that will make it more informative. The client here is a parameter to the hook and can be null. If it's null we error. Beyond that what else can we pull from context? What if the user is passing in a client they didn't create via context and it's still null?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right. I left a similar comment on signer hook prs, and left similar comments here, but I realized that the core SDK takes care of these already.

error: Error | null;
};

export function useSendUserOperation<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only meant to be used for smart accounts? we should check if account is connected to the client, not just that client exists. in general, throw more informative state error back to the caller.

Makes sense to group signer/smart account/modular account hooks separately in the subdirs of hooks for different accounts, and also have more common state checking/error messages/code shared.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client will throw if it is not connected to an account already and the typing on this specific client parameter forbids it from not not being connected anyways since it has to be a LA client or MA client

@avasisht23 avasisht23 force-pushed the ajv/add_sign_messages_and_typeddata_hooks branch from 6eb9f4f to 6a67fd0 Compare April 17, 2024 17:10
@avasisht23 avasisht23 force-pushed the 04-12-feat_add_useSendUserOperation_and_useDropAndReplaceUserOperation_hooks branch from 1ee77cd to 11d90d9 Compare April 17, 2024 20:12
@avasisht23 avasisht23 force-pushed the ajv/add_sign_messages_and_typeddata_hooks branch from 42cce3c to 8cc8e08 Compare April 18, 2024 07:04
@avasisht23 avasisht23 force-pushed the 04-12-feat_add_useSendUserOperation_and_useDropAndReplaceUserOperation_hooks branch from 13253a7 to caa5475 Compare April 18, 2024 07:05
rthomare
rthomare previously approved these changes Apr 18, 2024
@avasisht23 avasisht23 force-pushed the ajv/add_sign_messages_and_typeddata_hooks branch from 8cc8e08 to 82f9f13 Compare April 18, 2024 17:59
@avasisht23 avasisht23 force-pushed the 04-12-feat_add_useSendUserOperation_and_useDropAndReplaceUserOperation_hooks branch from caa5475 to 9a0cd70 Compare April 18, 2024 18:06
Base automatically changed from ajv/add_sign_messages_and_typeddata_hooks to main April 18, 2024 19:38
@avasisht23 avasisht23 dismissed rthomare’s stale review April 18, 2024 19:38

The base branch was changed.

@avasisht23 avasisht23 force-pushed the 04-12-feat_add_useSendUserOperation_and_useDropAndReplaceUserOperation_hooks branch from 9a0cd70 to 4090d5d Compare April 18, 2024 19:39
@avasisht23 avasisht23 merged commit 877785d into main Apr 18, 2024
2 checks passed
@avasisht23 avasisht23 deleted the 04-12-feat_add_useSendUserOperation_and_useDropAndReplaceUserOperation_hooks branch April 18, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants