@b3dotfun/sdk 0.0.47-test.4 → 0.0.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +2 -3
  3. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +64 -15
  4. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +2 -6
  5. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +21 -26
  6. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -2
  7. package/dist/cjs/global-account/react/components/B3Provider/types.js +0 -2
  8. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +2 -1
  9. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  10. package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  11. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  12. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
  13. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  14. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +22 -6
  15. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +2 -1
  16. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +2 -3
  17. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +2 -1
  18. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +45 -10
  19. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +2 -1
  20. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -2
  21. package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +1 -2
  22. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -51
  23. package/dist/cjs/global-account/react/hooks/useAuthentication.js +84 -134
  24. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  25. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +1 -2
  26. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +2 -0
  27. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +2 -3
  28. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +68 -19
  29. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +2 -6
  30. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +19 -24
  31. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -2
  32. package/dist/esm/global-account/react/components/B3Provider/types.js +0 -2
  33. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +2 -1
  34. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  35. package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  36. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  37. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
  38. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  39. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +23 -7
  40. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +2 -1
  41. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -4
  42. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +2 -1
  43. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +46 -11
  44. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +2 -1
  45. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -3
  46. package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +2 -3
  47. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -51
  48. package/dist/esm/global-account/react/hooks/useAuthentication.js +87 -137
  49. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  50. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -3
  51. package/dist/esm/global-account/react/stores/useModalStore.d.ts +2 -0
  52. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +2 -3
  53. package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +2 -6
  54. package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -2
  55. package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +2 -1
  56. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  57. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +2 -1
  58. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +2 -1
  59. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +2 -1
  60. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -51
  61. package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  62. package/dist/types/global-account/react/stores/useModalStore.d.ts +2 -0
  63. package/package.json +3 -3
  64. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +35 -51
  65. package/src/global-account/react/components/B3Provider/B3Provider.tsx +72 -28
  66. package/src/global-account/react/components/B3Provider/types.ts +0 -4
  67. package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +3 -2
  68. package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
  69. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
  70. package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
  71. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +23 -4
  72. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +3 -4
  73. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +46 -8
  74. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
  75. package/src/global-account/react/components/custom/ManageAccountButton.tsx +2 -3
  76. package/src/global-account/react/hooks/useAuthentication.ts +90 -159
  77. package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +2 -3
  78. package/src/global-account/react/stores/useModalStore.ts +2 -0
  79. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +0 -58
  80. package/dist/cjs/global-account/react/hooks/useUserQuery.js +0 -86
  81. package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +0 -13
  82. package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +0 -42
  83. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +0 -58
  84. package/dist/esm/global-account/react/hooks/useUserQuery.js +0 -83
  85. package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +0 -13
  86. package/dist/esm/global-account/react/hooks/useWagmiConfig.js +0 -39
  87. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +0 -58
  88. package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +0 -13
  89. package/src/global-account/react/hooks/useUserQuery.ts +0 -95
  90. package/src/global-account/react/hooks/useWagmiConfig.tsx +0 -44
@@ -1,6 +1,5 @@
1
- import { Wallet } from "thirdweb/wallets";
2
1
  import { preAuthenticate } from "thirdweb/wallets/in-app";
