Skip to content

Commit

Permalink
feat(connect-kit/hooks): create useConnectedAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
runjuu committed Mar 3, 2023
1 parent 7426e0f commit c54a6ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/connect-kit/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from "./use-account-character";
export * from "./use-account-character-id";
export * from "./use-account-characters";
export * from "./use-account-has-character";
export * from "./use-connected-account";
export * from "./use-connected-action";
export * from "./use-create-character";
export * from "./use-disconnect-account";
Expand Down
26 changes: 26 additions & 0 deletions packages/connect-kit/src/hooks/use-connected-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
GeneralAccount,
EmailAccount,
WalletAccount,
useAccountState,
} from "./account-state";

export function useConnectedAccount(type: "email"): EmailAccount | null;
export function useConnectedAccount(type: "wallet"): WalletAccount | null;
export function useConnectedAccount(
type?: GeneralAccount["type"]
): GeneralAccount | null;
export function useConnectedAccount(
type?: GeneralAccount["type"]
): GeneralAccount | null {
return useAccountState((s) => {
switch (type) {
case "email":
return s.email;
case "wallet":
return s.email ? null : s.wallet;
default:
return s.computed.account;
}
});
}

0 comments on commit c54a6ac

Please sign in to comment.