Skip to content

Commit 7873135

Browse files
authored
Polish private key onboarding texture (#2051)
1 parent 385dde1 commit 7873135

10 files changed

Lines changed: 375 additions & 84 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Textured Card asset
2+
3+
`Card variant="textured"` renders a cheap CSS nine-slice PNG at runtime. This
4+
folder preserves the procedural SVG recipe used to generate that asset.
5+
6+
## Regenerate
7+
8+
From `desktop/`:
9+
10+
```bash
11+
pnpm exec node scripts/texture-card/generate-card-texture.mjs
12+
```
13+
14+
This overwrites:
15+
16+
```text
17+
src/shared/ui/assets/card-texture.png
18+
```
19+
20+
The generator renders the archived SVG filter in headless Chromium at 2× DPR,
21+
then captures a transparent PNG. It is a development tool only and is not
22+
included in the production bundle.
23+
24+
After changing texture parameters:
25+
26+
1. Regenerate the asset.
27+
2. Compare the onboarding private-key card at its normal size.
28+
3. Check a tall/narrow textured Card and the smallest supported shape.
29+
4. Check both Retina and standard-density displays.
30+
5. Update the slice/outset values in `card-texture.css` only if the generated
31+
geometry changed.
32+
33+
The runtime component API remains `Card variant="textured"`; feature code owns
34+
padding, dimensions, typography, and placement.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Generates the baked nine-slice texture used by Card variant="textured".
4+
*
5+
* This file is the source of truth for the procedural visual. It deliberately
6+
* lives outside runtime code: edit the parameters below, run this script, then
7+
* visually compare the generated asset before committing it.
8+
*/
9+
import { chromium } from "@playwright/test";
10+
import { mkdir } from "node:fs/promises";
11+
import path from "node:path";
12+
import { fileURLToPath } from "node:url";
13+
14+
const HERE = path.dirname(fileURLToPath(import.meta.url));
15+
const OUTPUT = path.resolve(
16+
HERE,
17+
"../../src/shared/ui/assets/card-texture.png",
18+
);
19+
20+
// CSS-pixel source geometry. Screenshotting at DPR 2 produces a crisp asset.
21+
const CARD_SIZE = 640;
22+
const OUTSET = 96;
23+
const CAPTURE_SIZE = CARD_SIZE + OUTSET * 2;
24+
const DPR = 2;
25+
26+
// Approved texture parameters, archived from the former runtime SVG filter.
27+
const BLUR = 66;
28+
const DILATE = Math.round(BLUR * 0.85);
29+
const THRESHOLD_BIAS = 0.302;
30+
const SLOPE = 8;
31+
const FREQUENCY = 0.999;
32+
const OCTAVES = 3;
33+
const SEED = 5315;
34+
35+
await mkdir(path.dirname(OUTPUT), { recursive: true });
36+
37+
const browser = await chromium.launch();
38+
try {
39+
const page = await browser.newPage({
40+
deviceScaleFactor: DPR,
41+
viewport: { height: CAPTURE_SIZE, width: CAPTURE_SIZE },
42+
});
43+
44+
await page.setContent(`<!doctype html>
45+
<style>
46+
html, body { margin: 0; width: 100%; height: 100%; background: transparent; }
47+
#stage { position: relative; width: ${CAPTURE_SIZE}px; height: ${CAPTURE_SIZE}px; }
48+
#core {
49+
position: absolute;
50+
inset: ${OUTSET + BLUR / 2}px;
51+
background: white;
52+
filter: blur(${BLUR / 3}px);
53+
}
54+
</style>
55+
<div id="stage">
56+
<svg width="${CAPTURE_SIZE}" height="${CAPTURE_SIZE}" aria-hidden="true">
57+
<defs>
58+
<filter id="texture" x="0" y="0" width="100%" height="100%"
59+
filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
60+
<feMorphology in="SourceAlpha" operator="dilate" radius="${DILATE}" result="squared" />
61+
<feGaussianBlur in="squared" stdDeviation="${BLUR}" result="ramp" />
62+
<feTurbulence type="fractalNoise" baseFrequency="${FREQUENCY}"
63+
numOctaves="${OCTAVES}" seed="${SEED}" result="grain" />
64+
<feColorMatrix in="grain" result="grainAlpha" type="matrix"
65+
values="0 0 0 0 0
66+
0 0 0 0 0
67+
0 0 0 0 0
68+
1 0 0 0 0" />
69+
<feComposite in="ramp" in2="grainAlpha" operator="arithmetic"
70+
k1="0" k2="1" k3="-1" k4="${-THRESHOLD_BIAS}" result="dithered" />
71+
<feComponentTransfer in="dithered" result="specks">
72+
<feFuncA type="linear" slope="${SLOPE}" intercept="0" />
73+
</feComponentTransfer>
74+
<feFlood flood-color="white" result="white" />
75+
<feComposite in="white" in2="specks" operator="in" />
76+
</filter>
77+
</defs>
78+
<rect x="${OUTSET}" y="${OUTSET}" width="${CARD_SIZE}" height="${CARD_SIZE}"
79+
fill="white" filter="url(#texture)" />
80+
</svg>
81+
<span id="core"></span>
82+
</div>`);
83+
84+
await page.locator("#stage").screenshot({
85+
omitBackground: true,
86+
path: OUTPUT,
87+
});
88+
} finally {
89+
await browser.close();
90+
}
91+
92+
console.log(`Generated ${OUTPUT}`);
93+
console.log(`Asset: ${CAPTURE_SIZE * DPR}×${CAPTURE_SIZE * DPR}px @${DPR}x`);
94+
console.log(`Runtime slice: ${(OUTSET + 112) * DPR}px; outset: ${OUTSET}px`);

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

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,28 +215,35 @@ export function MachineOnboardingFlow({
215215
</OnboardingSlideTransition>
216216
) : page === "key-import" ? (
217217
<OnboardingSlideTransition
218-
className="flex w-full max-w-[640px] flex-col items-center text-center"
218+
className="flex min-h-[calc(100dvh-13.25rem)] w-full max-w-[837px] flex-col items-center text-center"
219219
direction="forward"
220+
effect="fade"
220221
transitionKey="machine-key-import"
221222
>
222-
<h1 className="text-title font-normal text-foreground">
223-
{identityLost ? "Re-import your key" : "Enter your private key"}
224-
</h1>
225-
<p className="mt-5 max-w-[440px] text-sm leading-6 text-foreground/80">
226-
{identityLost
227-
? "Your identity is no longer in the system keyring. Re-import your nsec to restore it."
228-
: "If you already have a Nostr account, enter your private key below to get started."}
229-
</p>
230-
<NostrKeyImportForm
231-
backLabel={identityLost ? "Start new identity" : "Back"}
232-
onBack={
233-
identityLost
234-
? () => void replaceLostIdentity()
235-
: () => setPage("identity")
236-
}
237-
onImport={importExistingIdentity}
238-
variant="spotlight"
239-
/>
223+
<div className="shrink-0">
224+
<h1 className="text-title font-normal text-foreground">
225+
{identityLost
226+
? "Re-import your key"
227+
: "Enter your private key"}
228+
</h1>
229+
<p className="mt-5 max-w-[440px] text-sm leading-6 text-foreground/80">
230+
{identityLost
231+
? "Your identity is no longer in the system keyring. Re-import your nsec to restore it."
232+
: "If you already have a Nostr account, enter your private key below to get started."}
233+
</p>
234+
</div>
235+
<div className="buzz-onboarding-key-import-position w-full">
236+
<NostrKeyImportForm
237+
backLabel={identityLost ? "Start new identity" : "Back"}
238+
onBack={
239+
identityLost
240+
? () => void replaceLostIdentity()
241+
: () => setPage("identity")
242+
}
243+
onImport={importExistingIdentity}
244+
variant="spotlight"
245+
/>
246+
</div>
240247
</OnboardingSlideTransition>
241248
) : page === "backup" ? (
242249
<BackupStep

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

Lines changed: 77 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Check, KeyRound } from "lucide-react";
44
import { cn } from "@/shared/lib/cn";
55
import { nsecToNpub } from "@/shared/lib/nostrUtils";
66
import { Button } from "@/shared/ui/button";
7+
import { Card } from "@/shared/ui/card";
78
import { Input } from "@/shared/ui/input";
89
import { Spinner } from "@/shared/ui/spinner";
910
import { ONBOARDING_PRIMARY_CTA_CLASS } from "./OnboardingChrome";
@@ -127,36 +128,56 @@ export function NostrKeyImportForm({
127128
}}
128129
>
129130
<div className="space-y-1.5 text-left">
130-
{variant === "spotlight" ? null : (
131-
<label
132-
className="text-sm font-medium text-foreground"
133-
htmlFor="nostr-private-key"
131+
<label
132+
className={cn(
133+
"text-sm font-medium text-foreground",
134+
variant === "spotlight" && "sr-only",
135+
)}
136+
htmlFor="nostr-private-key"
137+
>
138+
Private key
139+
</label>
140+
{variant === "spotlight" ? (
141+
<Card
142+
className="w-full px-8 py-12"
143+
data-testid="nostr-import-card"
144+
variant="textured"
134145
>
135-
Private key
136-
</label>
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+
/>
162+
</Card>
163+
) : (
164+
<Input
165+
autoComplete="off"
166+
autoCorrect="off"
167+
className="h-10 bg-background"
168+
data-testid="nostr-import-nsec-input"
169+
id="nostr-private-key"
170+
onChange={(event) => {
171+
setNsecInput(event.target.value);
172+
setImportError(null);
173+
}}
174+
placeholder="nsec1..."
175+
ref={inputRef}
176+
spellCheck={false}
177+
type="password"
178+
value={nsecInput}
179+
/>
137180
)}
138-
<Input
139-
autoComplete="off"
140-
autoCorrect="off"
141-
className={
142-
variant === "spotlight"
143-
? "h-16 rounded-2xl border-0 bg-white/85 text-center font-mono !text-xl shadow-[0_0_70px_45px_rgba(255,255,255,0.85)] placeholder:text-foreground/30 focus-visible:ring-0"
144-
: "h-10 bg-background"
145-
}
146-
data-testid="nostr-import-nsec-input"
147-
id="nostr-private-key"
148-
onChange={(event) => {
149-
setNsecInput(event.target.value);
150-
setImportError(null);
151-
}}
152-
placeholder={
153-
variant === "spotlight" ? "Enter your key here" : "nsec1..."
154-
}
155-
ref={inputRef}
156-
spellCheck={false}
157-
type="password"
158-
value={nsecInput}
159-
/>
160181
</div>
161182

162183
{variant === "spotlight" ? null : (
@@ -244,32 +265,37 @@ export function NostrKeyImportForm({
244265
</>
245266
)}
246267

247-
{previewNpub ? (
248-
<div
249-
className="flex items-start gap-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2 text-xs"
250-
data-testid="nostr-import-npub-preview"
251-
>
252-
<Check className="mt-0.5 h-4 w-4 shrink-0 text-primary" />
253-
<div className="min-w-0 space-y-0.5">
254-
<p className="font-medium text-foreground">
255-
This will use this Nostr identity:
256-
</p>
257-
<p className="break-all font-mono text-2xs text-muted-foreground">
258-
{previewNpub}
259-
</p>
268+
<div
269+
className={cn("min-h-8", variant === "spotlight" && "mt-6 text-center")}
270+
data-testid="nostr-import-feedback"
271+
>
272+
{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:
281+
</p>
282+
<p className="break-all font-mono text-2xs text-muted-foreground">
283+
{previewNpub}
284+
</p>
285+
</div>
260286
</div>
261-
</div>
262-
) : null}
287+
) : null}
263288

264-
{showInvalidHint && !errorMessage ? (
265-
<p className="text-xs text-muted-foreground">
266-
Waiting for a valid nsec1 key.
267-
</p>
268-
) : null}
289+
{showInvalidHint && !errorMessage ? (
290+
<p className="text-xs text-muted-foreground">
291+
Waiting for a valid nsec1 key.
292+
</p>
293+
) : null}
269294

270-
{errorMessage ? (
271-
<p className="text-center text-sm text-destructive">{errorMessage}</p>
272-
) : null}
295+
{errorMessage ? (
296+
<p className="text-center text-sm text-destructive">{errorMessage}</p>
297+
) : null}
298+
</div>
273299

274300
<OnboardingFooter>
275301
<Button

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type OnboardingSlideTransitionProps = React.HTMLAttributes<HTMLDivElement> & {
1212

1313
export type OnboardingTransitionDirection = "forward" | "backward";
1414
export type OnboardingTransitionEffect =
15+
| "fade"
1516
| "line-slide"
1617
| "mask-reveal-up"
1718
| "none";

‎desktop/src/shared/styles/globals/components.css‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,34 @@
338338
--buzz-onboarding-emoji-picker-input: 10, 10, 10;
339339
}
340340

341+
/* The key-import card is viewport-centered on ordinary windows, independent
342+
of the top heading and bottom-docked actions. Short windows return it to
343+
document flow so the shell can grow and scroll instead of overlapping. */
344+
.buzz-onboarding-key-import-position {
345+
position: absolute;
346+
left: 50%;
347+
top: calc(50dvh - 6.625rem);
348+
transform: translate(-50%, -50%);
349+
}
350+
351+
@media (max-height: 44rem) {
352+
.buzz-onboarding-key-import-position {
353+
position: static;
354+
margin-top: 3rem;
355+
transform: none;
356+
}
357+
}
358+
341359
.buzz-onboarding-transition-content {
342360
animation-delay: var(--buzz-onboarding-transition-delay, 0ms);
343361
}
344362

363+
.buzz-onboarding-transition-line[data-onboarding-effect="fade"]
364+
> .buzz-onboarding-transition-content {
365+
animation: buzz-onboarding-fade-in 300ms ease-out backwards;
366+
animation-delay: var(--buzz-onboarding-transition-delay, 0ms);
367+
}
368+
345369
.buzz-onboarding-transition-line[data-onboarding-effect="line-slide"]
346370
> .buzz-onboarding-transition-content {
347371
animation-duration: 650ms;
@@ -392,6 +416,16 @@
392416
}
393417
}
394418

419+
@keyframes buzz-onboarding-fade-in {
420+
from {
421+
opacity: 0;
422+
}
423+
424+
to {
425+
opacity: 1;
426+
}
427+
}
428+
395429
@keyframes buzz-onboarding-line-slide-forward {
396430
from {
397431
opacity: 0;
1.13 MB
Loading

0 commit comments

Comments
 (0)