3
- export declare function useAuthentication(partnerId: string): {
2
+ export declare function useAuthentication(partnerId: string, loginWithSiwe?: boolean): {
4
3
  logout: (callback?: () => void) => Promise<void>;
5
4
  isAuthenticated: boolean;
6
5
  isReady: boolean;
@@ -8,54 +7,6 @@ export declare function useAuthentication(partnerId: string): {
8
7
  isConnected: boolean;
9
8
  wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
10
9
  preAuthenticate: typeof preAuthenticate;
11
- connect: (wallet: Wallet) => Promise<void>;
10
+ connect: (strategyOptions?: import("thirdweb/wallets").SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
12
11
  isAuthenticating: boolean;
13
- onConnect: (wallet: Wallet) => Promise<void>;
14
- user: {
15
- email?: string | undefined;
16
- username?: string | undefined;
17
- telNumber?: string | undefined;
18
- ens?: string | undefined;
19
- avatar?: string | undefined;
20
- preferences?: {} | undefined;
21
- referredBy?: string | {} | undefined;
22
- sourceApp?: string | undefined;
23
- referralCode?: string | undefined;
24
- userGroups?: number[] | undefined;
25
- isMigratedFromBSMNT?: boolean | undefined;
26
- privyLinkedAccounts?: {
27
- name?: string | undefined;
28
- address?: string | undefined;
29
- email?: string | undefined;
30
- chain_type?: string | undefined;
31
- lv?: number | undefined;
32
- wallet_client_type?: string | undefined;
33
- smart_wallet_type?: string | undefined;
34
- subject?: string | undefined;
35
- type: string;
36
- }[] | undefined;
37
- twProfiles?: {
38
- type: string;
39
- details: {
40
- id?: string | undefined;
41
- name?: string | undefined;
42
- address?: string | undefined;
43
- email?: string | undefined;
44
- phone?: string | undefined;
45
- username?: string | undefined;
46
- fid?: string | undefined;
47
- };
48
- }[] | undefined;
49
- _id: string | {};
50
- userId: string;
51
- smartAccountAddress: string;
52
- createdAt: number;
53
- updatedAt: number;
54
- partnerIds: {
55
- privyId?: string | undefined;
56
- thirdwebId?: string | undefined;
57
- };
58
- } | undefined;
59
- refetchUser: (wallet?: Wallet) => Promise<void>;
60
- setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
61
12
  };
@@ -8,148 +8,116 @@ const app_1 = __importDefault(require("../../../global-account/app"));
8
8
  const bsmnt_1 = require("../../../global-account/bsmnt");
9
9
  const react_1 = require("../../../global-account/react");
10
10
  const constants_1 = require("../../../shared/constants");
11
+ const supported_1 = require("../../../shared/constants/chains/supported");
11
12
  const debug_1 = require("../../../shared/utils/debug");
12
13
  const thirdweb_1 = require("../../../shared/utils/thirdweb");
13
- const core_1 = require("@wagmi/core");
14
14
  const react_2 = require("react");
15
15
  const react_3 = require("thirdweb/react");
16
16
  const wallets_1 = require("thirdweb/wallets");
17
17
  const in_app_1 = require("thirdweb/wallets/in-app");
18
- const wagmi_1 = require("wagmi");
19
- const useUserQuery_1 = require("./useUserQuery");
20
- const useWagmiConfig_1 = require("./useWagmiConfig");
18
+ const useConnect_1 = require("./useConnect");
19
+ const useSiwe_1 = require("./useSiwe");
21
20
  const debug = (0, debug_1.debugB3React)("useAuthentication");
22
- function useAuthentication(partnerId) {
21
+ function useAuthentication(partnerId, loginWithSiwe) {
23
22
  const { disconnect } = (0, react_3.useDisconnect)();
24
23
  const wallets = (0, react_3.useConnectedWallets)();
25
24
  const activeWallet = (0, react_3.useActiveWallet)();
25
+ const { authenticate } = (0, useSiwe_1.useSiwe)();
26
+ const { setUser } = (0, react_1.useB3)();
26
27
  const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
27
28
  const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
29
+ const setIsConnecting = (0, react_1.useAuthStore)(state => state.setIsConnecting);
28
30
  const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
29
31
  const isConnecting = (0, react_1.useAuthStore)(state => state.isConnecting);
30
32
  const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
31
- const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
33
+ const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
32
34
  const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
33
- const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
34
- const setActiveWallet = (0, react_3.useSetActiveWallet)();
35
+ const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
35
36
  const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
36
- const { authenticate } = (0, react_1.useSiwe)();
37
- const { user, setUser } = (0, useUserQuery_1.useUserQuery)();
38
- const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
39
- const wagmiConfig = (0, useWagmiConfig_1.useWagmiConfig)(partnerId);
40
- const { connect } = (0, wagmi_1.useConnect)();
41
- const activeWagmiAccount = (0, wagmi_1.useAccount)();
42
- debug("@@activeWagmiAccount", activeWagmiAccount);
37
+ const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
38
+ const { connect } = (0, useConnect_1.useConnect)(partnerId, supported_1.b3MainnetThirdWeb);
43
39
  const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
44
40
  partnerId: partnerId,
45
41
  });
46
- const syncWagmi = (0, react_2.useCallback)(async () => {
47
- function syncWagmiFunc() {
48
- const connectors = (0, core_1.getConnectors)(wagmiConfig);
49
- debug("@@syncWagmi", {
50
- connectors,
51
- wallets,
52
- });
53
- // For each that matchs a TW wallet on wallets, connect to the wagmi connector
54
- // or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
55
- connectors.forEach(async (connector) => {
56
- const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
57
- if (twWallet &&
58
- // If it's not an in-app wallet or it is the ecosystem wallet, connect
59
- (connector.id !== "in-app-wallet" || (connector.id === "in-app-wallet" && twWallet.id === constants_1.ecosystemWalletId))) {
60
- try {
61
- const options = {
62
- wallet: twWallet, // the connected wallet
63
- };
64
- debug("@@syncWagmi:connecting", { twWallet, connector });
65
- connect({
66
- connector,
67
- ...options,
68
- });
69
- }
70
- catch (error) {
71
- console.error("@@syncWagmi:error", error);
72
- }
42
+ const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
43
+ client: thirdweb_1.client,
44
+ wallets: [wallet],
45
+ onConnect: async (wallet) => {
46
+ setHasStartedConnecting(true);
47
+ try {
48
+ setIsConnected(true);
49
+ if (!loginWithSiwe) {
50
+ debug("Skipping SIWE login", { loginWithSiwe });
51
+ setIsAuthenticated(true);
52
+ setIsAuthenticating(false);
53
+ return;
73
54
  }
74
- else {
75
- debug("@@syncWagmi:not-connecting", connector);
55
+ debug("setIsAuthenticating:true:4");
56
+ const account = await wallet.getAccount();
57
+ if (!account) {
58
+ throw new Error("No account found during auto-connect");
76
59
  }
77
- });
78
- }
79
- syncWagmiFunc();
80
- // wagmi config shouldn't change
81
- // eslint-disable-next-line react-hooks/exhaustive-deps
82
- }, [partnerId, wallets]);
83
- (0, react_2.useEffect)(() => {
84
- syncWagmi();
85
- }, [wallets, syncWagmi]);
86
- const authenticateUser = (0, react_2.useCallback)(async (wallet) => {
87
- setHasStartedConnecting(true);
88
- const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
89
- if (!account) {
90
- throw new Error("No account found during auto-connect");
91
- }
92
- if (!account) {
93
- throw new Error("No account found during auto-connect");
94
- }
95
- // Try to re-authenticate first
96
- try {
97
- const userAuth = await app_1.default.reAuthenticate();
98
- setUser(userAuth.user);
99
- setIsAuthenticated(true);
60
+ // Try to re-authenticate first
61
+ try {
62
+ const userAuth = await app_1.default.reAuthenticate();
63
+ setUser(userAuth.user);
64
+ setIsAuthenticated(true);
65
+ setIsAuthenticating(false);
66
+ debug("Re-authenticated successfully", { userAuth });
67
+ // Authenticate on BSMNT with B3 JWT
68
+ const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
69
+ console.log("@@b3Jwt", b3Jwt);
70
+ }
71
+ catch (error) {
72
+ // If re-authentication fails, try fresh authentication
73
+ debug("Re-authentication failed, attempting fresh authentication");
74
+ const userAuth = await authenticate(account, partnerId);
75
+ setUser(userAuth.user);
76
+ setIsAuthenticated(true);
77
+ setIsAuthenticating(false);
78
+ debug("Fresh authentication successful", { userAuth });
79
+ // Authenticate on BSMNT with B3 JWT
80
+ const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
81
+ console.log("@@b3Jwt", b3Jwt);
82
+ }
83
+ }
84
+ catch (error) {
85
+ debug("Auto-connect authentication failed", { error });
86
+ setIsAuthenticated(false);
87
+ debug("setIsAuthenticating:false:4");
88
+ setUser();
89
+ }
100
90
  setIsAuthenticating(false);
101
- debug("Re-authenticated successfully", { userAuth });
102
- // Authenticate on BSMNT with B3 JWT
103
- const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
104
- debug("@@b3Jwt", b3Jwt);
105
- }
106
- catch (error) {
107
- // If re-authentication fails, try fresh authentication
108
- debug("Re-authentication failed, attempting fresh authentication");
109
- const userAuth = await authenticate(account, partnerId);
110
- setUser(userAuth.user);
111
- setIsAuthenticated(true);
91
+ },
92
+ });
93
+ /**
94
+ * useAutoConnectLoading starts as false
95
+ */
96
+ (0, react_2.useEffect)(() => {
97
+ if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
112
98
  setIsAuthenticating(false);
113
- debug("Fresh authentication successful", { userAuth });
114
- // Authenticate on BSMNT with B3 JWT
115
- const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
116
- debug("@@b3Jwt", b3Jwt);
117
99
  }
118
- }, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
119
- const onConnect = (0, react_2.useCallback)(async (wallet) => {
120
- debug("@@useAuthentication:onConnect", { wallet });
121
- try {
122
- setHasStartedConnecting(true);
123
- setIsConnected(true);
124
- setIsAuthenticating(true);
125
- await setActiveWallet(wallet);
126
- await authenticateUser(wallet);
100
+ useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
101
+ }, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
102
+ // Ensure isAuthenticating stays true until we're fully ready
103
+ (0, react_2.useEffect)(() => {
104
+ if (useAutoConnectLoading) {
105
+ setIsConnecting(true);
127
106
  }
128
- catch (error) {
129
- debug("@@useAuthentication:onConnect:failed", { error });
130
- setIsAuthenticated(false);
131
- setUser(undefined);
107
+ else if (!isAuthenticated) {
108
+ // Only set isAuthenticating to false if we're not authenticated
109
+ // This prevents the flicker state where both isAuthenticating and isAuthenticated are false
110
+ const timeout = setTimeout(() => {
111
+ debug("setIsAuthenticating:false:5a");
112
+ setIsConnecting(false);
113
+ }, 100); // Add a small delay to prevent quick flickers
114
+ return () => clearTimeout(timeout);
132
115
  }
133
- finally {
134
- setIsAuthenticating(false);
116
+ else {
117
+ debug("setIsAuthenticating:false:5b");
118
+ setIsConnecting(false);
135
119
  }
136
- debug({
137
- isAuthenticated,
138
- isAuthenticating,
139
- isConnected,
140
- });
141
- }, [
142
- authenticateUser,
143
- isAuthenticated,
144
- isAuthenticating,
145
- isConnected,
146
- setActiveWallet,
147
- setHasStartedConnecting,
148
- setIsAuthenticated,
149
- setIsAuthenticating,
150
- setIsConnected,
151
- setUser,
152
- ]);
120
+ }, [useAutoConnectLoading, isAuthenticated, setIsConnecting, setIsConnected]);
153
121
  const logout = async (callback) => {
154
122
  if (activeWallet) {
155
123
  debug("@@logout:activeWallet", activeWallet);
@@ -175,21 +143,7 @@ function useAuthentication(partnerId) {
175
143
  setUser();
176
144
  callback?.();
177
145
  };
178
- const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
179
- client: thirdweb_1.client,
180
- wallets: [wallet],
181
- onConnect: onConnect,
182
- });
183
- /**
184
- * useAutoConnectLoading starts as false
185
- */
186
- (0, react_2.useEffect)(() => {
187
- if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
188
- setIsAuthenticating(false);
189
- }
190
- useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
191
- }, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
192
- const isReady = isAuthenticated && !isAuthenticating;
146
+ const isReady = isAuthenticated && !useAutoConnectLoading && !isAuthenticating;
193
147
  return {
194
148
  logout,
195
149
  isAuthenticated,
@@ -198,11 +152,7 @@ function useAuthentication(partnerId) {
198
152
  isConnected,
199
153
  wallet,
200
154
  preAuthenticate: in_app_1.preAuthenticate,
201
- connect: onConnect,
155
+ connect,
202
156
  isAuthenticating,
203
- onConnect,
204
- user,
205
- refetchUser: authenticateUser,
206
- setUser,
207
157
  };
208
158
  }
@@ -4,7 +4,7 @@ import { Account } from "thirdweb/wallets";
4
4
  * This essentially wraps our useConnect hook to handle the Privy auth flow.
5
5
  * Currently, this is for the basement-privy strategy
6
6
  */
7
- export declare function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void): {
7
+ export declare function useHandleConnectWithPrivy(partnerId: string, chain?: Chain, onSuccess?: (account: Account) => void): {
8
8
  connectTw: () => Promise<import("thirdweb/wallets").Wallet | null | undefined>;
9
9
  isLoading: boolean;
10
10
  fullToken: string | null;
@@ -10,8 +10,7 @@ const debug = (0, debug_1.debugB3React)("@@b3:useHandleConnectWithPrivy");
10
10
  * This essentially wraps our useConnect hook to handle the Privy auth flow.
11
11
  * Currently, this is for the basement-privy strategy
12
12
  */
13
- function useHandleConnectWithPrivy(chain, onSuccess) {
14
- const { partnerId } = (0, react_1.useB3)();
13
+ function useHandleConnectWithPrivy(partnerId, chain, onSuccess) {
15
14
  if (!chain) {
16
15
  throw new Error("Chain is required");
17
16
  }
@@ -32,6 +32,8 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
32
32
  sessionKeyAddress?: Address;
33
33
  /** Unique identifier for the partner application */
34
34
  partnerId: string;
35
+ /** Whether to authenticate with Sign In With Ethereum */
36
+ loginWithSiwe?: boolean;
35
37
  /** Whether to close the modal after successful login */
36
38
  closeAfterLogin?: boolean;
37
39
  /** Source of the sign-in request */
@@ -19,12 +19,12 @@ export declare function B3Provider({ theme, children, accountOverride, environme
19
19
  };
20
20
  clientType?: ClientType;
21
21
  rpcUrls?: Record<number, string>;
22
- partnerId: string;
22
+ partnerId?: string;
23
23
  }): import("react/jsx-runtime").JSX.Element;
24
24
  /**
25
25
  * Inner provider component that provides the actual B3Context
26
26
  */
27
- export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, }: {
27
+ export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, }: {
28
28
  children: React.ReactNode;
29
29
  accountOverride?: Account;
30
30
  environment: B3ContextType["environment"];
@@ -32,5 +32,4 @@ export declare function InnerProvider({ children, accountOverride, environment,
32
32
  automaticallySetFirstEoa: boolean;
33
33
  theme: "light" | "dark";
34
34
  clientType?: ClientType;
35
- partnerId: string;
36
35
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,14 +1,17 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { RelayKitProviderWrapper, TooltipProvider, useAuthentication, useAuthStore, } from "../../../../global-account/react/index.js";
3
- import { useWagmiConfig } from "../../../../global-account/react/hooks/useWagmiConfig.js";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { RelayKitProviderWrapper, TooltipProvider, useAuthStore } from "../../../../global-account/react/index.js";
4
3
  import { loadGA4Script } from "../../../../global-account/utils/analytics.js";
4
+ import { ecosystemWalletId } from "../../../../shared/constants/index.js";
5
+ import { supportedChains } from "../../../../shared/constants/chains/supported.js";
5
6
  import { debugB3React } from "../../../../shared/utils/debug.js";
7
+ import { client } from "../../../../shared/utils/thirdweb.js";
6
8
  import "@reservoir0x/relay-kit-ui/styles.css";
7
9
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
8
- import { useCallback, useEffect, useState } from "react";
10
+ import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
11
+ import { useCallback, useEffect, useMemo, useState } from "react";
9
12
  import { Toaster } from "sonner";
10
13
  import { getLastAuthProvider, ThirdwebProvider, useActiveAccount, useConnectedWallets, useSetActiveWallet, } from "thirdweb/react";
11
- import { WagmiProvider } from "wagmi";
14
+ import { createConfig, http, WagmiProvider } from "wagmi";
12
15
  import { setClientType } from "../../../client-manager.js";
13
16
  import { StyleRoot } from "../StyleRoot.js";
14
17
  import { B3Context } from "./types.js";
@@ -36,25 +39,76 @@ export function B3Provider({ theme = "light", children, accountOverride, environ
36
39
  useEffect(() => {
37
40
  setClientType(clientType);
38
41
  }, [clientType]);
39
- 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 })] }) }) }) }) }) }));
42
+ const ecocystemConfig = useMemo(() => {
43
+ if (!partnerId)
44
+ return undefined;
45
+ return {
46
+ ecosystemId: ecosystemWalletId,
47
+ partnerId: partnerId,
48
+ client,
49
+ };
50
+ }, [partnerId]);
51
+ // Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
52
+ // when parent component passes new object references with same content
53
+ const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
54
+ /**
55
+ * Creates wagmi config with optional custom RPC URLs
56
+ * @param rpcUrls - Optional mapping of chain IDs to RPC URLs
57
+ */
58
+ const wagmiConfig = useMemo(() => {
59
+ const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
60
+ return createConfig({
61
+ chains: [supportedChains[0], ...supportedChains.slice(1)],
62
+ transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
63
+ connectors: [
64
+ inAppWalletConnector({
65
+ ...(ecocystemConfig || {}),
66
+ client,
67
+ }),
68
+ // injected(),
69
+ // coinbaseWallet({ appName: "HypeDuel" }),
70
+ ],
71
+ });
72
+ }, [ecocystemConfig, rpcUrlsString]);
73
+ return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, children: _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" }), _jsx(Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
41
74
  }
