@b3dotfun/sdk 0.0.54 → 0.0.55

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 (26) hide show
  1. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  2. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +3 -2
  3. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +3 -2
  4. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +3 -2
  5. package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +16 -0
  6. package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.js +17 -0
  7. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -1
  8. package/dist/cjs/global-account/react/hooks/useAuthentication.js +9 -1
  9. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  10. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +3 -2
  11. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +3 -2
  12. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +3 -2
  13. package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +16 -0
  14. package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.js +13 -0
  15. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -1
  16. package/dist/esm/global-account/react/hooks/useAuthentication.js +10 -2
  17. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  18. package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +3 -2
  19. package/dist/types/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +16 -0
  20. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -1
  21. package/package.json +1 -1
  22. package/src/anyspend/utils/chain.ts +4 -1
  23. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +18 -13
  24. package/src/global-account/react/components/B3Provider/B3Provider.tsx +20 -16
  25. package/src/global-account/react/components/B3Provider/LocalSDKProvider.tsx +35 -0
  26. package/src/global-account/react/hooks/useAuthentication.ts +13 -2
@@ -1,12 +1,12 @@
1
1
  import { PermissionsConfig } from "../../../../global-account/types/permissions";
2
2
  import "@relayprotocol/relay-kit-ui/styles.css";
3
- import { Account } from "thirdweb/wallets";
3
+ import { Account, Wallet } from "thirdweb/wallets";
4
4
  import { ClientType } from "../../../client-manager";
5
5
  import { B3ContextType } from "./types";
6
6
  /**
7
7
  * Main B3Provider component
8
8
  */
9
- export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, }: {
9
+ export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, onConnect, }: {
10
10
  theme: "light" | "dark";
11
11
  children: React.ReactNode;
12
12
  accountOverride?: Account;
@@ -20,6 +20,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
20
20
  clientType?: ClientType;
21
21
  rpcUrls?: Record<number, string>;
22
22
  partnerId: string;
23
+ onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
23
24
  }): import("react/jsx-runtime").JSX.Element;
24
25
  /**
25
26
  * Inner provider component that provides the actual B3Context
@@ -15,6 +15,7 @@ const react_3 = require("thirdweb/react");
15
15
  const wagmi_1 = require("wagmi");
16
16
  const client_manager_1 = require("../../../client-manager");
17
17
  const StyleRoot_1 = require("../StyleRoot");
18
+ const LocalSDKProvider_1 = require("./LocalSDKProvider");
18
19
  const types_1 = require("./types");
19
20
  const debug = (0, debug_1.debugB3React)("B3Provider");
20
21
  /**
@@ -31,7 +32,7 @@ const queryClient = new react_query_1.QueryClient();
31
32
  /**
32
33
  * Main B3Provider component
33
34
  */
34
- function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", rpcUrls, partnerId, }) {
35
+ function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", rpcUrls, partnerId, onConnect, }) {
35
36
  // Initialize Google Analytics on mount
36
37
  (0, react_2.useEffect)(() => {
37
38
  (0, analytics_1.loadGA4Script)();
@@ -41,7 +42,7 @@ function B3Provider({ theme = "light", children, accountOverride, environment, a
41
42
  (0, client_manager_1.setClientType)(clientType);
42
43
  }, [clientType]);
43
44
  const wagmiConfig = (0, useWagmiConfig_1.useWagmiConfig)(partnerId, rpcUrls);
44
- 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)(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, partnerId: partnerId, children: (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)(sonner_1.Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
45
+ 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)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, children: (0, jsx_runtime_1.jsx)(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, partnerId: partnerId, children: (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)(sonner_1.Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }) }));
45
46
  }
46
47
  /**
47
48
  * Inner provider component that provides the actual B3Context
@@ -1,11 +1,11 @@
1
1
  import { PermissionsConfig } from "../../../../global-account/types/permissions";
2
- import { Account } from "thirdweb/wallets";
2
+ import { Account, Wallet } from "thirdweb/wallets";
3
3
  import { ClientType } from "../../../client-manager";
4
4
  import { B3ContextType } from "./types";
5
5
  /**
6
6
  * Main B3Provider component
7
7
  */
