celo-org / react-celo

Connect your react dApp to Celo
https://react-celo.vercel.app
MIT License
58 stars 42 forks source link

Add tokens to MetaMask using wallet watchAsset bug #157

Open zhaonancy opened 2 years ago

zhaonancy commented 2 years ago

MetaMask didn't add cUSD, cEUR, cREAL automatically when switching to a new network. Found when investigating https://github.com/celo-org/use-contractkit/issues/146

When calling addTokensToMetamask which uses wallet_watchAsset (https://github.com/celo-org/use-contractkit/blob/master/packages/use-contractkit/src/utils/metamask.ts#L137), a popup prompts the user separately for each token every time, even if the token has already been added.

The wallet_watchAsset request return type is documented as a boolean for if the token is added, but actually returns an object immediately with status as pending, found when @nicolasbrugneaux and I tried storing the boolean in local storage to know whether to call addTokensToMetamask in order to avoid the recurring popup.

Previous MetaMask Integration PR: https://github.com/celo-org/use-contractkit/pull/80

Docs for wallet_watchAsset:

MetaMask Issues related to wallet_watchAsset (not working in Firefox, immediate return in Chrome):

nicolasbrugneaux commented 2 years ago

With @zhaonancy we double checked the state of that issue. Metamask has the fixed merged in, and released a build with it. We tried it and it seems to fix our issues.

However tha specifc fix isn't part of released extension on the chrome/firefox store yet. PR in question: https://github.com/MetaMask/metamask-extension/pull/14545