import { useCopyTimeout } from '@vegaprotocol/react-helpers'; import { TradingButton as Button, VegaIcon, VegaIconNames, } from '@vegaprotocol/ui-toolkit'; import { truncateByChars } from '@vegaprotocol/utils'; import { type Key } from '@vegaprotocol/wallet'; import { useVegaWallet } from '@vegaprotocol/wallet-react'; import { useCallback, useMemo } from 'react'; import CopyToClipboard from 'react-copy-to-clipboard'; import { ViewType, useSidebar } from '../sidebar'; import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id'; import { useT } from '../../lib/use-t'; import { usePartyProfilesQuery } from '../vega-wallet-connect-button/__generated__/PartyProfiles'; import { useProfileDialogStore } from '../../stores/profile-dialog-store'; export const VegaWalletMenu = ({ setMenu, }: { setMenu: (open: 'nav' | 'wallet' | null) => void; }) => { const t = useT(); const { pubKey, pubKeys, selectPubKey, disconnect } = useVegaWallet(); const currentRouteId = useGetCurrentRouteId(); const setViews = useSidebar((store) => store.setViews); const { data } = usePartyProfilesQuery({ variables: { partyIds: pubKeys.map((pk) => pk.publicKey) }, skip: pubKeys.length <= 0, fetchPolicy: 'cache-and-network', }); const activeKey = useMemo(() => { return pubKeys?.find((pk) => pk.publicKey === pubKey); }, [pubKey, pubKeys]); const onSelectItem = useCallback( (pubkey: string) => { selectPubKey(pubkey); }, [selectPubKey] ); return (
{(pubKeys || []).map((pk) => { const profile = data?.partiesProfilesConnection?.edges.find( (e) => e.node.partyId === pk.publicKey ); return ( ); })}
); }; const KeypairListItem = ({ pk, isActive, alias, onSelectItem, setMenu, }: { pk: Key; isActive: boolean; alias: string | undefined; onSelectItem: (pk: string) => void; setMenu: (open: 'nav' | 'wallet' | null) => void; }) => { const t = useT(); const [copied, setCopied] = useCopyTimeout(); const setOpen = useProfileDialogStore((store) => store.setOpen); return (
{isActive && } {truncateByChars(pk.publicKey)}{' '} setCopied(true)}> {copied && {t('Copied')}} {alias ? alias : t('No alias')} {isActive && ( )}
); };