@b3dotfun/sdk 0.0.87-alpha.2 → 0.0.87-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +2 -1
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +0 -1
  3. package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +1 -1
  4. package/dist/cjs/global-account/react/components/AvatarEditor/AvatarEditor.js +2 -1
  5. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +17 -47
  6. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +6 -7
  7. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -5
  8. package/dist/cjs/global-account/react/components/B3Provider/types.js +4 -4
  9. package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +1 -0
  10. package/dist/cjs/global-account/react/components/B3Provider/useB3.js +1 -0
  11. package/dist/cjs/global-account/react/components/B3Provider/useB3Account.d.ts +1 -0
  12. package/dist/cjs/global-account/react/components/B3Provider/useB3Account.js +10 -0
  13. package/dist/cjs/global-account/react/components/B3Provider/useB3Config.d.ts +9 -0
  14. package/dist/cjs/global-account/react/components/B3Provider/useB3Config.js +23 -0
  15. package/dist/cjs/global-account/react/components/LinkAccount/LinkAccount.js +1 -1
  16. package/dist/cjs/global-account/react/components/LinkAccount/LinkNewAccount.js +1 -2
  17. package/dist/cjs/global-account/react/components/ManageAccount/ProfileSection.js +2 -1
  18. package/dist/cjs/global-account/react/components/ManageAccount/SettingsProfileCard.js +2 -1
  19. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -1
  20. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +2 -1
  21. package/dist/cjs/global-account/react/components/index.d.ts +2 -0
  22. package/dist/cjs/global-account/react/components/index.js +7 -3
  23. package/dist/cjs/global-account/react/hooks/useAccountWallet.js +3 -2
  24. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -1
  25. package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.d.ts +7 -0
  26. package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.js +42 -0
  27. package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +6 -4
  28. package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +2 -2
  29. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
  30. package/dist/esm/anyspend/react/components/AnySpendCustom.js +0 -1
  31. package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +1 -1
  32. package/dist/esm/global-account/react/components/AvatarEditor/AvatarEditor.js +3 -2
  33. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +21 -51
  34. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +6 -7
  35. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -5
  36. package/dist/esm/global-account/react/components/B3Provider/types.js +4 -4
  37. package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +1 -0
  38. package/dist/esm/global-account/react/components/B3Provider/useB3.js +1 -0
  39. package/dist/esm/global-account/react/components/B3Provider/useB3Account.d.ts +1 -0
  40. package/dist/esm/global-account/react/components/B3Provider/useB3Account.js +6 -0
  41. package/dist/esm/global-account/react/components/B3Provider/useB3Config.d.ts +9 -0
  42. package/dist/esm/global-account/react/components/B3Provider/useB3Config.js +19 -0
  43. package/dist/esm/global-account/react/components/LinkAccount/LinkAccount.js +2 -2
  44. package/dist/esm/global-account/react/components/LinkAccount/LinkNewAccount.js +2 -3
  45. package/dist/esm/global-account/react/components/ManageAccount/ProfileSection.js +3 -2
  46. package/dist/esm/global-account/react/components/ManageAccount/SettingsProfileCard.js +3 -2
  47. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +3 -2
  48. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +3 -2
  49. package/dist/esm/global-account/react/components/index.d.ts +2 -0
  50. package/dist/esm/global-account/react/components/index.js +2 -0
  51. package/dist/esm/global-account/react/hooks/useAccountWallet.js +4 -3
  52. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -1
  53. package/dist/esm/global-account/react/hooks/useAutoSelectWallet.d.ts +7 -0
  54. package/dist/esm/global-account/react/hooks/useAutoSelectWallet.js +39 -0
  55. package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +6 -4
  56. package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +2 -2
  57. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
  58. package/dist/types/anyspend/react/hooks/useSigMint.d.ts +1 -1
  59. package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -5
  60. package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +1 -0
  61. package/dist/types/global-account/react/components/B3Provider/useB3Account.d.ts +1 -0
  62. package/dist/types/global-account/react/components/B3Provider/useB3Config.d.ts +9 -0
  63. package/dist/types/global-account/react/components/index.d.ts +2 -0
  64. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -1
  65. package/dist/types/global-account/react/hooks/useAutoSelectWallet.d.ts +7 -0
  66. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
  67. package/package.json +1 -1
  68. package/src/anyspend/react/components/AnySpendCustom.tsx +0 -2
  69. package/src/global-account/react/components/AvatarEditor/AvatarEditor.tsx +10 -2
  70. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +6 -7
  71. package/src/global-account/react/components/B3Provider/B3Provider.tsx +20 -71
  72. package/src/global-account/react/components/B3Provider/types.ts +8 -9
  73. package/src/global-account/react/components/B3Provider/useB3.ts +1 -0
  74. package/src/global-account/react/components/B3Provider/useB3Account.ts +7 -0
  75. package/src/global-account/react/components/B3Provider/useB3Config.ts +34 -0
  76. package/src/global-account/react/components/LinkAccount/LinkAccount.tsx +2 -2
  77. package/src/global-account/react/components/LinkAccount/LinkNewAccount.tsx +2 -3
  78. package/src/global-account/react/components/ManageAccount/ProfileSection.tsx +10 -2
  79. package/src/global-account/react/components/ManageAccount/SettingsProfileCard.tsx +3 -2
  80. package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
  81. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +5 -2
  82. package/src/global-account/react/components/index.ts +2 -0
  83. package/src/global-account/react/hooks/useAccountWallet.tsx +4 -3
  84. package/src/global-account/react/hooks/useAutoSelectWallet.ts +51 -0
  85. package/src/global-account/react/hooks/useTurnkeyAuth.ts +7 -5
  86. package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +2 -2
@@ -1,19 +1,18 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { RelayKitProviderWrapper, TooltipProvider, useAuthentication, useAuthStore, } from "../../../../global-account/react/index.js";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { RelayKitProviderWrapper, TooltipProvider, useAuthStore } from "../../../../global-account/react/index.js";
3
+ import { useAutoSelectWallet } from "../../../../global-account/react/hooks/useAutoSelectWallet.js";
3
4
  import { createWagmiConfig } from "../../../../global-account/react/utils/createWagmiConfig.js";
4
5
  import { loadGA4Script } from "../../../../global-account/utils/analytics.js";
5
- import { debugB3React } from "../../../../shared/utils/debug.js";
6
6
  import "@relayprotocol/relay-kit-ui/styles.css";
7
7
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
8
- import { useCallback, useEffect, useMemo, useState } from "react";
9
- import { getLastAuthProvider, ThirdwebProvider, useActiveAccount, useConnectedWallets, useSetActiveWallet, } from "thirdweb/react";
8
+ import { useEffect, useMemo } from "react";
9
+ import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
10
10
  import { WagmiProvider } from "wagmi";
11
11
  import { setClientType } from "../../../client-manager.js";
12
12
  import { StyleRoot } from "../StyleRoot.js";
13
13
  import { setToastContext, ToastProvider, useToastContext } from "../Toast/index.js";
14
14
  import { LocalSDKProvider } from "./LocalSDKProvider.js";
15
15
  import { B3Context } from "./types.js";
16
- const debug = debugB3React("B3Provider");
17
16
  /**
18
17
  * Default permissions configuration for B3 provider
19
18
  */
@@ -47,52 +46,26 @@ toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey
47
46
  */
48
47
  export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket", partnerId, stripePublishableKey, createClientReferenceId, enableTurnkey, }) {
49
48
  const activeAccount = useActiveAccount();
50
- const [manuallySelectedWallet, setManuallySelectedWallet] = useState(undefined);
51
- const wallets = useConnectedWallets();
52
49
  const isAuthenticated = useAuthStore(state => state.isAuthenticated);
53
- const isConnected = useAuthStore(state => state.isConnected);
54
- const justCompletedLogin = useAuthStore(state => state.justCompletedLogin);
55
- const setActiveWallet = useSetActiveWallet();
56
- const { user, setUser, refetchUser } = useAuthentication(partnerId);
57
- debug("@@B3Provider:isConnected", isConnected);
58
- debug("@@wallets", wallets);
59
- debug("@@B3Provider:user", user);
60
- debug("@@B3Provider:justCompletedLogin", justCompletedLogin);
50
+ //const isConnected = useAuthStore(state => state.isConnected);
51
+ //const justCompletedLogin = useAuthStore(state => state.justCompletedLogin);
61
52
  // Use given accountOverride or activeAccount from thirdweb
53
+ // WOJ: why if isAuthenticated is false, we don't use activeAccount, which should be undefined?
54
+ // skip isAuthenticated check ?
62
55
  const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
63
- const setWallet = useCallback((wallet) => {
64
- setManuallySelectedWallet(wallet);
65
- const account = wallet.getAccount();
66
- debug("@@setWallet", wallet.id, account?.address);
67
- setActiveWallet(wallet);
68
- }, [setManuallySelectedWallet, setActiveWallet]);
69
- useEffect(() => {
70
- const autoSelectFirstEOAWallet = async () => {
71
- // Only proceed if auto-selection is enabled and user is authenticated
72
- if (!automaticallySetFirstEoa || !isAuthenticated) {
73
- return;
74
- }
75
- // Find the first EOA wallet (excluding ecosystem wallets)
76
- const isEOAWallet = (wallet) => !wallet.id.startsWith("ecosystem.");
77
- const firstEOAWallet = wallets.find(isEOAWallet);
78
- if (firstEOAWallet) {
79
- // Only auto-select if the last auth was via wallet or no previous auth provider
80
- const lastAuthProvider = await getLastAuthProvider();
81
- const shouldAutoSelect = lastAuthProvider === null || lastAuthProvider === "wallet";
82
- if (shouldAutoSelect) {
83
- setWallet(firstEOAWallet);
84
- }
85
- }
86
- };
87
- autoSelectFirstEOAWallet();
88
- }, [automaticallySetFirstEoa, isAuthenticated, setWallet, wallets]);
56
+ // Wrapper to set active wallet via thirdweb
57
+ // Note: `wallet` in context is deprecated - use useActiveWallet() from thirdweb/react instead
58
+ // Auto-select first EOA wallet when enabled
59
+ useAutoSelectWallet({
60
+ enabled: automaticallySetFirstEoa,
61
+ });
89
62
  return (_jsx(B3Context.Provider, { value: {
90
63
  account: effectiveAccount,
91
- setWallet,
92
- wallet: manuallySelectedWallet,
93
- user,
94
- setUser,
95
- refetchUser,
64
+ // setWallet,
65
+ //wallet: undefined, // Deprecated: use useActiveWallet() from thirdweb/react instead
66
+ //user,
67
+ //setUser,
68
+ //refetchUser,
96
69
  initialized: true,
97
70
  ready: !!effectiveAccount,
98
71
  automaticallySetFirstEoa,
@@ -104,11 +77,8 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
104
77
  stripePublishableKey,
105
78
  createClientReferenceId,
106
79
  enableTurnkey,
107
- }, children: _jsx(InnerProvider2, { children: children }) }));
80
+ }, children: children }));
108
81
  }
109
- const InnerProvider2 = ({ children }) => {
110
- return _jsx(_Fragment, { children: children });
111
- };
112
82
  /**
113
83
  * Component to connect the toast context to the global toast API
114
84
  */
@@ -2,7 +2,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3
3
  import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
4
4
  import { WagmiProvider } from "wagmi";
5
- import { useAuthentication } from "../../hooks/useAuthentication.js";
6
5
  import { createWagmiConfig } from "../../utils/createWagmiConfig.js";
7
6
  import { LocalSDKProvider } from "./LocalSDKProvider.js";
8
7
  import { B3Context } from "./types.js";
@@ -28,17 +27,17 @@ export function B3Provider({ theme = "light", children, accountOverride, environ
28
27
  */
29
28
  export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, theme = "light", clientType = "socket", partnerId, rpcUrls, }) {
30
29
  const activeAccount = useActiveAccount();
31
- const { user, setUser, refetchUser } = useAuthentication(partnerId);
30
+ //const { user, setUser, refetchUser } = useAuthentication(partnerId);
32
31
  const wagmiConfig = createWagmiConfig({ partnerId, rpcUrls });
33
32
  // Use given accountOverride or activeAccount from thirdweb
34
33
  const effectiveAccount = accountOverride || activeAccount;
35
34
  return (_jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(B3Context.Provider, { value: {
36
- account: effectiveAccount,
35
+ //account: effectiveAccount,
37
36
  automaticallySetFirstEoa: false,
38
- setWallet: () => { },
37
+ //setWallet: () => {},
39
38
  wallet: undefined,
40
- user,
41
- setUser,
39
+ //user,
40
+ //setUser,
42
41
  initialized: true,
43
42
  ready: !!effectiveAccount,
44
43
  environment,
@@ -46,6 +45,6 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
46
45
  theme,
47
46
  clientType,
48
47
  partnerId,
49
- refetchUser,
48
+ //refetchUser,
50
49
  }, children: children }) }) }));
51
50
  }
@@ -1,4 +1,3 @@
1
- import { Users } from "@b3dotfun/b3-api";
2
1
  import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOnrampOrder";
3
2
  import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
4
3
  import { PermissionsConfig } from "../../../../global-account/types/permissions";