8
- export declare function B3Provider({ theme, children, accountOverride, environment, clientType, partnerId, rpcUrls, }: {
8
+ export declare function B3Provider({ theme, children, accountOverride, environment, clientType, partnerId, rpcUrls, onConnect, }: {
9
9
  theme: "light" | "dark";
10
10
  children: React.ReactNode;
11
11
  accountOverride?: Account;
@@ -13,6 +13,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
13
13
  clientType?: ClientType;
14
14
  partnerId: string;
15
15
  rpcUrls?: Record<number, string>;
16
+ onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
16
17
  }): import("react/jsx-runtime").JSX.Element;
17
18
  /**
18
19
  * Inner provider component that provides the actual B3Context
@@ -8,6 +8,7 @@ const react_1 = require("thirdweb/react");
8
8
  const wagmi_1 = require("wagmi");
9
9
  const useAuthentication_1 = require("../../hooks/useAuthentication");
10
10
  const useWagmiConfig_1 = require("../../hooks/useWagmiConfig");
11
+ const LocalSDKProvider_1 = require("./LocalSDKProvider");
11
12
  const types_1 = require("./types");
12
13
  /**
13
14
  * Default permissions configuration for B3 provider
@@ -23,8 +24,8 @@ const queryClient = new react_query_1.QueryClient();
23
24
  /**
24
25
  * Main B3Provider component
25
26
  */
26
- function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", partnerId, rpcUrls, }) {
27
- return ((0, jsx_runtime_1.jsx)(react_1.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, clientType: clientType, partnerId: partnerId, rpcUrls: rpcUrls, children: children }) }));
27
+ function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", partnerId, rpcUrls, onConnect, }) {
28
+ return ((0, jsx_runtime_1.jsx)(react_1.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, children: (0, jsx_runtime_1.jsx)(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, clientType: clientType, partnerId: partnerId, rpcUrls: rpcUrls, children: children }) }) }));
28
29
  }
29
30
  /**
30
31
  * Inner provider component that provides the actual B3Context
@@ -0,0 +1,16 @@
1
+ import { Wallet } from "thirdweb/wallets";
2
+ /**
3
+ * Local SDK Context for internal SDK state (like authentication callbacks)
4
+ * This context is separate from B3Context and is available before B3Context.Provider is instantiated
5
+ */
6
+ export interface LocalSDKContextType {
7
+ onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
8
+ }
9
+ export declare const LocalSDKContext: import("react").Context<LocalSDKContextType>;
10
+ /**
11
+ * Local SDK Provider that wraps the app and provides internal SDK state
12
+ */
13
+ export declare function LocalSDKProvider({ children, onConnectCallback, }: {
14
+ children: React.ReactNode;
15
+ onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
16
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalSDKContext = void 0;
4
+ exports.LocalSDKProvider = LocalSDKProvider;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ exports.LocalSDKContext = (0, react_1.createContext)({
8
+ onConnectCallback: undefined,
9
+ });
10
+ /**
11
+ * Local SDK Provider that wraps the app and provides internal SDK state
12
+ */
13
+ function LocalSDKProvider({ children, onConnectCallback, }) {
14
+ return ((0, jsx_runtime_1.jsx)(exports.LocalSDKContext.Provider, { value: {
15
+ onConnectCallback,
16
+ }, children: children }));
17
+ }
@@ -56,6 +56,6 @@ export declare function useAuthentication(partnerId: string): {
56
56
  thirdwebId?: string | undefined;
57
57
  };
58
58
  } | undefined;
59
- refetchUser: (wallet?: Wallet) => Promise<void>;
59
+ refetchUser: (wallet?: Wallet) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
60
60
  setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
61
61
  };
@@ -16,11 +16,13 @@ const react_3 = require("thirdweb/react");
16
16
  const wallets_1 = require("thirdweb/wallets");
17
17
  const in_app_1 = require("thirdweb/wallets/in-app");
18
18
  const wagmi_1 = require("wagmi");
19
+ const LocalSDKProvider_1 = require("../components/B3Provider/LocalSDKProvider");
19
20
  const useTWAuth_1 = require("./useTWAuth");
20
21
  const useUserQuery_1 = require("./useUserQuery");
21
22
  const useWagmiConfig_1 = require("./useWagmiConfig");
