Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desktop/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ function MachineBootstrap({ sharedIdentity }: { sharedIdentity: boolean }) {
<>
<MachineOnboardingFlow
complete={completeMachineOnboarding}
continueWithIdentity={machine.continueWithIdentity}
identityLost={machine.identityLost}
initialPage={machineInitialPage}
queryClient={machine.queryClient}
Expand Down
13 changes: 12 additions & 1 deletion desktop/src/features/onboarding/machineOnboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export function useMachineOnboardingState({
const [evaluatedPubkey, setEvaluatedPubkey] = React.useState<string | null>(
null,
);
const continuingPubkeyRef = React.useRef<string | null>(null);
const startupPubkeyRef = React.useRef<string | null>(null);
const [bootedLost, setBootedLost] = React.useState(false);
const [bootedLocked, setBootedLocked] = React.useState(false);
Expand Down Expand Up @@ -157,6 +158,10 @@ export function useMachineOnboardingState({
[currentPubkey],
);

const continueWithIdentity = React.useCallback((pubkey: string) => {
continuingPubkeyRef.current = pubkey;
}, []);

const reopen = React.useCallback(() => {
clearMachineOnboardingCompletion(currentPubkey);
setCompletedPubkey((pubkey) => (pubkey === currentPubkey ? null : pubkey));
Expand Down Expand Up @@ -188,7 +193,12 @@ export function useMachineOnboardingState({
identityQuery.fetchStatus === "fetching",
) ||
!currentPubkey ||
(!hasCompletedCurrentPubkey && evaluatedPubkey !== currentPubkey)
// Imported identities are published before the flow can advance to setup.
// Keep that explicitly requested identity switch in onboarding; only the
// startup identity needs the one-render evaluation gate above.
(!hasCompletedCurrentPubkey &&
evaluatedPubkey !== currentPubkey &&
continuingPubkeyRef.current !== currentPubkey)
) {
stage = "blocking";
} else if (identityLost || !hasCompletedCurrentPubkey) {
Expand All @@ -199,6 +209,7 @@ export function useMachineOnboardingState({

return {
complete,
continueWithIdentity,
currentPubkey,
identityLost,
queryClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ export type MachineOnboardingPage =

export function MachineOnboardingFlow({
complete,
continueWithIdentity,
identityLost,
initialPage,
queryClient,
}: {
complete: (pubkey?: string) => void;
continueWithIdentity: (pubkey: string) => void;
identityLost: boolean;
initialPage?: MachineOnboardingPage;
queryClient: QueryClient;
Expand Down Expand Up @@ -141,12 +143,13 @@ export function MachineOnboardingFlow({
const importExistingIdentity = React.useCallback(
async (nsec: string) => {
const identity = await importIdentity(nsec);
continueWithIdentity(identity.pubkey);
queryClient.setQueryData(["identity"], identity);
setIdentityWasImported(true);
setSelectedPubkey(identity.pubkey);
setPage("setup");
},
[queryClient],
[continueWithIdentity, queryClient],
);

return (
Expand Down
17 changes: 17 additions & 0 deletions desktop/tests/e2e/onboarding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,23 @@ test("completed users skip the loading gate while profile is still settling", as
await expectHomeView(page);
});

test("first-launch key import continues to machine setup", async ({ page }) => {
await installMockBridge(page, undefined, {
skipCommunitySeed: true,
skipOnboardingSeed: true,
});
await page.goto("/");

await page.getByRole("button", { name: "Enter a key" }).click();
const importedNsec = nsecEncode(hexToBytes(TEST_IDENTITIES.alice.privateKey));
await page.getByTestId("nostr-import-nsec-input").fill(importedNsec);
await page.getByTestId("nostr-import-submit").click();

await expect(page.getByTestId("onboarding-page-2")).toBeVisible();
await expect(page.getByTestId("machine-onboarding-gate")).toBeVisible();
await expect(page.getByTestId("app-loading-gate")).toHaveCount(0);
});

test("first-community choices expose npub and invite input", async ({
page,
}) => {
Expand Down
Loading