@b3dotfun/sdk 0.0.46 → 0.0.47-test.4

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 (174) hide show
  1. package/README.md +6 -225
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +13 -14
  3. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +14 -15
  4. package/dist/cjs/anyspend/react/components/common/OrderHistory.js +2 -2
  5. package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +6 -3
  6. package/dist/cjs/anyspend/types/api.d.ts +176 -0
  7. package/dist/cjs/anyspend/utils/chain.js +1 -1
  8. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  9. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -64
  10. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  11. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +26 -21
  12. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
  13. package/dist/cjs/global-account/react/components/B3Provider/types.js +2 -0
  14. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  15. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  16. package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  17. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  18. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
  19. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  20. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +6 -22
  21. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  22. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -2
  23. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  24. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +10 -45
  25. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  26. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -1
  27. package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -1
  28. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +51 -2
  29. package/dist/cjs/global-account/react/hooks/useAuthentication.js +134 -84
  30. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  31. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -1
  32. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +58 -0
  33. package/dist/cjs/global-account/react/hooks/useUserQuery.js +86 -0
  34. package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  35. package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +42 -0
  36. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
  37. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
  38. package/dist/cjs/shared/utils/index.d.ts +0 -1
  39. package/dist/cjs/shared/utils/index.js +0 -1
  40. package/dist/esm/anyspend/react/components/AnySpend.js +14 -15
  41. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +15 -16
  42. package/dist/esm/anyspend/react/components/common/OrderHistory.js +2 -2
  43. package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +8 -5
  44. package/dist/esm/anyspend/types/api.d.ts +176 -0
  45. package/dist/esm/anyspend/utils/chain.js +1 -1
  46. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  47. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -68
  48. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  49. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +24 -19
  50. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
  51. package/dist/esm/global-account/react/components/B3Provider/types.js +2 -0
  52. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  53. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  54. package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  55. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  56. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
  57. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  58. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +7 -23
  59. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  60. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +4 -3
  61. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  62. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +11 -46
  63. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  64. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
  65. package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +3 -2
  66. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +51 -2
  67. package/dist/esm/global-account/react/hooks/useAuthentication.js +137 -87
  68. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  69. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +3 -2
  70. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +58 -0
  71. package/dist/esm/global-account/react/hooks/useUserQuery.js +83 -0
  72. package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  73. package/dist/esm/global-account/react/hooks/useWagmiConfig.js +39 -0
  74. package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
  75. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  76. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
  77. package/dist/esm/shared/utils/index.d.ts +0 -1
  78. package/dist/esm/shared/utils/index.js +0 -1
  79. package/dist/styles/index.css +1 -1
  80. package/dist/types/anyspend/types/api.d.ts +176 -0
  81. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  82. package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  83. package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
  84. package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  85. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  86. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  87. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  88. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  89. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +51 -2
  90. package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  91. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +58 -0
  92. package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  93. package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
  94. package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  95. package/dist/types/shared/utils/index.d.ts +0 -1
  96. package/package.json +4 -23
  97. package/src/anyspend/react/components/AnySpend.tsx +21 -19
  98. package/src/anyspend/react/components/AnyspendDepositHype.tsx +21 -21
  99. package/src/anyspend/react/components/common/OrderHistory.tsx +11 -11
  100. package/src/anyspend/react/components/common/OrderHistoryItem.tsx +124 -129
  101. package/src/anyspend/types/api.ts +176 -0
  102. package/src/anyspend/utils/chain.ts +1 -4
  103. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +51 -35
  104. package/src/global-account/react/components/B3Provider/B3Provider.tsx +28 -72
  105. package/src/global-account/react/components/B3Provider/types.ts +4 -0
  106. package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +2 -3
  107. package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
  108. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
  109. package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
  110. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +4 -23
  111. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +4 -3
  112. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +8 -46
  113. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
  114. package/src/global-account/react/components/custom/ManageAccountButton.tsx +3 -2
  115. package/src/global-account/react/hooks/useAuthentication.ts +159 -90
  116. package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +3 -2
  117. package/src/global-account/react/hooks/useUserQuery.ts +95 -0
  118. package/src/global-account/react/hooks/useWagmiConfig.tsx +44 -0
  119. package/src/global-account/react/stores/useModalStore.ts +0 -2
  120. package/src/shared/utils/index.ts +0 -1
  121. package/dist/cjs/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  122. package/dist/cjs/anyspend/react/components/common/ErrorSection.js +0 -12
  123. package/dist/cjs/notifications/index.d.ts +0 -3
  124. package/dist/cjs/notifications/index.js +0 -25
  125. package/dist/cjs/notifications/react/hooks/index.d.ts +0 -1
  126. package/dist/cjs/notifications/react/hooks/index.js +0 -17
  127. package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +0 -42
  128. package/dist/cjs/notifications/react/hooks/useNotifications.js +0 -148
  129. package/dist/cjs/notifications/react/index.d.ts +0 -1
  130. package/dist/cjs/notifications/react/index.js +0 -17
  131. package/dist/cjs/notifications/services/api.d.ts +0 -67
  132. package/dist/cjs/notifications/services/api.js +0 -184
  133. package/dist/cjs/notifications/services/index.d.ts +0 -1
  134. package/dist/cjs/notifications/services/index.js +0 -17
  135. package/dist/cjs/notifications/types/index.d.ts +0 -51
  136. package/dist/cjs/notifications/types/index.js +0 -2
  137. package/dist/cjs/shared/utils/auth-token.d.ts +0 -7
  138. package/dist/cjs/shared/utils/auth-token.js +0 -17
  139. package/dist/esm/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  140. package/dist/esm/anyspend/react/components/common/ErrorSection.js +0 -9
  141. package/dist/esm/notifications/index.d.ts +0 -3
  142. package/dist/esm/notifications/index.js +0 -7
  143. package/dist/esm/notifications/react/hooks/index.d.ts +0 -1
  144. package/dist/esm/notifications/react/hooks/index.js +0 -1
  145. package/dist/esm/notifications/react/hooks/useNotifications.d.ts +0 -42
  146. package/dist/esm/notifications/react/hooks/useNotifications.js +0 -145
  147. package/dist/esm/notifications/react/index.d.ts +0 -1
  148. package/dist/esm/notifications/react/index.js +0 -1
  149. package/dist/esm/notifications/services/api.d.ts +0 -67
  150. package/dist/esm/notifications/services/api.js +0 -179
  151. package/dist/esm/notifications/services/index.d.ts +0 -1
  152. package/dist/esm/notifications/services/index.js +0 -1
  153. package/dist/esm/notifications/types/index.d.ts +0 -51
  154. package/dist/esm/shared/utils/auth-token.d.ts +0 -7
  155. package/dist/esm/shared/utils/auth-token.js +0 -11
  156. package/dist/types/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  157. package/dist/types/notifications/index.d.ts +0 -3
  158. package/dist/types/notifications/react/hooks/index.d.ts +0 -1
  159. package/dist/types/notifications/react/hooks/useNotifications.d.ts +0 -42
  160. package/dist/types/notifications/react/index.d.ts +0 -1
  161. package/dist/types/notifications/services/api.d.ts +0 -67
  162. package/dist/types/notifications/services/index.d.ts +0 -1
  163. package/dist/types/notifications/types/index.d.ts +0 -51
  164. package/dist/types/shared/utils/auth-token.d.ts +0 -7
  165. package/src/anyspend/react/components/common/ErrorSection.tsx +0 -21
  166. package/src/notifications/index.ts +0 -9
  167. package/src/notifications/react/hooks/index.ts +0 -1
  168. package/src/notifications/react/hooks/useNotifications.ts +0 -153
  169. package/src/notifications/react/index.ts +0 -1
  170. package/src/notifications/services/api.ts +0 -217
  171. package/src/notifications/services/index.ts +0 -1
  172. package/src/notifications/types/index.ts +0 -58
  173. package/src/shared/utils/auth-token.ts +0 -13
  174. /package/dist/{esm/notifications/types/index.js → cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts} +0 -0
