From d17337ff07adec3f3606e91fa52164ba0c674b13 Mon Sep 17 00:00:00 2001 From: Shenghu Yang Date: Mon, 9 Dec 2024 15:51:42 -0800 Subject: [PATCH 1/2] chore: add loading state to the response of useUser --- account-kit/react/src/hooks/useUser.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/account-kit/react/src/hooks/useUser.ts b/account-kit/react/src/hooks/useUser.ts index 26e370cfbf..9911d54139 100644 --- a/account-kit/react/src/hooks/useUser.ts +++ b/account-kit/react/src/hooks/useUser.ts @@ -5,8 +5,12 @@ import type { User } from "@account-kit/signer"; import { useMemo, useSyncExternalStore } from "react"; import { useAccount as wagmi_useAccount } from "wagmi"; import { useAlchemyAccountContext } from "../context.js"; +import type { Address } from "@aa-sdk/core"; -export type UseUserResult = (User & { type: "eoa" | "sca" }) | null; +export type UseUserResult = + | (User & { type: "eoa" | "sca"; loading?: never }) + | null + | { address?: Address; type: "eoa" | "sca"; loading: true }; /** * A React hook that returns the current user information, either from an External Owned Account (EOA) or from the client store. It uses the Alchemy account context and synchronizes with external store updates. @@ -35,6 +39,13 @@ export const useUser = (): UseUserResult => { const eoaUser = useMemo(() => { if (account.status !== "connected" && account.status !== "reconnecting") { return null; + } else if (account.status == "reconnecting") { + //return user info for "reconnecting" status + return { + address: account.address, + type: "eoa" as const, + loading: true as const, + }; } if (!account.address) { From 1033a1e7e669c58c4207663459a49421ca02076c Mon Sep 17 00:00:00 2001 From: Shenghu Yang Date: Mon, 9 Dec 2024 16:38:48 -0800 Subject: [PATCH 2/2] chore: typo fix based code review from moldy --- account-kit/react/src/hooks/useUser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account-kit/react/src/hooks/useUser.ts b/account-kit/react/src/hooks/useUser.ts index 9911d54139..4aa103d4f1 100644 --- a/account-kit/react/src/hooks/useUser.ts +++ b/account-kit/react/src/hooks/useUser.ts @@ -39,7 +39,7 @@ export const useUser = (): UseUserResult => { const eoaUser = useMemo(() => { if (account.status !== "connected" && account.status !== "reconnecting") { return null; - } else if (account.status == "reconnecting") { + } else if (account.status === "reconnecting") { //return user info for "reconnecting" status return { address: account.address,