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

Merged
merged 10 commits into from
Dec 16, 2024

Conversation

EdouardBougon
Copy link
Contributor

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

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

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 16, 2024 11:45am
sdk-tools ✅ Ready (Inspect) Visit Preview Dec 16, 2024 11:45am
swap-dev ✅ Ready (Inspect) Visit Preview Dec 16, 2024 11:45am

@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
Contributor

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

@baptiste-marchand
Copy link
Contributor

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
Contributor 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
Contributor

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
Contributor

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

@baptiste-marchand
Copy link
Contributor

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
Contributor

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

socket-security bot commented Dec 16, 2024

@shoom3301 shoom3301 merged commit fe8f376 into cowprotocol:develop Dec 16, 2024
5 of 9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 16, 2024
@elena-zh
Copy link

elena-zh commented Dec 17, 2024

Hey @EdouardBougon , @baptiste-marchand ,
we were about to include this PR into the release, but, unfortunately, we had to revert these changes in #5125.
Main problems:

  1. Impossible to sign orders in a mobile device (using WC connector): the app hangs in this state (see the image) and there is no request in MM
    image
  2. MM is not installed on a desktop version, I connected to it using a native connector: impossible to sign transactions using it
    image
    image
  3. MM is not installed on a desktop version, I connected to it using regular WC option> each time I pick a token, and try signing an order, this modal pops up

image

Please feel free to open a new PR with the fixes.
Thank you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants