Skip to content

Commit 1bdd938

Browse files
morgmartnpub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsexwesbillmanPinky
authored
Add identity key help and reveal toggle to machine onboarding (#2064)
Signed-off-by: npub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsex <6e967af659416160ab4f2fd56d74c8c6f273791ee7bfc9468a1be37c387947be@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Wes <[email protected]> Co-authored-by: npub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsex <6e967af659416160ab4f2fd56d74c8c6f273791ee7bfc9468a1be37c387947be@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent 89bcbd8 commit 1bdd938

16 files changed

Lines changed: 500 additions & 73 deletions

‎desktop/playwright.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export default defineConfig({
2121
testMatch: [
2222
"**/smoke.spec.ts",
2323
"**/onboarding-docked-cta-screenshots.spec.ts",
24+
"**/identity-key-help.spec.ts",
25+
"**/key-import-reveal.spec.ts",
2426
"**/navigation.spec.ts",
2527
"**/channels.spec.ts",
2628
"**/channel-shared-header-backdrop.spec.ts",
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import * as React from "react";
2+
3+
import { Button } from "@/shared/ui/button";
4+
import {
5+
Dialog,
6+
DialogContent,
7+
DialogDescription,
8+
DialogTitle,
9+
DialogTrigger,
10+
} from "@/shared/ui/dialog";
11+
import { ONBOARDING_INK_ICON_CLASS } from "./OnboardingChrome";
12+
import { OnboardingFooter } from "./OnboardingFooter";
13+
14+
const IDENTITY_KEY_HELP_SEEN_STORAGE_KEY =
15+
"buzz.machine-onboarding.identity-key-help-seen.v1";
16+
const IDENTITY_KEY_HELP_DELAY_MS = 2_000;
17+
18+
function hasSeenIdentityKeyHelp(): boolean {
19+
try {
20+
return (
21+
window.localStorage.getItem(IDENTITY_KEY_HELP_SEEN_STORAGE_KEY) === "true"
22+
);
23+
} catch {
24+
return false;
25+
}
26+
}
27+
28+
function rememberIdentityKeyHelpSeen() {
29+
try {
30+
window.localStorage.setItem(IDENTITY_KEY_HELP_SEEN_STORAGE_KEY, "true");
31+
} catch {
32+
// The help remains available for this visit if storage is unavailable.
33+
}
34+
}
35+
36+
export function IdentityKeyHelpDialog() {
37+
const [isVisible, setIsVisible] = React.useState(hasSeenIdentityKeyHelp);
38+
39+
React.useEffect(() => {
40+
if (isVisible) return;
41+
42+
const timeout = window.setTimeout(() => {
43+
rememberIdentityKeyHelpSeen();
44+
setIsVisible(true);
45+
}, IDENTITY_KEY_HELP_DELAY_MS);
46+
47+
return () => window.clearTimeout(timeout);
48+
}, [isVisible]);
49+
50+
return (
51+
<Dialog>
52+
<OnboardingFooter className="max-w-none">
53+
<DialogTrigger asChild>
54+
<Button
55+
className={`text-foreground/70 transition-opacity duration-300 hover:text-foreground motion-reduce:transition-none ${
56+
isVisible ? "opacity-100" : "pointer-events-none opacity-0"
57+
}`}
58+
data-testid="identity-key-help-trigger"
59+
tabIndex={isVisible ? 0 : -1}
60+
type="button"
61+
variant="link"
62+
>
63+
What’s an identity key?
64+
</Button>
65+
</DialogTrigger>
66+
</OnboardingFooter>
67+
<DialogContent
68+
className="buzz-onboarding-neutral-theme max-w-[47.5rem] -translate-y-5"
69+
closeButtonClassName={ONBOARDING_INK_ICON_CLASS}
70+
data-testid="identity-key-help-dialog"
71+
overlayVariant="transparent"
72+
surface="textured"
73+
>
74+
<div className="mx-auto w-full max-w-[35rem] py-14 text-left max-sm:py-6">
75+
<DialogTitle className="text-balance pr-8 text-3xl font-normal text-foreground">
76+
What’s an identity key?
77+
</DialogTitle>
78+
<DialogDescription
79+
asChild
80+
className="mt-6 space-y-4 text-pretty text-base leading-7 text-[color:var(--buzz-onboarding-backup-ink)]"
81+
>
82+
<div>
83+
<p>
84+
Buzz uses an identity key instead of a traditional account. It’s
85+
created on your device and represents you whenever you use Buzz.
86+
</p>
87+
<p>
88+
Your identity belongs to you, not Buzz. There’s no password to
89+
reset, and Buzz can’t recover your key if you lose it. Keep a
90+
backup somewhere safe and never share it. Anyone with your key
91+
can act as you.
92+
</p>
93+
<p>
94+
If you’re new to Buzz, create a new identity key. If you already
95+
have a Nostr identity, use your existing key.
96+
</p>
97+
</div>
98+
</DialogDescription>
99+
</div>
100+
</DialogContent>
101+
</Dialog>
102+
);
103+
}

‎desktop/src/features/onboarding/ui/MachineOnboardingFlow.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Button } from "@/shared/ui/button";
1414
import { StartupWindowDragRegion } from "@/shared/ui/StartupWindowDragRegion";
1515
import { BackupStep } from "./BackupStep";
1616
import { DefaultConfigStep } from "./DefaultConfigStep";
17+
import { IdentityKeyHelpDialog } from "./IdentityKeyHelpDialog";
1718
import { LandingBees } from "./LandingBees";
1819
import { NostrKeyImportForm } from "./NostrKeyImportForm";
1920
import {
@@ -154,7 +155,7 @@ export function MachineOnboardingFlow({
154155

155156
return (
156157
<div
157-
className={`buzz-onboarding-neutral-theme buzz-startup-shell flex max-h-dvh items-start justify-center overflow-y-auto px-4 text-foreground ${
158+
className={`buzz-onboarding-neutral-theme buzz-startup-shell flex max-h-dvh items-start justify-center overflow-x-hidden overflow-y-auto px-4 text-foreground ${
158159
page === "identity"
159160
? "buzz-onboarding-welcome py-8"
160161
: "pb-28 pt-[106px]"
@@ -200,7 +201,7 @@ export function MachineOnboardingFlow({
200201
onClick={() => void loadFreshIdentity()}
201202
type="button"
202203
>
203-
{isPending ? "Saving identity…" : "Get started"}
204+
{isPending ? "Saving identity…" : "Create a new identity key"}
204205
</Button>
205206
<Button
206207
className="h-9 rounded-full bg-foreground/10 px-5 hover:bg-foreground/15"
@@ -209,9 +210,10 @@ export function MachineOnboardingFlow({
209210
type="button"
210211
variant="ghost"
211212
>
212-
Enter a key
213+
Use an existing key
213214
</Button>
214215
</div>
216+
<IdentityKeyHelpDialog />
215217
</OnboardingSlideTransition>
216218
) : page === "key-import" ? (
217219
<OnboardingSlideTransition

‎desktop/src/features/onboarding/ui/NostrKeyImportForm.tsx‎

Lines changed: 90 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as React from "react";
2-
import { Check, KeyRound } from "lucide-react";
2+
import { Check, Eye, EyeOff, KeyRound } from "lucide-react";
33

44
import { cn } from "@/shared/lib/cn";
55
import { nsecToNpub } from "@/shared/lib/nostrUtils";
66
import { Button } from "@/shared/ui/button";
77
import { Card } from "@/shared/ui/card";
88
import { Input } from "@/shared/ui/input";
99
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";
1114
import { OnboardingFooter } from "./OnboardingFooter";
1215

1316
const NOSTR_KEY_FILE_MAX_BYTES = 1024;
@@ -41,11 +44,21 @@ export function NostrKeyImportForm({
4144
const [isImporting, setIsImporting] = React.useState(false);
4245
const [importError, setImportError] = React.useState<string | null>(null);
4346
const [isDragging, setIsDragging] = React.useState(false);
47+
const [isRevealed, setIsRevealed] = React.useState(false);
4448
const inputRef = React.useRef<HTMLInputElement | null>(null);
4549
const fileInputRef = React.useRef<HTMLInputElement | null>(null);
4650
const previewNpub = React.useMemo(() => nsecToNpub(nsecInput), [nsecInput]);
4751
const trimmedInput = nsecInput.trim();
4852
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]);
4962
const isValid = previewNpub !== null;
5063
const isInteractionDisabled = disabled || isImporting;
5164
const showInvalidHint = hasInput && !isValid && trimmedInput.length >= 5;
@@ -143,22 +156,52 @@ export function NostrKeyImportForm({
143156
data-testid="nostr-import-card"
144157
variant="textured"
145158
>
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>
162205
</Card>
163206
) : (
164207
<Input
@@ -270,25 +313,42 @@ export function NostrKeyImportForm({
270313
data-testid="nostr-import-feedback"
271314
>
272315
{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
281326
</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)]">
283328
{previewNpub}
284329
</p>
285330
</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+
)
287347
) : null}
288348

289349
{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
292352
</p>
293353
) : null}
294354

‎desktop/src/features/onboarding/ui/OnboardingChrome.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ export const ONBOARDING_PRIMARY_CTA_CLASS = `${ONBOARDING_CTA_SHAPE} text-[var(-
2424
*/
2525
export const ONBOARDING_LANDING_CTA_CLASS = `${ONBOARDING_CTA_SHAPE} text-[var(--buzz-welcome-chartreuse)]`;
2626

27+
/**
28+
* Icon-control styling for onboarding surfaces that sit on the textured card:
29+
* olive backup ink (`--buzz-onboarding-backup-ink`) with a plain
30+
* brighten-to-foreground hover (no hover pill, which would read as a floating
31+
* box on the texture). Used by the identity-help dialog close button and the
32+
* key-import reveal toggle.
33+
*/
34+
export const ONBOARDING_INK_ICON_CLASS =
35+
"text-[color:var(--buzz-onboarding-backup-ink)] hover:bg-transparent hover:text-foreground";
36+
2737
/**
2838
* Shared onboarding chrome shown on every page after the landing screen: a
2939
* static Buzz mark pinned to the top-left, and a centered pagination track that

‎desktop/src/shared/ui/card-texture.css‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,30 @@
77
* fixed and repeats edge texture while the white center fills any card size.
88
*/
99
.buzz-card-textured {
10+
/*
11+
* The asset has three zones, from outside in:
12+
* 1. transparent powder bleed (outside the layout box, via outset)
13+
* 2. feathered fade (inside the layout edge, white is NOT fully opaque)
14+
* 3. solid white center (safe for content)
15+
*
16+
* `--buzz-card-textured-safe-inset` is the distance from the layout edge
17+
* to zone 3. `Card variant="textured"` applies it as default padding so
18+
* content always lands on solid fill. Features may add more padding,
19+
* never less — and must never layer an opaque surface on top of the
20+
* texture; the baked white center IS the surface.
21+
*/
22+
--buzz-card-textured-safe-inset: 5rem;
1023
border: 0 solid transparent;
24+
/*
25+
* Each border-image band is 208px wide but extends 96px outside the layout
26+
* box (outset), leaving 112px per edge inside it. Below 224px (2 × 112px)
27+
* on either axis the opposing bands collapse into each other: the solid
28+
* white center region disappears and the bands meet on a semi-transparent
29+
* row of the fade, which shows the page background through as a thin seam
30+
* line. Enforce the floor so the texture can never degenerate.
31+
*/
32+
min-height: 224px;
33+
min-width: 224px;
1134
border-image-source: url("./assets/card-texture.png");
1235
border-image-slice: 416 fill;
1336
border-image-width: 208px;

0 commit comments

Comments
 (0)