[feature] Expose `getNetworkDisabled` functionality
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!
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.
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.
Thanks Dahaca! cool to see your solution. We will take this into account and create this as a feature request.
@Sam-Newman glad to hear! ✌
@Sam-Newman hey! Any updates on this? 👀
Thanks for adding it 🫡