HyperPlay-Gaming / hyperplay-desktop-client

The HyperPlay desktop app
https://hyperplay.xyz
GNU General Public License v3.0
78 stars 31 forks source link

[Fix] Network add in portfolio swap #1153

Closed BrettCleary closed 1 week ago

BrettCleary commented 1 week ago

Summary

closes https://github.com/HyperPlay-Gaming/product-management/issues/765

Ethers has several situations where it throws an error like the following

Error: could not coalesce error (error={ "code": 4902, "message": "Unrecognized chain ID \"0x144\". Try adding the chain using wallet_addEthereumChain first." }, payload={ "id": 13, "jsonrpc": "2.0", "method": "wallet_switchEthereumChain", "params": [ { "chainId": "0x144" } ] }, code=UNKNOWN_ERROR, version=6.13.2)

e.g. https://github.com/ethers-io/ethers.js/issues/4576

The above error was generated when trying to switch chains. Because makeError fails at ethers\lib.commonjs\utils\errors.js, the error object is not correctly formed. We can parse the error object out of the error string as a fallback here.

Note that since this error was not being re-thrown, the catch block in the portfolio that checks the error code E.code === 4902 was not returning true resulting in wallet_addEthereumChain not being called.

The user impact is that chains that were not already added to the users wallet could not be added/switched to in the portfolio.