@b3dotfun/sdk 0.0.83-test.0 → 0.0.84-alpha.0
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.
- package/dist/cjs/anyspend/constants/index.d.ts +1 -1
- package/dist/cjs/anyspend/constants/index.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpend.js +21 -12
- package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -6
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +2 -4
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +47 -177
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +28 -0
- package/dist/cjs/anyspend/react/components/common/InsufficientDepositPayment.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +5 -4
- package/dist/cjs/anyspend/react/components/common/OrderToken.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmountFiat.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmountNew.js +2 -2
- package/dist/cjs/anyspend/react/components/common/PaymentStripeWeb2.js +4 -6
- package/dist/cjs/anyspend/react/components/common/PaymentVendorUI.js +41 -2
- package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.js +1 -1
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +2 -3
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +0 -3
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.js +5 -8
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.js +133 -0
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +1 -13
- package/dist/cjs/anyspend/types/chain.d.ts +10 -2
- package/dist/cjs/anyspend/types/chain.js +1 -0
- package/dist/cjs/anyspend/utils/address.d.ts +11 -0
- package/dist/cjs/anyspend/utils/address.js +15 -0
- package/dist/cjs/anyspend/utils/chain.d.ts +58 -1
- package/dist/cjs/anyspend/utils/chain.js +94 -4
- package/dist/cjs/anyspend/utils/token.d.ts +4 -0
- package/dist/cjs/anyspend/utils/token.js +35 -6
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +3 -4
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +12 -57
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/cjs/global-account/react/hooks/index.d.ts +0 -2
- package/dist/cjs/global-account/react/hooks/index.js +1 -5
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +63 -72
- package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +0 -3
- package/dist/cjs/global-account/react/hooks/useTWAuth.js +0 -8
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +24 -54
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/cjs/shared/utils/payment.utils.d.ts +1 -0
- package/dist/cjs/shared/utils/payment.utils.js +9 -0
- package/dist/esm/anyspend/constants/index.d.ts +1 -1
- package/dist/esm/anyspend/constants/index.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +22 -13
- package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -7
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +4 -6
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +45 -175
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +25 -0
- package/dist/esm/anyspend/react/components/common/InsufficientDepositPayment.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +6 -5
- package/dist/esm/anyspend/react/components/common/OrderToken.js +3 -3
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderTokenAmountFiat.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderTokenAmountNew.js +3 -3
- package/dist/esm/anyspend/react/components/common/PaymentStripeWeb2.js +2 -4
- package/dist/esm/anyspend/react/components/common/PaymentVendorUI.js +9 -3
- package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.js +2 -2
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +3 -4
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +0 -3
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.js +6 -9
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.js +127 -0
- package/dist/esm/anyspend/react/providers/AnyspendProvider.js +1 -13
- package/dist/esm/anyspend/types/chain.d.ts +10 -2
- package/dist/esm/anyspend/types/chain.js +1 -0
- package/dist/esm/anyspend/utils/address.d.ts +11 -0
- package/dist/esm/anyspend/utils/address.js +14 -0
- package/dist/esm/anyspend/utils/chain.d.ts +58 -1
- package/dist/esm/anyspend/utils/chain.js +91 -4
- package/dist/esm/anyspend/utils/token.d.ts +4 -0
- package/dist/esm/anyspend/utils/token.js +32 -6
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +4 -5
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +12 -57
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +0 -2
- package/dist/esm/global-account/react/hooks/index.js +0 -2
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +63 -72
- package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +0 -3
- package/dist/esm/global-account/react/hooks/useTWAuth.js +0 -8
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +24 -54
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/esm/shared/utils/payment.utils.d.ts +1 -0
- package/dist/esm/shared/utils/payment.utils.js +9 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/constants/index.d.ts +1 -1
- package/dist/types/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/types/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/types/anyspend/types/chain.d.ts +10 -2
- package/dist/types/anyspend/utils/address.d.ts +11 -0
- package/dist/types/anyspend/utils/chain.d.ts +58 -1
- package/dist/types/anyspend/utils/token.d.ts +4 -0
- package/dist/types/global-account/react/hooks/index.d.ts +0 -2
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/types/global-account/react/hooks/useTWAuth.d.ts +0 -3
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/types/shared/utils/payment.utils.d.ts +1 -0
- package/package.json +1 -1
- package/src/anyspend/constants/index.ts +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +31 -13
- package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +1 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +9 -29
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +7 -30
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +22 -253
- package/src/anyspend/react/components/common/CryptoPaymentMethodDisplay.tsx +64 -0
- package/src/anyspend/react/components/common/InsufficientDepositPayment.tsx +2 -2
- package/src/anyspend/react/components/common/OrderDetails.tsx +6 -5
- package/src/anyspend/react/components/common/OrderToken.tsx +5 -5
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +3 -3
- package/src/anyspend/react/components/common/OrderTokenAmountFiat.tsx +3 -3
- package/src/anyspend/react/components/common/OrderTokenAmountNew.tsx +6 -6
- package/src/anyspend/react/components/common/PaymentStripeWeb2.tsx +3 -5
- package/src/anyspend/react/components/common/PaymentVendorUI.tsx +26 -2
- package/src/anyspend/react/components/common/TransferCryptoDetails.tsx +2 -2
- package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +3 -5
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +0 -4
- package/src/anyspend/react/hooks/useConnectedUserProfile.ts +7 -10
- package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +2 -15
- package/src/anyspend/react/hooks/useHyperliquidTransfer.ts +152 -0
- package/src/anyspend/react/providers/AnyspendProvider.tsx +7 -22
- package/src/anyspend/types/chain.ts +10 -1
- package/src/anyspend/utils/address.ts +15 -0
- package/src/anyspend/utils/chain.ts +115 -5
- package/src/anyspend/utils/token.ts +36 -7
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +6 -2
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +4 -6
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +22 -77
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +1 -1
- package/src/global-account/react/hooks/index.ts +0 -2
- package/src/global-account/react/hooks/useAccountWallet.tsx +12 -11
- package/src/global-account/react/hooks/useAuthentication.ts +85 -88
- package/src/global-account/react/hooks/useTWAuth.tsx +0 -10
- package/src/global-account/react/hooks/useTurnkeyAuth.ts +26 -59
- package/src/shared/utils/payment.utils.ts +10 -1
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -73
- package/dist/cjs/global-account/react/hooks/useAuth.d.ts +0 -76
- package/dist/cjs/global-account/react/hooks/useAuth.js +0 -338
- package/dist/cjs/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/dist/cjs/global-account/react/hooks/useBestTransactionPath.js +0 -148
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -70
- package/dist/esm/global-account/react/hooks/useAuth.d.ts +0 -76
- package/dist/esm/global-account/react/hooks/useAuth.js +0 -332
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +0 -145
- package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/types/global-account/react/hooks/useAuth.d.ts +0 -76
- package/dist/types/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +0 -80
- package/src/global-account/react/hooks/useAuth.ts +0 -380
- package/src/global-account/react/hooks/useBestTransactionPath.tsx +0 -201
|
@@ -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 {
|
|
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 {
|
|
37
|
-
const { authenticate } = useAuth();
|
|
35
|
+
const { user } = useB3();
|
|
38
36
|
|
|
39
37
|
/**
|
|
40
38
|
* Step 1: Initiate login with email
|
|
41
|
-
* - Calls backend
|
|
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
|
-
//
|
|
57
|
-
|
|
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
|
|
105
|
-
* - Gets Turnkey session JWT
|
|
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...`, {
|
|
87
|
+
debug(`Verifying OTP...`, { userId: user?.userId });
|
|
117
88
|
|
|
118
|
-
// Step 1: Verify OTP
|
|
119
|
-
|
|
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
|
-
}
|
|
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!
|
|
95
|
+
debug(`OTP verified! Authenticating with b3-api...`);
|
|
132
96
|
|
|
133
97
|
// Step 2: Authenticate with b3-api using Turnkey JWT
|
|
134
|
-
//
|
|
135
|
-
const authResult = await authenticate(
|
|
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
|
-
[
|
|
124
|
+
[user, setIsAuthenticating, setIsAuthenticated],
|
|
158
125
|
);
|
|
159
126
|
|
|
160
127
|
const clearError = useCallback(() => {
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { VENDOR_DISPLAY_NAMES } from "@b3dotfun/sdk/anyspend/constants";
|
|
1
|
+
import { STRIPE_CONFIG, VENDOR_DISPLAY_NAMES } from "@b3dotfun/sdk/anyspend/constants";
|
|
2
2
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
3
|
+
import { loadStripe } from "@stripe/stripe-js";
|
|
4
|
+
|
|
5
|
+
let stripePromise: ReturnType<typeof loadStripe> | null = null;
|
|
6
|
+
export function getStripePromise() {
|
|
7
|
+
if (!stripePromise) {
|
|
8
|
+
stripePromise = loadStripe(STRIPE_CONFIG.publishableKey);
|
|
9
|
+
}
|
|
10
|
+
return stripePromise;
|
|
11
|
+
}
|
|
3
12
|
|
|
4
13
|
export function getVendorDisplayName(vendor?: components["schemas"]["OnrampMetadata"]["vendor"]): string {
|
|
5
14
|
switch (vendor) {
|
|
@@ -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
|
-
};
|
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useAuth = useAuth;
|
|
7
|
-
const app_1 = __importDefault(require("../../../global-account/app"));
|
|
8
|
-
const bsmnt_1 = require("../../../global-account/bsmnt");
|
|
9
|
-
const react_1 = require("../../../global-account/react");
|
|
10
|
-
const constants_1 = require("../../../shared/constants");
|
|
11
|
-
const debug_1 = require("../../../shared/utils/debug");
|
|
12
|
-
const thirdweb_1 = require("../../../shared/utils/thirdweb");
|
|
13
|
-
const core_1 = require("@wagmi/core");
|
|
14
|
-
const react_2 = require("react");
|
|
15
|
-
const react_3 = require("thirdweb/react");
|
|
16
|
-
const wallets_1 = require("thirdweb/wallets");
|
|
17
|
-
const in_app_1 = require("thirdweb/wallets/in-app");
|
|
18
|
-
const wagmi_1 = require("wagmi");
|
|
19
|
-
const LocalSDKProvider_1 = require("../components/B3Provider/LocalSDKProvider");
|
|
20
|
-
const useB3_1 = require("../components/B3Provider/useB3");
|
|
21
|
-
const createWagmiConfig_1 = require("../utils/createWagmiConfig");
|
|
22
|
-
const useSearchParamsSSR_1 = require("./useSearchParamsSSR");
|
|
23
|
-
const useUserQuery_1 = require("./useUserQuery");
|
|
24
|
-
const debug = (0, debug_1.debugB3React)("useAuth");
|
|
25
|
-
/**
|
|
26
|
-
* Unified authentication hook that uses Turnkey for authentication
|
|
27
|
-
* This replaces the previous Thirdweb-based authentication
|
|
28
|
-
*
|
|
29
|
-
* This hook provides 1:1 feature parity with useAuthentication.ts
|
|
30
|
-
*/
|
|
31
|
-
function useAuth() {
|
|
32
|
-
const { onConnectCallback } = (0, react_2.useContext)(LocalSDKProvider_1.LocalSDKContext);
|
|
33
|
-
const { disconnect } = (0, react_3.useDisconnect)();
|
|
34
|
-
const wallets = (0, react_3.useConnectedWallets)();
|
|
35
|
-
const activeWallet = (0, react_3.useActiveWallet)();
|
|
36
|
-
const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
|
|
37
|
-
const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
|
|
38
|
-
const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
|
|
39
|
-
const isConnecting = (0, react_1.useAuthStore)(state => state.isConnecting);
|
|
40
|
-
const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
|
|
41
|
-
const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
|
|
42
|
-
const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
43
|
-
const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
|
|
44
|
-
const setActiveWallet = (0, react_3.useSetActiveWallet)();
|
|
45
|
-
const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
|
|
46
|
-
const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
|
|
47
|
-
const referralCode = (0, useSearchParamsSSR_1.useSearchParam)("referralCode");
|
|
48
|
-
const { partnerId } = (0, useB3_1.useB3)();
|
|
49
|
-
const wagmiConfig = (0, createWagmiConfig_1.createWagmiConfig)({ partnerId });
|
|
50
|
-
const { connect } = (0, wagmi_1.useConnect)();
|
|
51
|
-
const activeWagmiAccount = (0, wagmi_1.useAccount)();
|
|
52
|
-
const { switchAccount } = (0, wagmi_1.useSwitchAccount)();
|
|
53
|
-
const { user, setUser } = (0, useUserQuery_1.useUserQuery)();
|
|
54
|
-
debug("@@activeWagmiAccount", activeWagmiAccount);
|
|
55
|
-
const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
|
|
56
|
-
partnerId: partnerId,
|
|
57
|
-
});
|
|
58
|
-
/**
|
|
59
|
-
* Re-authenticate using existing session
|
|
60
|
-
* Also updates user state and authenticates with BSMNT
|
|
61
|
-
*/
|
|
62
|
-
const reAuthenticate = (0, react_2.useCallback)(async () => {
|
|
63
|
-
debug("Re-authenticating...");
|
|
64
|
-
try {
|
|
65
|
-
const response = await app_1.default.reAuthenticate();
|
|
66
|
-
debug("Re-authentication successful", response);
|
|
67
|
-
// Update user state if user data exists
|
|
68
|
-
if (response.user) {
|
|
69
|
-
setUser(response.user);
|
|
70
|
-
debug("User state updated", response.user);
|
|
71
|
-
}
|
|
72
|
-
// Authenticate with BSMNT
|
|
73
|
-
try {
|
|
74
|
-
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(response.accessToken);
|
|
75
|
-
debug("BSMNT re-authentication successful", b3Jwt);
|
|
76
|
-
}
|
|
77
|
-
catch (bsmntError) {
|
|
78
|
-
// BSMNT authentication failure shouldn't block the main auth flow
|
|
79
|
-
debug("BSMNT re-authentication failed (non-critical)", bsmntError);
|
|
80
|
-
}
|
|
81
|
-
return response;
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
debug("Re-authentication failed", err);
|
|
85
|
-
throw err;
|
|
86
|
-
}
|
|
87
|
-
}, [setUser]);
|
|
88
|
-
const syncWagmi = (0, react_2.useCallback)(async () => {
|
|
89
|
-
function syncWagmiFunc() {
|
|
90
|
-
const connectors = (0, core_1.getConnectors)(wagmiConfig);
|
|
91
|
-
debug("@@syncWagmi", {
|
|
92
|
-
connectors,
|
|
93
|
-
wallets,
|
|
94
|
-
});
|
|
95
|
-
// For each that matchs a TW wallet on wallets, connect to the wagmi connector
|
|
96
|
-
// or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
|
|
97
|
-
connectors.forEach(async (connector) => {
|
|
98
|
-
const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
|
|
99
|
-
// If no TW wallet, do not prompt the user to connect
|
|
100
|
-
if (!twWallet) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
// Metamask will prompt to connect, we can just switch accounts here.
|
|
104
|
-
if (connector.id === "io.metamask") {
|
|
105
|
-
return switchAccount({ connector });
|
|
106
|
-
}
|
|
107
|
-
if (
|
|
108
|
-
// If it's not an in-app wallet or it is the ecosystem wallet, connect
|
|
109
|
-
connector.id !== "in-app-wallet" ||
|
|
110
|
-
(connector.id === "in-app-wallet" && twWallet.id === constants_1.ecosystemWalletId)) {
|
|
111
|
-
try {
|
|
112
|
-
const options = {
|
|
113
|
-
wallet: twWallet, // the connected wallet
|
|
114
|
-
};
|
|
115
|
-
debug("@@syncWagmi:connecting", { twWallet, connector });
|
|
116
|
-
connect({
|
|
117
|
-
connector,
|
|
118
|
-
...options,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
console.error("@@syncWagmi:error", error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
debug("@@syncWagmi:not-connecting", connector);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
syncWagmiFunc();
|
|
131
|
-
// wagmi config shouldn't change
|
|
132
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
133
|
-
}, [partnerId, wallets]);
|
|
134
|
-
(0, react_2.useEffect)(() => {
|
|
135
|
-
syncWagmi();
|
|
136
|
-
}, [wallets, syncWagmi]);
|
|
137
|
-
/**
|
|
138
|
-
* Authenticate user using Turnkey
|
|
139
|
-
* Note: This no longer requires a wallet for authentication.
|
|
140
|
-
* Wallets are still used for signing transactions, but authentication is done via Turnkey email OTP.
|
|
141
|
-
*
|
|
142
|
-
* For backward compatibility, this function still accepts a wallet parameter,
|
|
143
|
-
* but it's not used for authentication anymore.
|
|
144
|
-
*/
|
|
145
|
-
const authenticateUser = (0, react_2.useCallback)(async () => {
|
|
146
|
-
setHasStartedConnecting(true);
|
|
147
|
-
// Try to re-authenticate first
|
|
148
|
-
try {
|
|
149
|
-
const userAuth = await reAuthenticate();
|
|
150
|
-
setUser(userAuth.user);
|
|
151
|
-
setIsAuthenticated(true);
|
|
152
|
-
setIsAuthenticating(false);
|
|
153
|
-
debug("Re-authenticated successfully", { userAuth });
|
|
154
|
-
// Authenticate on BSMNT with B3 JWT
|
|
155
|
-
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
156
|
-
debug("@@b3Jwt", b3Jwt);
|
|
157
|
-
return userAuth;
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
// If re-authentication fails, user needs to authenticate via Turnkey
|
|
161
|
-
// This should be handled by the Turnkey auth modal/flow
|
|
162
|
-
debug("Re-authentication failed. User needs to authenticate via Turnkey.", error);
|
|
163
|
-
setIsAuthenticated(false);
|
|
164
|
-
setIsAuthenticating(false);
|
|
165
|
-
throw new Error("Authentication required. Please authenticate via Turnkey.");
|
|
166
|
-
}
|
|
167
|
-
}, [reAuthenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
|
|
168
|
-
/**
|
|
169
|
-
* Authenticate with Turnkey using email OTP
|
|
170
|
-
* This is the primary authentication method, replacing Thirdweb wallet-based auth
|
|
171
|
-
*
|
|
172
|
-
* This function:
|
|
173
|
-
* 1. Authenticates with FeathersJS (persists session via cookies)
|
|
174
|
-
* 2. Sets user state in the user store (persists to localStorage)
|
|
175
|
-
* 3. Authenticates with BSMNT for basement integration
|
|
176
|
-
*/
|
|
177
|
-
const authenticate = (0, react_2.useCallback)(async (turnkeySessionJwt, partnerId) => {
|
|
178
|
-
if (!turnkeySessionJwt) {
|
|
179
|
-
throw new Error("Turnkey session JWT is required");
|
|
180
|
-
}
|
|
181
|
-
debug("Authenticating with Turnkey JWT", { referralCode, partnerId });
|
|
182
|
-
try {
|
|
183
|
-
// Step 1: Authenticate with FeathersJS (session persisted via cookies)
|
|
184
|
-
const response = await app_1.default.authenticate({
|
|
185
|
-
strategy: "turnkey-jwt",
|
|
186
|
-
accessToken: turnkeySessionJwt,
|
|
187
|
-
referralCode,
|
|
188
|
-
partnerId: partnerId,
|
|
189
|
-
});
|
|
190
|
-
debug("Authentication successful", response);
|
|
191
|
-
// Step 2: Set user state (persists to localStorage via Zustand)
|
|
192
|
-
if (response.user) {
|
|
193
|
-
setUser(response.user);
|
|
194
|
-
debug("User state updated", response.user);
|
|
195
|
-
}
|
|
196
|
-
// Step 3: Authenticate with BSMNT for basement integration
|
|
197
|
-
try {
|
|
198
|
-
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(response.accessToken);
|
|
199
|
-
debug("BSMNT authentication successful", b3Jwt);
|
|
200
|
-
}
|
|
201
|
-
catch (bsmntError) {
|
|
202
|
-
// BSMNT authentication failure shouldn't block the main auth flow
|
|
203
|
-
debug("BSMNT authentication failed (non-critical)", bsmntError);
|
|
204
|
-
}
|
|
205
|
-
return response;
|
|
206
|
-
}
|
|
207
|
-
catch (err) {
|
|
208
|
-
debug("Authentication failed", err);
|
|
209
|
-
throw err;
|
|
210
|
-
}
|
|
211
|
-
}, [referralCode, setUser]);
|
|
212
|
-
/**
|
|
213
|
-
* Handle wallet connection
|
|
214
|
-
* Note: With Turnkey migration, wallet connection is primarily for signing transactions,
|
|
215
|
-
* not for authentication. Authentication should be done separately via Turnkey email OTP.
|
|
216
|
-
*/
|
|
217
|
-
/**
|
|
218
|
-
* Handle wallet connection
|
|
219
|
-
* Note: With Turnkey migration, wallet connection is primarily for signing transactions,
|
|
220
|
-
* not for authentication. Authentication should be done separately via Turnkey email OTP.
|
|
221
|
-
*/
|
|
222
|
-
const onConnect = (0, react_2.useCallback)(async (_walleAutoConnectedWith, allConnectedWallets) => {
|
|
223
|
-
debug("@@useAuth:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
|
|
224
|
-
const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
|
|
225
|
-
if (!wallet) {
|
|
226
|
-
throw new Error("No smart wallet found during auto-connect");
|
|
227
|
-
}
|
|
228
|
-
debug("@@useAuth:onConnect", { wallet });
|
|
229
|
-
try {
|
|
230
|
-
setHasStartedConnecting(true);
|
|
231
|
-
setIsConnected(true);
|
|
232
|
-
setIsAuthenticating(true);
|
|
233
|
-
await setActiveWallet(wallet);
|
|
234
|
-
// Try to authenticate user (will use re-authenticate if session exists)
|
|
235
|
-
// If no session exists, authentication will need to happen via Turnkey flow
|
|
236
|
-
try {
|
|
237
|
-
const userAuth = await authenticateUser();
|
|
238
|
-
if (userAuth && onConnectCallback) {
|
|
239
|
-
await onConnectCallback(wallet, userAuth.accessToken);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
catch (authError) {
|
|
243
|
-
// Authentication failed - this is expected if user hasn't authenticated via Turnkey yet
|
|
244
|
-
// The Turnkey auth modal should handle this
|
|
245
|
-
debug("@@useAuth:onConnect:authFailed", { authError });
|
|
246
|
-
// Don't set isAuthenticated to false here - let the Turnkey flow handle it
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
debug("@@useAuth:onConnect:failed", { error });
|
|
251
|
-
setIsAuthenticated(false);
|
|
252
|
-
setUser(undefined);
|
|
253
|
-
}
|
|
254
|
-
finally {
|
|
255
|
-
setIsAuthenticating(false);
|
|
256
|
-
}
|
|
257
|
-
debug({
|
|
258
|
-
isAuthenticated,
|
|
259
|
-
isAuthenticating,
|
|
260
|
-
isConnected,
|
|
261
|
-
});
|
|
262
|
-
}, [
|
|
263
|
-
onConnectCallback,
|
|
264
|
-
authenticateUser,
|
|
265
|
-
isAuthenticated,
|
|
266
|
-
isAuthenticating,
|
|
267
|
-
isConnected,
|
|
268
|
-
setActiveWallet,
|
|
269
|
-
setHasStartedConnecting,
|
|
270
|
-
setIsAuthenticated,
|
|
271
|
-
setIsAuthenticating,
|
|
272
|
-
setIsConnected,
|
|
273
|
-
setUser,
|
|
274
|
-
]);
|
|
275
|
-
const logout = (0, react_2.useCallback)(async (callback) => {
|
|
276
|
-
if (activeWallet) {
|
|
277
|
-
debug("@@logout:activeWallet", activeWallet);
|
|
278
|
-
disconnect(activeWallet);
|
|
279
|
-
debug("@@logout:activeWallet", activeWallet);
|
|
280
|
-
}
|
|
281
|
-
// Log out of each wallet
|
|
282
|
-
wallets.forEach(wallet => {
|
|
283
|
-
console.log("@@logging out", wallet);
|
|
284
|
-
disconnect(wallet);
|
|
285
|
-
});
|
|
286
|
-
// Delete localStorage thirdweb:connected-wallet-ids
|
|
287
|
-
// https://npc-labs.slack.com/archives/C070E6HNG85/p1750185115273099
|
|
288
|
-
if (typeof localStorage !== "undefined") {
|
|
289
|
-
localStorage.removeItem("thirdweb:connected-wallet-ids");
|
|
290
|
-
localStorage.removeItem("wagmi.store");
|
|
291
|
-
localStorage.removeItem("lastAuthProvider");
|
|
292
|
-
localStorage.removeItem("b3-user");
|
|
293
|
-
}
|
|
294
|
-
app_1.default.logout();
|
|
295
|
-
debug("@@logout:loggedOut");
|
|
296
|
-
setIsAuthenticated(false);
|
|
297
|
-
setIsConnected(false);
|
|
298
|
-
setUser();
|
|
299
|
-
callback?.();
|
|
300
|
-
}, [activeWallet, disconnect, wallets, setIsAuthenticated, setUser, setIsConnected]);
|
|
301
|
-
const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
|
|
302
|
-
client: thirdweb_1.client,
|
|
303
|
-
wallets: [wallet],
|
|
304
|
-
onConnect,
|
|
305
|
-
onTimeout: () => {
|
|
306
|
-
logout().catch(error => {
|
|
307
|
-
debug("@@useAuth:logout on timeout failed", { error });
|
|
308
|
-
});
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
/**
|
|
312
|
-
* useAutoConnectLoading starts as false
|
|
313
|
-
*/
|
|
314
|
-
(0, react_2.useEffect)(() => {
|
|
315
|
-
if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
|
|
316
|
-
setIsAuthenticating(false);
|
|
317
|
-
}
|
|
318
|
-
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
319
|
-
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
|
|
320
|
-
const isReady = isAuthenticated && !isAuthenticating;
|
|
321
|
-
return {
|
|
322
|
-
authenticate,
|
|
323
|
-
reAuthenticate,
|
|
324
|
-
logout,
|
|
325
|
-
isAuthenticated,
|
|
326
|
-
isReady,
|
|
327
|
-
isConnecting,
|
|
328
|
-
isConnected,
|
|
329
|
-
wallet,
|
|
330
|
-
preAuthenticate: in_app_1.preAuthenticate,
|
|
331
|
-
connect: onConnect,
|
|
332
|
-
isAuthenticating,
|
|
333
|
-
onConnect,
|
|
334
|
-
user,
|
|
335
|
-
refetchUser: authenticateUser,
|
|
336
|
-
setUser,
|
|
337
|
-
};
|
|
338
|
-
}
|