@b3dotfun/sdk 0.1.1 → 0.1.2-test.2
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/global-account/react/components/B3Provider/B3Provider.d.ts +3 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +4 -1
- package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.js +3 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +12 -3
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +3 -0
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +4 -1
- package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.js +3 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -4
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +3 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -1
- package/dist/types/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +4 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +3 -0
- package/package.json +1 -1
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +8 -1
- package/src/global-account/react/components/B3Provider/LocalSDKProvider.tsx +6 -0
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +17 -5
- package/src/global-account/react/stores/useModalStore.ts +3 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
3
|
import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
4
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
@@ -8,7 +9,7 @@ import { ClientType } from "../../../client-manager";
|
|
|
8
9
|
/**
|
|
9
10
|
* Main B3Provider component
|
|
10
11
|
*/
|
|
11
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, enableTurnkey, defaultPermissions, }: {
|
|
12
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, enableTurnkey, defaultPermissions, onTurnkeyConnect, }: {
|
|
12
13
|
theme: "light" | "dark";
|
|
13
14
|
children: React.ReactNode;
|
|
14
15
|
accountOverride?: Account;
|
|
@@ -31,4 +32,5 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
31
32
|
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
32
33
|
enableTurnkey?: boolean;
|
|
33
34
|
defaultPermissions?: PermissionsConfig;
|
|
35
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
34
36
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -26,7 +26,7 @@ const queryClient = new react_query_1.QueryClient();
|
|
|
26
26
|
*/
|
|
27
27
|
function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey,
|
|
28
28
|
// deprecated since v0.0.87
|
|
29
|
-
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId, enableTurnkey = false, defaultPermissions, }) {
|
|
29
|
+
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId, enableTurnkey = false, defaultPermissions, onTurnkeyConnect, }) {
|
|
30
30
|
// Initialize Google Analytics on mount
|
|
31
31
|
(0, react_2.useEffect)(() => {
|
|
32
32
|
(0, analytics_1.loadGA4Script)();
|
|
@@ -36,7 +36,7 @@ toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey
|
|
|
36
36
|
(0, client_manager_1.setClientType)(clientType);
|
|
37
37
|
}, [clientType]);
|
|
38
38
|
const wagmiConfig = (0, react_2.useMemo)(() => (0, createWagmiConfig_1.createWagmiConfig)({ partnerId, rpcUrls, connectors, overrideDefaultConnectors }), [partnerId, rpcUrls, connectors, overrideDefaultConnectors]);
|
|
39
|
-
return ((0, jsx_runtime_1.jsx)(react_3.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(react_1.TooltipProvider, { children: (0, jsx_runtime_1.jsx)(index_1.ToastProvider, { children: (0, jsx_runtime_1.jsx)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout, children: (0, jsx_runtime_1.jsxs)(B3ConfigProvider_1.B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, enableTurnkey: enableTurnkey, defaultPermissions: defaultPermissions, children: [(0, jsx_runtime_1.jsx)(ToastContextConnector, {}), (0, jsx_runtime_1.jsxs)(react_1.RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, (0, jsx_runtime_1.jsx)(StyleRoot_1.StyleRoot, { id: "b3-root" })] }), (0, jsx_runtime_1.jsx)(AuthenticationProvider_1.default, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }) }));
|
|
39
|
+
return ((0, jsx_runtime_1.jsx)(react_3.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(react_1.TooltipProvider, { children: (0, jsx_runtime_1.jsx)(index_1.ToastProvider, { children: (0, jsx_runtime_1.jsx)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout, onTurnkeyConnect: onTurnkeyConnect, children: (0, jsx_runtime_1.jsxs)(B3ConfigProvider_1.B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, enableTurnkey: enableTurnkey, defaultPermissions: defaultPermissions, children: [(0, jsx_runtime_1.jsx)(ToastContextConnector, {}), (0, jsx_runtime_1.jsxs)(react_1.RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, (0, jsx_runtime_1.jsx)(StyleRoot_1.StyleRoot, { id: "b3-root" })] }), (0, jsx_runtime_1.jsx)(AuthenticationProvider_1.default, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }) }));
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Component to connect the toast context to the global toast API
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { Wallet } from "thirdweb/wallets";
|
|
2
3
|
/**
|
|
3
4
|
* Local SDK Context for internal SDK state (like authentication callbacks)
|
|
@@ -6,13 +7,15 @@ import { Wallet } from "thirdweb/wallets";
|
|
|
6
7
|
export interface LocalSDKContextType {
|
|
7
8
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
8
9
|
onLogoutCallback?: () => void | Promise<void>;
|
|
10
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
9
11
|
}
|
|
10
12
|
export declare const LocalSDKContext: import("react").Context<LocalSDKContextType>;
|
|
11
13
|
/**
|
|
12
14
|
* Local SDK Provider that wraps the app and provides internal SDK state
|
|
13
15
|
*/
|
|
14
|
-
export declare function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, }: {
|
|
16
|
+
export declare function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, onTurnkeyConnect, }: {
|
|
15
17
|
children: React.ReactNode;
|
|
16
18
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
17
19
|
onLogoutCallback?: () => void | Promise<void>;
|
|
20
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
18
21
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -7,13 +7,15 @@ const react_1 = require("react");
|
|
|
7
7
|
exports.LocalSDKContext = (0, react_1.createContext)({
|
|
8
8
|
onConnectCallback: undefined,
|
|
9
9
|
onLogoutCallback: undefined,
|
|
10
|
+
onTurnkeyConnect: undefined,
|
|
10
11
|
});
|
|
11
12
|
/**
|
|
12
13
|
* Local SDK Provider that wraps the app and provides internal SDK state
|
|
13
14
|
*/
|
|
14
|
-
function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, }) {
|
|
15
|
+
function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, onTurnkeyConnect, }) {
|
|
15
16
|
return ((0, jsx_runtime_1.jsx)(exports.LocalSDKContext.Provider, { value: {
|
|
16
17
|
onConnectCallback,
|
|
17
18
|
onLogoutCallback,
|
|
19
|
+
onTurnkeyConnect,
|
|
18
20
|
}, children: children }));
|
|
19
21
|
}
|
|
@@ -6,6 +6,7 @@ const react_1 = require("../../../../global-account/react");
|
|
|
6
6
|
const debug_1 = require("../../../../shared/utils/debug");
|
|
7
7
|
const react_2 = require("react");
|
|
8
8
|
const react_3 = require("thirdweb/react");
|
|
9
|
+
const LocalSDKProvider_1 = require("../B3Provider/LocalSDKProvider");
|
|
9
10
|
const TurnkeyAuthModal_1 = require("../TurnkeyAuthModal");
|
|
10
11
|
const SignInWithB3Privy_1 = require("./SignInWithB3Privy");
|
|
11
12
|
const LoginStep_1 = require("./steps/LoginStep");
|
|
@@ -19,6 +20,7 @@ const MAX_REFETCH_ATTEMPTS = 20;
|
|
|
19
20
|
function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, source = "signInWithB3Button", signersEnabled = false, }) {
|
|
20
21
|
const { automaticallySetFirstEoa, enableTurnkey } = (0, react_1.useB3Config)();
|
|
21
22
|
const { user, refetchUser, logout } = (0, react_1.useAuthentication)(partnerId);
|
|
23
|
+
const { onTurnkeyConnect } = (0, react_2.useContext)(LocalSDKProvider_1.LocalSDKContext);
|
|
22
24
|
// FIXME Logout before login to ensure a clean state
|
|
23
25
|
const hasLoggedOutRef = (0, react_2.useRef)(false);
|
|
24
26
|
(0, react_2.useEffect)(() => {
|
|
@@ -135,11 +137,14 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
135
137
|
]);
|
|
136
138
|
// Define handleTurnkeySuccess before the useEffect that uses it
|
|
137
139
|
const handleTurnkeySuccess = (0, react_2.useCallback)(async (user) => {
|
|
138
|
-
debug("Turnkey authentication successful - setting completed flag", { user });
|
|
140
|
+
debug("Turnkey authentication successful - setting completed flag", { user, onTurnkeyConnect });
|
|
141
|
+
// Call the onTurnkeyConnect callback
|
|
142
|
+
onTurnkeyConnect?.(user);
|
|
139
143
|
// Set completed flag FIRST before any async operations
|
|
140
144
|
setTurnkeyAuthCompleted(true);
|
|
141
145
|
// Refetch user to update the user state with Turnkey ID
|
|
142
146
|
debug("Refetching user after Turnkey success...");
|
|
147
|
+
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
143
148
|
await refetchUser();
|
|
144
149
|
debug("User refetched successfully");
|
|
145
150
|
// Set authentication and connection state so UI updates properly
|
|
@@ -163,6 +168,7 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
163
168
|
});
|
|
164
169
|
// The useEffect will re-run with updated user data to complete the sign-in process
|
|
165
170
|
}, [
|
|
171
|
+
onTurnkeyConnect,
|
|
166
172
|
refetchUser,
|
|
167
173
|
strategies,
|
|
168
174
|
onLoginSuccess,
|
|
@@ -338,8 +344,6 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
338
344
|
content = ((0, jsx_runtime_1.jsx)(LoginStep_1.LoginStepContainer, { partnerId: partnerId, children: (0, jsx_runtime_1.jsx)(TurnkeyAuthModal_1.TurnkeyAuthModal, { onSuccess: async (authenticatedUser) => {
|
|
339
345
|
debug("Turnkey authentication successful in primary flow", { authenticatedUser });
|
|
340
346
|
setTurnkeyAuthCompleted(true);
|
|
341
|
-
// After Turnkey auth, refetch user to get the full user object
|
|
342
|
-
await refetchUser();
|
|
343
347
|
// User is now authenticated via Turnkey
|
|
344
348
|
// Set both isAuthenticated and isConnected to true so UI updates properly
|
|
345
349
|
// Wallet connection is optional and can happen later for signing transactions
|
|
@@ -348,6 +352,11 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
348
352
|
setJustCompletedLogin(true);
|
|
349
353
|
// Call the login success callback
|
|
350
354
|
onLoginSuccess?.({});
|
|
355
|
+
// Call the onTurnkeyConnect callback
|
|
356
|
+
onTurnkeyConnect?.(authenticatedUser);
|
|
357
|
+
// After Turnkey auth, refetch user to get the full user object
|
|
358
|
+
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
359
|
+
await refetchUser();
|
|
351
360
|
}, onClose: () => {
|
|
352
361
|
// If user closes Turnkey modal, they can still use wallet connection as fallback
|
|
353
362
|
setTurnkeyAuthCompleted(true);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { components } from "../../../anyspend/types/api";
|
|
2
3
|
import { GenerateSigMintResponse } from "../../../anyspend/types/signatureMint";
|
|
3
4
|
import { AllowedStrategy } from "../../../global-account/react";
|
|
@@ -40,6 +41,8 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
|
|
|
40
41
|
source?: "signInWithB3Button" | "requestPermissions";
|
|
41
42
|
/** Whether to show the signers enabled modal */
|
|
42
43
|
signersEnabled?: boolean;
|
|
44
|
+
/** Callback for turnkey auth */
|
|
45
|
+
onTurnkeyConnect?: (user: Users) => void;
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
48
|
* Props for the Turnkey Authentication modal
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
3
|
import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
4
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
@@ -8,7 +9,7 @@ import { ClientType } from "../../../client-manager";
|
|
|
8
9
|
/**
|
|
9
10
|
* Main B3Provider component
|
|
10
11
|
*/
|
|
11
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, enableTurnkey, defaultPermissions, }: {
|
|
12
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, enableTurnkey, defaultPermissions, onTurnkeyConnect, }: {
|
|
12
13
|
theme: "light" | "dark";
|
|
13
14
|
children: React.ReactNode;
|
|
14
15
|
accountOverride?: Account;
|
|
@@ -31,4 +32,5 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
31
32
|
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
32
33
|
enableTurnkey?: boolean;
|
|
33
34
|
defaultPermissions?: PermissionsConfig;
|
|
35
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
34
36
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -20,7 +20,7 @@ const queryClient = new QueryClient();
|
|
|
20
20
|
*/
|
|
21
21
|
export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey,
|
|
22
22
|
// deprecated since v0.0.87
|
|
23
|
-
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId, enableTurnkey = false, defaultPermissions, }) {
|
|
23
|
+
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId, enableTurnkey = false, defaultPermissions, onTurnkeyConnect, }) {
|
|
24
24
|
// Initialize Google Analytics on mount
|
|
25
25
|
useEffect(() => {
|
|
26
26
|
loadGA4Script();
|
|
@@ -30,7 +30,7 @@ toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey
|
|
|
30
30
|
setClientType(clientType);
|
|
31
31
|
}, [clientType]);
|
|
32
32
|
const wagmiConfig = useMemo(() => createWagmiConfig({ partnerId, rpcUrls, connectors, overrideDefaultConnectors }), [partnerId, rpcUrls, connectors, overrideDefaultConnectors]);
|
|
33
|
-
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(ToastProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout, children: _jsxs(B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, enableTurnkey: enableTurnkey, defaultPermissions: defaultPermissions, children: [_jsx(ToastContextConnector, {}), _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" })] }), _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }) }));
|
|
33
|
+
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(ToastProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout, onTurnkeyConnect: onTurnkeyConnect, children: _jsxs(B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, enableTurnkey: enableTurnkey, defaultPermissions: defaultPermissions, children: [_jsx(ToastContextConnector, {}), _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" })] }), _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }) }));
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Component to connect the toast context to the global toast API
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { Wallet } from "thirdweb/wallets";
|
|
2
3
|
/**
|
|
3
4
|
* Local SDK Context for internal SDK state (like authentication callbacks)
|
|
@@ -6,13 +7,15 @@ import { Wallet } from "thirdweb/wallets";
|
|
|
6
7
|
export interface LocalSDKContextType {
|
|
7
8
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
8
9
|
onLogoutCallback?: () => void | Promise<void>;
|
|
10
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
9
11
|
}
|
|
10
12
|
export declare const LocalSDKContext: import("react").Context<LocalSDKContextType>;
|
|
11
13
|
/**
|
|
12
14
|
* Local SDK Provider that wraps the app and provides internal SDK state
|
|
13
15
|
*/
|
|
14
|
-
export declare function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, }: {
|
|
16
|
+
export declare function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, onTurnkeyConnect, }: {
|
|
15
17
|
children: React.ReactNode;
|
|
16
18
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
17
19
|
onLogoutCallback?: () => void | Promise<void>;
|
|
20
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
18
21
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,13 +3,15 @@ import { createContext } from "react";
|
|
|
3
3
|
export const LocalSDKContext = createContext({
|
|
4
4
|
onConnectCallback: undefined,
|
|
5
5
|
onLogoutCallback: undefined,
|
|
6
|
+
onTurnkeyConnect: undefined,
|
|
6
7
|
});
|
|
7
8
|
/**
|
|
8
9
|
* Local SDK Provider that wraps the app and provides internal SDK state
|
|
9
10
|
*/
|
|
10
|
-
export function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, }) {
|
|
11
|
+
export function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, onTurnkeyConnect, }) {
|
|
11
12
|
return (_jsx(LocalSDKContext.Provider, { value: {
|
|
12
13
|
onConnectCallback,
|
|
13
14
|
onLogoutCallback,
|
|
15
|
+
onTurnkeyConnect,
|
|
14
16
|
}, children: children }));
|
|
15
17
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Loading, useAuthentication, useAuthStore, useB3Config, useGetAllTWSigners, useModalStore, } from "../../../../global-account/react/index.js";
|
|
3
3
|
import { debugB3React } from "../../../../shared/utils/debug.js";
|
|
4
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
5
5
|
import { useActiveAccount } from "thirdweb/react";
|
|
6
|
+
import { LocalSDKContext } from "../B3Provider/LocalSDKProvider.js";
|
|
6
7
|
import { TurnkeyAuthModal } from "../TurnkeyAuthModal.js";
|
|
7
8
|
import { SignInWithB3Privy } from "./SignInWithB3Privy.js";
|
|
8
9
|
import { LoginStep, LoginStepContainer } from "./steps/LoginStep.js";
|
|
@@ -16,6 +17,7 @@ const MAX_REFETCH_ATTEMPTS = 20;
|
|
|
16
17
|
export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, source = "signInWithB3Button", signersEnabled = false, }) {
|
|
17
18
|
const { automaticallySetFirstEoa, enableTurnkey } = useB3Config();
|
|
18
19
|
const { user, refetchUser, logout } = useAuthentication(partnerId);
|
|
20
|
+
const { onTurnkeyConnect } = useContext(LocalSDKContext);
|
|
19
21
|
// FIXME Logout before login to ensure a clean state
|
|
20
22
|
const hasLoggedOutRef = useRef(false);
|
|
21
23
|
useEffect(() => {
|
|
@@ -132,11 +134,14 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
132
134
|
]);
|
|
133
135
|
// Define handleTurnkeySuccess before the useEffect that uses it
|
|
134
136
|
const handleTurnkeySuccess = useCallback(async (user) => {
|
|
135
|
-
debug("Turnkey authentication successful - setting completed flag", { user });
|
|
137
|
+
debug("Turnkey authentication successful - setting completed flag", { user, onTurnkeyConnect });
|
|
138
|
+
// Call the onTurnkeyConnect callback
|
|
139
|
+
onTurnkeyConnect?.(user);
|
|
136
140
|
// Set completed flag FIRST before any async operations
|
|
137
141
|
setTurnkeyAuthCompleted(true);
|
|
138
142
|
// Refetch user to update the user state with Turnkey ID
|
|
139
143
|
debug("Refetching user after Turnkey success...");
|
|
144
|
+
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
140
145
|
await refetchUser();
|
|
141
146
|
debug("User refetched successfully");
|
|
142
147
|
// Set authentication and connection state so UI updates properly
|
|
@@ -160,6 +165,7 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
160
165
|
});
|
|
161
166
|
// The useEffect will re-run with updated user data to complete the sign-in process
|
|
162
167
|
}, [
|
|
168
|
+
onTurnkeyConnect,
|
|
163
169
|
refetchUser,
|
|
164
170
|
strategies,
|
|
165
171
|
onLoginSuccess,
|
|
@@ -335,8 +341,6 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
335
341
|
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx(TurnkeyAuthModal, { onSuccess: async (authenticatedUser) => {
|
|
336
342
|
debug("Turnkey authentication successful in primary flow", { authenticatedUser });
|
|
337
343
|
setTurnkeyAuthCompleted(true);
|
|
338
|
-
// After Turnkey auth, refetch user to get the full user object
|
|
339
|
-
await refetchUser();
|
|
340
344
|
// User is now authenticated via Turnkey
|
|
341
345
|
// Set both isAuthenticated and isConnected to true so UI updates properly
|
|
342
346
|
// Wallet connection is optional and can happen later for signing transactions
|
|
@@ -345,6 +349,11 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
345
349
|
setJustCompletedLogin(true);
|
|
346
350
|
// Call the login success callback
|
|
347
351
|
onLoginSuccess?.({});
|
|
352
|
+
// Call the onTurnkeyConnect callback
|
|
353
|
+
onTurnkeyConnect?.(authenticatedUser);
|
|
354
|
+
// After Turnkey auth, refetch user to get the full user object
|
|
355
|
+
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
356
|
+
await refetchUser();
|
|
348
357
|
}, onClose: () => {
|
|
349
358
|
// If user closes Turnkey modal, they can still use wallet connection as fallback
|
|
350
359
|
setTurnkeyAuthCompleted(true);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { components } from "../../../anyspend/types/api";
|
|
2
3
|
import { GenerateSigMintResponse } from "../../../anyspend/types/signatureMint";
|
|
3
4
|
import { AllowedStrategy } from "../../../global-account/react";
|
|
@@ -40,6 +41,8 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
|
|
|
40
41
|
source?: "signInWithB3Button" | "requestPermissions";
|
|
41
42
|
/** Whether to show the signers enabled modal */
|
|
42
43
|
signersEnabled?: boolean;
|
|
44
|
+
/** Callback for turnkey auth */
|
|
45
|
+
onTurnkeyConnect?: (user: Users) => void;
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
48
|
* Props for the Turnkey Authentication modal
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
3
|
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
4
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
@@ -8,7 +9,7 @@ import { ClientType } from "../../../client-manager";
|
|
|
8
9
|
/**
|
|
9
10
|
* Main B3Provider component
|
|
10
11
|
*/
|
|
11
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, enableTurnkey, defaultPermissions, }: {
|
|
12
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, enableTurnkey, defaultPermissions, onTurnkeyConnect, }: {
|
|
12
13
|
theme: "light" | "dark";
|
|
13
14
|
children: React.ReactNode;
|
|
14
15
|
accountOverride?: Account;
|
|
@@ -31,4 +32,5 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
31
32
|
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
32
33
|
enableTurnkey?: boolean;
|
|
33
34
|
defaultPermissions?: PermissionsConfig;
|
|
35
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
34
36
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { Wallet } from "thirdweb/wallets";
|
|
2
3
|
/**
|
|
3
4
|
* Local SDK Context for internal SDK state (like authentication callbacks)
|
|
@@ -6,13 +7,15 @@ import { Wallet } from "thirdweb/wallets";
|
|
|
6
7
|
export interface LocalSDKContextType {
|
|
7
8
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
8
9
|
onLogoutCallback?: () => void | Promise<void>;
|
|
10
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
9
11
|
}
|
|
10
12
|
export declare const LocalSDKContext: import("react").Context<LocalSDKContextType>;
|
|
11
13
|
/**
|
|
12
14
|
* Local SDK Provider that wraps the app and provides internal SDK state
|
|
13
15
|
*/
|
|
14
|
-
export declare function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, }: {
|
|
16
|
+
export declare function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, onTurnkeyConnect, }: {
|
|
15
17
|
children: React.ReactNode;
|
|
16
18
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
17
19
|
onLogoutCallback?: () => void | Promise<void>;
|
|
20
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
18
21
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
2
3
|
import { GenerateSigMintResponse } from "@b3dotfun/sdk/anyspend/types/signatureMint";
|
|
3
4
|
import { AllowedStrategy } from "@b3dotfun/sdk/global-account/react";
|
|
@@ -40,6 +41,8 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
|
|
|
40
41
|
source?: "signInWithB3Button" | "requestPermissions";
|
|
41
42
|
/** Whether to show the signers enabled modal */
|
|
42
43
|
signersEnabled?: boolean;
|
|
44
|
+
/** Callback for turnkey auth */
|
|
45
|
+
onTurnkeyConnect?: (user: Users) => void;
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
48
|
* Props for the Turnkey Authentication modal
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
3
|
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
4
|
import { RelayKitProviderWrapper, TooltipProvider } from "@b3dotfun/sdk/global-account/react";
|
|
@@ -43,6 +44,7 @@ export function B3Provider({
|
|
|
43
44
|
createClientReferenceId,
|
|
44
45
|
enableTurnkey = false,
|
|
45
46
|
defaultPermissions,
|
|
47
|
+
onTurnkeyConnect,
|
|
46
48
|
}: {
|
|
47
49
|
theme: "light" | "dark";
|
|
48
50
|
children: React.ReactNode;
|
|
@@ -66,6 +68,7 @@ export function B3Provider({
|
|
|
66
68
|
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
67
69
|
enableTurnkey?: boolean;
|
|
68
70
|
defaultPermissions?: PermissionsConfig;
|
|
71
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
69
72
|
}) {
|
|
70
73
|
// Initialize Google Analytics on mount
|
|
71
74
|
useEffect(() => {
|
|
@@ -88,7 +91,11 @@ export function B3Provider({
|
|
|
88
91
|
<QueryClientProvider client={queryClient}>
|
|
89
92
|
<TooltipProvider>
|
|
90
93
|
<ToastProvider>
|
|
91
|
-
<LocalSDKProvider
|
|
94
|
+
<LocalSDKProvider
|
|
95
|
+
onConnectCallback={onConnect}
|
|
96
|
+
onLogoutCallback={onLogout}
|
|
97
|
+
onTurnkeyConnect={onTurnkeyConnect}
|
|
98
|
+
>
|
|
92
99
|
<B3ConfigProvider
|
|
93
100
|
accountOverride={accountOverride}
|
|
94
101
|
environment={environment}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { createContext } from "react";
|
|
2
3
|
import { Wallet } from "thirdweb/wallets";
|
|
3
4
|
|
|
@@ -8,11 +9,13 @@ import { Wallet } from "thirdweb/wallets";
|
|
|
8
9
|
export interface LocalSDKContextType {
|
|
9
10
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
10
11
|
onLogoutCallback?: () => void | Promise<void>;
|
|
12
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export const LocalSDKContext = createContext<LocalSDKContextType>({
|
|
14
16
|
onConnectCallback: undefined,
|
|
15
17
|
onLogoutCallback: undefined,
|
|
18
|
+
onTurnkeyConnect: undefined,
|
|
16
19
|
});
|
|
17
20
|
|
|
18
21
|
/**
|
|
@@ -22,16 +25,19 @@ export function LocalSDKProvider({
|
|
|
22
25
|
children,
|
|
23
26
|
onConnectCallback,
|
|
24
27
|
onLogoutCallback,
|
|
28
|
+
onTurnkeyConnect,
|
|
25
29
|
}: {
|
|
26
30
|
children: React.ReactNode;
|
|
27
31
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
28
32
|
onLogoutCallback?: () => void | Promise<void>;
|
|
33
|
+
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
29
34
|
}) {
|
|
30
35
|
return (
|
|
31
36
|
<LocalSDKContext.Provider
|
|
32
37
|
value={{
|
|
33
38
|
onConnectCallback,
|
|
34
39
|
onLogoutCallback,
|
|
40
|
+
onTurnkeyConnect,
|
|
35
41
|
}}
|
|
36
42
|
>
|
|
37
43
|
{children}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import {
|
|
2
3
|
Loading,
|
|
3
4
|
SignInWithB3ModalProps,
|
|
@@ -8,9 +9,10 @@ import {
|
|
|
8
9
|
useModalStore,
|
|
9
10
|
} from "@b3dotfun/sdk/global-account/react";
|
|
10
11
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
11
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
12
|
+
import { useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
12
13
|
import { useActiveAccount } from "thirdweb/react";
|
|
13
14
|
import { Account } from "thirdweb/wallets";
|
|
15
|
+
import { LocalSDKContext } from "../B3Provider/LocalSDKProvider";
|
|
14
16
|
import { TurnkeyAuthModal } from "../TurnkeyAuthModal";
|
|
15
17
|
import { SignInWithB3Privy } from "./SignInWithB3Privy";
|
|
16
18
|
import { LoginStep, LoginStepContainer } from "./steps/LoginStep";
|
|
@@ -37,6 +39,7 @@ export function SignInWithB3Flow({
|
|
|
37
39
|
}: SignInWithB3ModalProps) {
|
|
38
40
|
const { automaticallySetFirstEoa, enableTurnkey } = useB3Config();
|
|
39
41
|
const { user, refetchUser, logout } = useAuthentication(partnerId);
|
|
42
|
+
const { onTurnkeyConnect } = useContext(LocalSDKContext);
|
|
40
43
|
|
|
41
44
|
// FIXME Logout before login to ensure a clean state
|
|
42
45
|
const hasLoggedOutRef = useRef(false);
|
|
@@ -163,13 +166,17 @@ export function SignInWithB3Flow({
|
|
|
163
166
|
// Define handleTurnkeySuccess before the useEffect that uses it
|
|
164
167
|
const handleTurnkeySuccess = useCallback(
|
|
165
168
|
async (user: any) => {
|
|
166
|
-
debug("Turnkey authentication successful - setting completed flag", { user });
|
|
169
|
+
debug("Turnkey authentication successful - setting completed flag", { user, onTurnkeyConnect });
|
|
170
|
+
|
|
171
|
+
// Call the onTurnkeyConnect callback
|
|
172
|
+
onTurnkeyConnect?.(user);
|
|
167
173
|
|
|
168
174
|
// Set completed flag FIRST before any async operations
|
|
169
175
|
setTurnkeyAuthCompleted(true);
|
|
170
176
|
|
|
171
177
|
// Refetch user to update the user state with Turnkey ID
|
|
172
178
|
debug("Refetching user after Turnkey success...");
|
|
179
|
+
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
173
180
|
await refetchUser();
|
|
174
181
|
debug("User refetched successfully");
|
|
175
182
|
|
|
@@ -196,6 +203,7 @@ export function SignInWithB3Flow({
|
|
|
196
203
|
// The useEffect will re-run with updated user data to complete the sign-in process
|
|
197
204
|
},
|
|
198
205
|
[
|
|
206
|
+
onTurnkeyConnect,
|
|
199
207
|
refetchUser,
|
|
200
208
|
strategies,
|
|
201
209
|
onLoginSuccess,
|
|
@@ -395,11 +403,9 @@ export function SignInWithB3Flow({
|
|
|
395
403
|
content = (
|
|
396
404
|
<LoginStepContainer partnerId={partnerId}>
|
|
397
405
|
<TurnkeyAuthModal
|
|
398
|
-
onSuccess={async (authenticatedUser:
|
|
406
|
+
onSuccess={async (authenticatedUser: Users) => {
|
|
399
407
|
debug("Turnkey authentication successful in primary flow", { authenticatedUser });
|
|
400
408
|
setTurnkeyAuthCompleted(true);
|
|
401
|
-
// After Turnkey auth, refetch user to get the full user object
|
|
402
|
-
await refetchUser();
|
|
403
409
|
// User is now authenticated via Turnkey
|
|
404
410
|
// Set both isAuthenticated and isConnected to true so UI updates properly
|
|
405
411
|
// Wallet connection is optional and can happen later for signing transactions
|
|
@@ -408,6 +414,12 @@ export function SignInWithB3Flow({
|
|
|
408
414
|
setJustCompletedLogin(true);
|
|
409
415
|
// Call the login success callback
|
|
410
416
|
onLoginSuccess?.({} as Account);
|
|
417
|
+
// Call the onTurnkeyConnect callback
|
|
418
|
+
onTurnkeyConnect?.(authenticatedUser);
|
|
419
|
+
|
|
420
|
+
// After Turnkey auth, refetch user to get the full user object
|
|
421
|
+
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
422
|
+
await refetchUser();
|
|
411
423
|
}}
|
|
412
424
|
onClose={() => {
|
|
413
425
|
// If user closes Turnkey modal, they can still use wallet connection as fallback
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
1
2
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
2
3
|
import { GenerateSigMintResponse } from "@b3dotfun/sdk/anyspend/types/signatureMint";
|
|
3
4
|
import { AllowedStrategy } from "@b3dotfun/sdk/global-account/react";
|
|
@@ -43,6 +44,8 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
|
|
|
43
44
|
source?: "signInWithB3Button" | "requestPermissions";
|
|
44
45
|
/** Whether to show the signers enabled modal */
|
|
45
46
|
signersEnabled?: boolean;
|
|
47
|
+
/** Callback for turnkey auth */
|
|
48
|
+
onTurnkeyConnect?: (user: Users) => void;
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
/**
|