@@ -10,11 +9,7 @@ import { ClientType } from "../../../client-manager";
10
9
  export interface B3ContextType {
11
10
  account?: Account;
12
11
  automaticallySetFirstEoa: boolean;
13
- user?: Users;
14
- setWallet: (wallet: Wallet) => void;
15
12
  wallet?: Wallet;
16
- setUser: (user?: Users) => void;
17
- refetchUser: () => Promise<any>;
18
13
  initialized: boolean;
19
14
  ready: boolean;
20
15
  environment?: "development" | "production";
@@ -5,11 +5,11 @@ import { createContext } from "react";
5
5
  export const B3Context = createContext({
6
6
  account: undefined,
7
7
  automaticallySetFirstEoa: false,
8
- user: undefined,
9
- setWallet: () => { },
8
+ //user: undefined,
9
+ //setWallet: () => {},
10
10
  wallet: undefined,
11
- setUser: () => { },
12
- refetchUser: async () => { },
11
+ //setUser: () => {},
12
+ //refetchUser: async () => {},
13
13
  initialized: false,
14
14
  ready: false,
15
15
  environment: "development",
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Hook to access the B3 context
3
3
  * @throws Error if used outside a B3Provider
4
+ * @deprecated Use useB3Config or useB3Account instead
4
5
  */
5
6
  export declare function useB3(): import("./types").B3ContextType;
@@ -3,6 +3,7 @@ import { B3Context } from "./types.js";
3
3
  /**
4
4
  * Hook to access the B3 context
5
5
  * @throws Error if used outside a B3Provider
6
+ * @deprecated Use useB3Config or useB3Account instead
6
7
  */
7
8
  export function useB3() {
8
9
  const context = useContext(B3Context);
@@ -0,0 +1 @@
1
+ export declare const useB3Account: () => import("thirdweb/wallets").Account | undefined;
@@ -0,0 +1,6 @@
1
+ import { useActiveAccount } from "thirdweb/react";
2
+ // Wrapper around useActiveAccount
3
+ export const useB3Account = () => {
4
+ const account = useActiveAccount();
5
+ return account;
6
+ };
@@ -0,0 +1,9 @@
1
+ export declare const useB3Config: () => {
2
+ automaticallySetFirstEoa: boolean;
3
+ environment: "development" | "production" | undefined;
4
+ theme: "light" | "dark";
5
+ clientType: import("../../../client-manager").ClientType;
6
+ partnerId: string;
7
+ createClientReferenceId: ((params: import("../../../../anyspend/react").CreateOrderParams | import("../../../../anyspend/react").CreateOnrampOrderParams) => Promise<string>) | undefined;
8
+ enableTurnkey: boolean | undefined;
9
+ };
@@ -0,0 +1,19 @@
1
+ import { useContext, useMemo } from "react";
2
+ import { B3Context } from "./types.js";
3
+ export const useB3Config = () => {
4
+ const context = useContext(B3Context);
5
+ if (!context) {
6
+ throw new Error("useB3 must be used within a B3Provider");
7
+ }
8
+ const { automaticallySetFirstEoa, environment, theme, clientType, partnerId, createClientReferenceId, enableTurnkey, } = context;
9
+ // Return a stable reference
10
+ return useMemo(() => ({
11
+ automaticallySetFirstEoa,
12
+ environment,
13
+ theme,
14
+ clientType,
15
+ partnerId,
16
+ createClientReferenceId,
17
+ enableTurnkey,
18
+ }), [automaticallySetFirstEoa, environment, theme, clientType, partnerId, createClientReferenceId, enableTurnkey]);
19
+ };
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import app from "../../../../global-account/app.js";
3
- import { Button, toast, useB3, useModalStore, useQueryB3, } from "../../../../global-account/react/index.js";
3
+ import { Button, toast, useAuthentication, useModalStore, useQueryB3, } from "../../../../global-account/react/index.js";
4
4
  import { client } from "../../../../shared/utils/thirdweb.js";
5
5
  import { Copy, Loader2, Pencil } from "lucide-react";
6
6
  import { useEffect, useRef, useState } from "react";
@@ -17,7 +17,7 @@ export const LinkAccount = ({ partnerId, onLogout: _onLogout, chain, }) => {
17
17
  const isLinking = useModalStore(state => state.isLinking);
18
18
  const setB3ModalOpen = useModalStore(state => state.setB3ModalOpen);
19
19
  const contentType = useModalStore(state => state.contentType);
20
- const { user, setUser } = useB3();
20
+ const { user, setUser } = useAuthentication(partnerId);
21
21
  const [isUpdatingCode, setIsUpdatingCode] = useState(false);
22
22
  const [newReferralCode, setNewReferralCode] = useState("");
23
23
  const [isEditingCode, setIsEditingCode] = useState(false);
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import app from "../../../../global-account/app.js";
3
- import { toast } from "../../../../global-account/react/index.js";
3
+ import { toast, useB3Account } from "../../../../global-account/react/index.js";
4
4
  import { ecosystemWalletId } from "../../../../shared/constants/index.js";
5
5
  import { thirdwebB3Mainnet } from "../../../../shared/constants/chains/b3Chain.js";
6
6
  import { client } from "../../../../shared/utils/thirdweb.js";
@@ -11,7 +11,6 @@ import { createWallet, preAuthenticate } from "thirdweb/wallets";
11
11
  import { WalletRow } from "../../index.js";
12
12
  import { useModalStore } from "../../stores/useModalStore.js";
13
13
  import { getProfileDisplayInfo } from "../../utils/profileDisplay.js";
14
- import { useB3 } from "../B3Provider/useB3.js";
15
14
  import { AppleIcon } from "../icons/AppleIcon.js";
16
15
  import { DiscordIcon } from "../icons/DiscordIcon.js";
17
16
  import { FarcasterIcon } from "../icons/FarcasterIcon.js";
@@ -90,7 +89,7 @@ export function LinkNewAccount({ onSuccess: onSuccessCallback, onError, onClose,
90
89
  ...getProfileDisplayInfo(profile),
91
90
  originalProfile: profile,
92
91
  }));
93
- const { account } = useB3();
92
+ const account = useB3Account();
94
93
  const { mutate: linkProfile } = useLinkProfile();
95
94
  const onSuccess = useCallback(async () => {
96
95
  await onSuccessCallback?.();
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAccountWallet, useB3, useModalStore, useProfile, useSimBalance } from "../../../../global-account/react/index.js";
2
+ import { useAccountWallet, useAuthentication, useB3Config, useModalStore, useProfile, useSimBalance, } from "../../../../global-account/react/index.js";
3
3
  import { formatUsername } from "../../../../shared/utils/index.js";
4
4
  import { formatDisplayNumber } from "../../../../shared/utils/number.js";
5
5
  import { Pencil } from "lucide-react";
@@ -15,7 +15,8 @@ const ProfileSection = () => {
15
15
  address: eoaAddress || account?.address,
16
16
  fresh: true,
17
17
  });
18
- const { user } = useB3();
18
+ const { partnerId } = useB3Config();
19
+ const { user } = useAuthentication(partnerId);
19
20
  const setB3ModalOpen = useModalStore(state => state.setB3ModalOpen);
20
21
  const setB3ModalContentType = useModalStore(state => state.setB3ModalContentType);
21
22
  const navigateBack = useModalStore(state => state.navigateBack);
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { ens_normalize } from "@adraffy/ens-normalize";
3
3
  import app from "../../../../global-account/app.js";
4
- import { toast, useB3, useModalStore, useProfile } from "../../../../global-account/react/index.js";
4
+ import { toast, useAuthentication, useB3Config, useModalStore, useProfile } from "../../../../global-account/react/index.js";
5
5
  import { formatUsername } from "../../../../shared/utils/index.js";
6
6
  import { Check, Loader2, Pencil, X } from "lucide-react";
7
7
  import { useEffect, useRef, useState } from "react";
@@ -15,7 +15,8 @@ const SettingsProfileCard = () => {
15
15
  address: eoaAddress || account?.address,
16
16
  fresh: true,
17
17
  });
18
- const { user, setUser } = useB3();
18
+ const { partnerId } = useB3Config();
19
+ const { user, setUser } = useAuthentication(partnerId);
19
20
  const setB3ModalOpen = useModalStore(state => state.setB3ModalOpen);
20
21
  const setB3ModalContentType = useModalStore(state => state.setB3ModalContentType);
21
22
  const navigateBack = useModalStore(state => state.navigateBack);
@@ -1,11 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Button, StyleRoot, useAuthStore, useB3, useIsMobile, useModalStore, } from "../../../../global-account/react/index.js";
2
+ import { Button, StyleRoot, useAuthStore, useIsMobile, useModalStore, } from "../../../../global-account/react/index.js";
3
3
  import { useEffect } from "react";
4
+ import { useB3Account } from "../B3Provider/useB3Account.js";
4
5
  import { ManageAccountButton } from "../custom/ManageAccountButton.js";
5
6
  import { Loading } from "../ui/Loading.js";
6
7
  export function SignInWithB3(props) {
7
8
  const { setB3ModalOpen, setB3ModalContentType, setEcoSystemAccountAddress } = useModalStore();
8
- const { account } = useB3();
9
+ const account = useB3Account();
9
10
  const { isAuthenticating, isAuthenticated } = useAuthStore();
10
11
  const isMobile = useIsMobile();
11
12
  useEffect(() => {
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Loading, useAuthStore, useB3, useGetAllTWSigners, useModalStore, } from "../../../../global-account/react/index.js";
2
+ import { Loading, useAuthentication, useAuthStore, useB3Config, useGetAllTWSigners, useModalStore, } from "../../../../global-account/react/index.js";
3
3
  import { debugB3React } from "../../../../shared/utils/debug.js";
4
4
  import { useCallback, useEffect, useState } from "react";
5
5
  import { useActiveAccount } from "thirdweb/react";
@@ -13,7 +13,8 @@ const MAX_REFETCH_ATTEMPTS = 20;
13
13
  * Handles different login providers, authentication steps, and session key management
14
14
  */
15
15
  export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, source = "signInWithB3Button", signersEnabled = false, }) {
16
- const { automaticallySetFirstEoa, user, refetchUser, enableTurnkey } = useB3();
16
+ const { automaticallySetFirstEoa, enableTurnkey } = useB3Config();
17
+ const { user, refetchUser } = useAuthentication(partnerId);
17
18
  const [step, setStep] = useState(source === "requestPermissions" ? null : "login");
18
19
  const [sessionKeyAdded, setSessionKeyAdded] = useState(source === "requestPermissions" ? true : false);
19
20
  const { setB3ModalContentType, setB3ModalOpen, isOpen, contentType } = useModalStore();
@@ -3,6 +3,8 @@ export { B3Provider, InnerProvider } from "./B3Provider/B3Provider";
3
3
  export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper";
4
4
  export { B3Context, type B3ContextType } from "./B3Provider/types";
5
5
  export { useB3 } from "./B3Provider/useB3";
6
+ export { useB3Account } from "./B3Provider/useB3Account";
7
+ export { useB3Config } from "./B3Provider/useB3Config";
6
8
  export { StyleRoot } from "./StyleRoot";
7
9
  export { AuthButton } from "./SignInWithB3/components/AuthButton";
8
10
  export { PermissionItem } from "./SignInWithB3/components/PermissionItem";
@@ -5,6 +5,8 @@ export { B3Provider, InnerProvider } from "./B3Provider/B3Provider.js";
5
5
  export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper.js";
6
6
  export { B3Context } from "./B3Provider/types.js";
7
7
  export { useB3 } from "./B3Provider/useB3.js";
8
+ export { useB3Account } from "./B3Provider/useB3Account.js";
9
+ export { useB3Config } from "./B3Provider/useB3Config.js";
8
10
  export { StyleRoot } from "./StyleRoot.js";
9
11
  // SignInWithB3 Components
10
12
  export { AuthButton } from "./SignInWithB3/components/AuthButton.js";
@@ -1,9 +1,10 @@
1
- import { useB3, useProfile } from "../../../global-account/react/index.js";
1
+ import { useProfile } from "../../../global-account/react/index.js";
2
2
  import { ecosystemWalletId } from "../../../shared/constants/index.js";
3
3
  import { debugB3React } from "../../../shared/utils/debug.js";
4
4
  import { useEffect, useMemo, useState } from "react";
5
5
  import { getLastAuthProvider, useActiveWallet, useConnectedWallets, useWalletImage } from "thirdweb/react";
6
6
  import { socialIcons } from "thirdweb/wallets/in-app";
7
+ import { useB3Account } from "../components/B3Provider/useB3Account.js";
7
8
  const debug = debugB3React("useAccountWallet");
8
9
  function useLastAuthProvider() {
9
10
  const [lastAuthProvider, setLastAuthProvider] = useState(null);
@@ -23,7 +24,7 @@ export function useAccountWallet() {
23
24
  // const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
24
25
  // can we possibly just use useActiveAccount here?
25
26
  // --------------------
26
- const { account } = useB3();
27
+ const account = useB3Account();
27
28
  const activeWallet = useActiveWallet();
28
29
  const connectedWallets = useConnectedWallets();
29
30
  const connectedSmartWallet = connectedWallets.find(wallet => wallet.id === ecosystemWalletId);
@@ -71,7 +72,7 @@ export function useAccountWallet() {
71
72
  return res;
72
73
  }
73
74
  export function useAccountWalletImage() {
74
- const { account } = useB3();
75
+ const account = useB3Account();
75
76
  const activeWallet = useActiveWallet();
76
77
  const connectedWallets = useConnectedWallets();
77
78
  const connectedSmartWallet = connectedWallets.find(wallet => wallet.id === ecosystemWalletId);
@@ -13,8 +13,8 @@ export declare function useAuthentication(partnerId: string): {
13
13
  onConnect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
14
14
  user: {
15
15
  email?: string | undefined;
16
- telNumber?: string | undefined;
17
16
  username?: string | undefined;
17
+ telNumber?: string | undefined;
18
18
  ens?: string | undefined;
19
19
  avatar?: string | undefined;
20
20
  preferences?: {} | undefined;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Hook to automatically select the first EOA wallet when user is authenticated
3
+ * Only auto-selects if the last auth was via wallet or no previous auth provider
4
+ */
5
+ export declare function useAutoSelectWallet({ enabled }: {
6
+ enabled: boolean;
7
+ }): void;
@@ -0,0 +1,39 @@
1
+ import { debugB3React } from "../../../shared/utils/debug.js";
2
+ import { useCallback, useEffect } from "react";
3
+ import { getLastAuthProvider, useConnectedWallets, useSetActiveWallet } from "thirdweb/react";
4
+ import { useAuthStore } from "../stores/index.js";
5
+ const debug = debugB3React("useAutoSelectWallet");
6
+ /**
7
+ * Hook to automatically select the first EOA wallet when user is authenticated
8
+ * Only auto-selects if the last auth was via wallet or no previous auth provider
9
+ */
10
+ export function useAutoSelectWallet({ enabled }) {
11
+ const isAuthenticated = useAuthStore(state => state.isAuthenticated);
12
+ const wallets = useConnectedWallets();
13
+ const setActiveWallet = useSetActiveWallet();
14
+ const setWallet = useCallback((wallet) => {
15
+ debug("@@setWallet", wallet.id, wallet.getAccount()?.address);
16
+ setActiveWallet(wallet);
17
+ }, [setActiveWallet]);
18
+ useEffect(() => {
19
+ const autoSelectFirstEOAWallet = async () => {
20
+ // Only proceed if auto-selection is enabled and user is authenticated
21
+ if (!enabled || !isAuthenticated) {
22
+ return;
23
+ }
24
+ // Find the first EOA wallet (excluding ecosystem wallets)
25
+ const isEOAWallet = (wallet) => !wallet.id.startsWith("ecosystem.");
26
+ const firstEOAWallet = wallets.find(isEOAWallet);
27
+ if (firstEOAWallet) {
28
+ // Only auto-select if the last auth was via wallet or no previous auth provider
29
+ const lastAuthProvider = await getLastAuthProvider();
30
+ const shouldAutoSelect = lastAuthProvider === null || lastAuthProvider === "wallet";
31
+ if (shouldAutoSelect) {
32
+ debug("Auto-selecting first EOA wallet", firstEOAWallet.id);
33
+ setWallet(firstEOAWallet);
34
+ }
35
+ }
36
+ };
37
+ autoSelectFirstEOAWallet();
38
+ }, [enabled, isAuthenticated, setWallet, wallets]);
39
+ }
@@ -1,8 +1,9 @@
1
+ import { debugB3React } from "../../../shared/utils/debug.js";
2
+ import { useCallback, useState } from "react";
1
3
  import app from "../../app.js";
4
+ import { useB3Config } from "../components/index.js";
2
5
  import { useAuthStore } from "../stores/index.js";
3
- import { useCallback, useState } from "react";
4
- import { useB3 } from "../components/B3Provider/useB3.js";
5
- import { debugB3React } from "../../../shared/utils/debug.js";
6
+ import { useAuthentication } from "./useAuthentication.js";
6
7
  const debug = debugB3React("useTurnkeyAuth");
7
8
  /**
8
9
  * Hook for Turnkey email-based OTP authentication
@@ -17,7 +18,8 @@ export function useTurnkeyAuth() {
17
18
  const [error, setError] = useState(null);
18
19
  const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
19
20
  const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
20
- const { user } = useB3();
21
+ const { partnerId } = useB3Config();
22
+ const { user } = useAuthentication(partnerId);
21
23
  /**
22
24
  * Step 1: Initiate login with email
23
25
  * - Calls backend to create sub-org (if needed) and send OTP
@@ -8,7 +8,7 @@ import { useCallback, useState } from "react";
8
8
  import { prepareTransaction, sendTransaction as twSendTransaction } from "thirdweb";
9
9
  import { isAddress } from "viem";
10
10
  import { useSwitchChain } from "wagmi";
11
- import { useB3 } from "../components/index.js";
11
+ import { useB3Account } from "../components/B3Provider/useB3Account.js";
12
12
  import { useAccountWallet } from "./useAccountWallet.js";
13
13
  const partnerId = String(process.env.PUBLIC_THIRDWEB_PARTNER_ID ||
14
14
  process.env.NEXT_PUBLIC_THIRDWEB_PARTNER_ID ||
@@ -19,7 +19,7 @@ export function useUnifiedChainSwitchAndExecute() {
19
19
  const { switchChainAsync } = useSwitchChain();
20
20
  const [isSwitchingOrExecuting, setIsSwitchingOrExecuting] = useState(false);
21
21
  const { isActiveSmartWallet, isActiveEOAWallet, connectedEOAWallet } = useAccountWallet();
22
- const { account: aaAccount } = useB3();
22
+ const aaAccount = useB3Account();
23
23
  // Handle EOA wallet chain switch and execute transaction
24
24
  const handleEOASwitchChainAndSendTransaction = useCallback(async (targetChainId, params) => {
25
25
  if (!connectedEOAWallet) {
@@ -8,8 +8,8 @@ import { Users } from "@b3dotfun/b3-api";
8
8
  export declare function useUserQuery(): {
9
9
  user: {
10
10
  email?: string | undefined;
11
- telNumber?: string | undefined;
12
11
  username?: string | undefined;
12
+ telNumber?: string | undefined;
13
13
  ens?: string | undefined;
14
14
  avatar?: string | undefined;
15
15
  preferences?: {} | undefined;
@@ -48,8 +48,8 @@ export declare const useGenerateSigMintData: ({ recipientAddress, contractAddres
48
48
  creatorMap?: {} | undefined;
49
49
  chainId: number;
50
50
  address: string;
51
- _id: string | {};
52
51
  title: string;
52
+ _id: string | {};
53
53
  };
54
54
  } | null;
55
55
  error: Error | null;
@@ -1,4 +1,3 @@
1
- import { Users } from "@b3dotfun/b3-api";
2
1
  import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
3
2
  import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
4
3
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
@@ -10,11 +9,7 @@ import { ClientType } from "../../../client-manager";
10
9
  export interface B3ContextType {
11
10
  account?: Account;
12
11
  automaticallySetFirstEoa: boolean;
13
- user?: Users;
14
- setWallet: (wallet: Wallet) => void;
15
12
  wallet?: Wallet;
16
- setUser: (user?: Users) => void;
17
- refetchUser: () => Promise<any>;
18
13
  initialized: boolean;
19
14
  ready: boolean;
20
15
  environment?: "development" | "production";
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Hook to access the B3 context
3
3
  * @throws Error if used outside a B3Provider
4
+ * @deprecated Use useB3Config or useB3Account instead
4
5
  */
5
6
  export declare function useB3(): import("./types").B3ContextType;
@@ -0,0 +1 @@
1
+ export declare const useB3Account: () => import("thirdweb/wallets").Account | undefined;
@@ -0,0 +1,9 @@
1
+ export declare const useB3Config: () => {
2
+ automaticallySetFirstEoa: boolean;
3
+ environment: "development" | "production" | undefined;
4
+ theme: "light" | "dark";
5
+ clientType: import("../../../client-manager").ClientType;
6
+ partnerId: string;
7
+ createClientReferenceId: ((params: import("../../../../anyspend/react").CreateOrderParams | import("../../../../anyspend/react").CreateOnrampOrderParams) => Promise<string>) | undefined;
8
+ enableTurnkey: boolean | undefined;
9
+ };
@@ -3,6 +3,8 @@ export { B3Provider, InnerProvider } from "./B3Provider/B3Provider";
3
3
  export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper";
4
4
  export { B3Context, type B3ContextType } from "./B3Provider/types";
5
5
  export { useB3 } from "./B3Provider/useB3";
6
+ export { useB3Account } from "./B3Provider/useB3Account";
7
+ export { useB3Config } from "./B3Provider/useB3Config";
6
8
  export { StyleRoot } from "./StyleRoot";
7
9
  export { AuthButton } from "./SignInWithB3/components/AuthButton";
8
10
  export { PermissionItem } from "./SignInWithB3/components/PermissionItem";
@@ -13,8 +13,8 @@ export declare function useAuthentication(partnerId: string): {
13
13
  onConnect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
14
14
  user: {
15
15
  email?: string | undefined;
16
- telNumber?: string | undefined;
17
16
  username?: string | undefined;
17
+ telNumber?: string | undefined;
18
18
  ens?: string | undefined;
19
19
  avatar?: string | undefined;
20
20
  preferences?: {} | undefined;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Hook to automatically select the first EOA wallet when user is authenticated
3
+ * Only auto-selects if the last auth was via wallet or no previous auth provider
4
+ */
5
+ export declare function useAutoSelectWallet({ enabled }: {
6
+ enabled: boolean;
7
+ }): void;
@@ -8,8 +8,8 @@ import { Users } from "@b3dotfun/b3-api";
8
8
  export declare function useUserQuery(): {
9
9
  user: {
10
10
  email?: string | undefined;
11
- telNumber?: string | undefined;
12
11
  username?: string | undefined;
12
+ telNumber?: string | undefined;
13
13
  ens?: string | undefined;
14
14
  avatar?: string | undefined;
15
15
  preferences?: {} | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.87-alpha.2",
3
+ "version": "0.0.87-alpha.3",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",