@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,173 +1,124 @@
1
1
  import app from "@b3dotfun/sdk/global-account/app";
2
2
  import { authenticateWithB3JWT } from "@b3dotfun/sdk/global-account/bsmnt";
3
- import { useAuthStore, useSiwe } from "@b3dotfun/sdk/global-account/react";
3
+ import { useAuthStore, useB3 } from "@b3dotfun/sdk/global-account/react";
4
4
  import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
5
+ import { b3MainnetThirdWeb } from "@b3dotfun/sdk/shared/constants/chains/supported";
5
6
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
6
7
  import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
7
- import { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
8
- import { getConnectors } from "@wagmi/core";
9
- import { useCallback, useEffect, useRef } from "react";
10
- import {
11
- useActiveWallet,
12
- useAutoConnect,
13
- useConnectedWallets,
14
- useDisconnect,
15
- useSetActiveWallet,
16
- } from "thirdweb/react";
17
- import { ecosystemWallet, Wallet } from "thirdweb/wallets";
8
+ import { useEffect, useRef } from "react";
9
+ import { useActiveWallet, useAutoConnect, useConnectedWallets, useDisconnect } from "thirdweb/react";
10
+ import { ecosystemWallet } from "thirdweb/wallets";
18
11
  import { preAuthenticate } from "thirdweb/wallets/in-app";
19
- import { useAccount, useConnect } from "wagmi";
20
- import { useUserQuery } from "./useUserQuery";
21
- import { useWagmiConfig } from "./useWagmiConfig";
12
+ import { useConnect } from "./useConnect";
13
+ import { useSiwe } from "./useSiwe";
22
14
 
23
15
  const debug = debugB3React("useAuthentication");
24
16
 
25
- export function useAuthentication(partnerId: string) {
17
+ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
26
18
  const { disconnect } = useDisconnect();
27
19
  const wallets = useConnectedWallets();
28
20
  const activeWallet = useActiveWallet();
21
+ const { authenticate } = useSiwe();
22
+ const { setUser } = useB3();
29
23
  const isAuthenticated = useAuthStore(state => state.isAuthenticated);
30
24
  const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
25
+ const setIsConnecting = useAuthStore(state => state.setIsConnecting);
31
26
  const setIsConnected = useAuthStore(state => state.setIsConnected);
32
27
  const isConnecting = useAuthStore(state => state.isConnecting);
33
28
  const isConnected = useAuthStore(state => state.isConnected);
34
- const isAuthenticating = useAuthStore(state => state.isAuthenticating);
29
+ const useAutoConnectLoadingPrevious = useRef(false);
35
30
  const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
36
- const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
37
- const setActiveWallet = useSetActiveWallet();
31
+ const isAuthenticating = useAuthStore(state => state.isAuthenticating);
38
32
  const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
39
- const { authenticate } = useSiwe();
40
- const { user, setUser } = useUserQuery();
41
- const useAutoConnectLoadingPrevious = useRef(false);
42
- const wagmiConfig = useWagmiConfig(partnerId);
43
- const { connect } = useConnect();
44
- const activeWagmiAccount = useAccount();
45
- debug("@@activeWagmiAccount", activeWagmiAccount);
33
+ const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
34
+ const { connect } = useConnect(partnerId, b3MainnetThirdWeb);
46
35
 
47
36
  const wallet = ecosystemWallet(ecosystemWalletId, {
48
37
  partnerId: partnerId,
49
38
  });
50
39
 
51
- const syncWagmi = useCallback(async () => {
52
- function syncWagmiFunc() {
53
- const connectors = getConnectors(wagmiConfig);
54
- debug("@@syncWagmi", {
55
- connectors,
56
- wallets,
57
- });
58
-
59
- // For each that matchs a TW wallet on wallets, connect to the wagmi connector
60
- // or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
61
- connectors.forEach(async connector => {
62
- const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
63
- if (
64
- twWallet &&
65
- // If it's not an in-app wallet or it is the ecosystem wallet, connect
66
- (connector.id !== "in-app-wallet" || (connector.id === "in-app-wallet" && twWallet.id === ecosystemWalletId))
67
- ) {
68
- try {
69
- const options = {
70
- wallet: twWallet, // the connected wallet
71
- } satisfies ConnectionOptions;
72
- debug("@@syncWagmi:connecting", { twWallet, connector });
73
- connect({
74
- connector,
75
- ...options,
76
- });
77
- } catch (error) {
78
- console.error("@@syncWagmi:error", error);
79
- }
80
- } else {
81
- debug("@@syncWagmi:not-connecting", connector);
82
- }
83
- });
84
- }
85
- syncWagmiFunc();
86
- // wagmi config shouldn't change
87
- // eslint-disable-next-line react-hooks/exhaustive-deps
88
- }, [partnerId, wallets]);
89
-
90
- useEffect(() => {
91
- syncWagmi();
92
- }, [wallets, syncWagmi]);
93
-
94
- const authenticateUser = useCallback(
95
- async (wallet?: Wallet) => {
40
+ const { isLoading: useAutoConnectLoading } = useAutoConnect({
41
+ client,
42
+ wallets: [wallet],
43
+ onConnect: async wallet => {
96
44
  setHasStartedConnecting(true);
97
45
 
98
- const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
99
- if (!account) {
100
- throw new Error("No account found during auto-connect");
101
- }
102
- if (!account) {
103
- throw new Error("No account found during auto-connect");
104
- }
105
-
106
- // Try to re-authenticate first
107
46
  try {
108
- const userAuth = await app.reAuthenticate();
109
- setUser(userAuth.user);
110
- setIsAuthenticated(true);
111
- setIsAuthenticating(false);
112
- debug("Re-authenticated successfully", { userAuth });
113
-
114
- // Authenticate on BSMNT with B3 JWT
115
- const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
116
- debug("@@b3Jwt", b3Jwt);
117
- } catch (error) {
118
- // If re-authentication fails, try fresh authentication
119
- debug("Re-authentication failed, attempting fresh authentication");
120
- const userAuth = await authenticate(account, partnerId);
121
- setUser(userAuth.user);
122
- setIsAuthenticated(true);
123
- setIsAuthenticating(false);
124
- debug("Fresh authentication successful", { userAuth });
125
-
126
- // Authenticate on BSMNT with B3 JWT
127
- const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
128
- debug("@@b3Jwt", b3Jwt);
129
- }
130
- },
131
- [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting],
132
- );
47
+ setIsConnected(true);
48
+ if (!loginWithSiwe) {
49
+ debug("Skipping SIWE login", { loginWithSiwe });
50
+ setIsAuthenticated(true);
133
51
 
134
- const onConnect = useCallback(
135
- async (wallet: Wallet) => {
136
- debug("@@useAuthentication:onConnect", { wallet });
52
+ setIsAuthenticating(false);
53
+ return;
54
+ }
55
+ debug("setIsAuthenticating:true:4");
56
+ const account = await wallet.getAccount();
57
+ if (!account) {
58
+ throw new Error("No account found during auto-connect");
59
+ }
137
60
 
138
- try {
139
- setHasStartedConnecting(true);
140
- setIsConnected(true);
141
- setIsAuthenticating(true);
142
- await setActiveWallet(wallet);
143
- await authenticateUser(wallet);
61
+ // Try to re-authenticate first
62
+ try {
63
+ const userAuth = await app.reAuthenticate();
64
+ setUser(userAuth.user);
65
+ setIsAuthenticated(true);
66
+ setIsAuthenticating(false);
67
+ debug("Re-authenticated successfully", { userAuth });
68
+
69
+ // Authenticate on BSMNT with B3 JWT
70
+ const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
71
+ console.log("@@b3Jwt", b3Jwt);
72
+ } catch (error) {
73
+ // If re-authentication fails, try fresh authentication
74
+ debug("Re-authentication failed, attempting fresh authentication");
75
+ const userAuth = await authenticate(account, partnerId);
76
+ setUser(userAuth.user);
77
+ setIsAuthenticated(true);
78
+ setIsAuthenticating(false);
79
+ debug("Fresh authentication successful", { userAuth });
80
+
81
+ // Authenticate on BSMNT with B3 JWT
82
+ const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
83
+ console.log("@@b3Jwt", b3Jwt);
84
+ }
144
85
  } catch (error) {
145
- debug("@@useAuthentication:onConnect:failed", { error });
86
+ debug("Auto-connect authentication failed", { error });
146
87
  setIsAuthenticated(false);
147
- setUser(undefined);
148
- } finally {
149
- setIsAuthenticating(false);
88
+ debug("setIsAuthenticating:false:4");
89
+ setUser();
150
90
  }
151
-
152
- debug({
153
- isAuthenticated,
154
- isAuthenticating,
155
- isConnected,
156
- });
91
+ setIsAuthenticating(false);
157
92
  },
158
- [
159
- authenticateUser,
160
- isAuthenticated,
161
- isAuthenticating,
162
- isConnected,
163
- setActiveWallet,
164
- setHasStartedConnecting,
165
- setIsAuthenticated,
166
- setIsAuthenticating,
167
- setIsConnected,
168
- setUser,
169
- ],
170
- );
93
+ });
94
+
95
+ /**
96
+ * useAutoConnectLoading starts as false
97
+ */
98
+ useEffect(() => {
99
+ if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
100
+ setIsAuthenticating(false);
101
+ }
102
+ useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
103
+ }, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
104
+
105
+ // Ensure isAuthenticating stays true until we're fully ready
106
+ useEffect(() => {
107
+ if (useAutoConnectLoading) {
108
+ setIsConnecting(true);
109
+ } else if (!isAuthenticated) {
110
+ // Only set isAuthenticating to false if we're not authenticated
111
+ // This prevents the flicker state where both isAuthenticating and isAuthenticated are false
112
+ const timeout = setTimeout(() => {
113
+ debug("setIsAuthenticating:false:5a");
114
+ setIsConnecting(false);
115
+ }, 100); // Add a small delay to prevent quick flickers
116
+ return () => clearTimeout(timeout);
117
+ } else {
118
+ debug("setIsAuthenticating:false:5b");
119
+ setIsConnecting(false);
120
+ }
121
+ }, [useAutoConnectLoading, isAuthenticated, setIsConnecting, setIsConnected]);
171
122
 
172
123
  const logout = async (callback?: () => void) => {
173
124
  if (activeWallet) {
@@ -199,23 +150,7 @@ export function useAuthentication(partnerId: string) {
199
150
  callback?.();
200
151
  };
201
152
 
202
- const { isLoading: useAutoConnectLoading } = useAutoConnect({
203
- client,
204
- wallets: [wallet],
205
- onConnect: onConnect,
206
- });
207
-
208
- /**
209
- * useAutoConnectLoading starts as false
210
- */
211
- useEffect(() => {
212
- if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
213
- setIsAuthenticating(false);
214
- }
215
- useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
216
- }, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
217
-
218
- const isReady = isAuthenticated && !isAuthenticating;
153
+ const isReady = isAuthenticated && !useAutoConnectLoading && !isAuthenticating;
219
154
 
220
155
  return {
221
156
  logout,
@@ -225,11 +160,7 @@ export function useAuthentication(partnerId: string) {
225
160
  isConnected,
226
161
  wallet,
227
162
  preAuthenticate,
228
- connect: onConnect,
163
+ connect,
229
164
  isAuthenticating,
230
- onConnect,
231
- user,
232
- refetchUser: authenticateUser,
233
- setUser,
234
165
  };
235
166
  }
@@ -1,4 +1,4 @@
1
- import { useB3, useConnect } from "@b3dotfun/sdk/global-account/react";
1
+ import { useConnect } from "@b3dotfun/sdk/global-account/react";
2
2
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
3
3
  import { useIdentityToken, usePrivy } from "@privy-io/react-auth";
4
4
  import { useCallback, useRef, useState } from "react";
@@ -10,8 +10,7 @@ const debug = 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
- export function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void) {
14
- const { partnerId } = useB3();
13
+ export function useHandleConnectWithPrivy(partnerId: string, chain?: Chain, onSuccess?: (account: Account) => void) {
15
14
  if (!chain) {
16
15
  throw new Error("Chain is required");
17
16
  }
@@ -35,6 +35,8 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
35
35
  sessionKeyAddress?: Address;
36
36
  /** Unique identifier for the partner application */
37
37
  partnerId: string;
38
+ /** Whether to authenticate with Sign In With Ethereum */
39
+ loginWithSiwe?: boolean;
38
40
  /** Whether to close the modal after successful login */
39
41
  closeAfterLogin?: boolean;
40
42
  /** Source of the sign-in request */
@@ -1,58 +0,0 @@
1
- import { Users } from "@b3dotfun/b3-api";
2
- /**
3
- * NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
4
- *
5
- * Custom hook to manage user state with react-query
6
- * This allows for invalidation and refetching of user data
7
- */
8
- export declare function useUserQuery(): {
9
- user: {
10
- email?: string | undefined;
11
- username?: string | undefined;
12
- telNumber?: string | undefined;
13
- ens?: string | undefined;
14
- avatar?: string | undefined;
15
- preferences?: {} | undefined;
16
- referredBy?: string | {} | undefined;
17
- sourceApp?: string | undefined;
18
- referralCode?: string | undefined;
19
- userGroups?: number[] | undefined;
20
- isMigratedFromBSMNT?: boolean | undefined;
21
- privyLinkedAccounts?: {
22
- name?: string | undefined;
23
- address?: string | undefined;
24
- email?: string | undefined;
25
- chain_type?: string | undefined;
26
- lv?: number | undefined;
27
- wallet_client_type?: string | undefined;
28
- smart_wallet_type?: string | undefined;
29
- subject?: string | undefined;
30
- type: string;
31
- }[] | undefined;
32
- twProfiles?: {
33
- type: string;
34
- details: {
35
- id?: string | undefined;
36
- name?: string | undefined;
37
- address?: string | undefined;
38
- email?: string | undefined;
39
- phone?: string | undefined;
40
- username?: string | undefined;
41
- fid?: string | undefined;
42
- };
43
- }[] | undefined;
44
- _id: string | {};
45
- userId: string;
46
- smartAccountAddress: string;
47
- createdAt: number;
48
- updatedAt: number;
49
- partnerIds: {
50
- privyId?: string | undefined;
51
- thirdwebId?: string | undefined;
52
- };
53
- } | undefined;
54
- setUser: (newUser?: Users) => void;
55
- refetchUser: () => Promise<void>;
56
- clearUser: () => void;
57
- queryKey: string[];
58
- };
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useUserQuery = useUserQuery;
4
- const debug_1 = require("../../../shared/utils/debug");
5
- const react_query_1 = require("@tanstack/react-query");
6
- const debug = (0, debug_1.debugB3React)("useUserQuery");
7
- const USER_QUERY_KEY = ["b3-user"];
8
- /**
9
- * Retrieves the user from localStorage
10
- */
11
- function getUserFromStorage() {
12
- if (typeof window === "undefined") {
13
- return null;
14
- }
15
- try {
16
- const storedUser = localStorage.getItem("b3-user");
17
- return storedUser ? JSON.parse(storedUser) : null;
18
- }
19
- catch (error) {
20
- console.warn("Failed to restore user from localStorage:", error);
21
- return null;
22
- }
23
- }
24
- /**
25
- * Saves user to localStorage
26
- */
27
- function saveUserToStorage(user) {
28
- if (typeof window === "undefined") {
29
- return;
30
- }
31
- if (user) {
32
- localStorage.setItem("b3-user", JSON.stringify(user));
33
- }
34
- else {
35
- localStorage.removeItem("b3-user");
36
- }
37
- }
38
- /**
39
- * NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
40
- *
41
- * Custom hook to manage user state with react-query
42
- * This allows for invalidation and refetching of user data
43
- */
44
- function useUserQuery() {
45
- const queryClient = (0, react_query_1.useQueryClient)();
46
- // Query to get user data (primarily from cache/localStorage)
47
- const { data: user } = (0, react_query_1.useQuery)({
48
- queryKey: USER_QUERY_KEY,
49
- queryFn: getUserFromStorage,
50
- staleTime: Infinity, // User data doesn't go stale automatically
51
- gcTime: Infinity, // Keep in cache indefinitely
52
- initialData: getUserFromStorage,
53
- });
54
- // Mutation to update user
55
- const setUserMutation = (0, react_query_1.useMutation)({
56
- mutationFn: async (newUser) => {
57
- const userToSave = newUser ?? null;
58
- saveUserToStorage(userToSave);
59
- return userToSave;
60
- },
61
- onSuccess: data => {
62
- queryClient.setQueryData(USER_QUERY_KEY, data);
63
- debug("User updated", data);
64
- },
65
- });
66
- // Helper function to set user (maintains backward compatibility)
67
- const setUser = (newUser) => {
68
- setUserMutation.mutate(newUser);
69
- };
70
- // Helper function to invalidate and refetch user
71
- const refetchUser = async () => {
72
- await queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
73
- return queryClient.refetchQueries({ queryKey: USER_QUERY_KEY });
74
- };
75
- // Helper function to clear user
76
- const clearUser = () => {
77
- setUser(undefined);
78
- };
79
- return {
80
- user: user ?? undefined,
81
- setUser,
82
- refetchUser,
83
- clearUser,
84
- queryKey: USER_QUERY_KEY,
85
- };
86
- }
@@ -1,13 +0,0 @@
1
- export declare function useWagmiConfig(partnerId: string, rpcUrls?: Record<number, string>): import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], {
2
- [k: string]: import("viem").HttpTransport<undefined, false>;
3
- }, readonly [import("wagmi").CreateConnectorFn<import("thirdweb/dist/types/adapters/eip1193").EIP1193Provider | undefined, {
4
- connect<withCapabilities extends boolean = false>(parameters?: import("@thirdweb-dev/wagmi-adapter").ConnectionOptions<withCapabilities> | undefined): Promise<{
5
- accounts: withCapabilities extends true ? readonly {
6
- address: `0x${string}`;
7
- capabilities: Record<string, unknown>;
8
- }[] : readonly `0x${string}`[];
9
- chainId: number;
10
- }>;
11
- }, {
12
- "thirdweb:lastChainId": number;
13
- }>]>;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useWagmiConfig = useWagmiConfig;
4
- const constants_1 = require("../../../shared/constants");
5
- const supported_1 = require("../../../shared/constants/chains/supported");
6
- const thirdweb_1 = require("../../../shared/utils/thirdweb");
7
- const wagmi_adapter_1 = require("@thirdweb-dev/wagmi-adapter");
8
- const react_1 = require("react");
9
- const viem_1 = require("viem");
10
- const wagmi_1 = require("wagmi");
11
- function useWagmiConfig(partnerId, rpcUrls) {
12
- // Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
13
- // when parent component passes new object references with same content
14
- const rpcUrlsString = (0, react_1.useMemo)(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
15
- const ecocystemConfig = (0, react_1.useMemo)(() => {
16
- return {
17
- ecosystemId: constants_1.ecosystemWalletId,
18
- partnerId: partnerId,
19
- client: thirdweb_1.client,
20
- };
21
- }, [partnerId]);
22
- /**
23
- * Creates wagmi config with optional custom RPC URLs
24
- * @param rpcUrls - Optional mapping of chain IDs to RPC URLs
25
- */
26
- const wagmiConfig = (0, react_1.useMemo)(() => {
27
- const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
28
- return (0, wagmi_1.createConfig)({
29
- chains: [supported_1.supportedChains[0], ...supported_1.supportedChains.slice(1)],
30
- transports: Object.fromEntries(supported_1.supportedChains.map(chain => [chain.id, (0, viem_1.http)(parsedRpcUrls?.[chain.id])])),
31
- connectors: [
32
- (0, wagmi_adapter_1.inAppWalletConnector)({
33
- ...ecocystemConfig,
34
- client: thirdweb_1.client,
35
- }),
36
- // injected(),
37
- // coinbaseWallet({ appName: "HypeDuel" }),
38
- ],
39
- });
40
- }, [rpcUrlsString, ecocystemConfig]);
41
- return wagmiConfig;
42
- }
@@ -1,58 +0,0 @@
1
- import { Users } from "@b3dotfun/b3-api";
2
- /**
3
- * NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
4
- *
5
- * Custom hook to manage user state with react-query
6
- * This allows for invalidation and refetching of user data
7
- */
8
- export declare function useUserQuery(): {
9
- user: {
10
- email?: string | undefined;
11
- username?: string | undefined;
12
- telNumber?: string | undefined;
13
- ens?: string | undefined;
14
- avatar?: string | undefined;
15
- preferences?: {} | undefined;
16
- referredBy?: string | {} | undefined;
17
- sourceApp?: string | undefined;
18
- referralCode?: string | undefined;
19
- userGroups?: number[] | undefined;
20
- isMigratedFromBSMNT?: boolean | undefined;
21
- privyLinkedAccounts?: {
22
- name?: string | undefined;
23
- address?: string | undefined;
24
- email?: string | undefined;
25
- chain_type?: string | undefined;
26
- lv?: number | undefined;
27
- wallet_client_type?: string | undefined;
28
- smart_wallet_type?: string | undefined;
29
- subject?: string | undefined;
30
- type: string;
31
- }[] | undefined;
32
- twProfiles?: {
33
- type: string;
34
- details: {
35
- id?: string | undefined;
36
- name?: string | undefined;
37
- address?: string | undefined;
38
- email?: string | undefined;
39
- phone?: string | undefined;
40
- username?: string | undefined;
41
- fid?: string | undefined;
42
- };
43
- }[] | undefined;
44
- _id: string | {};
45
- userId: string;
46
- smartAccountAddress: string;
47
- createdAt: number;
48
- updatedAt: number;
49
- partnerIds: {
50
- privyId?: string | undefined;
51
- thirdwebId?: string | undefined;
52
- };
53
- } | undefined;
54
- setUser: (newUser?: Users) => void;
55
- refetchUser: () => Promise<void>;
56
- clearUser: () => void;
57
- queryKey: string[];
58
- };
@@ -1,83 +0,0 @@
1
- import { debugB3React } from "../../../shared/utils/debug.js";
2
- import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
- const debug = debugB3React("useUserQuery");
4
- const USER_QUERY_KEY = ["b3-user"];
5
- /**
6
- * Retrieves the user from localStorage
7
- */
8
- function getUserFromStorage() {
9
- if (typeof window === "undefined") {
10
- return null;
11
- }
12
- try {
13
- const storedUser = localStorage.getItem("b3-user");
14
- return storedUser ? JSON.parse(storedUser) : null;
15
- }
16
- catch (error) {
17
- console.warn("Failed to restore user from localStorage:", error);
18
- return null;
19
- }
20
- }
21
- /**
22
- * Saves user to localStorage
23
- */
24
- function saveUserToStorage(user) {
25
- if (typeof window === "undefined") {
26
- return;
27
- }
28
- if (user) {
29
- localStorage.setItem("b3-user", JSON.stringify(user));
30
- }
31
- else {
32
- localStorage.removeItem("b3-user");
33
- }
34
- }
35
- /**
36
- * NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
37
- *
38
- * Custom hook to manage user state with react-query
39
- * This allows for invalidation and refetching of user data
40
- */
41
- export function useUserQuery() {
42
- const queryClient = useQueryClient();
43
- // Query to get user data (primarily from cache/localStorage)
44
- const { data: user } = useQuery({
45
- queryKey: USER_QUERY_KEY,
46
- queryFn: getUserFromStorage,
47
- staleTime: Infinity, // User data doesn't go stale automatically
48
- gcTime: Infinity, // Keep in cache indefinitely
49
- initialData: getUserFromStorage,
50
- });
51
- // Mutation to update user
52
- const setUserMutation = useMutation({
53
- mutationFn: async (newUser) => {
54
- const userToSave = newUser ?? null;
55
- saveUserToStorage(userToSave);
56
- return userToSave;
57
- },
58
- onSuccess: data => {
59
- queryClient.setQueryData(USER_QUERY_KEY, data);
60
- debug("User updated", data);
61
- },
62
- });
63
- // Helper function to set user (maintains backward compatibility)
64
- const setUser = (newUser) => {
65
- setUserMutation.mutate(newUser);
66
- };
67
- // Helper function to invalidate and refetch user
68
- const refetchUser = async () => {
69
- await queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
70
- return queryClient.refetchQueries({ queryKey: USER_QUERY_KEY });
71
- };
72
- // Helper function to clear user
73
- const clearUser = () => {
74
- setUser(undefined);
75
- };
76
- return {
77
- user: user ?? undefined,
78
- setUser,
79
- refetchUser,
80
- clearUser,
81
- queryKey: USER_QUERY_KEY,
82
- };
83
- }