import { t, truncateByChars } from '@vegaprotocol/react-helpers'; import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuItemIndicator, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, Icon, } from '@vegaprotocol/ui-toolkit'; import { useVegaWallet } from '@vegaprotocol/wallet'; import { useEffect, useMemo, 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 { 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((k) => ( ))} {t('Disconnect')} ); } return ( setConnectDialog(true)} size="sm" > {t('Connect Vega wallet')} ); }; const KeypairItem = ({ kp }: { kp: string }) => { 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 ( {truncateByChars(kp)} setCopied(true)}> e.stopPropagation()} > {t('Copy')} {copied && ( {t('Copied')} )} ); };