42
75
  /**
43
76
  * Inner provider component that provides the actual B3Context
44
77
  */
45
- export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket", partnerId, }) {
78
+ export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket", }) {
46
79
  const activeAccount = useActiveAccount();
47
80
  const [manuallySelectedWallet, setManuallySelectedWallet] = useState(undefined);
48
81
  const wallets = useConnectedWallets();
49
- const isAuthenticated = useAuthStore(state => state.isAuthenticated);
50
- const isConnected = useAuthStore(state => state.isConnected);
51
82
  const setActiveWallet = useSetActiveWallet();
52
- const { user, setUser, refetchUser } = useAuthentication(partnerId);
53
- debug("@@B3Provider:isConnected", isConnected);
83
+ const isAuthenticated = useAuthStore(state => state.isAuthenticated);
54
84
  debug("@@wallets", wallets);
55
- debug("@@B3Provider:user", user);
85
+ const [user, setUser] = useState(() => {
86
+ // Try to restore user from localStorage on initialization
87
+ if (typeof window !== "undefined") {
88
+ try {
89
+ const storedUser = localStorage.getItem("b3-user");
90
+ return storedUser ? JSON.parse(storedUser) : undefined;
91
+ }
92
+ catch (error) {
93
+ console.warn("Failed to restore user from localStorage:", error);
94
+ return undefined;
95
+ }
96
+ }
97
+ return undefined;
98
+ });
56
99
  // Use given accountOverride or activeAccount from thirdweb
