Files
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

78 lines
2.7 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import { getFeaturePayload } from 'configs/app/features/types';
import config from 'configs/app';
import { useMultichainContext } from 'lib/contexts/multichain';
import detectWallet from './detectWallet';
import useDetectWalletEip6963 from './useDetectWalletEip6963';
export default function useProvider() {
const multichainContext = useMultichainContext();
const feature = (multichainContext?.chain.app_config ?? config).features.web3Wallet;
const wallets = getFeaturePayload(feature)?.wallets;
const { detect: detectWalletEip6963 } = useDetectWalletEip6963();
return useQuery({
queryKey: [ 'web3-wallet' ],
// react-query v5 forbids a queryFn resolving to `undefined` ("Query data
// cannot be undefined"). Every no-wallet-found branch returns `null`.
queryFn: async() => {
if (!feature.isEnabled || !wallets) {
return null;
}
if (!('ethereum' in window && window.ethereum)) {
if (wallets.includes('metamask') && window.navigator.userAgent.includes('Firefox')) {
const { WindowPostMessageStream } = (await import('@metamask/post-message-stream'));
const { initializeProvider } = (await import('@metamask/providers'));
// workaround for MetaMask in Firefox
// Firefox blocks MetaMask injection script because of our CSP for 'script-src'
// so we have to inject it manually while the issue is not fixed
// https://github.com/MetaMask/metamask-extension/issues/3133#issuecomment-1025641185
const metamaskStream = new WindowPostMessageStream({
name: 'metamask-inpage',
target: 'metamask-contentscript',
});
// this will initialize the provider and set it as window.ethereum
initializeProvider({
connectionStream: metamaskStream as never,
shouldShimWeb3: true,
});
} else {
return null;
}
}
// have to check again in case provider was not set as window.ethereum in the previous step for MM in FF
// and also it makes typescript happy
if (!('ethereum' in window && window.ethereum)) {
return null;
}
for (const wallet of wallets) {
const detectedWalletEip6963 = await detectWalletEip6963(wallet);
if (detectedWalletEip6963) {
return detectedWalletEip6963;
}
const detectedWallet = detectWallet(wallet);
if (detectedWallet) {
return detectedWallet;
}
}
return null;
},
enabled: Boolean(feature.isEnabled || !wallets),
refetchOnMount: false,
staleTime: Infinity,
});
}