Files
explore/lib/web3/useSwitchChain.tsx
T
zeekayandHanzo Dev e471fb7641 explore v1.1.4: native all-chains wallet-connect, login/menu fixes, correct chain manifest
- wallet: brandFamilyChains derives sibling networks (Lux mainnet/testnet/devnet)
  from the multi-tenant chain registry so connect/add presents EVERY registered
  network for the brand, not just the env chain; dedupe by id.
- login/menu: useProvider queryFn returns null (react-query v5 forbids undefined)
  + callers switched from '= {}' destructure default to '?? {}' so a null result
  no longer crashes the wallet hooks (the busted-menu root cause).
- manifest: fix Pars chainId 7070 -> 494949 (regression) and drop the forbidden
  'Subnet' term from sovereign L1 network names (-> '<Brand> Network').
- Validators page + /api/pchain proxy present; rebuild makes the live 5-validator
  view visible on explore.lux.network.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-08 11:44:04 -07:00

39 lines
1.1 KiB
TypeScript

import React from 'react';
import config from 'configs/app';
import { useMultichainContext } from 'lib/contexts/multichain';
import useProvider from './useProvider';
import { getHexadecimalChainId } from './utils';
function getParams(chainConfig: typeof config): { chainId: string } {
if (!chainConfig.chain.id) {
throw new Error('Missing required chain config');
}
return { chainId: getHexadecimalChainId(Number(chainConfig.chain.id)) };
}
interface Params {
chainConfig?: typeof config;
}
export default function useSwitchChain(params?: Params) {
const { data: providerData } = useProvider();
const { wallet, provider } = providerData ?? {};
const multichainContext = useMultichainContext();
const chainConfig = params?.chainConfig || multichainContext?.chain.app_config || config;
return React.useCallback(() => {
if (!wallet || !provider) {
throw new Error('Wallet or provider not found');
}
return provider.request({
method: 'wallet_switchEthereumChain',
params: [ getParams(chainConfig) ],
});
}, [ wallet, provider, chainConfig ]);
}