57
100
  const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
101
+ // Persist user to localStorage when it changes
102
+ useEffect(() => {
103
+ if (typeof window !== "undefined") {
104
+ if (user) {
105
+ localStorage.setItem("b3-user", JSON.stringify(user));
106
+ }
107
+ else {
108
+ localStorage.removeItem("b3-user");
109
+ }
110
+ }
111
+ }, [user]);
58
112
  const setWallet = useCallback((wallet) => {
59
113
  setManuallySelectedWallet(wallet);
60
114
  const account = wallet.getAccount();
@@ -87,7 +141,6 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
87
141
  wallet: manuallySelectedWallet,
88
142
  user,
89
143
  setUser,
90
- refetchUser,
91
144
  initialized: true,
92
145
  ready: !!effectiveAccount,
93
146
  automaticallySetFirstEoa,
@@ -95,9 +148,5 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
95
148
  defaultPermissions,
96
149
  theme,
97
150
  clientType,
98
- partnerId: partnerId,
99
- }, children: _jsx(InnerProvider2, { children: children }) }));
151
+ }, children: children }));
100
152
  }
101
- const InnerProvider2 = ({ children }) => {
102
- return _jsx(_Fragment, { children: children });
103
- };
@@ -5,25 +5,21 @@ 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, }: {
9
9
  theme: "light" | "dark";
10
10
  children: React.ReactNode;
11
11
  accountOverride?: Account;
12
12
  environment: B3ContextType["environment"];
13
13
  clientType?: ClientType;
14
- partnerId: string;
15
- rpcUrls?: Record<number, string>;
16
14
  }): import("react/jsx-runtime").JSX.Element;
