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

chore: store both MAv2 modes & use standard hook for minting 7702 in ui demo #1361

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

jakehobbs
Copy link
Member

@jakehobbs jakehobbs commented Feb 12, 2025

Pull Request Checklist


PR-Codex overview

This PR focuses on refactoring the account management system to support multiple account modes, specifically integrating a "default" and "7702" mode for various account types. It updates related components, hooks, and tests to accommodate this change.

Detailed summary

  • Updated version from 13 to 14 in multiple files.
  • Renamed useModularAccountV2Client to useMAv2Client.
  • Replaced walletType with accountMode in configuration and state management.
  • Modified hooks to accept mode parameter.
  • Adjusted components to conditionally render based on accountMode.
  • Enhanced tests for account modes and configurations.
  • Added new type definitions for SupportedAccountModes.
  • Updated account creation and state management logic to handle modes.

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

Copy link

vercel bot commented Feb 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
aa-sdk-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 21, 2025 9:57pm
aa-sdk-ui-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 21, 2025 9:57pm

@jakehobbs jakehobbs force-pushed the jake/mav2-hooks-switch-mode-experiement branch 2 times, most recently from 5ffc7c0 to 9834b82 Compare February 12, 2025 23:59
@jakehobbs jakehobbs force-pushed the jake/mav2-hooks-switch-mode-experiement branch from 48e1cbe to 0d5a958 Compare February 13, 2025 02:22
@jakehobbs jakehobbs changed the title [DRAFT] support multiple modes in store chore: store both MAv2 modes & use standard hook for minting 7702 in ui demo Feb 13, 2025
@jakehobbs jakehobbs marked this pull request as ready for review February 13, 2025 02:22
@@ -81,15 +82,23 @@ export type StoreState = {
signer?: AlchemyWebSigner;
accounts?: {
[chain: number]: {
[key in SupportedAccountTypes]: AccountState<key>;
[T in SupportedAccountTypes]: T extends "ModularAccountV2"
Copy link
Member Author

Choose a reason for hiding this comment

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

i am slightly debating if it might be worth just nesting the accounts, configs, and clients for each type under a mode, even if they don't have different modes. it would just be default for all types other than MAv2. if people are okay w/ that, it would lead to less branching in a lot of places where we have to check the type to determine how we need to access the final objects.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not only an easier (for future devs) but probably safer option.

Comment on lines 100 to 104
const cachedAccount = (
type === "ModularAccountV2"
? accounts[chain.id]?.["ModularAccountV2"]?.[mode]
: accounts[chain.id]?.[type]
) as AccountState<TAccount>;
Copy link
Contributor

@jaypaik jaypaik Feb 13, 2025

Choose a reason for hiding this comment

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

Is line 106 safe? We're casting it to a non-nullable type, but it seems like the actual thing can be undefined?

Lol maybe I've forgotten how js/ts works.

Copy link
Member Author

@jakehobbs jakehobbs Feb 14, 2025

Choose a reason for hiding this comment

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

i think it is always initialized with a defaultAccountState like this:

{
  status: "DISCONNECTED",
  account: undefined,
}

so shouldn't ever be undefined... i think the optional chaining here is redundant and the TS compiler knows it should always be defined.

Copy link
Collaborator

@moldy530 moldy530 left a comment

Choose a reason for hiding this comment

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

this looks reasonable to me!


const accountPromise = (() => {
switch (type) {
case "LightAccount":
return createLightAccount({
...params,
...cachedConfig,
...(cachedConfig as OmitSignerTransportChain<CreateLightAccountParams>),
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious why now we have to do an as ... and didn't have to before?

Copy link
Collaborator

Choose a reason for hiding this comment

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

is there any way to do this without hardcoding? (i know that's what we did before so it might be OOS for this)

Copy link
Member Author

Choose a reason for hiding this comment

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

let me work through that real quick

Copy link
Member Author

Choose a reason for hiding this comment

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

i can simplify it if we're ok w/ a type assertion

@jakehobbs jakehobbs marked this pull request as ready for review February 21, 2025 19:20
@jakehobbs jakehobbs requested a review from moldy530 February 21, 2025 19:22
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