@@ -1,124 +1,173 @@
1
1
  import app from "@b3dotfun/sdk/global-account/app";
2
2
  import { authenticateWithB3JWT } from "@b3dotfun/sdk/global-account/bsmnt";
3
- import { useAuthStore, useB3 } from "@b3dotfun/sdk/global-account/react";
3
+ import { useAuthStore, useSiwe } 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";
6
5
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
7
6
  import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
8
- import { useEffect, useRef } from "react";
9
- import { useActiveWallet, useAutoConnect, useConnectedWallets, useDisconnect } from "thirdweb/react";
10
- import { ecosystemWallet } from "thirdweb/wallets";
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";
11
18
  import { preAuthenticate } from "thirdweb/wallets/in-app";
12
- import { useConnect } from "./useConnect";
13
- import { useSiwe } from "./useSiwe";
19
+ import { useAccount, useConnect } from "wagmi";
20
+ import { useUserQuery } from "./useUserQuery";
21
+ import { useWagmiConfig } from "./useWagmiConfig";
14
22
 
15
23
  const debug = debugB3React("useAuthentication");
16
24
 
17
- export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
25
+ export function useAuthentication(partnerId: string) {
18
26
  const { disconnect } = useDisconnect();
19
27
  const wallets = useConnectedWallets();
20
28
  const activeWallet = useActiveWallet();
21
- const { authenticate } = useSiwe();
22
- const { setUser } = useB3();
23
29
  const isAuthenticated = useAuthStore(state => state.isAuthenticated);
24
30
  const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
25
- const setIsConnecting = useAuthStore(state => state.setIsConnecting);
26
31
  const setIsConnected = useAuthStore(state => state.setIsConnected);
27
32
  const isConnecting = useAuthStore(state => state.isConnecting);
28
33
  const isConnected = useAuthStore(state => state.isConnected);
29
- const useAutoConnectLoadingPrevious = useRef(false);
30
- const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
31
34
  const isAuthenticating = useAuthStore(state => state.isAuthenticating);
32
- const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
35
+ const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
33
36
  const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
34
- const { connect } = useConnect(partnerId, b3MainnetThirdWeb);
37
+ const setActiveWallet = useSetActiveWallet();
38
+ 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);
35
46
 
