Files
explore/lib/web3/useAddChainClick.ts
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

50 lines
1.2 KiB
TypeScript

import { toaster } from '@luxfi/ui/toaster';
import React from 'react';
import * as mixpanel from 'lib/mixpanel/index';
import useAddChain from './useAddChain';
import useProvider from './useProvider';
import useSwitchChain from './useSwitchChain';
interface Props {
source: 'Footer' | 'Top bar' | 'Chain widget';
onSuccess?: () => void;
}
export default function useAddChainClick({ source, onSuccess }: Props) {
const { data: providerData } = useProvider();
const { wallet, provider } = providerData ?? {};
const addChain = useAddChain();
const switchChain = useSwitchChain();
return React.useCallback(async() => {
if (!wallet || !provider) {
return;
}
try {
await addChain();
await switchChain();
toaster.success({
title: 'Success',
description: 'Successfully added network to your wallet',
});
mixpanel.logEvent(mixpanel.EventTypes.ADD_TO_WALLET, {
Target: 'network',
Wallet: wallet,
Source: source,
});
onSuccess?.();
} catch (error) {
toaster.error({
title: 'Error',
description: (error as Error)?.message || 'Something went wrong',
});
}
}, [ addChain, provider, wallet, switchChain, source, onSuccess ]);
}