17
15
  /**
18
16
  * Inner provider component that provides the actual B3Context
19
17
  */
20
- export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme, clientType, partnerId, rpcUrls, }: {
18
+ export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme, clientType, }: {
21
19
  children: React.ReactNode;
22
20
  accountOverride?: Account;
23
21
  environment: B3ContextType["environment"];
24
22
  defaultPermissions?: PermissionsConfig;
25
23
  theme: "light" | "dark";
26
24
  clientType?: ClientType;
27
- partnerId: string;
28
- rpcUrls?: Record<number, string>;
29
25
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3
+ import { useState } from "react";
3
4
  import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
4
- import { WagmiProvider } from "wagmi";
5
- import { useAuthentication } from "../../hooks/useAuthentication.js";
6
- import { useWagmiConfig } from "../../hooks/useWagmiConfig.js";
7
5
  import { B3Context } from "./types.js";
8
6
  /**
9
7
  * Default permissions configuration for B3 provider
@@ -19,32 +17,29 @@ const queryClient = new QueryClient();
19
17
  /**
20
18
  * Main B3Provider component
21
19
  */
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 }) }));
20
+ export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", }) {
21
+ return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(ThirdwebProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, clientType: clientType, children: children }) }) }));
24
22
  }
25
23
  /**
26
24
  * Inner provider component that provides the actual B3Context
27
25
  */
28
- export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, theme = "light", clientType = "socket", partnerId, rpcUrls, }) {
26
+ export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, theme = "light", clientType = "socket", }) {
29
27
  const activeAccount = useActiveAccount();
30
- const { user, setUser, refetchUser } = useAuthentication(partnerId);
31
- const wagmiConfig = useWagmiConfig(partnerId, rpcUrls);
28
+ const [user, setUser] = useState(undefined);
32
29
  // Use given accountOverride or activeAccount from thirdweb
33
30
  const effectiveAccount = accountOverride || activeAccount;
34
- return (_jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(B3Context.Provider, { value: {
35
- account: effectiveAccount,
36
- automaticallySetFirstEoa: false,
37
- setWallet: () => { },
38
- wallet: undefined,
39
- user,
40
- setUser,
41
- initialized: true,
42
- ready: !!effectiveAccount,
43
- environment,
44
- defaultPermissions,
45
- theme,
46
- clientType,
47
- partnerId,
48
- refetchUser,
49
- }, children: children }) }) }));
31
+ return (_jsx(B3Context.Provider, { value: {
32
+ account: effectiveAccount,
33
+ automaticallySetFirstEoa: false,
34
+ setWallet: () => { },
35
+ wallet: undefined,
36
+ user,
37
+ setUser,
38
+ initialized: true,
39
+ ready: !!effectiveAccount,
40
+ environment,
41
+ defaultPermissions,
42
+ theme,
43
+ clientType,
44
+ }, children: children }));
50
45
  }
