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 metaMask SDK connector #5028

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

EdouardBougon
Copy link

MetaMask SDK integration

This PR adds the connection to MetaMask using the MetaMask SDK.

The SDK must be used for both connecting via the extension and on mobile.

Copy link

vercel bot commented Oct 23, 2024

@EdouardBougon is attempting to deploy a commit to the cow Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

github-actions bot commented Oct 23, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Copy link

socket-security bot commented Oct 23, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Protestware or potentially unwanted behavior npm/[email protected]
  • Note: The script attempts to run a local post-install script, which could potentially contain malicious code. The error handling suggests that it is designed to fail silently, which is a common tactic in malicious scripts.
⚠︎
Protestware or potentially unwanted behavior npm/[email protected]
  • Note: This package prints a protestware console message on install regarding Ukraine for users with Russian language locale
⚠︎
Critical CVE npm/[email protected] ⚠︎

View full report↗︎

Next steps

What is protestware?

This package is a joke, parody, or includes undocumented or hidden behavior unrelated to its primary function.

Consider that consuming this package may come along with functionality unrelated to its primary purpose.

What is a critical CVE?

Contains a Critical Common Vulnerability and Exposure (CVE).

Remove or replace dependencies that include known critical CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

Copy link

vercel bot commented Oct 24, 2024

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

Name Status Preview Updated (UTC)
cowfi ✅ Ready (Inspect) Visit Preview Dec 12, 2024 11:29am
sdk-tools ❌ Failed (Inspect) Dec 12, 2024 11:29am
swap-dev ✅ Ready (Inspect) Visit Preview Dec 12, 2024 11:29am

@elena-zh
Copy link

Hey @EdouardBougon , thank you for your contribution!

I've reviewed the PR and have some issues to report:

  1. Different networks when connect to MM:
  • open cowswap
  • connect to MM on Sepolia (for example) --> the app sends a request to change a network to Ethereum.
    Expected: it should not force a user to connect to Ethereum. Sepolia details should be displayed on CoW Swap
    change back
  1. When another wallet extensions are enabled in a browser, they are duplicating in a connection modal
    duplicating
  2. Mobile: in 3 cases out of 4, when I connected to MM, I saw 'could not load balances' error message --> balances were not loaded
    image
  3. When I finally saw balances, I tried placing a trade, but a request was not sent to the wallet. Tested on iOS 17.6.1, Chrome+MM (WC)
  4. (reproduced only once): I sent a request to change a network in MM ( iOS 17.6.1, Safari+MM (WC)), accepted in MM app, and the app started to redirect me to MM again and again until I closed it. See the video:
IMG_7190.MP4

Could you please take a look at these issues?

Copy link
Collaborator

@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

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

Hey there, thanks a lot for your contribution!

There are a few issues we have noticed, could you please take a look at them?

One question, I see the SDK is bringing a lot of dependencies.
What's the bundle size it's adding?

@baptiste-marchand
Copy link

I have read the CLA Document and I hereby sign the CLA

@baptiste-marchand
Copy link

Hi @elena-zh and @alfetopito,

Thank you for your feedback! I'm taking over Edouard's work.

I took care of fixing all the identified issues. The 4th one never happened to me, so please let me know if you're still facing it with this version.

@baptiste
Copy link

baptiste commented Nov 5, 2024

I will not sign the CLA

Copy link
Collaborator

@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

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

It's working great!

Can I just ask that the original author (@EdouardBougon) sign the CLA too?

@EdouardBougon
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Copy link

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

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

Great job!
Thank you for addressing all these!

There is 1 nitpick related to networks change using WC, but this is happening on Prod now. so is not related to the current implementation.
change sep and eth
sepolia

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

I think the app was already detecting Metmask as per https://eips.ethereum.org/EIPS/eip-6963

My concern with the PR is that its not working great when you use other injected wallet that is not Metamask.

Also Metamask icon shows first instead of the ones of the available wallets.

Look what we show in production:
image

I am a Rabby wallet user (sorry, I switched some time ago), and this version show the Metamask icon first. We should give more priority to the wallets the user has. If they have Metamask, it will show up.

image

There's a second issue, if I click in "Metamask" it doesn't do anything, it remains connecting forever (not realising I don't have it installed)
image

Another issue has been raised by Leandro above. He is concerned with the bundle size. I think you lazyload, but still would be good to have the dependencies in check, plus having more dependencies adds vulnerabilities (see what happened with Ledger library some months ago). If they are not necessary and we can use EIP standards instead, I would prefer to do so. Ultimately every wallet wants to push for their SDK into the Dapps, but this is not sustainable

@elena-zh
Copy link

elena-zh commented Nov 8, 2024

Hey @baptiste-marchand , thank you for the fix!
One nitpick related to the uninstalled case: when I close 'connect' modal that appears when MM is not installed, connection modals remains in the 'connecting' state. It would be nice to show a connection error instead (like it works for WC option:
failed
image

@baptiste-marchand
Copy link

baptiste-marchand commented Nov 12, 2024

There's a second issue, if I click in "Metamask" it doesn't do anything, it remains connecting forever (not realising I don't have it installed)

@anxolin I managed to reproduce it only by disabling the MetaMask extension after having clicked on connect wallet on Cowswap. Is that also the situation you found yourself in, or it was in a more normal situation?

@baptiste-marchand
Copy link

About your questions related to the MetaMask SDK, a member from the team should reach out to you on telegram

@baptiste-marchand
Copy link

One nitpick related to the uninstalled case: when I close 'connect' modal that appears when MM is not installed, connection modals remains in the 'connecting' state. It would be nice to show a connection error instead (like it works for WC option:

@elena-zh I'm not sure I can fix this one. This is related to how web3-react and MetaMask SDK are integrated together. From what I understood WC is throwing an error when the modal is closed, while MetaMask doesn't.

@baptiste-marchand
Copy link

Hi @anxolin! I wanted to give you a quick update: our team is actively working on reducing the MetaMask SDK bundle size and removing some dependencies. We will provide you with further updates next week.

Copy link

Report too large to display inline

View full report↗︎

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.

6 participants