import { useState, ReactElement, useEffect } from 'react' import './PrivateKeyModal.scss' import { Button } from '../Button/Button' import { setSignerPk, getSigner } from '../../utils/common' import { PrivateKey } from '@ethersphere/bee-js' import ClipboardIcon from 'remixicon-react/FileCopyLineIcon' import CheckDoubleLineIcon from 'remixicon-react/CheckDoubleLineIcon' import { Tooltip } from '../Tooltip/Tooltip' import { TOOLTIPS } from '../../constants/tooltips' type Props = { onSaved: () => void } export function PrivateKeyModal({ onSaved }: Props): ReactElement { const [value, setValue] = useState('') const [confirmValue, setConfirmValue] = useState('') const [showError, setShowError] = useState(false) const [copied, setCopied] = useState(false) useEffect(() => { handleGenerateNew() }, []) const handleCopyPrivateKey = async () => { try { await navigator.clipboard.writeText(value) setCopied(true) } catch { // eslint-disable-next-line no-console console.debug('Failed to copy private key to clipboard') } } const handleGenerateNew = () => { const id = crypto.randomUUID() const signer = getSigner(id) const privKey = signer.toHex() setValue(privKey) setConfirmValue('') setCopied(false) setShowError(false) } const handleBlur = () => { if (!value.trim()) { return } try { new PrivateKey(value) setShowError(false) } catch { setShowError(true) setCopied(false) } } const handleSave = () => { try { new PrivateKey(value) setSignerPk(value) onSaved() } catch { setShowError(true) } } return (