web3modal icon indicating copy to clipboard operation
web3modal copied to clipboard

[feature] Expose `getNetworkDisabled` functionality

Open dahaca opened this issue 7 months ago • 4 comments

What problem does this new feature solve?

Hey!

At the moment there's a major difference in UX between using a wallet like Rainbow, which grants permissions to all networks right away but whose available networks are controlled by the wallet itself and MetaMask, which asks users every time they want to switch a network but they support many more networks.

These behaviors are actually reflected in the Modal with a clear message explaining why some networks are disabled, which is great!

Image

However with Rainbow connected, when switchChain() form the useSwitchChain() hook is called the action just fails silently. AFAIK there is no universal way to track this behavior... Well, after some digging I actually found one – the getNetworkDisabled() method used to determine if a network is accessible or not in the modal. I've tried replicating it but some Controllers are simply not exported from the library, so it's super tricky. Another way is to use wagmi connectors and implement checks for each of them. It is very likely that I am missing something, however I was not able to find the right solution :(

Describe the solution you'd like

Exposing the getNetworkDisabled() functionality, either as a hook or a method on Modal's instance would allow devs to check how exactly a wallet treats network switching and display relevant UI. In the case of Rainbow, such hook would allow to check if a certain network is available, and if not – display a message that a network is not supported by the wallet.

dahaca avatar May 20 '25 15:05 dahaca

For anyone looking into it, ended up creating this solution:

...
export const AppKitInstance = createAppKit({
...

...
 const { connector } = useAccount();
...

...
const supportedChains = AppKitInstance.getApprovedCaipNetworkIds();
const areAllNetworksSupported =
      connector?.name.toLowerCase() === "metamask" || !supportedChains.length;
...

It differs from getNetworkDisabled() but in my tests with 6 different wallets produced a desired behavior of spotting unsupported chains, allowing you to display custom UI to inform users.

dahaca avatar May 27 '25 15:05 dahaca

Thanks Dahaca! cool to see your solution. We will take this into account and create this as a feature request.

Sam-Newman avatar Jun 12 '25 21:06 Sam-Newman

@Sam-Newman glad to hear! ✌

dahaca avatar Jun 17 '25 13:06 dahaca

@Sam-Newman hey! Any updates on this? 👀

dahaca avatar Sep 08 '25 19:09 dahaca

Thanks for adding it 🫡

dahaca avatar Dec 12 '25 19:12 dahaca