22
23
  const debug = (0, debug_1.debugB3React)("useAuthentication");
23
24
  function useAuthentication(partnerId) {
25
+ const { onConnectCallback } = (0, react_2.useContext)(LocalSDKProvider_1.LocalSDKContext);
24
26
  const { disconnect } = (0, react_3.useDisconnect)();
25
27
  const wallets = (0, react_3.useConnectedWallets)();
26
28
  const activeWallet = (0, react_3.useActiveWallet)();
@@ -124,6 +126,7 @@ function useAuthentication(partnerId) {
124
126
  // Authenticate on BSMNT with B3 JWT
125
127
  const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
126
128
  debug("@@b3Jwt", b3Jwt);
129
+ return userAuth;
127
130
  }
128
131
  catch (error) {
129
132
  // If re-authentication fails, try fresh authentication
@@ -136,6 +139,7 @@ function useAuthentication(partnerId) {
136
139
  // Authenticate on BSMNT with B3 JWT
137
140
  const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
138
141
  debug("@@b3Jwt", b3Jwt);
142
+ return userAuth;
139
143
  }
140
144
  }, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
141
145
  const onConnect = (0, react_2.useCallback)(async (wallet) => {
@@ -145,7 +149,10 @@ function useAuthentication(partnerId) {
145
149
  setIsConnected(true);
146
150
  setIsAuthenticating(true);
147
151
  await setActiveWallet(wallet);
148
- await authenticateUser(wallet);
152
+ const userAuth = await authenticateUser(wallet);
153
+ if (userAuth && onConnectCallback) {
154
+ await onConnectCallback(wallet, userAuth.accessToken);
155
+ }
149
156
  }
150
157
  catch (error) {
151
158
  debug("@@useAuthentication:onConnect:failed", { error });
@@ -161,6 +168,7 @@ function useAuthentication(partnerId) {
161
168
  isConnected,
162
169
  });
163
170
  }, [
171
+ onConnectCallback,
164
172
  authenticateUser,
165
173
  isAuthenticated,
166
174
  isAuthenticating,
@@ -1,12 +1,12 @@
1
1
  import { PermissionsConfig } from "../../../../global-account/types/permissions";
2
2
  import "@relayprotocol/relay-kit-ui/styles.css";
3
- import { Account } from "thirdweb/wallets";
3
+ import { Account, Wallet } from "thirdweb/wallets";
4
4
  import { ClientType } from "../../../client-manager";
5
5
  import { B3ContextType } from "./types";
6
6
  /**
7
7
  * Main B3Provider component
8
8
  */
9
- export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, }: {
9
+ export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, onConnect, }: {
10
10
  theme: "light" | "dark";
11
11
  children: React.ReactNode;
12
12
  accountOverride?: Account;
@@ -20,6 +20,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
20
20
  clientType?: ClientType;
21
21
  rpcUrls?: Record<number, string>;
22
22
  partnerId: string;
23
+ onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
23
24
  }): import("react/jsx-runtime").JSX.Element;
24
25
  /**
25
26
  * Inner provider component that provides the actual B3Context
@@ -11,6 +11,7 @@ import { getLastAuthProvider, ThirdwebProvider, useActiveAccount, useConnectedWa
11
11
  import { WagmiProvider } from "wagmi";
12
12
  import { setClientType } from "../../../client-manager.js";
13
13
  import { StyleRoot } from "../StyleRoot.js";
14
+ import { LocalSDKProvider } from "./LocalSDKProvider.js";
14
15
  import { B3Context } from "./types.js";
15
16
  const debug = debugB3React("B3Provider");
16
17
  /**
@@ -27,7 +28,7 @@ const queryClient = new QueryClient();
27
28
  /**
28
29
  * Main B3Provider component
29
30
  */
30
- export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", rpcUrls, partnerId, }) {
31
+ export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", rpcUrls, partnerId, onConnect, }) {
31
32
  // Initialize Google Analytics on mount
32
33
  useEffect(() => {
33
34
  loadGA4Script();
@@ -37,7 +38,7 @@ export function B3Provider({ theme = "light", children, accountOverride, environ
37
38
  setClientType(clientType);
38
39
  }, [clientType]);
39
40
  const wagmiConfig = useWagmiConfig(partnerId, rpcUrls);
40
- return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, partnerId: partnerId, children: _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" }), _jsx(Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
41
+ return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, partnerId: partnerId, children: _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" }), _jsx(Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }) }));
41
42
  }
42
43
  /**
43
44
  * Inner provider component that provides the actual B3Context
@@ -1,11 +1,11 @@
1
1
  import { PermissionsConfig } from "../../../../global-account/types/permissions";
2
- import { Account } from "thirdweb/wallets";
2
+ import { Account, Wallet } from "thirdweb/wallets";
3
3
  import { ClientType } from "../../../client-manager";
4
4
  import { B3ContextType } from "./types";
5
5
  /**
6
6
  * Main B3Provider component
7
7
  */
8
- export declare function B3Provider({ theme, children, accountOverride, environment, clientType, partnerId, rpcUrls, }: {
8
+ export declare function B3Provider({ theme, children, accountOverride, environment, clientType, partnerId, rpcUrls, onConnect, }: {
9
9
  theme: "light" | "dark";
10
10
  children: React.ReactNode;
11
11
  accountOverride?: Account;
@@ -13,6 +13,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
13
13
  clientType?: ClientType;
14
14
  partnerId: string;
15
15
  rpcUrls?: Record<number, string>;
16
+ onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
16
17
  }): import("react/jsx-runtime").JSX.Element;
17
18
  /**
18
19
  * Inner provider component that provides the actual B3Context
@@ -4,6 +4,7 @@ import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
4
4
  import { WagmiProvider } from "wagmi";
5
5
  import { useAuthentication } from "../../hooks/useAuthentication.js";
6
6
  import { useWagmiConfig } from "../../hooks/useWagmiConfig.js";
7
+ import { LocalSDKProvider } from "./LocalSDKProvider.js";
7
8
  import { B3Context } from "./types.js";
8
9
  /**
9
10
  * Default permissions configuration for B3 provider
@@ -19,8 +20,8 @@ const queryClient = new QueryClient();
19
20
  /**
20
21
  * Main B3Provider component
21
22
  */
22
- export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", partnerId, rpcUrls, }) {
23
- return (_jsx(ThirdwebProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, clientType: clientType, partnerId: partnerId, rpcUrls: rpcUrls, children: children }) }));
23
+ export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", partnerId, rpcUrls, onConnect, }) {
24
+ return (_jsx(ThirdwebProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, clientType: clientType, partnerId: partnerId, rpcUrls: rpcUrls, children: children }) }) }));
24
25
  }
