-
Notifications
You must be signed in to change notification settings - Fork 197
feat(connectors-web): add alchemySmartWallet connector #2115
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
base: moldy/v5-base
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
🌿 Documentation Preview
|
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 is awesome, tested it out in the demo and it's working well!
Few comments but happy for any changes to be made in subsequent PRs if you wanna merge this
*/ | ||
const loggedOutProvider: Provider = { | ||
on: () => {}, | ||
removeListener: () => {}, |
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 sure if this is overkill/needed, do you think we should have some code to remove the listeners?
const listeners = new Map();
const loggedOutProvider: Provider = {
on: (event, listener) => {
if (!listeners.has(event)) listeners.set(event, new Set());
listeners.get(event)?.add(listener);
return () => listeners.get(event)?.delete(listener);
},
removeListener: (event, listener) => {
listeners.get(event)?.delete(listener);
},
};
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.
Since right now this provider never emits events, what I wrote should be equivalent behavior and I think there's no reason to store listeners that won't be called.
(We could forward listeners to the inner provider, but that feels like it could have unpredictable consequences.)
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 sure if this is applicable here, but in alchemyAuth
we used a resumePromise
(link) as a standard promise that we wait for on reload.
does the getProvider()
only get called on reload, which is the case that the logged out provider is supposed to be for?
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 that's really interesting, I assumed that wagmi wouldn't accept us until we produced a provider, but it seems like just a promise of a provider is good enough for wagmi. Let me try that, and also see what built-in connectors are doing.
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.
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 only time we would need the dummy provider during this implementation is during reconnect
, right?
when getProvider
is called here, could we await the inner connector being ready, then await the smart wallet client creation so that we have the provider here?
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.
Thinking about it more, I'm not sure I like the idea of returning a suspended promise that resolves once the user logs in. That seems like it could be unexpected behavior for callers, who might call await connector.getProvider()
and then be surprised that their program hangs forever. I think the expected behavior would be to return a provider that reflects the logged out state. What do you think?
*/ | ||
const loggedOutProvider: Provider = { | ||
on: () => {}, | ||
removeListener: () => {}, |
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 sure if this is applicable here, but in alchemyAuth
we used a resumePromise
(link) as a standard promise that we wait for on reload.
does the getProvider()
only get called on reload, which is the case that the logged out provider is supposed to be for?
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.
left a couple of questions. good work so far! cool to see this coming along.
could i request that we update the "send call via smart wallet client" button in the connector-web-example to just be "send call" and use the wagmi action to send a call via the connector?
*/ | ||
const loggedOutProvider: Provider = { | ||
on: () => {}, | ||
removeListener: () => {}, |
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.
*/ | ||
const loggedOutProvider: Provider = { | ||
on: () => {}, | ||
removeListener: () => {}, |
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 only time we would need the dummy provider during this implementation is during reconnect
, right?
when getProvider
is called here, could we await the inner connector being ready, then await the smart wallet client creation so that we have the provider here?
async connect(parameters) { | ||
await baseConnector.connect(parameters); | ||
throw new Error("Not implemented: connect"); | ||
async connect(params): Promise<{ accounts: Address[]; chainId: number }> { |
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 sure if this would change anything for your implementation, but just want to flag that connect
has an { isReconnecting: true }
param whenever it's called via wagmi's reconnect
action.
b13c98a
to
2429bd5
Compare
Basic implementation of a connector which uses the Wallet API to perform actions using an Alchemy smart account, wrapping another connector to perform signing. This version is tested to work when wrapping both the Metamask connector and the Alchemy Auth connector, including many edge cases such as changing accounts or configs in the Metamask UI after connecting.
2429bd5
to
8592acc
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Basic implementation of a connector which uses the Wallet API to perform actions using an Alchemy smart account, wrapping another connector to perform signing.
This version is tested to work with the Metamask connector, although there is additional work that can done to clean up code and polish edge cases, as marked with TODO's.
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 primarily focuses on enhancing the
@alchemy/connectors-web
library by introducing thealchemySmartWallet
connector, updating existing connectors, and refining the integration with Alchemy's authentication and wallet APIs.Detailed summary
resolveConnector.ts
andresolveAlchemyAuthConnector.mdx
.package.json
files to include new dependencies.alchemySmartWallet
connector with detailed options and parameters.resolveAlchemyAuthConnector
to improve connector resolution.alchemySmartWallet
functionality.