|
1 | 1 | import * as React from "react"; |
2 | | -import { Check, KeyRound } from "lucide-react"; |
| 2 | +import { Check, Eye, EyeOff, KeyRound } from "lucide-react"; |
3 | 3 |
|
4 | 4 | import { cn } from "@/shared/lib/cn"; |
5 | 5 | import { nsecToNpub } from "@/shared/lib/nostrUtils"; |
6 | 6 | import { Button } from "@/shared/ui/button"; |
7 | 7 | import { Card } from "@/shared/ui/card"; |
8 | 8 | import { Input } from "@/shared/ui/input"; |
9 | 9 | import { Spinner } from "@/shared/ui/spinner"; |
10 | | -import { ONBOARDING_PRIMARY_CTA_CLASS } from "./OnboardingChrome"; |
| 10 | +import { |
| 11 | + ONBOARDING_INK_ICON_CLASS, |
| 12 | + ONBOARDING_PRIMARY_CTA_CLASS, |
| 13 | +} from "./OnboardingChrome"; |
11 | 14 | import { OnboardingFooter } from "./OnboardingFooter"; |
12 | 15 |
|
13 | 16 | const NOSTR_KEY_FILE_MAX_BYTES = 1024; |
@@ -41,11 +44,21 @@ export function NostrKeyImportForm({ |
41 | 44 | const [isImporting, setIsImporting] = React.useState(false); |
42 | 45 | const [importError, setImportError] = React.useState<string | null>(null); |
43 | 46 | const [isDragging, setIsDragging] = React.useState(false); |
| 47 | + const [isRevealed, setIsRevealed] = React.useState(false); |
44 | 48 | const inputRef = React.useRef<HTMLInputElement | null>(null); |
45 | 49 | const fileInputRef = React.useRef<HTMLInputElement | null>(null); |
46 | 50 | const previewNpub = React.useMemo(() => nsecToNpub(nsecInput), [nsecInput]); |
47 | 51 | const trimmedInput = nsecInput.trim(); |
48 | 52 | const hasInput = trimmedInput.length > 0; |
| 53 | + |
| 54 | + // Masked-by-default must re-assert whenever the field empties: a sticky |
| 55 | + // reveal from a previous key must never apply to newly pasted content the |
| 56 | + // user hasn't chosen to expose. |
| 57 | + React.useEffect(() => { |
| 58 | + if (!hasInput) { |
| 59 | + setIsRevealed(false); |
| 60 | + } |
| 61 | + }, [hasInput]); |
49 | 62 | const isValid = previewNpub !== null; |
50 | 63 | const isInteractionDisabled = disabled || isImporting; |
51 | 64 | const showInvalidHint = hasInput && !isValid && trimmedInput.length >= 5; |
@@ -143,22 +156,52 @@ export function NostrKeyImportForm({ |
143 | 156 | data-testid="nostr-import-card" |
144 | 157 | variant="textured" |
145 | 158 | > |
146 | | - <Input |
147 | | - autoComplete="off" |
148 | | - autoCorrect="off" |
149 | | - className="h-[3.6875rem] rounded-none border-0 bg-transparent px-0 text-center font-mono !text-4xl shadow-none placeholder:text-foreground/30 focus-visible:ring-0" |
150 | | - data-testid="nostr-import-nsec-input" |
151 | | - id="nostr-private-key" |
152 | | - onChange={(event) => { |
153 | | - setNsecInput(event.target.value); |
154 | | - setImportError(null); |
155 | | - }} |
156 | | - placeholder="Enter your key here" |
157 | | - ref={inputRef} |
158 | | - spellCheck={false} |
159 | | - type="password" |
160 | | - value={nsecInput} |
161 | | - /> |
| 159 | + <div className="relative w-full"> |
| 160 | + <Input |
| 161 | + autoComplete="off" |
| 162 | + autoCorrect="off" |
| 163 | + // Symmetric px reserves the absolutely positioned toggle's |
| 164 | + // footprint on BOTH sides, so the centered key text never |
| 165 | + // runs under the eye control and stays optically centered. |
| 166 | + className="h-[3.6875rem] rounded-none border-0 bg-transparent px-10 text-center font-mono !text-4xl text-[color:var(--buzz-onboarding-backup-ink)] shadow-none placeholder:text-foreground/30 focus-visible:ring-0" |
| 167 | + data-testid="nostr-import-nsec-input" |
| 168 | + id="nostr-private-key" |
| 169 | + onChange={(event) => { |
| 170 | + setNsecInput(event.target.value); |
| 171 | + setImportError(null); |
| 172 | + }} |
| 173 | + placeholder="Enter your key here" |
| 174 | + ref={inputRef} |
| 175 | + spellCheck={false} |
| 176 | + type={isRevealed ? "text" : "password"} |
| 177 | + value={nsecInput} |
| 178 | + /> |
| 179 | + {/* Absolutely positioned so appearing/disappearing never resizes |
| 180 | + the input or shifts its centered text; fades with hasInput. */} |
| 181 | + <Button |
| 182 | + aria-hidden={!hasInput} |
| 183 | + aria-label={ |
| 184 | + isRevealed ? "Hide private key" : "Reveal private key" |
| 185 | + } |
| 186 | + className={cn( |
| 187 | + ONBOARDING_INK_ICON_CLASS, |
| 188 | + "absolute -right-2 top-1/2 h-10 w-10 -translate-y-1/2 transition-opacity duration-300 motion-reduce:transition-none", |
| 189 | + hasInput ? "opacity-100" : "pointer-events-none opacity-0", |
| 190 | + )} |
| 191 | + data-testid="nostr-import-reveal-toggle" |
| 192 | + onClick={() => setIsRevealed((current) => !current)} |
| 193 | + size="icon" |
| 194 | + tabIndex={hasInput ? 0 : -1} |
| 195 | + type="button" |
| 196 | + variant="ghost" |
| 197 | + > |
| 198 | + {isRevealed ? ( |
| 199 | + <EyeOff aria-hidden="true" className="h-6 w-6" /> |
| 200 | + ) : ( |
| 201 | + <Eye aria-hidden="true" className="h-6 w-6" /> |
| 202 | + )} |
| 203 | + </Button> |
| 204 | + </div> |
162 | 205 | </Card> |
163 | 206 | ) : ( |
164 | 207 | <Input |
@@ -270,25 +313,42 @@ export function NostrKeyImportForm({ |
270 | 313 | data-testid="nostr-import-feedback" |
271 | 314 | > |
272 | 315 | {previewNpub ? ( |
273 | | - <div |
274 | | - className="flex items-start gap-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2 text-xs" |
275 | | - data-testid="nostr-import-npub-preview" |
276 | | - > |
277 | | - <Check className="mt-0.5 h-4 w-4 shrink-0 text-primary" /> |
278 | | - <div className="min-w-0 space-y-0.5"> |
279 | | - <p className="font-medium text-foreground"> |
280 | | - This will use this Nostr identity: |
| 316 | + variant === "spotlight" ? ( |
| 317 | + // Spotlight uses the backup step's quiet caption language: |
| 318 | + // centered, unboxed, with the npub in the shared olive key ink. |
| 319 | + <div |
| 320 | + className="space-y-1 text-sm" |
| 321 | + data-testid="nostr-import-npub-preview" |
| 322 | + > |
| 323 | + <p className="flex items-center justify-center gap-1.5 text-foreground"> |
| 324 | + <Check aria-hidden="true" className="h-4 w-4 shrink-0" /> |
| 325 | + Nostr identity found |
281 | 326 | </p> |
282 | | - <p className="break-all font-mono text-2xs text-muted-foreground"> |
| 327 | + <p className="break-all font-mono text-[color:var(--buzz-onboarding-backup-ink)]"> |
283 | 328 | {previewNpub} |
284 | 329 | </p> |
285 | 330 | </div> |
286 | | - </div> |
| 331 | + ) : ( |
| 332 | + <div |
| 333 | + className="flex items-start gap-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2 text-xs" |
| 334 | + data-testid="nostr-import-npub-preview" |
| 335 | + > |
| 336 | + <Check className="mt-0.5 h-4 w-4 shrink-0 text-primary" /> |
| 337 | + <div className="min-w-0 space-y-0.5"> |
| 338 | + <p className="font-medium text-foreground"> |
| 339 | + This will use this Nostr identity: |
| 340 | + </p> |
| 341 | + <p className="break-all font-mono text-2xs text-muted-foreground"> |
| 342 | + {previewNpub} |
| 343 | + </p> |
| 344 | + </div> |
| 345 | + </div> |
| 346 | + ) |
287 | 347 | ) : null} |
288 | 348 |
|
289 | 349 | {showInvalidHint && !errorMessage ? ( |
290 | | - <p className="text-xs text-muted-foreground"> |
291 | | - Waiting for a valid nsec1 key. |
| 350 | + <p className="text-sm text-muted-foreground"> |
| 351 | + Waiting for a valid nsec1 key |
292 | 352 | </p> |
293 | 353 | ) : null} |
294 | 354 |
|
|
0 commit comments