@b3dotfun/sdk 0.0.47-alpha.2 → 0.0.47-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 (90) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  3. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -64
  4. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  5. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +26 -21
  6. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
  7. package/dist/cjs/global-account/react/components/B3Provider/types.js +2 -0
  8. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  9. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  10. package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  11. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  12. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
  13. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  14. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +6 -22
  15. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  16. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -2
  17. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  18. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +10 -45
  19. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  20. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -1
  21. package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -1
  22. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +51 -2
  23. package/dist/cjs/global-account/react/hooks/useAuthentication.js +141 -81
  24. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  25. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -1
  26. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +58 -0
  27. package/dist/cjs/global-account/react/hooks/useUserQuery.js +86 -0
  28. package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  29. package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +42 -0
  30. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
  31. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  32. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -68
  33. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  34. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +24 -19
  35. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
  36. package/dist/esm/global-account/react/components/B3Provider/types.js +2 -0
  37. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  38. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  39. package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  40. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  41. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
  42. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  43. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +7 -23
  44. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  45. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +4 -3
  46. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  47. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +11 -46
  48. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  49. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
  50. package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +3 -2
  51. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +51 -2
  52. package/dist/esm/global-account/react/hooks/useAuthentication.js +144 -84
  53. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  54. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +3 -2
  55. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +58 -0
  56. package/dist/esm/global-account/react/hooks/useUserQuery.js +83 -0
  57. package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  58. package/dist/esm/global-account/react/hooks/useWagmiConfig.js +39 -0
  59. package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
  60. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  61. package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  62. package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
  63. package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  64. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  65. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  66. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  67. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  68. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +51 -2
  69. package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  70. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +58 -0
  71. package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  72. package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
  73. package/package.json +3 -3
  74. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +51 -35
  75. package/src/global-account/react/components/B3Provider/B3Provider.tsx +28 -72
  76. package/src/global-account/react/components/B3Provider/types.ts +4 -0
  77. package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +2 -3
  78. package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
  79. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
  80. package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
  81. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +4 -23
  82. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +4 -3
  83. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +8 -46
  84. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
  85. package/src/global-account/react/components/custom/ManageAccountButton.tsx +3 -2
  86. package/src/global-account/react/hooks/useAuthentication.ts +170 -89
  87. package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +3 -2
  88. package/src/global-account/react/hooks/useUserQuery.ts +95 -0
  89. package/src/global-account/react/hooks/useWagmiConfig.tsx +44 -0
  90. package/src/global-account/react/stores/useModalStore.ts +0 -2
@@ -1,5 +1,6 @@
1
+ import { Wallet } from "thirdweb/wallets";
1
2
  import { preAuthenticate } from "thirdweb/wallets/in-app";
