-
Notifications
You must be signed in to change notification settings - Fork 133
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 alchemy accounts context #539
Conversation
7b451ff
to
dbca7a3
Compare
example usage can be found in alchemyplatform/embedded-accounts-demo#4 |
TODOS
|
dbca7a3
to
bed4a62
Compare
return user; | ||
}, | ||
}, | ||
queryClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do this because for w/e reason react-query exports hooks under modern
or under legacy
. aa-alchemy
was using legacy and the demo app was using modern. doing it this way ensures a query client is always present
? Omit<CreateLightAccountParams, "signer" | "transport" | "chain"> | ||
: Omit< | ||
CreateMultiOwnerModularAccountParams, | ||
"signer" | "transport" | "chain" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, we shouldn't omit the signer
here and instead make it optional. that would allow someone to create a session key signer based account
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not gonna do this now actually as it requires customizing signer in a lot of other places. opting for simplicity over flexibility / power in this first approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we want session keys, we can always add a hook for that later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want this to be with the CreateModularAccountParams
, since we made CreateMultiOwnerModularAccountParams
different from the base modular account?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah for now, I think we just want MultiOwner
and LA
and not MultiSig
or other MA
types.
export type CreateConfigProps = ConnectionConfig & { | ||
chain: Chain; | ||
sessionConfig?: AlchemySignerParams["sessionConfig"]; | ||
signerConnection?: ConnectionConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be used as an override if you have different rpc urls. This is most useful if devs are doing what they shouldn't be doing and putting their API keys in the front end
children, | ||
}: React.PropsWithChildren<AlchemyAccountsProviderProps>) => { | ||
// Note: we don't use .tsx because we don't wanna use rollup or similar to bundle this package. | ||
// This lets us continue to use TSC for building the packages which preserves the "use client" above |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to expand a bit more, when I first prototyped this outside of this repo, I was initially using rollup to build. This was fine except that it wouldn't preserve the use client
directive so some hooks weren't working well in nextjs.
We'll need to figure this out when we add UI components, but for hooks I think this is fine for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i assume this .ts vs. .tsx reason applies to the other client-side hooks? if so, we should leave comments there too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the hooks files don't actually have any jsx
syntax in them so we don't have to do that there
597086e
to
2891ade
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still reading through this, some initial thoughts for now. This general approach seems great to me.
@@ -232,5 +232,14 @@ export class SessionManager { | |||
|
|||
this.setSession({ type: "passkey", user }); | |||
}); | |||
|
|||
window.addEventListener("storage", (e: StorageEvent) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know this event existed. This will be very useful to me in Worth of Words, thanks for showing it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh speaking of worth of words! would be good to understand from your lens as a potential consumer of this what we should focus on supporting next for your use case. can be a good way to dogfood this; ideally, we can replace most of your aa-sdk usage with hooks from this package
2891ade
to
beb55c1
Compare
d84a1eb
to
55f757f
Compare
55f757f
to
5a88d2c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the way this ended up! That's a really nice organization to have the state management outside of React. I haven't seen that before but it feels like everyone should be doing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments here, but looks good!
? Omit<CreateLightAccountParams, "signer" | "transport" | "chain"> | ||
: Omit< | ||
CreateMultiOwnerModularAccountParams, | ||
"signer" | "transport" | "chain" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want this to be with the CreateModularAccountParams
, since we made CreateMultiOwnerModularAccountParams
different from the base modular account?
// TODO: figure out how to handle this on the server | ||
// I think we need a version of the signer that can be run on the server that essentially no-ops or errors | ||
// for all calls | ||
return useSyncExternalStore( | ||
watchSigner(config), | ||
() => config.signer, | ||
// We don't want to return null here, should return something of type AlchemySigner | ||
() => null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the reason it can't run work on server is because the alchemy signer needs the turnkey iframe? have we chatted with them on server-side solutions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not just that, but server-side state becomes global to the application. that means you can run into weird issues where you accidentally log a user in server side and that has all your other requests from other users authenticated as that user
children, | ||
}: React.PropsWithChildren<AlchemyAccountsProviderProps>) => { | ||
// Note: we don't use .tsx because we don't wanna use rollup or similar to bundle this package. | ||
// This lets us continue to use TSC for building the packages which preserves the "use client" above |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i assume this .ts vs. .tsx reason applies to the other client-side hooks? if so, we should leave comments there too?
Co-authored-by: Ajay Vasisht <43521356+avasisht23@users.noreply.github.com>
const search = new URLSearchParams(window.location.search); | ||
if (search.has("bundle")) { | ||
signer.authenticate({ type: "email", bundle: search.get("bundle")! }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ultra nit: but "bundle" is a keyword and might be worth turning into a const that we can update in case we want to modify it in the future more easily if our email redirect flow changes.
not necessary to do in this pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yea good shout
* docs(hooks): add initial react hooks docs * refactor: apply suggestions from code review Co-authored-by: Ajay Vasisht <43521356+avasisht23@users.noreply.github.com> --------- Co-authored-by: Ajay Vasisht <43521356+avasisht23@users.noreply.github.com>
Pull Request Checklist
yarn test
)site
folder, and guidelines for updating/adding docs can be found in the contribution guide)feat!: breaking change
)yarn lint:check
) and fix any issues? (yarn lint:write
)PR-Codex overview
This PR introduces new React hooks and config options, enhances error handling, and adds client-side properties.
Detailed summary
AWAITING_EMAIL_AUTH
status insigner/types.ts
config
withrpcUrl
andchain
insite/snippets/react/config.ts
ComponentWithSignerStatus
andComponentWithUser
insite/snippets/react/useSignerStatus.tsx
andsite/snippets/react/useUser.tsx
NoAlchemyAccountContextError
inpackages/alchemy/src/react/errors.ts
getBundlerClient
,getUser
,getSigner
,getSignerStatus
inpackages/alchemy/src/config/actions/
tsconfig.json
formoduleResolution
andmodule
packages/alchemy/src/signer/session/manager.ts
ClientOnlyPropertyError
inpackages/alchemy/src/config/errors.ts
ComponentWithSigner
andComponentWithBundlerClient
insite/snippets/react/useSigner.tsx
andsite/snippets/react/useBundlerClient.tsx
Login
component insite/snippets/react/login.tsx
watchUser
,watchSigner
, andwatchSignerStatus
inpackages/alchemy/src/config/actions/
useUser
anduseBundlerClient
hooks inpackages/alchemy/src/react/hooks/