mirror of
https://github.com/luxfi/explore.git
synced 2026-07-27 05:54:15 +00:00
- 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 <dev@hanzo.ai>
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import React from 'react';
|
|
import type { AddEthereumChainParameter } from 'viem';
|
|
|
|
import config from 'configs/app';
|
|
import { useMultichainContext } from 'lib/contexts/multichain';
|
|
import { SECOND } from 'toolkit/utils/consts';
|
|
|
|
import useRewardsActivity from '../hooks/useRewardsActivity';
|
|
import useProvider from './useProvider';
|
|
import { getHexadecimalChainId } from './utils';
|
|
|
|
function getParams(chainConfig: typeof config): AddEthereumChainParameter {
|
|
if (!chainConfig.chain.id) {
|
|
throw new Error('Missing required chain config');
|
|
}
|
|
|
|
return {
|
|
chainId: getHexadecimalChainId(Number(chainConfig.chain.id)),
|
|
chainName: chainConfig.chain.name ?? '',
|
|
nativeCurrency: {
|
|
name: chainConfig.chain.currency.name ?? '',
|
|
symbol: chainConfig.chain.currency.symbol ?? '',
|
|
decimals: chainConfig.chain.currency.decimals ?? 18,
|
|
},
|
|
rpcUrls: chainConfig.chain.rpcUrls,
|
|
blockExplorerUrls: [ chainConfig.app.baseUrl ],
|
|
};
|
|
}
|
|
|
|
interface Params {
|
|
chainConfig?: typeof config;
|
|
}
|
|
|
|
export default function useAddChain(params?: Params) {
|
|
const { data: providerData } = useProvider();
|
|
const { wallet, provider } = providerData ?? {};
|
|
const { trackUsage } = useRewardsActivity();
|
|
const multichainContext = useMultichainContext();
|
|
|
|
const chainConfig = params?.chainConfig || multichainContext?.chain.app_config || config;
|
|
|
|
return React.useCallback(async() => {
|
|
if (!wallet || !provider) {
|
|
throw new Error('Wallet or provider not found');
|
|
}
|
|
|
|
const start = Date.now();
|
|
|
|
await provider.request({
|
|
method: 'wallet_addEthereumChain',
|
|
params: [ getParams(chainConfig) ],
|
|
});
|
|
|
|
// if network is already added, the promise resolves immediately
|
|
if (Date.now() - start > SECOND) {
|
|
await trackUsage('add_network');
|
|
}
|
|
}, [ wallet, provider, chainConfig, trackUsage ]);
|
|
}
|