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: update metamask sdk and implement connectSign #4323

Closed
wants to merge 8 commits into from

Conversation

abretonc7s
Copy link
Collaborator

@abretonc7s abretonc7s commented Oct 8, 2024

Update metamask sdk to 0.29.1

Copy link

changeset-bot bot commented Oct 8, 2024

⚠️ No Changeset found

Latest commit: 51f778a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Oct 8, 2024

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

Name Status Preview Comments Updated (UTC)
wagmi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 11, 2024 4:32pm

Copy link

socket-security bot commented Oct 8, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/sdk@0.29.2 Transitive: environment, eval, filesystem, network, shell +79 54 MB metamaskbot

View full report↗︎

@abretonc7s abretonc7s marked this pull request as draft October 8, 2024 08:49
Copy link
Collaborator

@EdouardBougon EdouardBougon left a comment

Choose a reason for hiding this comment

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

Do you you know if other wallets have the same features of connectAndSign and connectWith?

If the app only uses the MetaMask connector, it works.
But if they use multiple connectors, this means that in the Dapp code, the connector will need to be tested:

  • If it’s MetaMask, then just call connect.
  • If it’s not MetaMask, you need to call connect and then signMessage.

--

The best solution would be to propose a new connectAndSign hook to Wagmi, where the above logic would be wrapped. We could also add a new optional signMessage parameter to the connect method of the connector: https://wagmi.sh/dev/creating-connectors#methods

I'm available to discuss about it

packages/connectors/src/metaMask.ts Outdated Show resolved Hide resolved
packages/connectors/src/metaMask.ts Outdated Show resolved Hide resolved
@abretonc7s
Copy link
Collaborator Author

Do you you know if other wallets have the same features of connectAndSign and connectWith?

If the app only uses the MetaMask connector, it works. But if they use multiple connectors, this means that in the Dapp code, the connector will need to be tested:

  • If it’s MetaMask, then just call connect.
  • If it’s not MetaMask, you need to call connect and then signMessage.

--

The best solution would be to propose a new connectAndSign hook to Wagmi, where the above logic would be wrapped. We could also add a new optional signMessage parameter to the connect method of the connector: https://wagmi.sh/dev/creating-connectors#methods

I'm available to discuss about it

The idea here is to have a least intrusive solution and allow the dapps using metamask to have a better U/X (no need for two deeplink for the mobile sign request)

Comment on lines 40 to 43
| 'useDeeplink'
| 'injectProvider'
| 'forceInjectProvider'
| 'forceDeleteProvider'
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep these around since otherwise it's a breaking change.

>

export type MetaMaskParameters = WagmiMetaMaskSDKOptions & {
// Shortcut to connect and sign a message
connectAndSign?: string
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
connectAndSign?: string
connectAndSign?: string | undefined

// Shortcut to connect and sign a message
connectAndSign?: string
// Allow connectWith any rpc method
connectWith?: { method: string; params: unknown[] }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
connectWith?: { method: string; params: unknown[] }
connectWith?: { method: string; params: unknown[] } | undefined

What methods are supported? We should be able to strongly type this with the utility types in Viem (e.g. EIP1474Methods) if we want.

Comment on lines +217 to +221
// @ts-ignore
if (typeof SDK !== 'function' && typeof SDK.default === 'function')
// @ts-ignore
return SDK.default
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

I'll take a crack on getting TS to play nice.

dappMetadata: parameters.dappMetadata ?? { name: 'wagmi' },
useDeeplink: parameters.useDeeplink ?? true,
dappMetadata: parameters.dappMetadata ?? {
url: `${window.location.protocol}//${window.location.host}`,
Copy link
Member

Choose a reason for hiding this comment

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

We should check that window is available (typeof window !== 'undefined')

Comment on lines +241 to +244
useDeeplink: true,
injectProvider: false,
forceInjectProvider: false,
forceDeleteProvider: false,
Copy link
Member

Choose a reason for hiding this comment

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

What were the defaults internally before? Just want to make sure changes these isn't too disruptive for folks. Probably should allow folks to override these manually so it's not a breaking change and remove that ability in the next major version. (Very unlikely anyone will override manually since people just use defaults, but want to make sure semver is respected.)

Copy link

Choose a reason for hiding this comment

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

We force inject provider but it can conflict with the injected provider by wagmi (see our other PR.)

Copy link
Member

Choose a reason for hiding this comment

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

Is this PR dependent on that one? Haven't had a chance to wrap up our thinking on that quite yet.

@tmm
Copy link
Member

tmm commented Oct 14, 2024

Closing in favor of #4337

@tmm tmm closed this Oct 14, 2024
@tmm tmm mentioned this pull request Oct 14, 2024
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