25
26
  /**
26
27
  * Inner provider component that provides the actual B3Context
@@ -0,0 +1,16 @@
1
+ import { Wallet } from "thirdweb/wallets";
2
+ /**
3
+ * Local SDK Context for internal SDK state (like authentication callbacks)
4
+ * This context is separate from B3Context and is available before B3Context.Provider is instantiated
5
+ */
6
+ export interface LocalSDKContextType {
7
+ onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
8
+ }
9
+ export declare const LocalSDKContext: import("react").Context<LocalSDKContextType>;
10
+ /**
11
+ * Local SDK Provider that wraps the app and provides internal SDK state
12
+ */
13
+ export declare function LocalSDKProvider({ children, onConnectCallback, }: {
14
+ children: React.ReactNode;
15
+ onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
16
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext } from "react";
3
+ export const LocalSDKContext = createContext({
4
+ onConnectCallback: undefined,
5
+ });
6
+ /**
7
+ * Local SDK Provider that wraps the app and provides internal SDK state
8
+ */
9
+ export function LocalSDKProvider({ children, onConnectCallback, }) {
10
+ return (_jsx(LocalSDKContext.Provider, { value: {
11
+ onConnectCallback,
12
+ }, children: children }));
13
+ }
@@ -56,6 +56,6 @@ export declare function useAuthentication(partnerId: string): {
56
56
  thirdwebId?: string | undefined;
57
57
  };
58
58
  } | undefined;
59
- refetchUser: (wallet?: Wallet) => Promise<void>;
59
+ refetchUser: (wallet?: Wallet) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
60
60
  setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
61
61
  };
@@ -5,16 +5,18 @@ import { ecosystemWalletId } from "../../../shared/constants/index.js";
5
5
  import { debugB3React } from "../../../shared/utils/debug.js";
6
6
  import { client } from "../../../shared/utils/thirdweb.js";
7
7
  import { getConnectors } from "@wagmi/core";
8
- import { useCallback, useEffect, useRef } from "react";
8
+ import { useCallback, useContext, useEffect, useRef } from "react";
9
9
  import { useActiveWallet, useAutoConnect, useConnectedWallets, useDisconnect, useSetActiveWallet, } from "thirdweb/react";
10
10
  import { ecosystemWallet } from "thirdweb/wallets";
11
11
  import { preAuthenticate } from "thirdweb/wallets/in-app";
12
12
  import { useAccount, useConnect, useSwitchAccount } from "wagmi";
13
+ import { LocalSDKContext } from "../components/B3Provider/LocalSDKProvider.js";
13
14
  import { useTWAuth } from "./useTWAuth.js";
14
15
  import { useUserQuery } from "./useUserQuery.js";
15
16
  import { useWagmiConfig } from "./useWagmiConfig.js";
16
17
  const debug = debugB3React("useAuthentication");
17
18
  export function useAuthentication(partnerId) {
19
+ const { onConnectCallback } = useContext(LocalSDKContext);
18
20
  const { disconnect } = useDisconnect();
19
21
  const wallets = useConnectedWallets();
20
22
  const activeWallet = useActiveWallet();
@@ -118,6 +120,7 @@ export function useAuthentication(partnerId) {
118
120
  // Authenticate on BSMNT with B3 JWT
119
121
  const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
120
122
  debug("@@b3Jwt", b3Jwt);
123
+ return userAuth;
121
124
  }
122
125
  catch (error) {
123
126
  // If re-authentication fails, try fresh authentication
@@ -130,6 +133,7 @@ export function useAuthentication(partnerId) {
130
133
  // Authenticate on BSMNT with B3 JWT
131
134
  const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
132
135
  debug("@@b3Jwt", b3Jwt);
136
+ return userAuth;
133
137
  }
134
138
  }, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
135
139
  const onConnect = useCallback(async (wallet) => {
@@ -139,7 +143,10 @@ export function useAuthentication(partnerId) {
139
143
  setIsConnected(true);
140
144
  setIsAuthenticating(true);
141
145
  await setActiveWallet(wallet);
142
- await authenticateUser(wallet);
146
+ const userAuth = await authenticateUser(wallet);
147
+ if (userAuth && onConnectCallback) {
148
+ await onConnectCallback(wallet, userAuth.accessToken);
149
+ }
143
150
  }
144
151
  catch (error) {
145
152
  debug("@@useAuthentication:onConnect:failed", { error });
@@ -155,6 +162,7 @@ export function useAuthentication(partnerId) {
155
162
  isConnected,
156
163
  });
157
164
  }, [
165
+ onConnectCallback,
158
166
  authenticateUser,
159
167
  isAuthenticated,
160
168
  isAuthenticating,
@@ -1,12 +1,12 @@
1
1
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
2
2
  import "@relayprotocol/relay-kit-ui/styles.css";
3
- import { Account } from "thirdweb/wallets";
3
+ import { Account, Wallet } from "thirdweb/wallets";
4
4
  import { ClientType } from "../../../client-manager";
5
5
  import { B3ContextType } from "./types";
6
6
  /**
7
7
  * Main B3Provider component
8
8
  */
9
- export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, }: {
9
+ export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, onConnect, }: {
10
10
  theme: "light" | "dark";
11
11
  children: React.ReactNode;
12
12
  accountOverride?: Account;
@@ -20,6 +20,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
20
20
  clientType?: ClientType;
21
21
  rpcUrls?: Record<number, string>;
22
22
  partnerId: string;
23
+ onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
23
24
  }): import("react/jsx-runtime").JSX.Element;
24
25
  /**
25
26
  * Inner provider component that provides the actual B3Context
@@ -1,11 +1,11 @@
1
1
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
2
- import { Account } from "thirdweb/wallets";
2
+ import { Account, Wallet } from "thirdweb/wallets";
3
3
  import { ClientType } from "../../../client-manager";
4
4
  import { B3ContextType } from "./types";
5
5
  /**
6
6
  * Main B3Provider component
7
7
  */
8
- export declare function B3Provider({ theme, children, accountOverride, environment, clientType, partnerId, rpcUrls, }: {
8
+ export declare function B3Provider({ theme, children, accountOverride, environment, clientType, partnerId, rpcUrls, onConnect, }: {
9
9
  theme: "light" | "dark";
10
10
  children: React.ReactNode;
11
11
  accountOverride?: Account;
@@ -13,6 +13,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
13
13
  clientType?: ClientType;
14
14
  partnerId: string;
15
15
  rpcUrls?: Record<number, string>;
16
+ onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
16
17
  }): import("react/jsx-runtime").JSX.Element;
17
18
  /**
18
19
  * Inner provider component that provides the actual B3Context
@@ -0,0 +1,16 @@
1
+ import { Wallet } from "thirdweb/wallets";
2
+ /**
3
+ * Local SDK Context for internal SDK state (like authentication callbacks)
4
+ * This context is separate from B3Context and is available before B3Context.Provider is instantiated
5
+ */
6
+ export interface LocalSDKContextType {
7
+ onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
8
+ }
9
+ export declare const LocalSDKContext: import("react").Context<LocalSDKContextType>;
10
+ /**
11
+ * Local SDK Provider that wraps the app and provides internal SDK state
12
+ */
13
+ export declare function LocalSDKProvider({ children, onConnectCallback, }: {
14
+ children: React.ReactNode;
15
+ onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
16
+ }): import("react/jsx-runtime").JSX.Element;
@@ -56,6 +56,6 @@ export declare function useAuthentication(partnerId: string): {
56
56
  thirdwebId?: string | undefined;
57
57
  };
58
58
  } | undefined;
59
- refetchUser: (wallet?: Wallet) => Promise<void>;
59
+ refetchUser: (wallet?: Wallet) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
60
60
  setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
61
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -144,7 +144,10 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
144
144
  canDepositNative: true,
145
145
  defaultToken: getBnbToken(),
146
146
  nativeToken: getBnbToken(),
147
- viem: getCustomEvmChain(bsc, "https://methodical-divine-flower.bsc.quiknode.pro/9fc7efd3c34cc016cceacc27ee95850629b7cd21/"),
147
+ viem: getCustomEvmChain(
148
+ bsc,
149
+ "https://methodical-divine-flower.bsc.quiknode.pro/9fc7efd3c34cc016cceacc27ee95850629b7cd21/",
150
+ ),
148
151
  pollingInterval: 1000, // 1 second for BSC
149
152
  zapperEnum: "BSC_MAINNET",
150
153
  coingeckoName: "bsc",
@@ -1,13 +1,14 @@
1
1
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
2
2
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3
3
  import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
4
- import { Account } from "thirdweb/wallets";
4
+ import { Account, Wallet } from "thirdweb/wallets";
5
5
 
6
6
  import { ClientType } from "../../../client-manager";
7
7
 
8
8
  import { WagmiProvider } from "wagmi";
9
9
  import { useAuthentication } from "../../hooks/useAuthentication";
10
10
  import { useWagmiConfig } from "../../hooks/useWagmiConfig";
11
+ import { LocalSDKProvider } from "./LocalSDKProvider";
11
12
  import { B3Context, B3ContextType } from "./types";
12
13
 
13
14
  /**
@@ -34,6 +35,7 @@ export function B3Provider({
34
35
  clientType = "socket",
35
36
  partnerId,
36
37
  rpcUrls,
38
+ onConnect,
37
39
  }: {
38
40
  theme: "light" | "dark";
39
41
  children: React.ReactNode;
@@ -42,21 +44,24 @@ export function B3Provider({
42
44
  clientType?: ClientType;
43
45
  partnerId: string;
44
46
  rpcUrls?: Record<number, string>;
47
+ onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
45
48
  }) {
46
49
  return (
47
50
  <ThirdwebProvider>
48
- <InnerProvider
49
- accountOverride={accountOverride}
50
- environment={environment}
51
- theme={theme}
52
- clientType={clientType}
53
- partnerId={partnerId}
54
- rpcUrls={rpcUrls}
55
- >
56
- {/* <RelayKitProviderWrapper> */}
57
- {children}
58
- {/* </RelayKitProviderWrapper> */}
59
- </InnerProvider>
51
+ <LocalSDKProvider onConnectCallback={onConnect}>
52
+ <InnerProvider
53
+ accountOverride={accountOverride}
54
+ environment={environment}
55
+ theme={theme}
56
+ clientType={clientType}
57
+ partnerId={partnerId}
58
+ rpcUrls={rpcUrls}
59
+ >
60
+ {/* <RelayKitProviderWrapper> */}
61
+ {children}
62
+ {/* </RelayKitProviderWrapper> */}
63
+ </InnerProvider>
64
+ </LocalSDKProvider>
60
65
  </ThirdwebProvider>
61
66
  );
62
67
  }
@@ -23,6 +23,7 @@ import { Account, Wallet } from "thirdweb/wallets";
23
23
  import { WagmiProvider } from "wagmi";
24
24
  import { ClientType, setClientType } from "../../../client-manager";
25
25
  import { StyleRoot } from "../StyleRoot";
26
+ import { LocalSDKProvider } from "./LocalSDKProvider";
26
27
  import { B3Context, B3ContextType } from "./types";
27
28
 
28
29
  const debug = debugB3React("B3Provider");
@@ -54,6 +55,7 @@ export function B3Provider({
54
55
  clientType = "rest",
55
56
  rpcUrls,
56
57
  partnerId,
58
+ onConnect,
57
59
  }: {
58
60
  theme: "light" | "dark";
59
61
  children: React.ReactNode;
@@ -68,6 +70,7 @@ export function B3Provider({
68
70
  clientType?: ClientType;
69
71
  rpcUrls?: Record<number, string>;
70
72
  partnerId: string;
73
+ onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
71
74
  }) {
72
75
  // Initialize Google Analytics on mount
73
76
  useEffect(() => {
@@ -85,21 +88,23 @@ export function B3Provider({
85
88
  <WagmiProvider config={wagmiConfig} reconnectOnMount={false}>
86
89
  <QueryClientProvider client={queryClient}>
87
90
  <TooltipProvider>
88
- <InnerProvider
89
- accountOverride={accountOverride}
90
- environment={environment}
91
- theme={theme}
92
- automaticallySetFirstEoa={!!automaticallySetFirstEoa}
93
- clientType={clientType}
94
- partnerId={partnerId}
95
- >
96
- <RelayKitProviderWrapper simDuneApiKey={simDuneApiKey}>
97
- {children}
98
- {/* For the modal https://github.com/b3-fun/b3/blob/main/packages/sdk/src/global-account/react/components/ui/dialog.tsx#L46 */}
99
- <StyleRoot id="b3-root" />
100
- <Toaster theme={theme} position={toaster?.position} style={toaster?.style} />
101
- </RelayKitProviderWrapper>
102
- </InnerProvider>
91
+ <LocalSDKProvider onConnectCallback={onConnect}>
92
+ <InnerProvider
93
+ accountOverride={accountOverride}
94
+ environment={environment}
95
+ theme={theme}
96
+ automaticallySetFirstEoa={!!automaticallySetFirstEoa}
97
+ clientType={clientType}
98
+ partnerId={partnerId}
99
+ >
100
+ <RelayKitProviderWrapper simDuneApiKey={simDuneApiKey}>
101
+ {children}
102
+ {/* For the modal https://github.com/b3-fun/b3/blob/main/packages/sdk/src/global-account/react/components/ui/dialog.tsx#L46 */}
103
+ <StyleRoot id="b3-root" />
104
+ <Toaster theme={theme} position={toaster?.position} style={toaster?.style} />
105
+ </RelayKitProviderWrapper>
106
+ </InnerProvider>
107
+ </LocalSDKProvider>
103
108
  </TooltipProvider>
104
109
  </QueryClientProvider>
105
110
  </WagmiProvider>
@@ -136,7 +141,6 @@ export function InnerProvider({
136
141
  const isConnected = useAuthStore(state => state.isConnected);
137
142
  const setActiveWallet = useSetActiveWallet();
138
143
  const { user, setUser, refetchUser } = useAuthentication(partnerId);
139
-
140
144
  debug("@@B3Provider:isConnected", isConnected);
141
145
  debug("@@wallets", wallets);
142
146
  debug("@@B3Provider:user", user);
@@ -0,0 +1,35 @@
1
+ import { createContext } from "react";
2
+ import { Wallet } from "thirdweb/wallets";
3
+
4
+ /**
5
+ * Local SDK Context for internal SDK state (like authentication callbacks)
6
+ * This context is separate from B3Context and is available before B3Context.Provider is instantiated
7
+ */
8
+ export interface LocalSDKContextType {
9
+ onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
10
+ }
11
+
12
+ export const LocalSDKContext = createContext<LocalSDKContextType>({
13
+ onConnectCallback: undefined,
14
+ });
15
+
16
+ /**
17
+ * Local SDK Provider that wraps the app and provides internal SDK state
18
+ */
19
+ export function LocalSDKProvider({
20
+ children,
21
+ onConnectCallback,
22
+ }: {
23
+ children: React.ReactNode;
24
+ onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
25
+ }) {
26
+ return (
27
+ <LocalSDKContext.Provider
28
+ value={{
29
+ onConnectCallback,
30
+ }}
31
+ >
32
+ {children}
33
+ </LocalSDKContext.Provider>
34
+ );
35
+ }
@@ -6,7 +6,7 @@ import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
6
6
  import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
7
7
  import { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
8
8
  import { getConnectors } from "@wagmi/core";
9
- import { useCallback, useEffect, useRef } from "react";
9
+ import { useCallback, useContext, useEffect, useRef } from "react";
10
10
  import {
11
11
  useActiveWallet,
12
12
  useAutoConnect,
@@ -17,6 +17,7 @@ import {
17
17
  import { Wallet, ecosystemWallet } from "thirdweb/wallets";
18
18
  import { preAuthenticate } from "thirdweb/wallets/in-app";
19
19
  import { useAccount, useConnect, useSwitchAccount } from "wagmi";
20
+ import { LocalSDKContext } from "../components/B3Provider/LocalSDKProvider";
20
21
  import { useTWAuth } from "./useTWAuth";
21
22
  import { useUserQuery } from "./useUserQuery";
22
23
  import { useWagmiConfig } from "./useWagmiConfig";
@@ -24,6 +25,7 @@ import { useWagmiConfig } from "./useWagmiConfig";
24
25
  const debug = debugB3React("useAuthentication");
25
26
 
26
27
  export function useAuthentication(partnerId: string) {
28
+ const { onConnectCallback } = useContext(LocalSDKContext);
27
29
  const { disconnect } = useDisconnect();
28
30
  const wallets = useConnectedWallets();
29
31
  const activeWallet = useActiveWallet();
@@ -140,6 +142,8 @@ export function useAuthentication(partnerId: string) {
140
142
  // Authenticate on BSMNT with B3 JWT
141
143
  const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
142
144
  debug("@@b3Jwt", b3Jwt);
145
+
146
+ return userAuth;
143
147
  } catch (error) {
144
148
  // If re-authentication fails, try fresh authentication
145
149
  debug("Re-authentication failed, attempting fresh authentication");
@@ -152,6 +156,8 @@ export function useAuthentication(partnerId: string) {
152
156
  // Authenticate on BSMNT with B3 JWT
153
157
  const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
154
158
  debug("@@b3Jwt", b3Jwt);
159
+
160
+ return userAuth;
155
161
  }
156
162
  },
157
163
  [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting],
@@ -166,7 +172,11 @@ export function useAuthentication(partnerId: string) {
166
172
  setIsConnected(true);
167
173
  setIsAuthenticating(true);
168
174
  await setActiveWallet(wallet);
169
- await authenticateUser(wallet);
175
+ const userAuth = await authenticateUser(wallet);
176
+
177
+ if (userAuth && onConnectCallback) {
178
+ await onConnectCallback(wallet, userAuth.accessToken);
179
+ }
170
180
  } catch (error) {
171
181
  debug("@@useAuthentication:onConnect:failed", { error });
172
182
  setIsAuthenticated(false);
@@ -182,6 +192,7 @@ export function useAuthentication(partnerId: string) {
182
192
  });
183
193
  },
184
194
  [
195
+ onConnectCallback,
185
196
  authenticateUser,
186
197
  isAuthenticated,
187
198
  isAuthenticating,