import { useMemo, useState } from 'react'; import CopyToClipboard from 'react-copy-to-clipboard'; import { isBrowserWalletInstalled } from '@vegaprotocol/wallet'; import { truncateByChars } from '@vegaprotocol/utils'; import { t } from '@vegaprotocol/i18n'; import { VegaIcon, VegaIconNames, TradingButton as Button, Intent, TradingDropdown, TradingDropdownTrigger, TradingDropdownContent, TradingDropdownRadioGroup, TradingDropdownSeparator, TradingDropdownItem, TradingDropdownRadioItem, TradingDropdownItemIndicator, } from '@vegaprotocol/ui-toolkit'; import type { PubKey } from '@vegaprotocol/wallet'; import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet'; import { useCopyTimeout } from '@vegaprotocol/react-helpers'; import { ViewType, useSidebar } from '../sidebar'; import classNames from 'classnames'; import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id'; export const VegaWalletConnectButton = () => { const [dropdownOpen, setDropdownOpen] = useState(false); const openVegaWalletDialog = useVegaWalletDialogStore( (store) => store.openVegaWalletDialog ); const currentRouteId = useGetCurrentRouteId(); const setViews = useSidebar((store) => store.setViews); const { pubKey, pubKeys, selectPubKey, disconnect, isReadOnly, fetchPubKeys, } = useVegaWallet(); const isConnected = pubKey !== null; const walletInstalled = isBrowserWalletInstalled(); const activeKey = useMemo(() => { return pubKeys?.find((pk) => pk.publicKey === pubKey); }, [pubKey, pubKeys]); if (isConnected && pubKeys) { return ( { if (fetchPubKeys) { fetchPubKeys(); } setDropdownOpen(!dropdownOpen); }} > } > setDropdownOpen(false)} sideOffset={12} side="bottom" align="end" onEscapeKeyDown={() => setDropdownOpen(false)} >
{ selectPubKey(value); }} > {pubKeys.map((pk) => ( ))} {!isReadOnly && ( { setViews({ type: ViewType.Transfer }, currentRouteId); setDropdownOpen(false); }} > {t('Transfer')} )} {t('Disconnect')}
); } return ( ); }; const KeypairItem = ({ pk, active }: { pk: PubKey; active: boolean }) => { const [copied, setCopied] = useCopyTimeout(); return (
{pk.name} {' | '} {truncateByChars(pk.publicKey)} setCopied(true)}> {copied && {t('Copied')}}
); };