Repository navigation
Add identity restore UI #1101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add identity restore UI #1101
Changes from all commits
7017a58
a284b48
adbbe4b
ef07a04
f3a5728
6fd79d0
af03309
d031907
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { useState } from "react"; | ||
| import { npubEncode } from "nostr-tools/nip19"; | ||
| import { publicKeyLabels } from "../../shared/identity/public-key"; | ||
| import { Button } from "../../shared/design-system/ui/Button"; | ||
| import { Field } from "../../shared/design-system/ui/Field"; | ||
| import { Radio, RadioGroup } from "../../shared/design-system/ui/RadioGroup"; | ||
| import type { Identity, RecoveryState } from "./service"; | ||
|
|
||
| export function RestoreIdentity({ | ||
| identity, | ||
| recovery, | ||
| }: { | ||
| identity: Identity; | ||
| recovery: RecoveryState; | ||
| }) { | ||
| const [selected, setSelected] = useState<{ | ||
| recovery: RecoveryState; | ||
| handle: string; | ||
| }>(); | ||
| const candidates = recovery.status === "choosing" ? recovery.candidates : []; | ||
| const labels = publicKeyLabels( | ||
| candidates.map((candidate) => candidate.pubkey), | ||
| ); | ||
| const current = | ||
| recovery.status === "choosing" | ||
| ? candidates.find( | ||
| (candidate) => candidate.pubkey === recovery.currentPubkey, | ||
| ) | ||
| : undefined; | ||
| const handle = | ||
| selected?.recovery === recovery ? selected.handle : current?.handle; | ||
| return ( | ||
| <section className="flex flex-col gap-4" aria-label="Restore from backup"> | ||
| {recovery.status === "waiting" ? ( | ||
| <p role="status">Sign in in your browser to find your backups…</p> | ||
| ) : recovery.status === "saving" ? ( | ||
| <p role="status">Saving your identity securely…</p> | ||
| ) : recovery.status === "canceling" ? ( | ||
| <p role="status">Canceling recovery…</p> | ||
| ) : recovery.status === "error" ? ( | ||
| <p role="alert">{recovery.error}</p> | ||
| ) : candidates.length === 0 ? ( | ||
| <p role={recovery.failedCount ? "alert" : "status"}> | ||
| {recovery.failedCount | ||
| ? "Your backups couldn’t be recovered. Try again." | ||
| : "No backups were found for this account."} | ||
| </p> | ||
| ) : ( | ||
| <> | ||
| <p> | ||
| {current | ||
| ? "Choose the Buzz identity to restore on this device." | ||
| : recovery.currentPubkey | ||
| ? "Your current identity isn’t in these backups. You can choose a previous identity." | ||
| : "Choose the Buzz identity to restore on this device."} | ||
| </p> | ||
| <p>This won’t change the identity linked to your account.</p> | ||
| {recovery.failedCount > 0 && ( | ||
| <p role="status">Some backups couldn’t be recovered.</p> | ||
| )} | ||
| <Field label="Identity to restore" nativeLabel={false}> | ||
| <RadioGroup | ||
| aria-label="Identity to restore" | ||
| value={handle ?? null} | ||
| onValueChange={(value) => | ||
| value && setSelected({ recovery, handle: value }) | ||
| } | ||
| > | ||
| {candidates.map((candidate) => ( | ||
| <Radio | ||
| key={candidate.handle} | ||
| value={candidate.handle} | ||
| label={labels.get(candidate.pubkey)} | ||
| description={ | ||
| <> | ||
| {candidate.pubkey === current?.pubkey | ||
| ? "Current identity" | ||
| : "Previous identity"} | ||
| <code className="block break-all text-mono"> | ||
| {npubEncode(candidate.pubkey)} | ||
| </code> | ||
| </> | ||
| } | ||
| /> | ||
| ))} | ||
| </RadioGroup> | ||
| </Field> | ||
| </> | ||
| )} | ||
| <div className="flex flex-wrap gap-3"> | ||
| <Button | ||
| disabled={ | ||
| recovery.status === "saving" || recovery.status === "canceling" | ||
| } | ||
| onClick={() => void identity.cancelRecovery()} | ||
| > | ||
| {recovery.status === "waiting" ? "Cancel" : "Back"} | ||
| </Button> | ||
| {recovery.status === "choosing" && candidates.length > 0 ? ( | ||
| <Button | ||
| variant="primary" | ||
| disabled={!handle} | ||
| onClick={() => handle && void identity.installRecovery(handle)} | ||
| > | ||
| Restore this identity | ||
| </Button> | ||
| ) : recovery.status === "error" || | ||
| (recovery.status === "choosing" && candidates.length === 0) ? ( | ||
| <Button | ||
| variant="primary" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 [P3] Preserve focus while recovery changes views. Try recovery again invokes cancellation, changes the phase to canceling, and unmounts the focused primary button. Entering restore and going Back similarly replace focused controls. Browser checks confirmed focus falls to body on entry and Back, although Tab still reaches useful controls and no keyboard trap was reproduced. Keep the focused control mounted and disabled during transitions, or explicitly move focus into the restore section and back to the entry control, consistent with DESIGN.md's focused-control guidance.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Non-blocking P3 follow-up. Focus loss was reproduced again at d031907 on entry, Back and cancellation-gated retry. Useful Tab navigation still works; no keyboard trap was demonstrated. Please preserve or restore focus; this does not block approval. |
||
| onClick={() => void identity.beginRecovery()} | ||
| > | ||
| Try recovery again | ||
| </Button> | ||
| ) : null} | ||
| </div> | ||
| </section> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit (optional): when
currentPubkeyisnull(the account has no linked identity), every candidate is labelled "Previous identity", which the data doesn't support. Use a neutral label such as "Backed-up identity" in that case.