Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add loading state to the response of useUser (initial PR, still polishing and testing) #1199

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion account-kit/react/src/hooks/useUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
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.
Expand Down Expand Up @@ -35,6 +39,13 @@
const eoaUser = useMemo(() => {
if (account.status !== "connected" && account.status !== "reconnecting") {
return null;
} else if (account.status == "reconnecting") {

Check warning on line 42 in account-kit/react/src/hooks/useUser.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected '===' and instead saw '=='
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] <eqeqeq> reported by reviewdog 🐶
Expected '===' and instead saw '=='.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @moldy530 . I am brand new to ts.

change is on its way.

//return user info for "reconnecting" status
return {
address: account.address,
type: "eoa" as const,
loading: true as const,
};
}

if (!account.address) {
Expand Down
Loading