@b3dotfun/sdk 0.0.83-test.0 → 0.0.83

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 (68) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +0 -3
  2. package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +1 -1
  3. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +0 -3
  4. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +47 -177
  5. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +0 -3
  6. package/dist/cjs/anyspend/utils/chain.d.ts +38 -0
  7. package/dist/cjs/anyspend/utils/chain.js +22 -1
  8. package/dist/cjs/anyspend/utils/token.d.ts +3 -0
  9. package/dist/cjs/anyspend/utils/token.js +17 -1
  10. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +12 -57
  11. package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
  12. package/dist/cjs/global-account/react/hooks/index.js +1 -3
  13. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
  14. package/dist/cjs/global-account/react/hooks/useAuthentication.js +63 -72
  15. package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +0 -3
  16. package/dist/cjs/global-account/react/hooks/useTWAuth.js +0 -8
  17. package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +24 -54
  18. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
  19. package/dist/esm/anyspend/react/components/AnySpend.js +0 -3
  20. package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +1 -1
  21. package/dist/esm/anyspend/react/components/AnySpendCustom.js +0 -3
  22. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +45 -175
  23. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +0 -3
  24. package/dist/esm/anyspend/utils/chain.d.ts +38 -0
  25. package/dist/esm/anyspend/utils/chain.js +22 -1
  26. package/dist/esm/anyspend/utils/token.d.ts +3 -0
  27. package/dist/esm/anyspend/utils/token.js +15 -1
  28. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +12 -57
  29. package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
  30. package/dist/esm/global-account/react/hooks/index.js +0 -1
  31. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
  32. package/dist/esm/global-account/react/hooks/useAuthentication.js +63 -72
  33. package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +0 -3
  34. package/dist/esm/global-account/react/hooks/useTWAuth.js +0 -8
  35. package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +24 -54
  36. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
  37. package/dist/styles/index.css +1 -1
  38. package/dist/types/anyspend/utils/chain.d.ts +38 -0
  39. package/dist/types/anyspend/utils/token.d.ts +3 -0
  40. package/dist/types/global-account/react/hooks/index.d.ts +0 -1
  41. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
  42. package/dist/types/global-account/react/hooks/useTWAuth.d.ts +0 -3
  43. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
  44. package/package.json +1 -1
  45. package/src/anyspend/react/components/AnySpend.tsx +0 -4
  46. package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +1 -1
  47. package/src/anyspend/react/components/AnySpendCustom.tsx +0 -4
  48. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +22 -253
  49. package/src/anyspend/react/hooks/useAnyspendFlow.ts +0 -4
  50. package/src/anyspend/utils/chain.ts +31 -1
  51. package/src/anyspend/utils/token.ts +17 -1
  52. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +22 -77
  53. package/src/global-account/react/hooks/index.ts +0 -1
  54. package/src/global-account/react/hooks/useAuthentication.ts +85 -88
  55. package/src/global-account/react/hooks/useTWAuth.tsx +0 -10
  56. package/src/global-account/react/hooks/useTurnkeyAuth.ts +26 -59
  57. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
  58. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -73
  59. package/dist/cjs/global-account/react/hooks/useAuth.d.ts +0 -76
  60. package/dist/cjs/global-account/react/hooks/useAuth.js +0 -338
  61. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
  62. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -70
  63. package/dist/esm/global-account/react/hooks/useAuth.d.ts +0 -76
  64. package/dist/esm/global-account/react/hooks/useAuth.js +0 -332
  65. package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
  66. package/dist/types/global-account/react/hooks/useAuth.d.ts +0 -76
  67. package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +0 -80
  68. package/src/global-account/react/hooks/useAuth.ts +0 -380
@@ -19,7 +19,7 @@ import { preAuthenticate } from "thirdweb/wallets/in-app";
19
19
  import { useAccount, useConnect, useSwitchAccount } from "wagmi";
20
20
  import { LocalSDKContext } from "../components/B3Provider/LocalSDKProvider";
21
21
  import { createWagmiConfig } from "../utils/createWagmiConfig";
22
- import { useAuth } from "./useAuth";
22
+ import { useTWAuth } from "./useTWAuth";
23
23
  import { useUserQuery } from "./useUserQuery";
24
24
 
25
25
  const debug = debugB3React("useAuthentication");
