import { t, truncateByChars } from '@vegaprotocol/react-helpers'; import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuItemIndicator, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, Icon, } from '@vegaprotocol/ui-toolkit'; import type { PubKey } from '@vegaprotocol/wallet'; import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet'; import { useEffect, useMemo, useState } from 'react'; import CopyToClipboard from 'react-copy-to-clipboard'; export const VegaWalletConnectButton = () => { const [dropdownOpen, setDropdownOpen] = useState(false); const { openVegaWalletDialog } = useVegaWalletDialogStore((store) => ({ openVegaWalletDialog: store.openVegaWalletDialog, })); const { pubKey, pubKeys, selectPubKey, disconnect } = useVegaWallet(); const isConnected = pubKey !== null; const activeKey = useMemo(() => { return pubKeys?.find((pk) => pk.publicKey === pubKey); }, [pubKey, pubKeys]); if (isConnected && pubKeys) { return ( setDropdownOpen((curr) => !curr)} > {activeKey && {activeKey.name}} {': '} {truncateByChars(pubKey)} setDropdownOpen(false)}>
{ selectPubKey(value); }} > {pubKeys.map((pk) => ( ))} {t('Disconnect')}
); } return ( ); }; const KeypairItem = ({ pk }: { pk: PubKey }) => { const [copied, setCopied] = useState(false); useEffect(() => { // eslint-disable-next-line let timeout: any; if (copied) { timeout = setTimeout(() => { setCopied(false); }, 800); } return () => { clearTimeout(timeout); }; }, [copied]); return (
{pk.name}:{' '} {truncateByChars(pk.publicKey)} setCopied(true)}> {copied && ( {t('Copied')} )}
); };