import { t, truncateByChars } from '@vegaprotocol/react-helpers'; import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuItemIndicator, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, Icon, } from '@vegaprotocol/ui-toolkit'; import type { VegaKeyExtended } from '@vegaprotocol/wallet'; import { useVegaWallet } from '@vegaprotocol/wallet'; import { useEffect, useState } from 'react'; import CopyToClipboard from 'react-copy-to-clipboard'; export interface VegaWalletConnectButtonProps { setConnectDialog: (isOpen: boolean) => void; } export const VegaWalletConnectButton = ({ setConnectDialog, }: VegaWalletConnectButtonProps) => { const [dropdownOpen, setDropdownOpen] = useState(false); const { keypair, keypairs, selectPublicKey, disconnect } = useVegaWallet(); const isConnected = keypair !== null; if (isConnected && keypairs) { return ( setDropdownOpen((curr) => !curr)} > {keypair.name}:{' '} {truncateByChars(keypair.pub)} setDropdownOpen(false)}> { selectPublicKey(value); }} > {keypairs.map((kp) => ( ))} {t('Disconnect')} ); } return ( setConnectDialog(true)} size="sm" > {t('Connect Vega wallet')} ); }; const KeypairItem = ({ kp }: { kp: VegaKeyExtended }) => { 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 ( {kp.name}:{' '} {truncateByChars(kp.pub)} setCopied(true)}> e.stopPropagation()} > {t('Copy')} {copied && ( {t('Copied')} )} ); };