36
47
  const wallet = ecosystemWallet(ecosystemWalletId, {
37
48
  partnerId: partnerId,
38
49
  });
39
50
 
40
- const { isLoading: useAutoConnectLoading } = useAutoConnect({
41
- client,
42
- wallets: [wallet],
43
- onConnect: async wallet => {
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) => {
44
96
  setHasStartedConnecting(true);
45
97
 
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
46
107
  try {
47
- setIsConnected(true);
48
- if (!loginWithSiwe) {
49
- debug("Skipping SIWE login", { loginWithSiwe });
50
- setIsAuthenticated(true);
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
+ );
51
133
 
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
- }
134
+ const onConnect = useCallback(
135
+ async (wallet: Wallet) => {
136
+ debug("@@useAuthentication:onConnect", { wallet });
60
137
 
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
- }
138
+ try {
139
+ setHasStartedConnecting(true);
140
+ setIsConnected(true);
141
+ setIsAuthenticating(true);
142
+ await setActiveWallet(wallet);
143
+ await authenticateUser(wallet);
85
144
  } catch (error) {
86
- debug("Auto-connect authentication failed", { error });
145
+ debug("@@useAuthentication:onConnect:failed", { error });
87
146
  setIsAuthenticated(false);
88
- debug("setIsAuthenticating:false:4");
89
- setUser();
147
+ setUser(undefined);
148
+ } finally {
149
+ setIsAuthenticating(false);
90
150
  }
91
- setIsAuthenticating(false);
92
- },
93
- });
94
151
 
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]);
152
+ debug({
153
+ isAuthenticated,
154
+ isAuthenticating,
155
+ isConnected,
156
+ });
157
+ },
158
+ [
159
+ authenticateUser,
160
+ isAuthenticated,
161
+ isAuthenticating,
162
+ isConnected,
163
+ setActiveWallet,
164
+ setHasStartedConnecting,
165
+ setIsAuthenticated,
166
+ setIsAuthenticating,
167
+ setIsConnected,
168
+ setUser,
169
+ ],
170
+ );
122
171
 
123
172
  const logout = async (callback?: () => void) => {
124
173
  if (activeWallet) {
@@ -150,7 +199,23 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
150
199
  callback?.();
151
200
  };
152
201
 
153
- const isReady = isAuthenticated && !useAutoConnectLoading && !isAuthenticating;
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;
154
219
 
155
220
  return {
156
221
  logout,
@@ -160,7 +225,11 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
160
225
  isConnected,
161
226
  wallet,
162
227
  preAuthenticate,
163
- connect,
228
+ connect: onConnect,
164
229
  isAuthenticating,
230
+ onConnect,
231
+ user,
232
+ refetchUser: authenticateUser,
233
+ setUser,
165
234
  };
166
235
  }
