fix: derive imported profile name
This commit is contained in:
parent
470a98f16e
commit
b368958a91
2 changed files with 76 additions and 0 deletions
43
frontend/src/screens/ImportProfileModal.tsx
Normal file
43
frontend/src/screens/ImportProfileModal.tsx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { useEffect, useRef, useState, type FormEvent } from 'react';
|
||||
import { Button } from '../components/Button';
|
||||
import { ErrorText } from '../components/ErrorText';
|
||||
import { Modal } from '../components/Modal';
|
||||
import { useApp } from '../state/AppProvider';
|
||||
|
||||
export function ImportProfileModal({ open, onClose }: { open: boolean; onClose: () => void }) {
|
||||
const { importProfile } = useApp();
|
||||
const [secret, setSecret] = useState('');
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const labelRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setSecret(''); setError(null); setSaving(false);
|
||||
requestAnimationFrame(() => labelRef.current?.focus());
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
const submit = async (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
if (!secret.trim() || saving) return;
|
||||
setSaving(true); setError(null);
|
||||
try { await importProfile('', secret.trim()); onClose(); }
|
||||
catch (err) { setError(err instanceof Error ? err.message : String(err)); setSaving(false); }
|
||||
};
|
||||
|
||||
return <Modal open={open} title="Add an existing account" onClose={onClose}>
|
||||
<form onSubmit={submit} noValidate>
|
||||
<p className="muted">Import an account using its private key. The key stays in your local vault and is never displayed.</p>
|
||||
<div className="field">
|
||||
<label htmlFor="import-profile-secret">Private key</label>
|
||||
<input id="import-profile-secret" type="password" value={secret} onChange={(e) => setSecret(e.target.value)} placeholder="nsec1... or 64-character hex" autoComplete="off" />
|
||||
{error && <ErrorText>{error}</ErrorText>}
|
||||
</div>
|
||||
<div className="modal-actions">
|
||||
<Button variant="ghost" onClick={onClose} disabled={saving}>Cancel</Button>
|
||||
<Button variant="primary" type="submit" loading={saving} disabled={!secret.trim()}>{saving ? 'Adding…' : 'Add account'}</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue