From 23c6d52ae2cdfe62234399722d39c53ce7699acf Mon Sep 17 00:00:00 2001 From: moldy Date: Mon, 23 Sep 2024 13:49:03 -0400 Subject: [PATCH] fix(ui-components): ensure the passkey prompt always shows up when qp is present --- aa-sdk/core/src/version.ts | 2 +- account-kit/core/src/version.ts | 2 +- account-kit/infra/src/version.ts | 2 +- account-kit/plugingen/src/version.ts | 2 +- .../components/auth/card/passkey-added.tsx | 7 ++++ account-kit/react/src/context.tsx | 33 ++++++++++++------- account-kit/react/src/version.ts | 2 +- account-kit/signer/src/version.ts | 2 +- 8 files changed, 34 insertions(+), 18 deletions(-) diff --git a/aa-sdk/core/src/version.ts b/aa-sdk/core/src/version.ts index 26e5449705..24bc1b17c3 100644 --- a/aa-sdk/core/src/version.ts +++ b/aa-sdk/core/src/version.ts @@ -1,3 +1,3 @@ // This file is autogenerated by inject-version.ts. Any changes will be // overwritten on commit! -export const VERSION = "4.0.0-beta.5"; +export const VERSION = "4.0.0-beta.6"; diff --git a/account-kit/core/src/version.ts b/account-kit/core/src/version.ts index 26e5449705..24bc1b17c3 100644 --- a/account-kit/core/src/version.ts +++ b/account-kit/core/src/version.ts @@ -1,3 +1,3 @@ // This file is autogenerated by inject-version.ts. Any changes will be // overwritten on commit! -export const VERSION = "4.0.0-beta.5"; +export const VERSION = "4.0.0-beta.6"; diff --git a/account-kit/infra/src/version.ts b/account-kit/infra/src/version.ts index 26e5449705..24bc1b17c3 100644 --- a/account-kit/infra/src/version.ts +++ b/account-kit/infra/src/version.ts @@ -1,3 +1,3 @@ // This file is autogenerated by inject-version.ts. Any changes will be // overwritten on commit! -export const VERSION = "4.0.0-beta.5"; +export const VERSION = "4.0.0-beta.6"; diff --git a/account-kit/plugingen/src/version.ts b/account-kit/plugingen/src/version.ts index 26e5449705..24bc1b17c3 100644 --- a/account-kit/plugingen/src/version.ts +++ b/account-kit/plugingen/src/version.ts @@ -1,3 +1,3 @@ // This file is autogenerated by inject-version.ts. Any changes will be // overwritten on commit! -export const VERSION = "4.0.0-beta.5"; +export const VERSION = "4.0.0-beta.6"; diff --git a/account-kit/react/src/components/auth/card/passkey-added.tsx b/account-kit/react/src/components/auth/card/passkey-added.tsx index 1a887d7f66..58207b8523 100644 --- a/account-kit/react/src/components/auth/card/passkey-added.tsx +++ b/account-kit/react/src/components/auth/card/passkey-added.tsx @@ -1,7 +1,14 @@ import { AddedPasskeyIllustration } from "../../../icons/illustrations/added-passkey.js"; +import { useAuthContext } from "../context.js"; // eslint-disable-next-line jsdoc/require-jsdoc export function PasskeyAdded() { + const { setAuthStep } = useAuthContext(); + + setTimeout(() => { + setAuthStep({ type: "complete" }); + }, 5000); + return (
diff --git a/account-kit/react/src/context.tsx b/account-kit/react/src/context.tsx index dcb8cbfc27..fc491a0e84 100644 --- a/account-kit/react/src/context.tsx +++ b/account-kit/react/src/context.tsx @@ -115,17 +115,21 @@ export const AlchemyAccountProvider = ( const openAuthModal = useCallback(() => setIsModalOpen(true), []); const closeAuthModal = useCallback(() => setIsModalOpen(false), []); + const clearAuthParams = () => { + const url = new URL(window.location.href); + url.searchParams.delete("orgId"); + url.searchParams.delete("bundle"); + url.searchParams.delete(IS_SIGNUP_QP); + window.history.replaceState({}, "", url.toString()); + }; + /** * Reset the auth step to the initial state. This also clears the email auth query params from the URL. */ const resetAuthStep = useCallback(() => { setAuthStep({ type: "initial" }); - const url = new URL(window.location.href); - url.searchParams.delete("orgId"); - url.searchParams.delete("bundle"); - url.searchParams.delete(IS_SIGNUP_QP); - window.history.replaceState({}, "", url.toString()); + clearAuthParams(); }, []); const initialContext = useMemo( @@ -144,22 +148,27 @@ export const AlchemyAccountProvider = ( [config, queryClient, openAuthModal, closeAuthModal, isModalOpen] ); - const { status, isAuthenticating } = useSignerStatus(initialContext); + const { isAuthenticating, isConnected } = useSignerStatus(initialContext); const [authStep, setAuthStep] = useState({ type: isAuthenticating ? "email_completing" : "initial", }); useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); if ( - status === "AWAITING_EMAIL_AUTH" && - config.ui?.auth?.addPasskeyOnSignup + isConnected && + config.ui?.auth?.addPasskeyOnSignup && + urlParams.get(IS_SIGNUP_QP) === "true" ) { - const urlParams = new URLSearchParams(window.location.search); - if (urlParams.get(IS_SIGNUP_QP) !== "true") return; - openAuthModal(); } - }, [status, config.ui, openAuthModal]); + }, [config.ui, isConnected, openAuthModal]); + + useEffect(() => { + if (authStep.type === "complete") { + clearAuthParams(); + } + }, [authStep]); return ( diff --git a/account-kit/react/src/version.ts b/account-kit/react/src/version.ts index 26e5449705..24bc1b17c3 100644 --- a/account-kit/react/src/version.ts +++ b/account-kit/react/src/version.ts @@ -1,3 +1,3 @@ // This file is autogenerated by inject-version.ts. Any changes will be // overwritten on commit! -export const VERSION = "4.0.0-beta.5"; +export const VERSION = "4.0.0-beta.6"; diff --git a/account-kit/signer/src/version.ts b/account-kit/signer/src/version.ts index 26e5449705..24bc1b17c3 100644 --- a/account-kit/signer/src/version.ts +++ b/account-kit/signer/src/version.ts @@ -1,3 +1,3 @@ // This file is autogenerated by inject-version.ts. Any changes will be // overwritten on commit! -export const VERSION = "4.0.0-beta.5"; +export const VERSION = "4.0.0-beta.6";