react-celo
                                
                                 react-celo copied to clipboard
                                
                                    react-celo copied to clipboard
                            
                            
                            
                        Add tokens to MetaMask using wallet watchAsset bug
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:
- https://docs.metamask.io/guide/rpc-api.html#wallet-watchasset
- https://docs.metamask.io/guide/registering-your-token.html#example
- https://github.com/ethereum/EIPs/blob/master/EIPS/eip-747.md
MetaMask Issues related to wallet_watchAsset (not working in Firefox, immediate return in Chrome):
- https://github.com/MetaMask/metamask-extension/issues/12416
- https://github.com/MetaMask/metamask-extension/issues/11377
- https://github.com/MetaMask/metamask-extension/issues/7360
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