mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
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>
This commit is contained in:
co-authored by
npub1t490dek5vslqxv0ft0jlft6j5fjlp74jery2tyj7ngf8ggd0pcnst8w25n
parent
34ef702638
commit
738d456367
@@ -478,6 +478,7 @@ function MachineBootstrap({ sharedIdentity }: { sharedIdentity: boolean }) {
|
||||
<>
|
||||
<MachineOnboardingFlow
|
||||
complete={completeMachineOnboarding}
|
||||
continueWithIdentity={machine.continueWithIdentity}
|
||||
identityLost={machine.identityLost}
|
||||
initialPage={machineInitialPage}
|
||||
queryClient={machine.queryClient}
|
||||
|
||||
@@ -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);
|
||||
@@ -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));
|
||||
@@ -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) {
|
||||
@@ -199,6 +209,7 @@ export function useMachineOnboardingState({
|
||||
|
||||
return {
|
||||
complete,
|
||||
continueWithIdentity,
|
||||
currentPubkey,
|
||||
identityLost,
|
||||
queryClient,
|
||||
|
||||
@@ -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;
|
||||
@@ -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 (
|
||||
|
||||
@@ -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,
|
||||
}) => {
|
||||
|
||||
Reference in New Issue
Block a user