Skip to content

Commit 9cd13f3

Browse files
authored
Restore npub copy option for private community joins (#2232)
1 parent c1de3e7 commit 9cd13f3

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

‎desktop/src/features/communities/ui/WelcomeSetup.tsx‎

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from "react";
2+
import { Check, Copy } from "lucide-react";
23

34
import { HostedCommunityOnboarding } from "@/features/communities/ui/HostedCommunityOnboarding";
45
import { useCommunityOnboarding } from "@/features/onboarding/communityOnboarding";
@@ -12,6 +13,9 @@ import {
1213
type OnboardingTransitionDirection,
1314
OnboardingSlideTransition,
1415
} from "@/features/onboarding/ui/OnboardingSlideTransition";
16+
import { useIdentityQuery } from "@/shared/api/hooks";
17+
import { writeTextToClipboard } from "@/shared/lib/clipboard";
18+
import { pubkeyToNpub } from "@/shared/lib/nostrUtils";
1519
import { useSystemColorScheme } from "@/shared/theme/useSystemColorScheme";
1620
import { Button } from "@/shared/ui/button";
1721
import { Card } from "@/shared/ui/card";
@@ -41,8 +45,18 @@ export function WelcomeSetup({
4145
// we only navigate to the hosted stage once sign-in completes, so the page
4246
// behind the modal never changes out from under the user.
4347
const [isHostedSignInOpen, setIsHostedSignInOpen] = React.useState(false);
48+
const [copiedNpub, setCopiedNpub] = React.useState(false);
4449
const communityOnboarding = useCommunityOnboarding();
50+
const identityQuery = useIdentityQuery();
4551
const systemColorScheme = useSystemColorScheme();
52+
const npub = identityQuery.data?.pubkey
53+
? pubkeyToNpub(identityQuery.data.pubkey)
54+
: "";
55+
const npubError = identityQuery.error
56+
? identityQuery.error instanceof Error
57+
? identityQuery.error.message
58+
: "Could not load your public key."
59+
: null;
4660

4761
const showPage = React.useCallback(
4862
(nextPage: WelcomeSetupPage, direction?: OnboardingTransitionDirection) => {
@@ -243,7 +257,7 @@ export function WelcomeSetup({
243257
: "Enter the invite link or community URL you received."}
244258
</p>
245259
</div>
246-
<div className="flex w-full flex-1 items-center justify-center">
260+
<div className="flex w-full flex-1 flex-col items-center justify-center gap-16">
247261
<InviteRedeemForm
248262
error={null}
249263
isRedeeming={false}
@@ -255,6 +269,52 @@ export function WelcomeSetup({
255269
placeholder="Invite link or community URL"
256270
variant="onboarding-spotlight"
257271
/>
272+
{page === "join" ? (
273+
<div className="w-full max-w-[560px] text-left">
274+
<p className="text-sm font-medium text-foreground">
275+
Joining a private community?
276+
</p>
277+
<p className="mt-2 text-sm leading-6 text-foreground/75">
278+
Some communities need the owner to add you before you can
279+
join. Copy your public ID and send it to the community
280+
owner.
281+
</p>
282+
<div className="mt-4 flex items-center gap-3 rounded-xl border border-foreground/10 bg-background/35 px-4 py-3">
283+
<code
284+
className="min-w-0 flex-1 truncate font-mono text-xs text-foreground/80"
285+
data-testid="welcome-join-npub"
286+
>
287+
{npub || "Loading…"}
288+
</code>
289+
<Button
290+
aria-label="Copy public ID"
291+
className="h-9 shrink-0 rounded-full px-3"
292+
disabled={!npub}
293+
onClick={() => {
294+
void writeTextToClipboard(npub).then(() => {
295+
setCopiedNpub(true);
296+
window.setTimeout(() => setCopiedNpub(false), 1500);
297+
});
298+
}}
299+
size="sm"
300+
type="button"
301+
variant="outline"
302+
>
303+
{copiedNpub ? (
304+
<Check className="h-4 w-4" aria-hidden="true" />
305+
) : (
306+
<Copy className="h-4 w-4" aria-hidden="true" />
307+
)}
308+
<span>{copiedNpub ? "Copied" : "Copy"}</span>
309+
</Button>
310+
</div>
311+
{npubError ? (
312+
<p className="mt-3 text-sm text-destructive">
313+
{npubError}
314+
</p>
315+
) : null}
316+
</div>
317+
) : null}
258318
</div>
259319
</OnboardingSlideTransition>
260320
)}

‎desktop/tests/e2e/onboarding.spec.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ test("first-community choices route join, create, owner, and member intents", as
621621
await expect(
622622
page.getByRole("heading", { name: "Join a community" }),
623623
).toBeVisible();
624+
await expect(page.getByText("Joining a private community?")).toBeVisible();
625+
await expect(page.getByTestId("welcome-join-npub")).toBeVisible();
626+
await expect(
627+
page.getByRole("button", { name: "Copy public ID" }),
628+
).toBeVisible();
624629
await accessInput.fill("https://default.example.com/invite/abc123");
625630
await expect(page.getByTestId("invite-redeem-submit")).toBeEnabled();
626631
});

0 commit comments

Comments
 (0)