2
- export declare function useAuthentication(partnerId: string, loginWithSiwe?: boolean): {
3
+ export declare function useAuthentication(partnerId: string): {
3
4
  logout: (callback?: () => void) => Promise<void>;
4
5
  isAuthenticated: boolean;
5
6
  isReady: boolean;
@@ -7,6 +8,54 @@ export declare function useAuthentication(partnerId: string, loginWithSiwe?: boo
7
8
  isConnected: boolean;
8
9
  wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
9
10
  preAuthenticate: typeof preAuthenticate;
10
- connect: (strategyOptions?: import("thirdweb/wallets").SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
11
+ connect: (wallet: Wallet) => Promise<void>;
11
12
  isAuthenticating: boolean;
13
+ onConnect: (wallet: Wallet) => Promise<void>;
14
+ user: {
15
+ email?: string | undefined;
16
+ username?: string | undefined;
17
+ telNumber?: string | undefined;
18
+ ens?: string | undefined;
19
+ avatar?: string | undefined;
20
+ preferences?: {} | undefined;
21
+ referredBy?: string | {} | undefined;
22
+ sourceApp?: string | undefined;
23
+ referralCode?: string | undefined;
24
+ userGroups?: number[] | undefined;
25
+ isMigratedFromBSMNT?: boolean | undefined;
26
+ privyLinkedAccounts?: {
27
+ name?: string | undefined;
28
+ address?: string | undefined;
29
+ email?: string | undefined;
30
+ chain_type?: string | undefined;
31
+ lv?: number | undefined;
32
+ wallet_client_type?: string | undefined;
33
+ smart_wallet_type?: string | undefined;
34
+ subject?: string | undefined;
35
+ type: string;
36
+ }[] | undefined;
37
+ twProfiles?: {
38
+ type: string;
39
+ details: {
40
+ id?: string | undefined;
41
+ name?: string | undefined;
42
+ address?: string | undefined;
43
+ email?: string | undefined;
44
+ phone?: string | undefined;
45
+ username?: string | undefined;
46
+ fid?: string | undefined;
47
+ };
48
+ }[] | undefined;
49
+ _id: string | {};
50
+ userId: string;
51
+ smartAccountAddress: string;
52
+ createdAt: number;
53
+ updatedAt: number;
54
+ partnerIds: {
55
+ privyId?: string | undefined;
56
+ thirdwebId?: string | undefined;
57
+ };
58
+ } | undefined;
59
+ refetchUser: (wallet?: Wallet) => Promise<void>;
60
+ setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
12
61
  };
@@ -8,116 +8,158 @@ const app_1 = __importDefault(require("../../../global-account/app"));
8
8
  const bsmnt_1 = require("../../../global-account/bsmnt");
9
9
  const react_1 = require("../../../global-account/react");
10
10
  const constants_1 = require("../../../shared/constants");
11
- const supported_1 = require("../../../shared/constants/chains/supported");
12
11
  const debug_1 = require("../../../shared/utils/debug");
13
12
  const thirdweb_1 = require("../../../shared/utils/thirdweb");
13
+ const core_1 = require("@wagmi/core");
14
14
  const react_2 = require("react");
15
15
  const react_3 = require("thirdweb/react");
16
16
  const wallets_1 = require("thirdweb/wallets");
17
17
  const in_app_1 = require("thirdweb/wallets/in-app");
18
- const useConnect_1 = require("./useConnect");
19
- const useSiwe_1 = require("./useSiwe");
18
+ const wagmi_1 = require("wagmi");
19
+ const useUserQuery_1 = require("./useUserQuery");
20
+ const useWagmiConfig_1 = require("./useWagmiConfig");
20
21
  const debug = (0, debug_1.debugB3React)("useAuthentication");
21
- function useAuthentication(partnerId, loginWithSiwe) {
22
+ function useAuthentication(partnerId) {
22
23
  const { disconnect } = (0, react_3.useDisconnect)();
23
24
  const wallets = (0, react_3.useConnectedWallets)();
24
25
  const activeWallet = (0, react_3.useActiveWallet)();
25
- const { authenticate } = (0, useSiwe_1.useSiwe)();
26
- const { setUser } = (0, react_1.useB3)();
27
26
  const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
28
27
  const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
29
- const setIsConnecting = (0, react_1.useAuthStore)(state => state.setIsConnecting);
30
28
  const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
31
29
  const isConnecting = (0, react_1.useAuthStore)(state => state.isConnecting);
32
30
  const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
33
- const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
34
- const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
35
31
  const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
36
- const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
32
+ const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
37
33
  const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
38
- const { connect } = (0, useConnect_1.useConnect)(partnerId, supported_1.b3MainnetThirdWeb);
34
+ const setActiveWallet = (0, react_3.useSetActiveWallet)();
35
+ const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
36
+ const { authenticate } = (0, react_1.useSiwe)();
37
+ const { user, setUser } = (0, useUserQuery_1.useUserQuery)();
38
+ const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
39
+ const wagmiConfig = (0, useWagmiConfig_1.useWagmiConfig)(partnerId);
40
+ const { connect } = (0, wagmi_1.useConnect)();
41
+ const activeWagmiAccount = (0, wagmi_1.useAccount)();
42
+ const { switchAccount } = (0, wagmi_1.useSwitchAccount)();
43
+ debug("@@activeWagmiAccount", activeWagmiAccount);
39
44
  const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
40
45
  partnerId: partnerId,
41
46
  });
42
- const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
43
- client: thirdweb_1.client,
44
- wallets: [wallet],
45
- onConnect: async (wallet) => {
46
- setHasStartedConnecting(true);
47
- try {
48
- setIsConnected(true);
49
- if (!loginWithSiwe) {
50
- debug("Skipping SIWE login", { loginWithSiwe });
51
- setIsAuthenticated(true);
52
- setIsAuthenticating(false);
47
+ const syncWagmi = (0, react_2.useCallback)(async () => {
48
+ function syncWagmiFunc() {
49
+ const connectors = (0, core_1.getConnectors)(wagmiConfig);
50
+ debug("@@syncWagmi", {
51
+ connectors,
52
+ wallets,
53
+ });
54
+ // For each that matchs a TW wallet on wallets, connect to the wagmi connector
55
+ // or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
56
+ connectors.forEach(async (connector) => {
57
+ const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
58
+ // If no TW wallet, do not prompt the user to connect
59
+ if (!twWallet) {
53
60
  return;
54
61
  }
55
- debug("setIsAuthenticating:true:4");
56
- const account = await wallet.getAccount();
57
- if (!account) {
58
- throw new Error("No account found during auto-connect");
62
+ // Metamask will prompt to connect, we can just switch accounts here.
63
+ if (connector.id === "io.metamask") {
64
+ return switchAccount({ connector });
59
65
  }
60
- // Try to re-authenticate first
61
- try {
62
- const userAuth = await app_1.default.reAuthenticate();
63
- setUser(userAuth.user);
64
- setIsAuthenticated(true);
65
- setIsAuthenticating(false);
66
- debug("Re-authenticated successfully", { userAuth });
67
- // Authenticate on BSMNT with B3 JWT
68
- const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
69
- console.log("@@b3Jwt", b3Jwt);
66
+ if (
67
+ // If it's not an in-app wallet or it is the ecosystem wallet, connect
68
+ connector.id !== "in-app-wallet" ||
69
+ (connector.id === "in-app-wallet" && twWallet.id === constants_1.ecosystemWalletId)) {
70
+ try {
71
+ const options = {
72
+ wallet: twWallet, // the connected wallet
73
+ };
74
+ debug("@@syncWagmi:connecting", { twWallet, connector });
75
+ connect({
76
+ connector,
77
+ ...options,
78
+ });
79
+ }
80
+ catch (error) {
81
+ console.error("@@syncWagmi:error", error);
82
+ }
70
83
  }
71
- catch (error) {
72
- // If re-authentication fails, try fresh authentication
73
- debug("Re-authentication failed, attempting fresh authentication");
74
- const userAuth = await authenticate(account, partnerId);
75
- setUser(userAuth.user);
76
- setIsAuthenticated(true);
77
- setIsAuthenticating(false);
78
- debug("Fresh authentication successful", { userAuth });
79
- // Authenticate on BSMNT with B3 JWT
80
- const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
81
- console.log("@@b3Jwt", b3Jwt);
84
+ else {
85
+ debug("@@syncWagmi:not-connecting", connector);
82
86
  }
83
- }
84
- catch (error) {
85
- debug("Auto-connect authentication failed", { error });
86
- setIsAuthenticated(false);
87
- debug("setIsAuthenticating:false:4");
88
- setUser();
89
- }
90
- setIsAuthenticating(false);
91
- },
92
- });
93
- /**
94
- * useAutoConnectLoading starts as false
95
- */
87
+ });
88
+ }
89
+ syncWagmiFunc();
90
+ // wagmi config shouldn't change
91
+ // eslint-disable-next-line react-hooks/exhaustive-deps
92
+ }, [partnerId, wallets]);
96
93
  (0, react_2.useEffect)(() => {
97
- if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
94
+ syncWagmi();
95
+ }, [wallets, syncWagmi]);
96
+ const authenticateUser = (0, react_2.useCallback)(async (wallet) => {
97
+ setHasStartedConnecting(true);
98
+ const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
99
+ if (!account) {
100
+ throw new Error("No account found during auto-connect");
101
+ }
102
+ if (!account) {
103
+ throw new Error("No account found during auto-connect");
104
+ }
105
+ // Try to re-authenticate first
106
+ try {
107
+ const userAuth = await app_1.default.reAuthenticate();
108
+ setUser(userAuth.user);
109
+ setIsAuthenticated(true);
98
110
  setIsAuthenticating(false);
111
+ debug("Re-authenticated successfully", { userAuth });
112
+ // Authenticate on BSMNT with B3 JWT
113
+ const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
114
+ debug("@@b3Jwt", b3Jwt);
99
115
  }
100
- useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
101
- }, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
102
- // Ensure isAuthenticating stays true until we're fully ready
103
- (0, react_2.useEffect)(() => {
104
- if (useAutoConnectLoading) {
105
- setIsConnecting(true);
116
+ catch (error) {
117
+ // If re-authentication fails, try fresh authentication
118
+ debug("Re-authentication failed, attempting fresh authentication");
119
+ const userAuth = await authenticate(account, partnerId);
120
+ setUser(userAuth.user);
121
+ setIsAuthenticated(true);
122
+ setIsAuthenticating(false);
123
+ debug("Fresh authentication successful", { userAuth });
124
+ // Authenticate on BSMNT with B3 JWT
125
+ const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
126
+ debug("@@b3Jwt", b3Jwt);
127
+ }
128
+ }, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
129
+ const onConnect = (0, react_2.useCallback)(async (wallet) => {
130
+ debug("@@useAuthentication:onConnect", { wallet });
131
+ try {
132
+ setHasStartedConnecting(true);
133
+ setIsConnected(true);
134
+ setIsAuthenticating(true);
135
+ await setActiveWallet(wallet);
136
+ await authenticateUser(wallet);
106
137
  }
107
- else if (!isAuthenticated) {
108
- // Only set isAuthenticating to false if we're not authenticated
109
- // This prevents the flicker state where both isAuthenticating and isAuthenticated are false
110
- const timeout = setTimeout(() => {
111
- debug("setIsAuthenticating:false:5a");
112
- setIsConnecting(false);
113
- }, 100); // Add a small delay to prevent quick flickers
114
- return () => clearTimeout(timeout);
138
+ catch (error) {
139
+ debug("@@useAuthentication:onConnect:failed", { error });
140
+ setIsAuthenticated(false);
141
+ setUser(undefined);
115
142
  }
116
- else {
117
- debug("setIsAuthenticating:false:5b");
118
- setIsConnecting(false);
143
+ finally {
144
+ setIsAuthenticating(false);
119
145
  }
120
- }, [useAutoConnectLoading, isAuthenticated, setIsConnecting, setIsConnected]);
146
+ debug({
147
+ isAuthenticated,
148
+ isAuthenticating,
149
+ isConnected,
150
+ });
151
+ }, [
152
+ authenticateUser,
153
+ isAuthenticated,
154
+ isAuthenticating,
155
+ isConnected,
156
+ setActiveWallet,
157
+ setHasStartedConnecting,
158
+ setIsAuthenticated,
159
+ setIsAuthenticating,
160
+ setIsConnected,
161
+ setUser,
162
+ ]);
121
163
  const logout = async (callback) => {
122
164
  if (activeWallet) {
123
165
  debug("@@logout:activeWallet", activeWallet);
@@ -143,7 +185,21 @@ function useAuthentication(partnerId, loginWithSiwe) {
143
185
  setUser();
144
186
  callback?.();
145
187
  };
146
- const isReady = isAuthenticated && !useAutoConnectLoading && !isAuthenticating;
188
+ const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
189
+ client: thirdweb_1.client,
190
+ wallets: [wallet],
191
+ onConnect: onConnect,
192
+ });
193
+ /**
194
+ * useAutoConnectLoading starts as false
195
+ */
196
+ (0, react_2.useEffect)(() => {
197
+ if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
198
+ setIsAuthenticating(false);
199
+ }
200
+ useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
201
+ }, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
202
+ const isReady = isAuthenticated && !isAuthenticating;
147
203
  return {
148
204
  logout,
149
205
  isAuthenticated,
@@ -152,7 +208,11 @@ function useAuthentication(partnerId, loginWithSiwe) {
152
208
  isConnected,
153
209
  wallet,
154
210
  preAuthenticate: in_app_1.preAuthenticate,
155
- connect,
211
+ connect: onConnect,
156
212
  isAuthenticating,
213
+ onConnect,
214
+ user,
215
+ refetchUser: authenticateUser,
216
+ setUser,
157
217
  };
158
218
  }
@@ -4,7 +4,7 @@ import { Account } from "thirdweb/wallets";
4
4
  * This essentially wraps our useConnect hook to handle the Privy auth flow.
5
5
  * Currently, this is for the basement-privy strategy
6
6
  */
7
- export declare function useHandleConnectWithPrivy(partnerId: string, chain?: Chain, onSuccess?: (account: Account) => void): {
7
+ export declare function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void): {
8
8
  connectTw: () => Promise<import("thirdweb/wallets").Wallet | null | undefined>;
9
9
  isLoading: boolean;
10
10
  fullToken: string | null;
@@ -10,7 +10,8 @@ const debug = (0, debug_1.debugB3React)("@@b3:useHandleConnectWithPrivy");
10
10
  * This essentially wraps our useConnect hook to handle the Privy auth flow.
11
11
  * Currently, this is for the basement-privy strategy
12
12
  */
13
- function useHandleConnectWithPrivy(partnerId, chain, onSuccess) {
13
+ function useHandleConnectWithPrivy(chain, onSuccess) {
14
+ const { partnerId } = (0, react_1.useB3)();
14
15
  if (!chain) {
15
16
  throw new Error("Chain is required");
16
17
  }
@@ -0,0 +1,58 @@
1
+ import { Users } from "@b3dotfun/b3-api";
2
+ /**
3
+ * NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
4
+ *
5
+ * Custom hook to manage user state with react-query
6
+ * This allows for invalidation and refetching of user data
7
+ */
8
+ export declare function useUserQuery(): {
9
+ user: {
10
+ email?: string | undefined;
11
+ username?: string | undefined;
12
+ telNumber?: string | undefined;
13
+ ens?: string | undefined;
14
+ avatar?: string | undefined;
15
+ preferences?: {} | undefined;
16
+ referredBy?: string | {} | undefined;
17
+ sourceApp?: string | undefined;
18
+ referralCode?: string | undefined;
19
+ userGroups?: number[] | undefined;
20
+ isMigratedFromBSMNT?: boolean | undefined;
21
+ privyLinkedAccounts?: {
22
+ name?: string | undefined;
23
+ address?: string | undefined;
24
+ email?: string | undefined;
25
+ chain_type?: string | undefined;
26
+ lv?: number | undefined;
27
+ wallet_client_type?: string | undefined;
28
+ smart_wallet_type?: string | undefined;
29
+ subject?: string | undefined;
30
+ type: string;
31
+ }[] | undefined;
32
+ twProfiles?: {
33
+ type: string;
34
+ details: {
35
+ id?: string | undefined;
36
+ name?: string | undefined;
37
+ address?: string | undefined;
38
+ email?: string | undefined;
39
+ phone?: string | undefined;
40
+ username?: string | undefined;
41
+ fid?: string | undefined;
42
+ };
43
+ }[] | undefined;
44
+ _id: string | {};
45
+ userId: string;
46
+ smartAccountAddress: string;
47
+ createdAt: number;
48
+ updatedAt: number;
49
+ partnerIds: {
50
+ privyId?: string | undefined;
51
+ thirdwebId?: string | undefined;
52
+ };
53
+ } | undefined;
54
+ setUser: (newUser?: Users) => void;
55
+ refetchUser: () => Promise<void>;
56
+ clearUser: () => void;
57
+ queryKey: string[];
58
+ };
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useUserQuery = useUserQuery;
4
+ const debug_1 = require("../../../shared/utils/debug");
5
+ const react_query_1 = require("@tanstack/react-query");
6
+ const debug = (0, debug_1.debugB3React)("useUserQuery");
7
+ const USER_QUERY_KEY = ["b3-user"];
8
+ /**
9
+ * Retrieves the user from localStorage
10
+ */
11
+ function getUserFromStorage() {
12
+ if (typeof window === "undefined") {
13
+ return null;
14
+ }
15
+ try {
16
+ const storedUser = localStorage.getItem("b3-user");
17
+ return storedUser ? JSON.parse(storedUser) : null;
18
+ }
19
+ catch (error) {
20
+ console.warn("Failed to restore user from localStorage:", error);
21
+ return null;
22
+ }
23
+ }
24
+ /**
25
+ * Saves user to localStorage
26
+ */
27
+ function saveUserToStorage(user) {
28
+ if (typeof window === "undefined") {
29
+ return;
30
+ }
31
+ if (user) {
32
+ localStorage.setItem("b3-user", JSON.stringify(user));
33
+ }
34
+ else {
35
+ localStorage.removeItem("b3-user");
36
+ }
37
+ }
38
+ /**
39
+ * NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
40
+ *
41
+ * Custom hook to manage user state with react-query
42
+ * This allows for invalidation and refetching of user data
43
+ */
44
+ function useUserQuery() {
45
+ const queryClient = (0, react_query_1.useQueryClient)();
46
+ // Query to get user data (primarily from cache/localStorage)
47
+ const { data: user } = (0, react_query_1.useQuery)({
48
+ queryKey: USER_QUERY_KEY,
49
+ queryFn: getUserFromStorage,
50
+ staleTime: Infinity, // User data doesn't go stale automatically
51
+ gcTime: Infinity, // Keep in cache indefinitely
52
+ initialData: getUserFromStorage,
53
+ });
54
+ // Mutation to update user
55
+ const setUserMutation = (0, react_query_1.useMutation)({
56
+ mutationFn: async (newUser) => {
57
+ const userToSave = newUser ?? null;
58
+ saveUserToStorage(userToSave);
59
+ return userToSave;
60
+ },
61
+ onSuccess: data => {
62
+ queryClient.setQueryData(USER_QUERY_KEY, data);
63
+ debug("User updated", data);
64
+ },
65
+ });
66
+ // Helper function to set user (maintains backward compatibility)
67
+ const setUser = (newUser) => {
68
+ setUserMutation.mutate(newUser);
69
+ };
70
+ // Helper function to invalidate and refetch user
71
+ const refetchUser = async () => {
72
+ await queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
73
+ return queryClient.refetchQueries({ queryKey: USER_QUERY_KEY });
74
+ };
75
+ // Helper function to clear user
76
+ const clearUser = () => {
77
+ setUser(undefined);
78
+ };
79
+ return {
80
+ user: user ?? undefined,
81
+ setUser,
82
+ refetchUser,
83
+ clearUser,
84
+ queryKey: USER_QUERY_KEY,
85
+ };
86
+ }
@@ -0,0 +1,13 @@
1
+ export declare function useWagmiConfig(partnerId: string, rpcUrls?: Record<number, string>): import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], {
2
+ [k: string]: import("viem").HttpTransport<undefined, false>;
3
+ }, readonly [import("wagmi").CreateConnectorFn<import("thirdweb/dist/types/adapters/eip1193").EIP1193Provider | undefined, {
4
+ connect<withCapabilities extends boolean = false>(parameters?: import("@thirdweb-dev/wagmi-adapter").ConnectionOptions<withCapabilities> | undefined): Promise<{
5
+ accounts: withCapabilities extends true ? readonly {
6
+ address: `0x${string}`;
7
+ capabilities: Record<string, unknown>;
8
+ }[] : readonly `0x${string}`[];
9
+ chainId: number;
10
+ }>;
11
+ }, {
12
+ "thirdweb:lastChainId": number;
13
+ }>]>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useWagmiConfig = useWagmiConfig;
4
+ const constants_1 = require("../../../shared/constants");
5
+ const supported_1 = require("../../../shared/constants/chains/supported");
6
+ const thirdweb_1 = require("../../../shared/utils/thirdweb");
7
+ const wagmi_adapter_1 = require("@thirdweb-dev/wagmi-adapter");
8
+ const react_1 = require("react");
9
+ const viem_1 = require("viem");
10
+ const wagmi_1 = require("wagmi");
11
+ function useWagmiConfig(partnerId, rpcUrls) {
12
+ // Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
13
+ // when parent component passes new object references with same content
14
+ const rpcUrlsString = (0, react_1.useMemo)(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
15
+ const ecocystemConfig = (0, react_1.useMemo)(() => {
16
+ return {
17
+ ecosystemId: constants_1.ecosystemWalletId,
18
+ partnerId: partnerId,
19
+ client: thirdweb_1.client,
20
+ };
21
+ }, [partnerId]);
22
+ /**
23
+ * Creates wagmi config with optional custom RPC URLs
24
+ * @param rpcUrls - Optional mapping of chain IDs to RPC URLs
25
+ */
26
+ const wagmiConfig = (0, react_1.useMemo)(() => {
27
+ const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
28
+ return (0, wagmi_1.createConfig)({
29
+ chains: [supported_1.supportedChains[0], ...supported_1.supportedChains.slice(1)],
30
+ transports: Object.fromEntries(supported_1.supportedChains.map(chain => [chain.id, (0, viem_1.http)(parsedRpcUrls?.[chain.id])])),
31
+ connectors: [
32
+ (0, wagmi_adapter_1.inAppWalletConnector)({
33
+ ...ecocystemConfig,
34
+ client: thirdweb_1.client,
35
+ }),
36
+ // injected(),
37
+ // coinbaseWallet({ appName: "HypeDuel" }),
38
+ ],
39
+ });
40
+ }, [rpcUrlsString, ecocystemConfig]);
41
+ return wagmiConfig;
42
+ }
@@ -32,8 +32,6 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
32
32
  sessionKeyAddress?: Address;
33
33
  /** Unique identifier for the partner application */
34
34
  partnerId: string;
35
- /** Whether to authenticate with Sign In With Ethereum */
36
- loginWithSiwe?: boolean;
37
35
  /** Whether to close the modal after successful login */
38
36
  closeAfterLogin?: boolean;
39
37
  /** Source of the sign-in request */
@@ -19,12 +19,12 @@ export declare function B3Provider({ theme, children, accountOverride, environme
19
19
  };
20
20
  clientType?: ClientType;
21
21
  rpcUrls?: Record<number, string>;
22
- partnerId?: string;
22
+ partnerId: string;
23
23
  }): import("react/jsx-runtime").JSX.Element;
24
24
  /**
25
25
  * Inner provider component that provides the actual B3Context
26
26
  */
27
- export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, }: {
27
+ export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, }: {
28
28
  children: React.ReactNode;
29
29
  accountOverride?: Account;
30
30
  environment: B3ContextType["environment"];
@@ -32,4 +32,5 @@ export declare function InnerProvider({ children, accountOverride, environment,
32
32
  automaticallySetFirstEoa: boolean;
33
33
  theme: "light" | "dark";
34
34
  clientType?: ClientType;
35
+ partnerId: string;
35
36
  }): import("react/jsx-runtime").JSX.Element;