@@ -12,14 +12,12 @@ export interface B3ContextType {
12
12
  setWallet: (wallet: Wallet) => void;
13
13
  wallet?: Wallet;
14
14
  setUser: (user?: Users) => void;
15
- refetchUser: () => Promise<any>;
16
15
  initialized: boolean;
17
16
  ready: boolean;
18
17
  environment?: "development" | "production";
19
18
  defaultPermissions?: PermissionsConfig;
20
19
  theme: "light" | "dark";
21
20
  clientType: ClientType;
22
- partnerId: string;
23
21
  }
24
22
  /**
25
23
  * Context for B3 provider
@@ -9,11 +9,9 @@ export const B3Context = createContext({
9
9
  setWallet: () => { },
10
10
  wallet: undefined,
11
11
  setUser: () => { },
12
- refetchUser: async () => { },
13
12
  initialized: false,
14
13
  ready: false,
15
14
  environment: "development",
16
15
  theme: "light",
17
16
  clientType: "rest",
18
- partnerId: "",
19
17
  });
@@ -1,7 +1,8 @@
1
1
  interface BalanceContentProps {
2
2
  onLogout?: () => void;
3
+ partnerId: string;
3
4
  showDeposit?: boolean;
4
5
  showSwap?: boolean;
5
6
  }
6
- export declare function BalanceContent({ onLogout, showDeposit, showSwap }: BalanceContentProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function BalanceContent({ onLogout, partnerId, showDeposit, showSwap }: BalanceContentProps): import("react/jsx-runtime").JSX.Element;
7
8
  export {};