Skip to content

Commit 738d456

Browse files
baxennpub1t490dek5vslqxv0ft0jlft6j5fjlp74jery2tyj7ngf8ggd0pcnst8w25n
andauthored
BOT-1359: Continue onboarding after key import (#2056)
Signed-off-by: npub1t490dek5vslqxv0ft0jlft6j5fjlp74jery2tyj7ngf8ggd0pcnst8w25n <5d4af6e6d4643e0331e95be5f4af52a265f0fab2c8c8a5925e9a127421af0e27@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1t490dek5vslqxv0ft0jlft6j5fjlp74jery2tyj7ngf8ggd0pcnst8w25n <5d4af6e6d4643e0331e95be5f4af52a265f0fab2c8c8a5925e9a127421af0e27@sprout-oss.stage.blox.sqprod.co>
1 parent 34ef702 commit 738d456

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎desktop/src/app/App.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ function MachineBootstrap({ sharedIdentity }: { sharedIdentity: boolean }) {
478478
<>
479479
<MachineOnboardingFlow
480480
complete={completeMachineOnboarding}
481+
continueWithIdentity={machine.continueWithIdentity}
481482
identityLost={machine.identityLost}
482483
initialPage={machineInitialPage}
483484
queryClient={machine.queryClient}

‎desktop/src/features/onboarding/machineOnboarding.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export function useMachineOnboardingState({
9898
const [evaluatedPubkey, setEvaluatedPubkey] = React.useState<string | null>(
9999
null,
100100
);
101+
const continuingPubkeyRef = React.useRef<string | null>(null);
101102
const startupPubkeyRef = React.useRef<string | null>(null);
102103
const [bootedLost, setBootedLost] = React.useState(false);
103104
const [bootedLocked, setBootedLocked] = React.useState(false);
@@ -157,6 +158,10 @@ export function useMachineOnboardingState({
157158
[currentPubkey],
158159
);
159160

161+
const continueWithIdentity = React.useCallback((pubkey: string) => {
162+
continuingPubkeyRef.current = pubkey;
163+
}, []);
164+
160165
const reopen = React.useCallback(() => {
161166
clearMachineOnboardingCompletion(currentPubkey);
162167
setCompletedPubkey((pubkey) => (pubkey === currentPubkey ? null : pubkey));
@@ -188,7 +193,12 @@ export function useMachineOnboardingState({
188193
identityQuery.fetchStatus === "fetching",
189194
) ||
190195
!currentPubkey ||
191-
(!hasCompletedCurrentPubkey && evaluatedPubkey !== currentPubkey)
196+
// Imported identities are published before the flow can advance to setup.
197+
// Keep that explicitly requested identity switch in onboarding; only the
198+
// startup identity needs the one-render evaluation gate above.
199+
(!hasCompletedCurrentPubkey &&
200+
evaluatedPubkey !== currentPubkey &&
201+
continuingPubkeyRef.current !== currentPubkey)
192202
) {
193203
stage = "blocking";
194204
} else if (identityLost || !hasCompletedCurrentPubkey) {
@@ -199,6 +209,7 @@ export function useMachineOnboardingState({
199209

200210
return {
201211
complete,
212+
continueWithIdentity,
202213
currentPubkey,
203214
identityLost,
204215
queryClient,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ export type MachineOnboardingPage =
3333

3434
export function MachineOnboardingFlow({
3535
complete,
36+
continueWithIdentity,
3637
identityLost,
3738
initialPage,
3839
queryClient,
3940
}: {
4041
complete: (pubkey?: string) => void;
42+
continueWithIdentity: (pubkey: string) => void;
4143
identityLost: boolean;
4244
initialPage?: MachineOnboardingPage;
4345
queryClient: QueryClient;
@@ -141,12 +143,13 @@ export function MachineOnboardingFlow({
141143
const importExistingIdentity = React.useCallback(
142144
async (nsec: string) => {
143145
const identity = await importIdentity(nsec);
146+
continueWithIdentity(identity.pubkey);
144147
queryClient.setQueryData(["identity"], identity);
145148
setIdentityWasImported(true);
146149
setSelectedPubkey(identity.pubkey);
147150
setPage("setup");
148151
},
149-
[queryClient],
152+
[continueWithIdentity, queryClient],
150153
);
151154

152155
return (

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,23 @@ test("completed users skip the loading gate while profile is still settling", as
565565
await expectHomeView(page);
566566
});
567567

568+
test("first-launch key import continues to machine setup", async ({ page }) => {
569+
await installMockBridge(page, undefined, {
570+
skipCommunitySeed: true,
571+
skipOnboardingSeed: true,
572+
});
573+
await page.goto("/");
574+
575+
await page.getByRole("button", { name: "Enter a key" }).click();
576+
const importedNsec = nsecEncode(hexToBytes(TEST_IDENTITIES.alice.privateKey));
577+
await page.getByTestId("nostr-import-nsec-input").fill(importedNsec);
578+
await page.getByTestId("nostr-import-submit").click();
579+
580+
await expect(page.getByTestId("onboarding-page-2")).toBeVisible();
581+
await expect(page.getByTestId("machine-onboarding-gate")).toBeVisible();
582+
await expect(page.getByTestId("app-loading-gate")).toHaveCount(0);
583+
});
584+
568585
test("first-community choices expose npub and invite input", async ({
569586
page,
570587
}) => {

0 commit comments

Comments
 (0)