@@ -39,7 +39,7 @@ export function useAuthentication(partnerId: string) {
39
39
  const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
40
40
  const setActiveWallet = useSetActiveWallet();
41
41
  const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
42
- const { reAuthenticate } = useAuth();
42
+ const { authenticate } = useTWAuth();
43
43
  const { user, setUser } = useUserQuery();
44
44
  const useAutoConnectLoadingPrevious = useRef(false);
45
45
  const wagmiConfig = createWagmiConfig({ partnerId });
@@ -106,104 +106,49 @@ export function useAuthentication(partnerId: string) {
106
106
  syncWagmi();
107
107
  }, [wallets, syncWagmi]);
108
108
 
109
- /**
110
- * Authenticate user using Turnkey
111
- * Note: This no longer requires a wallet for authentication.
112
- * Wallets are still used for signing transactions, but authentication is done via Turnkey email OTP.
113
- *
114
- * For backward compatibility, this function still accepts a wallet parameter,
115
- * but it's not used for authentication anymore.
116
- */
117
- const authenticateUser = useCallback(async () => {
118
- setHasStartedConnecting(true);
119
-
120
- // Try to re-authenticate first
121
- try {
122
- const userAuth = await reAuthenticate();
123
- setUser(userAuth.user);
124
- setIsAuthenticated(true);
125
- setIsAuthenticating(false);
126
- debug("Re-authenticated successfully", { userAuth });
127
-
128
- // Authenticate on BSMNT with B3 JWT
129
- const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
130
- debug("@@b3Jwt", b3Jwt);
131
-
132
- return userAuth;
133
- } catch (error) {
134
- // If re-authentication fails, user needs to authenticate via Turnkey
135
- // This should be handled by the Turnkey auth modal/flow
136
- debug("Re-authentication failed. User needs to authenticate via Turnkey.", error);
137
- setIsAuthenticated(false);
138
- setIsAuthenticating(false);
139
- throw new Error("Authentication required. Please authenticate via Turnkey.");
140
- }
141
- }, [reAuthenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
142
-
143
- /**
144
- * Handle wallet connection
145
- * Note: With Turnkey migration, wallet connection is primarily for signing transactions,
146
- * not for authentication. Authentication should be done separately via Turnkey email OTP.
147
- */
148
- const onConnect = useCallback(
149
- async (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => {
150
- debug("@@useAuthentication:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
151
-
152
- const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
109
+ const authenticateUser = useCallback(
110
+ async (wallet?: Wallet) => {
111
+ setHasStartedConnecting(true);
153
112
 
154
113
  if (!wallet) {
155
- throw new Error("No smart wallet found during auto-connect");
114
+ throw new Error("No wallet found during auto-connect");
156
115
  }
157
116
 
158
- debug("@@useAuthentication:onConnect", { wallet });
117
+ const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
118
+ if (!account) {
119
+ throw new Error("No account found during auto-connect");
120
+ }
159
121
 
122
+ // Try to re-authenticate first
160
123
  try {
161
- setHasStartedConnecting(true);
162
- setIsConnected(true);
163
- setIsAuthenticating(true);
164
- await setActiveWallet(wallet);
124
+ const userAuth = await app.reAuthenticate();
125
+ setUser(userAuth.user);
126
+ setIsAuthenticated(true);
127
+ setIsAuthenticating(false);
128
+ debug("Re-authenticated successfully", { userAuth });
165
129
 
166
- // Try to authenticate user (will use re-authenticate if session exists)
167
- // If no session exists, authentication will need to happen via Turnkey flow
168
- try {
169
- const userAuth = await authenticateUser();
130
+ // Authenticate on BSMNT with B3 JWT
131
+ const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
132
+ debug("@@b3Jwt", b3Jwt);
170
133
 
171
- if (userAuth && onConnectCallback) {
172
- await onConnectCallback(wallet, userAuth.accessToken);
173
- }
174
- } catch (authError) {
175
- // Authentication failed - this is expected if user hasn't authenticated via Turnkey yet
176
- // The Turnkey auth modal should handle this
177
- debug("@@useAuthentication:onConnect:authFailed", { authError });
178
- // Don't set isAuthenticated to false here - let the Turnkey flow handle it
179
- }
134
+ return userAuth;
180
135
  } catch (error) {
181
- debug("@@useAuthentication:onConnect:failed", { error });
182
- setIsAuthenticated(false);
183
- setUser(undefined);
184
- } finally {
136
+ // If re-authentication fails, try fresh authentication
137
+ debug("Re-authentication failed, attempting fresh authentication");
138
+ const userAuth = await authenticate(wallet, partnerId);
139
+ setUser(userAuth.user);
140
+ setIsAuthenticated(true);
185
141
  setIsAuthenticating(false);
186
- }
142
+ debug("Fresh authentication successful", { userAuth });
187
143
 
188
- debug({
189
- isAuthenticated,
190
- isAuthenticating,
191
- isConnected,
192
- });
144
+ // Authenticate on BSMNT with B3 JWT
145
+ const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
146
+ debug("@@b3Jwt", b3Jwt);
147
+
148
+ return userAuth;
149
+ }
193
150
  },
194
- [
195
- onConnectCallback,
196
- authenticateUser,
197
- isAuthenticated,
198
- isAuthenticating,
199
- isConnected,
200
- setActiveWallet,
201
- setHasStartedConnecting,
202
- setIsAuthenticated,
203
- setIsAuthenticating,
204
- setIsConnected,
205
- setUser,
206
- ],
151
+ [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting],
207
152
  );
208
153
 
209
154
  const logout = useCallback(
@@ -240,6 +185,58 @@ export function useAuthentication(partnerId: string) {
240
185
  [activeWallet, disconnect, wallets, setIsAuthenticated, setUser, setIsConnected],
241
186
  );
242
187
 
188
+ const onConnect = useCallback(
189
+ async (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => {
190
+ debug("@@useAuthentication:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
191
+ try {
192
+ const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
193
+
194
+ if (!wallet) {
195
+ throw new Error("No smart wallet found during auto-connect");
196
+ }
197
+
198
+ debug("@@useAuthentication:onConnect", { wallet });
199
+ setHasStartedConnecting(true);
200
+ setIsConnected(true);
201
+ setIsAuthenticating(true);
202
+ await setActiveWallet(wallet);
203
+ const userAuth = await authenticateUser(wallet);
204
+
205
+ if (userAuth && onConnectCallback) {
206
+ await onConnectCallback(wallet, userAuth.accessToken);
207
+ }
208
+ } catch (error) {
209
+ debug("@@useAuthentication:onConnect:failed", { error });
210
+ setIsAuthenticated(false);
211
+ setUser(undefined);
212
+
213
+ await logout();
214
+ } finally {
215
+ setIsAuthenticating(false);
216
+ }
217
+
218
+ debug({
219
+ isAuthenticated,
220
+ isAuthenticating,
221
+ isConnected,
222
+ });
223
+ },
224
+ [
225
+ isAuthenticated,
226
+ isAuthenticating,
227
+ isConnected,
228
+ setHasStartedConnecting,
229
+ setIsConnected,
230
+ setIsAuthenticating,
231
+ setActiveWallet,
232
+ authenticateUser,
233
+ onConnectCallback,
234
+ setIsAuthenticated,
235
+ setUser,
236
+ logout,
237
+ ],
238
+ );
239
+
243
240
  const { isLoading: useAutoConnectLoading } = useAutoConnect({
244
241
  client,
245
242
  wallets: [wallet],
@@ -1,20 +1,10 @@
1
- /**
2
- * @deprecated This hook is deprecated. Use useAuth() with Turnkey authentication instead.
3
- * This file is kept for backward compatibility but should not be used in new code.
4
- */
5
1
  import app from "@b3dotfun/sdk/global-account/app";
6
2
  import debug from "@b3dotfun/sdk/shared/utils/debug";
7
3
  import { useCallback } from "react";
8
4
  import { Wallet } from "thirdweb/wallets";
9
5
  import { useSearchParam } from "./useSearchParamsSSR";
10
6
 
11
- /**
12
- * @deprecated Use useAuth() with Turnkey authentication instead
13
- */
14
7
  export function useTWAuth() {
15
- console.warn(
16
- "useTWAuth is deprecated. Please migrate to useAuth() with Turnkey authentication. See useTurnkeyAuth.ts for the new implementation.",
17
- );
18
8
  const referralCode = useSearchParam("referralCode");
19
9
 
20
10
  const authenticate = useCallback(
@@ -1,10 +1,9 @@
1
- import { TurnkeyAuthInitResponse } from "@b3dotfun/b3-api";
2
- import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
3
- import { useCallback, useState } from "react";
4
1
  import app from "../../app";
5
- import { useB3 } from "../components/B3Provider/useB3";
6
2
  import { useAuthStore } from "../stores";
7
- import { useAuth } from "./useAuth";
3
+ import { useCallback, useState } from "react";
4
+ import { useB3 } from "../components/B3Provider/useB3";
5
+ import { TurnkeyAuthInitResponse } from "@b3dotfun/b3-api";
6
+ import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
8
7
 
9
8
  const debug = debugB3React("useTurnkeyAuth");
10
9
 
@@ -33,16 +32,12 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
33
32
  const [error, setError] = useState<string | null>(null);
34
33
  const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
35
34
  const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
36
- const { partnerId } = useB3();
37
- const { authenticate } = useAuth();
35
+ const { user } = useB3();
38
36
 
39
37
  /**
40
38
  * Step 1: Initiate login with email
41
- * - Calls backend turnkey-jwt strategy (init action) to create sub-org (if needed) and send OTP
39
+ * - Calls backend to create sub-org (if needed) and send OTP
42
40
  * - Returns otpId to use in verification step
43
- *
44
- * Note: Uses the turnkey-jwt authentication strategy, not the service directly.
45
- * The turnkey-jwt strategy handles both OTP flow (init/verify) and final authentication.
46
41
  */
47
42
  const initiateLogin = useCallback(
48
43
  async (email: string): Promise<TurnkeyAuthInitResponse> => {
@@ -51,44 +46,20 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
51
46
  setIsAuthenticating(true);
52
47
 
53
48
  try {
49
+ if (!user?.userId) {
50
+ throw new Error("User ID is required to initiate Turnkey login.");
51
+ }
54
52
  debug(`Initiating login for: ${email}`);
55
53
 
56
- // Use authentication service with turnkey-jwt strategy (init action)
57
- // userId is resolved from authentication context on the backend (params.user.userId)
58
- // Backend will get userId from _params.user?.userId if authenticated, or handle unauthenticated case
59
- // So we only need to send email
60
- debug(`Calling app.authenticate with turnkey-jwt strategy (init action)`, { email });
61
-
62
- const response = await app.authenticate({
63
- strategy: "turnkey-jwt",
64
- action: "init",
65
- email,
66
- } as any);
67
-
68
- // The strategy returns the TurnkeyAuthInitResponse directly
69
- const data = response as unknown as TurnkeyAuthInitResponse;
54
+ // Call FeathersJS service to initialize OTP
55
+ const data: TurnkeyAuthInitResponse = await app.service("turnkey-auth").init({ email, userId: user.userId });
70
56
 
71
57
  debug(`OTP initialized successfully. OtpId: ${data.otpId}`);
72
58
 
73
59
  return data;
74
60
  } catch (err: any) {
75
61
  debug("Error initiating login:", err);
76
-
77
- // Provide more detailed error information
78
- let errorMessage = "Failed to send OTP email. Please try again.";
79
-
80
- if (err.message) {
81
- errorMessage = err.message;
82
- } else if (err.name === "TypeError" && err.message?.includes("fetch")) {
83
- errorMessage = "Network error: Unable to reach the server. Please check your connection and try again.";
84
- } else if (err.code === "ECONNREFUSED" || err.code === "ENOTFOUND") {
85
- errorMessage = "Connection error: Unable to reach the server. Please check your internet connection.";
86
- } else if (err.response) {
87
- // FeathersJS error response
88
- errorMessage = err.response.message || err.message || errorMessage;
89
- debug("FeathersJS error response:", err.response);
90
- }
91
-
62
+ const errorMessage = err.message || "Failed to send OTP email. Please try again.";
92
63
  setError(errorMessage);
93
64
  throw err;
94
65
  } finally {
@@ -96,13 +67,13 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
96
67
  setIsAuthenticating(false);
97
68
  }
98
69
  },
99
- [setIsAuthenticating],
70
+ [user, setIsAuthenticating],
100
71
  );
101
72
 
102
73
  /**
103
74
  * Step 2: Verify OTP and authenticate
104
- * - Verifies OTP with backend via turnkey-jwt strategy (verify action)
105
- * - Gets Turnkey session JWT from the verify response
75
+ * - Verifies OTP with backend
76
+ * - Gets Turnkey session JWT
106
77
  * - Authenticates with b3-api using "turnkey-jwt" strategy
107
78
  * - JWT automatically stored in cookies by SDK
108
79
  */
@@ -113,26 +84,22 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
113
84
  setIsAuthenticating(true);
114
85
 
115
86
  try {
116
- debug(`Verifying OTP...`, { otpId });
87
+ debug(`Verifying OTP...`, { userId: user?.userId });
117
88
 
118
- // Step 1: Verify OTP with backend using turnkey-jwt strategy (verify action)
119
- // This returns the Turnkey session JWT
120
- const response = await app.authenticate({
121
- strategy: "turnkey-jwt",
122
- action: "verify",
89
+ // Step 1: Verify OTP and get Turnkey session JWT
90
+ const { turnkeySessionJwt }: TurnkeyVerifyResponse = await app.service("turnkey-auth").verify({
123
91
  otpId,
124
92
  otpCode,
125
- } as any);
126
-
127
- // The strategy returns the TurnkeyAuthVerifyResponse directly
128
- const verifyResult = response as unknown as TurnkeyVerifyResponse;
129
- const { turnkeySessionJwt } = verifyResult;
93
+ });
130
94
 
131
- debug(`OTP verified! Got Turnkey session JWT. Authenticating with b3-api...`);
95
+ debug(`OTP verified! Authenticating with b3-api...`);
132
96
 
133
97
  // Step 2: Authenticate with b3-api using Turnkey JWT
134
- // Use the unified useAuth hook for authentication with "turnkey-jwt" strategy
135
- const authResult = await authenticate(turnkeySessionJwt, partnerId || "");
98
+ // The SDK will automatically store the b3-api JWT in cookies
99
+ const authResult = await app.authenticate({
100
+ strategy: "turnkey-jwt",
101
+ accessToken: turnkeySessionJwt,
102
+ } as any);
136
103
 
137
104
  debug(`Successfully authenticated with b3-api!`, authResult);
138
105
 
@@ -154,7 +121,7 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
154
121
  setIsAuthenticating(false);
155
122
  }
156
123
  },
157
- [partnerId, setIsAuthenticating, setIsAuthenticated, authenticate],
124
+ [user, setIsAuthenticating, setIsAuthenticated],
158
125
  );
159
126
 
160
127
  const clearError = useCallback(() => {
@@ -1,10 +0,0 @@
1
- /**
2
- * Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
3
- *
4
- * This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
5
- * ensuring that when users connect via wagmi, the active wallet is properly set.
6
- *
7
- * Place this hook in components that stay mounted throughout the user flow
8
- * (not in components that unmount during navigation).
9
- */
10
- export declare function useAutoSetActiveWalletFromWagmi(): void;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAutoSetActiveWalletFromWagmi = useAutoSetActiveWalletFromWagmi;
4
- const thirdweb_1 = require("../../../shared/utils/thirdweb");
5
- const react_1 = require("react");
6
- const react_2 = require("thirdweb/react");
7
- const wallets_1 = require("thirdweb/wallets");
8
- const wagmi_1 = require("wagmi");
9
- /**
10
- * Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
11
- *
12
- * This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
13
- * ensuring that when users connect via wagmi, the active wallet is properly set.
14
- *
15
- * Place this hook in components that stay mounted throughout the user flow
16
- * (not in components that unmount during navigation).
17
- */
18
- function useAutoSetActiveWalletFromWagmi() {
19
- const { address: wagmiAddress, connector: wagmiConnector } = (0, wagmi_1.useAccount)();
20
- const setActiveWallet = (0, react_2.useSetActiveWallet)();
21
- const prevWagmiAddress = (0, react_1.useRef)(undefined);
22
- // Map wagmi connector names to thirdweb wallet IDs
23
- const getThirdwebWalletId = (0, react_1.useCallback)((connectorName) => {
24
- const walletMap = {
25
- MetaMask: "io.metamask",
26
- "Coinbase Wallet": "com.coinbase.wallet",
27
- Rainbow: "me.rainbow",
28
- WalletConnect: "walletConnect",
29
- Phantom: "app.phantom",
30
- };
31
- return walletMap[connectorName] || null;
32
- }, []);
33
- // Create thirdweb wallet from wagmi connector
34
- const createThirdwebWalletFromConnector = (0, react_1.useCallback)(async (connectorName) => {
35
- const walletId = getThirdwebWalletId(connectorName);
36
- if (!walletId) {
37
- console.warn(`No thirdweb wallet ID found for connector: ${connectorName}`);
38
- return null;
39
- }
40
- try {
41
- const thirdwebWallet = (0, wallets_1.createWallet)(walletId);
42
- await thirdwebWallet.connect({ client: thirdweb_1.client });
43
- return thirdwebWallet;
44
- }
45
- catch (error) {
46
- console.error(`Failed to create thirdweb wallet for ${connectorName}:`, error);
47
- return null;
48
- }
49
- }, [getThirdwebWalletId]);
50
- // Listen for wagmi wallet connections and automatically set active wallet
51
- (0, react_1.useEffect)(() => {
52
- const isNewConnection = wagmiAddress && wagmiAddress !== prevWagmiAddress.current;
53
- if (isNewConnection && wagmiConnector?.name) {
54
- prevWagmiAddress.current = wagmiAddress;
55
- const setupThirdwebWallet = async () => {
56
- try {
57
- const thirdwebWallet = await createThirdwebWalletFromConnector(wagmiConnector.name);
58
- if (thirdwebWallet) {
59
- setActiveWallet(thirdwebWallet);
60
- console.log(`Auto-set active wallet for ${wagmiConnector.name}`);
61
- }
62
- }
63
- catch (error) {
64
- console.error("Failed to auto-set active wallet:", error);
65
- }
66
- };
67
- setupThirdwebWallet();
68
- }
69
- if (!wagmiAddress) {
70
- prevWagmiAddress.current = undefined;
71
- }
72
- }, [wagmiAddress, wagmiConnector?.name, setActiveWallet, createThirdwebWalletFromConnector]);
73
- }
@@ -1,76 +0,0 @@
1
- import { Wallet } from "thirdweb/wallets";
2
- import { preAuthenticate } from "thirdweb/wallets/in-app";
3
- /**
4
- * Unified authentication hook that uses Turnkey for authentication
5
- * This replaces the previous Thirdweb-based authentication
6
- *
7
- * This hook provides 1:1 feature parity with useAuthentication.ts
8
- */
9
- export declare function useAuth(): {
10
- authenticate: (turnkeySessionJwt: string, partnerId: string) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
11
- reAuthenticate: () => Promise<import("@feathersjs/authentication").AuthenticationResult>;
12
- logout: (callback?: () => void) => Promise<void>;
13
- isAuthenticated: boolean;
14
- isReady: boolean;
15
- isConnecting: boolean;
16
- isConnected: boolean;
17
- wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
18
- preAuthenticate: typeof preAuthenticate;
19
- connect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
20
- isAuthenticating: boolean;
21
- onConnect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
22
- user: {
23
- email?: string | undefined;
24
- telNumber?: string | undefined;
25
- username?: string | undefined;
26
- ens?: string | undefined;
27
- avatar?: string | undefined;
28
- preferences?: {} | undefined;
29
- referredBy?: string | {} | undefined;
30
- sourceApp?: string | undefined;
31
- referralCode?: string | undefined;
32
- userGroups?: number[] | undefined;
33
- isMigratedFromBSMNT?: boolean | undefined;
34
- privyLinkedAccounts?: {
35
- name?: string | undefined;
36
- address?: string | undefined;
37
- email?: string | undefined;
38
- chain_type?: string | undefined;
39
- lv?: number | undefined;
40
- wallet_client_type?: string | undefined;
41
- smart_wallet_type?: string | undefined;
42
- subject?: string | undefined;
43
- type: string;
44
- }[] | undefined;
45
- twProfiles?: {
46
- type: string;
47
- details: {
48
- id?: string | undefined;
49
- name?: string | undefined;
50
- address?: string | undefined;
51
- email?: string | undefined;
52
- phone?: string | undefined;
53
- username?: string | undefined;
54
- fid?: string | undefined;
55
- };
56
- }[] | undefined;
57
- turnkeySubOrgs?: {
58
- hasDelegatedUser?: boolean | undefined;
59
- subOrgId: string;
60
- accounts: Record<string, any>[];
61
- }[] | undefined;
62
- _id: string | {};
63
- userId: string;
64
- smartAccountAddress: string;
65
- createdAt: number;
66
- updatedAt: number;
67
- partnerIds: {
68
- privyId?: string | undefined;
69
- thirdwebId?: string | undefined;
70
- turnkeyId?: string | undefined;
71
- turnkeyOtpId?: string | undefined;
72
- };
73
- } | undefined;
74
- refetchUser: () => Promise<import("@feathersjs/authentication").AuthenticationResult>;
75
- setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
76
- };