Skip to content

Commit 93b6d7a

Browse files
wesbillmanPinky
andauthored
fix(desktop): complete request access flow (block#2073)
Signed-off-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent 2d63705 commit 93b6d7a

3 files changed

Lines changed: 170 additions & 50 deletions

File tree

‎desktop/src/app/App.tsx‎

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { WelcomeSetup } from "@/features/communities/ui/WelcomeSetup";
3939
import { CommunityApplyErrorScreen } from "@/features/communities/ui/CommunityApplyErrorScreen";
4040
import { CommunityChangeOverlay } from "@/features/communities/ui/CommunityChangeOverlay";
4141
import { createBuzzQueryClient } from "@/shared/api/queryClient";
42+
import { getMyRelayMembershipLookup } from "@/shared/api/relayMembers";
4243
import { isSharedIdentity as isSharedIdentityCmd } from "@/shared/api/tauri";
4344
import {
4445
type AddCommunityDeepLinkPayload,
@@ -61,6 +62,16 @@ const BOOT_SPLASH_MIN_VISIBLE_MS = 1_200;
6162
const BOOT_SPLASH_FADE_MS = 200;
6263
const INITIAL_RENDER_READY_EVENT = "initial-render-ready";
6364

65+
function isRelayMembershipDeniedError(error: unknown): boolean {
66+
if (!(error instanceof Error)) return false;
67+
return [
68+
"You must be a relay member",
69+
"relay_membership_required",
70+
"restricted: not a relay member",
71+
"invalid: you are not a relay member",
72+
].some((message) => error.message.includes(message));
73+
}
74+
6475
type BootSplashPhase = "holding" | "fading" | "done";
6576

6677
function useInitialRenderReady() {
@@ -325,10 +336,45 @@ function CommunityApp({
325336
community.isReady &&
326337
community.appliedKey === communityKey;
327338
useEffect(() => {
328-
if (transaction?.stage === "connecting" && targetIsReady) {
329-
communityOnboarding.update({ stage: "profile", error: undefined });
339+
if (
340+
transaction?.stage !== "connecting" ||
341+
transaction.error ||
342+
!targetIsReady
343+
) {
344+
return;
330345
}
331-
}, [communityOnboarding.update, targetIsReady, transaction?.stage]);
346+
347+
let cancelled = false;
348+
void getMyRelayMembershipLookup()
349+
.then(({ membership, snapshotFound }) => {
350+
if (cancelled) return;
351+
if (snapshotFound && membership === null) {
352+
communityOnboarding.update({
353+
error:
354+
"You have not been added to this community yet. Ask the host to add your public key, then try again.",
355+
});
356+
return;
357+
}
358+
communityOnboarding.update({ stage: "profile", error: undefined });
359+
})
360+
.catch((error: unknown) => {
361+
if (cancelled) return;
362+
communityOnboarding.update({
363+
error: isRelayMembershipDeniedError(error)
364+
? "You have not been added to this community yet. Ask the host to add your public key, then try again."
365+
: "Could not check community access. Check the URL and try again.",
366+
});
367+
});
368+
369+
return () => {
370+
cancelled = true;
371+
};
372+
}, [
373+
communityOnboarding.update,
374+
targetIsReady,
375+
transaction?.error,
376+
transaction?.stage,
377+
]);
332378
// During "entering" the transaction stays alive as a curtain: the app mounts
333379
// underneath (already pointed at the Welcome channel route) while the
334380
// onboarding screen covers it, then fades once Welcome reports ready.

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

Lines changed: 115 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { openUrl } from "@tauri-apps/plugin-opener";
33
import { Check, Copy, Info } from "lucide-react";
44

55
import { useCommunityOnboarding } from "@/features/onboarding/communityOnboarding";
6+
import { normalizeRelayUrl } from "@/features/communities/relayProbe";
67
import { InviteRedeemForm } from "@/features/onboarding/ui/InviteRedeemForm";
78
import {
89
ONBOARDING_KEY_FRAME_CLASS,
@@ -20,6 +21,7 @@ import {
2021
import { getIdentity } from "@/shared/api/tauriIdentity";
2122
import { pubkeyToNpub } from "@/shared/lib/nostrUtils";
2223
import { Button } from "@/shared/ui/button";
24+
import { Input } from "@/shared/ui/input";
2325
import { StartupWindowDragRegion } from "@/shared/ui/StartupWindowDragRegion";
2426
import { useSystemColorScheme } from "@/shared/theme/useSystemColorScheme";
2527
import { OnboardingChrome } from "@/features/onboarding/ui/OnboardingChrome";
@@ -56,6 +58,8 @@ export function WelcomeSetup({
5658
React.useState<WelcomeTransitionMode>(initialTransitionMode);
5759
const [npub, setNpub] = React.useState("");
5860
const [identityError, setIdentityError] = React.useState<string | null>(null);
61+
const [relayUrl, setRelayUrl] = React.useState("");
62+
const [relayUrlError, setRelayUrlError] = React.useState<string | null>(null);
5963
const [copied, setCopied] = React.useState(false);
6064
const communityOnboarding = useCommunityOnboarding();
6165
const systemColorScheme = useSystemColorScheme();
@@ -79,6 +83,24 @@ export function WelcomeSetup({
7983
setPage(nextPage);
8084
}, []);
8185

86+
const handleJoin = React.useCallback(
87+
(event: React.FormEvent) => {
88+
event.preventDefault();
89+
const normalizedRelayUrl = normalizeRelayUrl(relayUrl);
90+
if (!normalizedRelayUrl) {
91+
setRelayUrlError("Enter a valid community URL.");
92+
return;
93+
}
94+
95+
setRelayUrlError(null);
96+
communityOnboarding.start({
97+
source: "first-community",
98+
relayUrl: normalizedRelayUrl,
99+
});
100+
},
101+
[communityOnboarding, relayUrl],
102+
);
103+
82104
const handleInviteRedeem = React.useCallback(
83105
(relayWsUrl: string, code: string, policyReceipt?: string) => {
84106
communityOnboarding.start({
@@ -172,58 +194,106 @@ export function WelcomeSetup({
172194
</p>
173195
</div>
174196
<div className="flex w-full flex-1 items-center justify-center pb-4 pt-12">
175-
<div className="w-full max-w-4xl">
176-
<div
177-
className={ONBOARDING_KEY_FRAME_CLASS}
178-
data-testid="welcome-join-npub-frame"
197+
<div className="w-full max-w-4xl space-y-7">
198+
<div>
199+
<div
200+
className={ONBOARDING_KEY_FRAME_CLASS}
201+
data-testid="welcome-join-npub-frame"
202+
>
203+
<div className={ONBOARDING_KEY_ROW_CLASS}>
204+
<div className="min-w-0 flex-1">
205+
<code
206+
className={`${ONBOARDING_KEY_TEXT_CLASS} block`}
207+
data-testid="welcome-join-npub"
208+
>
209+
{npub || "Loading…"}
210+
</code>
211+
</div>
212+
<Button
213+
aria-label="Copy npub"
214+
className="h-10 w-10 shrink-0 text-muted-foreground hover:text-foreground"
215+
disabled={!npub}
216+
onClick={() => {
217+
void writeTextToClipboard(npub).then(() => {
218+
setCopied(true);
219+
window.setTimeout(() => setCopied(false), 1500);
220+
});
221+
}}
222+
size="icon"
223+
type="button"
224+
variant="ghost"
225+
>
226+
{copied ? (
227+
<Check
228+
className="h-6 w-6 text-primary"
229+
aria-hidden="true"
230+
/>
231+
) : (
232+
<Copy className="h-6 w-6" aria-hidden="true" />
233+
)}
234+
</Button>
235+
</div>
236+
</div>
237+
{identityError ? (
238+
<p className="mt-4 text-sm text-destructive">
239+
{identityError}
240+
</p>
241+
) : (
242+
<p className="mx-auto mt-4 flex max-w-[440px] items-start justify-center gap-1.5 text-center text-xs leading-5 text-[var(--buzz-onboarding-backup-ink)]">
243+
<Info className="mt-0.5 h-3.5 w-3.5 shrink-0" />
244+
<span>
245+
This is safe to share. It does not reveal your private
246+
key.
247+
</span>
248+
</p>
249+
)}
250+
</div>
251+
<form
252+
className="mx-auto w-full max-w-[680px] text-left"
253+
onSubmit={handleJoin}
179254
>
180-
<div className={ONBOARDING_KEY_ROW_CLASS}>
255+
<label
256+
className="text-sm font-medium"
257+
htmlFor="welcome-join-community-url"
258+
>
259+
Community URL
260+
</label>
261+
<div className="mt-2 flex items-start gap-3">
181262
<div className="min-w-0 flex-1">
182-
<code
183-
className={`${ONBOARDING_KEY_TEXT_CLASS} block`}
184-
data-testid="welcome-join-npub"
185-
>
186-
{npub || "Loading…"}
187-
</code>
263+
<Input
264+
autoCapitalize="none"
265+
autoCorrect="off"
266+
data-testid="welcome-join-community-url"
267+
id="welcome-join-community-url"
268+
onChange={(event) => {
269+
setRelayUrl(event.target.value);
270+
setRelayUrlError(null);
271+
}}
272+
placeholder="https://community.example.com"
273+
spellCheck={false}
274+
type="url"
275+
value={relayUrl}
276+
/>
277+
{relayUrlError ? (
278+
<p className="mt-2 text-sm text-destructive">
279+
{relayUrlError}
280+
</p>
281+
) : (
282+
<p className="mt-2 text-xs leading-5 text-foreground/70">
283+
Once the host adds your public key, enter the URL to
284+
join. You can retry if access is not ready yet.
285+
</p>
286+
)}
188287
</div>
189288
<Button
190-
aria-label="Copy npub"
191-
className="h-10 w-10 shrink-0 text-muted-foreground hover:text-foreground"
192-
disabled={!npub}
193-
onClick={() => {
194-
void writeTextToClipboard(npub).then(() => {
195-
setCopied(true);
196-
window.setTimeout(() => setCopied(false), 1500);
197-
});
198-
}}
199-
size="icon"
200-
type="button"
201-
variant="ghost"
289+
className="h-10 shrink-0 rounded-full px-6"
290+
disabled={!relayUrl.trim()}
291+
type="submit"
202292
>
203-
{copied ? (
204-
<Check
205-
className="h-6 w-6 text-primary"
206-
aria-hidden="true"
207-
/>
208-
) : (
209-
<Copy className="h-6 w-6" aria-hidden="true" />
210-
)}
293+
Join community
211294
</Button>
212295
</div>
213-
</div>
214-
{identityError ? (
215-
<p className="mt-4 text-sm text-destructive">
216-
{identityError}
217-
</p>
218-
) : (
219-
<p className="mx-auto mt-6 flex max-w-[440px] items-start justify-center gap-1.5 text-center text-xs leading-5 text-[var(--buzz-onboarding-backup-ink)]">
220-
<Info className="mt-0.5 h-3.5 w-3.5 shrink-0" />
221-
<span>
222-
This is safe to share. It does not reveal your private
223-
key.
224-
</span>
225-
</p>
226-
)}
296+
</form>
227297
</div>
228298
</div>
229299
<OnboardingFooter>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ export function CommunityOnboardingFlow({
190190
};
191191
}, [clear, isEnteringStage]);
192192

193-
const retryClaim = () => update({ stage: "claiming", error: undefined });
193+
const retry = () =>
194+
update({
195+
stage: transaction?.inviteCode ? "claiming" : "connecting",
196+
error: undefined,
197+
});
194198
const relayUrl = transaction?.relayUrl;
195199
const finish = React.useCallback(async () => {
196200
if (!relayUrl) return;
@@ -362,7 +366,7 @@ export function CommunityOnboardingFlow({
362366
</p>
363367
<div className="mt-6 flex justify-center gap-3">
364368
{transaction.error ? (
365-
<Button className="rounded-full px-6" onClick={retryClaim}>
369+
<Button className="rounded-full px-6" onClick={retry}>
366370
Retry
367371
</Button>
368372
) : null}

0 commit comments

Comments
 (0)