11import * as React from "react" ;
2+ import { Check , Copy } from "lucide-react" ;
23
34import { HostedCommunityOnboarding } from "@/features/communities/ui/HostedCommunityOnboarding" ;
45import { 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" ;
1519import { useSystemColorScheme } from "@/shared/theme/useSystemColorScheme" ;
1620import { Button } from "@/shared/ui/button" ;
1721import { 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 ) }
0 commit comments