@@ -1,4 +1,4 @@
1
- import { useConnect } from "@b3dotfun/sdk/global-account/react";
1
+ import { useB3, 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,7 +10,8 @@ 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(partnerId: string, chain?: Chain, onSuccess?: (account: Account) => void) {
13
+ export function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void) {
14
+ const { partnerId } = useB3();
14
15
  if (!chain) {
15
16
  throw new Error("Chain is required");
16
17
  }
@@ -0,0 +1,95 @@
1
+ import { Users } from "@b3dotfun/b3-api";
2
+ import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
3
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
4
+
5
+ const debug = debugB3React("useUserQuery");
6
+
7
+ const USER_QUERY_KEY = ["b3-user"];
8
+
9
+ /**
10
+ * Retrieves the user from localStorage
11
+ */
12
+ function getUserFromStorage(): Users | null {
13
+ if (typeof window === "undefined") {
14
+ return null;
15
+ }
16
+
17
+ try {
18
+ const storedUser = localStorage.getItem("b3-user");
19
+ return storedUser ? JSON.parse(storedUser) : null;
20
+ } catch (error) {
21
+ console.warn("Failed to restore user from localStorage:", error);
22
+ return null;
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Saves user to localStorage
28
+ */
29
+ function saveUserToStorage(user: Users | null) {
30
+ if (typeof window === "undefined") {
31
+ return;
32
+ }
33
+
34
+ if (user) {
35
+ localStorage.setItem("b3-user", JSON.stringify(user));
36
+ } else {
37
+ localStorage.removeItem("b3-user");
38
+ }
39
+ }
40
+
41
+ /**
42
+ * NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
43
+ *
44
+ * Custom hook to manage user state with react-query
45
+ * This allows for invalidation and refetching of user data
46
+ */
47
+ export function useUserQuery() {
48
+ const queryClient = useQueryClient();
49
+
50
+ // Query to get user data (primarily from cache/localStorage)
51
+ const { data: user } = useQuery<Users | null>({
52
+ queryKey: USER_QUERY_KEY,
53
+ queryFn: getUserFromStorage,
54
+ staleTime: Infinity, // User data doesn't go stale automatically
55
+ gcTime: Infinity, // Keep in cache indefinitely
56
+ initialData: getUserFromStorage,
57
+ });
58
+
59
+ // Mutation to update user
60
+ const setUserMutation = useMutation({
61
+ mutationFn: async (newUser: Users | undefined) => {
62
+ const userToSave = newUser ?? null;
63
+ saveUserToStorage(userToSave);
64
+ return userToSave;
65
+ },
66
+ onSuccess: data => {
67
+ queryClient.setQueryData(USER_QUERY_KEY, data);
68
+ debug("User updated", data);
69
+ },
70
+ });
71
+
72
+ // Helper function to set user (maintains backward compatibility)
73
+ const setUser = (newUser?: Users) => {
74
+ setUserMutation.mutate(newUser);
75
+ };
76
+
77
+ // Helper function to invalidate and refetch user
78
+ const refetchUser = async () => {
79
+ await queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
80
+ return queryClient.refetchQueries({ queryKey: USER_QUERY_KEY });
81
+ };
82
+
83
+ // Helper function to clear user
84
+ const clearUser = () => {
85
+ setUser(undefined);
86
+ };
87
+
88
+ return {
89
+ user: user ?? undefined,
90
+ setUser,
91
+ refetchUser,
92
+ clearUser,
93
+ queryKey: USER_QUERY_KEY,
94
+ };
95
+ }
@@ -0,0 +1,44 @@
1
+ import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
2
+ import { supportedChains } from "@b3dotfun/sdk/shared/constants/chains/supported";
3
+ import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
4
+ import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
5
+ import { useMemo } from "react";
6
+ import { http } from "viem";
7
+ import { createConfig } from "wagmi";
8
+
9
+ export function useWagmiConfig(partnerId: string, rpcUrls?: Record<number, string>) {
10
+ // Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
11
+ // when parent component passes new object references with same content
12
+ const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
13
+
14
+ const ecocystemConfig = useMemo(() => {
15
+ return {
16
+ ecosystemId: ecosystemWalletId,
17
+ partnerId: partnerId,
18
+ client,
19
+ };
20
+ }, [partnerId]);
21
+
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 = useMemo(() => {
27
+ const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
28
+
29
+ return createConfig({
30
+ chains: [supportedChains[0], ...supportedChains.slice(1)],
31
+ transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
32
+ connectors: [
33
+ inAppWalletConnector({
34
+ ...ecocystemConfig,
35
+ client,
36
+ }),
37
+ // injected(),
38
+ // coinbaseWallet({ appName: "HypeDuel" }),
39
+ ],
40
+ });
41
+ }, [rpcUrlsString, ecocystemConfig]);
42
+
43
+ return wagmiConfig;
44
+ }
@@ -35,8 +35,6 @@ 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;
40
38
  /** Whether to close the modal after successful login */
41
39
  closeAfterLogin?: boolean;
42
40
  /** Source of the sign-in request */
@@ -1,5 +1,4 @@
1
1
  // Export utility functions
2
- export * from "./auth-token";
3
2
  export * from "./cn";
4
3
  export * from "./formatNumber";
5
4
  export * from "./formatUsername";
@@ -1,6 +0,0 @@
1
- interface ErrorSectionProps {
2
- error?: Error | null;
3
- message?: string;
4
- }
5
- export declare function ErrorSection({ error, message }: ErrorSectionProps): import("react/jsx-runtime").JSX.Element | null;
6
- export {};
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorSection = ErrorSection;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const lucide_react_1 = require("lucide-react");
6
- function ErrorSection({ error, message }) {
7
- if (!error && !message) {
8
- return null;
9
- }
10
- const errorMessage = message || error?.message || "An error occurred";
11
- return ((0, jsx_runtime_1.jsxs)("div", { className: "error-section bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl px-4 py-2", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.CircleAlert, { className: "bg-as-red h-4 min-h-4 w-4 min-w-4 rounded-full p-0 text-sm font-medium text-white" }), (0, jsx_runtime_1.jsx)("div", { className: "text-as-red text-sm", children: errorMessage })] }));
12
- }
@@ -1,3 +0,0 @@
1
- export * from "./types";
2
- export * from "./services";
3
- export { getAuthToken } from "../shared/utils/auth-token";
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getAuthToken = void 0;
18
- // Export types
19
- __exportStar(require("./types"), exports);
20
- // Export services
21
- __exportStar(require("./services"), exports);
22
- // Re-export auth token getter from shared for convenience
23
- // Note: Auth token is managed by B3 Global Account authentication
24
- var auth_token_1 = require("../shared/utils/auth-token");
25
- Object.defineProperty(exports, "getAuthToken", { enumerable: true, get: function () { return auth_token_1.getAuthToken; } });
@@ -1 +0,0 @@
1
- export * from "./useNotifications";
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./useNotifications"), exports);
@@ -1,42 +0,0 @@
1
- import type { UserData } from "../../types";
2
- /**
3
- * React hook for managing B3 notifications
4
- * Automatically uses the authenticated user's ID from JWT
5
- *
6
- * @example
7
- * ```tsx
8
- * import { useNotifications } from '../../../notifications/react';
9
- *
10
- * function NotificationSettings() {
11
- * const { user, loading, connectEmail, connectTelegram, isEmailConnected } = useNotifications();
12
- *
13
- * if (loading) return <div>Loading...</div>;
14
- *
15
- * return (
16
- * <div>
17
- * {!isEmailConnected && (
18
- * <button onClick={() => connectEmail('user@example.com')}>
19
- * Connect Email
20
- * </button>
21
- * )}
22
- * <button onClick={connectTelegram}>Connect Telegram</button>
23
- * </div>
24
- * );
25
- * }
26
- * ```
27
- */
28
- export declare function useNotifications(): {
29
- user: UserData | null;
30
- loading: boolean;
31
- error: Error | null;
32
- refresh: () => Promise<void>;
33
- connectEmail: (email: string) => Promise<void>;
34
- connectTelegram: () => Promise<void>;
35
- updateChannel: (channelId: string, updates: {
36
- enabled?: boolean;
37
- }) => Promise<void>;
38
- deleteChannel: (channelId: string) => Promise<void>;
39
- isEmailConnected: boolean;
40
- isTelegramConnected: boolean;
41
- isDiscordConnected: boolean;
42
- };