@b3dotfun/sdk 0.0.47 → 0.0.48-alpha.0

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 (151) hide show
  1. package/README.md +225 -6
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +5 -3
  3. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  4. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -64
  5. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  6. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +26 -21
  7. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
  8. package/dist/cjs/global-account/react/components/B3Provider/types.js +2 -0
  9. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  10. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  11. package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  12. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  13. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
  14. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  15. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +6 -22
  16. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  17. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -2
  18. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  19. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +10 -45
  20. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  21. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -1
  22. package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -1
  23. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +51 -2
  24. package/dist/cjs/global-account/react/hooks/useAuthentication.js +141 -81
  25. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  26. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -1
  27. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +58 -0
  28. package/dist/cjs/global-account/react/hooks/useUserQuery.js +86 -0
  29. package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  30. package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +42 -0
  31. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
  32. package/dist/cjs/notifications/index.d.ts +3 -0
  33. package/dist/cjs/notifications/index.js +25 -0
  34. package/dist/cjs/notifications/react/hooks/index.d.ts +1 -0
  35. package/dist/cjs/notifications/react/hooks/index.js +17 -0
  36. package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +42 -0
  37. package/dist/cjs/notifications/react/hooks/useNotifications.js +148 -0
  38. package/dist/cjs/notifications/react/index.d.ts +1 -0
  39. package/dist/cjs/notifications/react/index.js +17 -0
  40. package/dist/cjs/notifications/services/api.d.ts +67 -0
  41. package/dist/cjs/notifications/services/api.js +184 -0
  42. package/dist/cjs/notifications/services/index.d.ts +1 -0
  43. package/dist/cjs/notifications/services/index.js +17 -0
  44. package/dist/cjs/notifications/types/index.d.ts +51 -0
  45. package/dist/cjs/notifications/types/index.js +2 -0
  46. package/dist/cjs/shared/utils/auth-token.d.ts +7 -0
  47. package/dist/cjs/shared/utils/auth-token.js +17 -0
  48. package/dist/cjs/shared/utils/index.d.ts +1 -0
  49. package/dist/cjs/shared/utils/index.js +1 -0
  50. package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -3
  51. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  52. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -68
  53. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  54. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +24 -19
  55. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
  56. package/dist/esm/global-account/react/components/B3Provider/types.js +2 -0
  57. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  58. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  59. package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  60. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  61. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
  62. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  63. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +7 -23
  64. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  65. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +4 -3
  66. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  67. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +11 -46
  68. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  69. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
  70. package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +3 -2
  71. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +51 -2
  72. package/dist/esm/global-account/react/hooks/useAuthentication.js +144 -84
  73. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  74. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +3 -2
  75. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +58 -0
  76. package/dist/esm/global-account/react/hooks/useUserQuery.js +83 -0
  77. package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  78. package/dist/esm/global-account/react/hooks/useWagmiConfig.js +39 -0
  79. package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
  80. package/dist/esm/notifications/index.d.ts +3 -0
  81. package/dist/esm/notifications/index.js +7 -0
  82. package/dist/esm/notifications/react/hooks/index.d.ts +1 -0
  83. package/dist/esm/notifications/react/hooks/index.js +1 -0
  84. package/dist/esm/notifications/react/hooks/useNotifications.d.ts +42 -0
  85. package/dist/esm/notifications/react/hooks/useNotifications.js +145 -0
  86. package/dist/esm/notifications/react/index.d.ts +1 -0
  87. package/dist/esm/notifications/react/index.js +1 -0
  88. package/dist/esm/notifications/services/api.d.ts +67 -0
  89. package/dist/esm/notifications/services/api.js +179 -0
  90. package/dist/esm/notifications/services/index.d.ts +1 -0
  91. package/dist/esm/notifications/services/index.js +1 -0
  92. package/dist/esm/notifications/types/index.d.ts +51 -0
  93. package/dist/esm/shared/utils/auth-token.d.ts +7 -0
  94. package/dist/esm/shared/utils/auth-token.js +11 -0
  95. package/dist/esm/shared/utils/index.d.ts +1 -0
  96. package/dist/esm/shared/utils/index.js +1 -0
  97. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  98. package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  99. package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
  100. package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  101. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  102. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  103. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  104. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  105. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +51 -2
  106. package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  107. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +58 -0
  108. package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  109. package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
  110. package/dist/types/notifications/index.d.ts +3 -0
  111. package/dist/types/notifications/react/hooks/index.d.ts +1 -0
  112. package/dist/types/notifications/react/hooks/useNotifications.d.ts +42 -0
  113. package/dist/types/notifications/react/index.d.ts +1 -0
  114. package/dist/types/notifications/services/api.d.ts +67 -0
  115. package/dist/types/notifications/services/index.d.ts +1 -0
  116. package/dist/types/notifications/types/index.d.ts +51 -0
  117. package/dist/types/shared/utils/auth-token.d.ts +7 -0
  118. package/dist/types/shared/utils/index.d.ts +1 -0
  119. package/package.json +23 -3
  120. package/src/anyspend/react/components/AnySpendCustom.tsx +5 -3
  121. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +51 -35
  122. package/src/global-account/react/components/B3Provider/B3Provider.tsx +28 -72
  123. package/src/global-account/react/components/B3Provider/types.ts +4 -0
  124. package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +2 -3
  125. package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
  126. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
  127. package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
  128. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +4 -23
  129. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +4 -3
  130. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +8 -46
  131. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
  132. package/src/global-account/react/components/custom/ManageAccountButton.tsx +3 -2
  133. package/src/global-account/react/hooks/useAuthentication.ts +170 -89
  134. package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +3 -2
  135. package/src/global-account/react/hooks/useUserQuery.ts +95 -0
  136. package/src/global-account/react/hooks/useWagmiConfig.tsx +44 -0
  137. package/src/global-account/react/stores/useModalStore.ts +0 -2
  138. package/src/notifications/index.ts +9 -0
  139. package/src/notifications/react/hooks/index.ts +1 -0
  140. package/src/notifications/react/hooks/useNotifications.ts +153 -0
  141. package/src/notifications/react/index.ts +1 -0
  142. package/src/notifications/services/api.ts +217 -0
  143. package/src/notifications/services/index.ts +1 -0
  144. package/src/notifications/types/index.ts +58 -0
  145. package/src/shared/utils/auth-token.ts +13 -0
  146. package/src/shared/utils/index.ts +1 -0
  147. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -245
  148. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
  149. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -243
  150. package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
  151. /package/dist/{cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts → esm/notifications/types/index.js} +0 -0
@@ -3,4 +3,4 @@ import { SignInWithB3ModalProps } from "../../../../global-account/react";
3
3
  * Component that manages the authentication flow for Sign In With B3
4
4
  * Handles different login providers, authentication steps, and session key management
5
5
  */
6
- export declare function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin, loginWithSiwe, source, signersEnabled, }: SignInWithB3ModalProps): import("react/jsx-runtime").JSX.Element | null;
6
+ export declare function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin, source, signersEnabled, }: SignInWithB3ModalProps): import("react/jsx-runtime").JSX.Element | null;
@@ -15,16 +15,14 @@ const MAX_REFETCH_ATTEMPTS = 20;
15
15
  * Component that manages the authentication flow for Sign In With B3
16
16
  * Handles different login providers, authentication steps, and session key management
17
17
  */
18
- function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, loginWithSiwe = false, source = "signInWithB3Button", signersEnabled = false, }) {
19
- const { setUser, automaticallySetFirstEoa } = (0, react_1.useB3)();
18
+ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, source = "signInWithB3Button", signersEnabled = false, }) {
19
+ const { automaticallySetFirstEoa } = (0, react_1.useB3)();
20
20
  const [step, setStep] = (0, react_2.useState)(source === "requestPermissions" ? null : "login");
21
21
  const [sessionKeyAdded, setSessionKeyAdded] = (0, react_2.useState)(source === "requestPermissions" ? true : false);
22
22
  const { setB3ModalContentType, setB3ModalOpen, isOpen } = (0, react_1.useModalStore)();
23
23
  const account = (0, react_3.useActiveAccount)();
24
- const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
25
24
  const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
26
25
  const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
27
- const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
28
26
  const [refetchCount, setRefetchCount] = (0, react_2.useState)(0);
29
27
  const [refetchError, setRefetchError] = (0, react_2.useState)(null);
30
28
  const { data: signers, refetch: refetchSigners, isFetching: isFetchingSigners, } = (0, react_1.useGetAllTWSigners)({
@@ -34,7 +32,6 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
34
32
  enabled: signersEnabled,
35
33
  },
36
34
  });
37
- const { authenticate } = (0, react_1.useSiwe)();
38
35
  const [refetchQueued, setRefetchQueued] = (0, react_2.useState)(false);
39
36
  // Enhanced refetchSigners function that tracks number of attempts
40
37
  const handleRefetchSigners = (0, react_2.useCallback)(() => {
@@ -145,13 +142,11 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
145
142
  sessionKeyAddress,
146
143
  partnerId,
147
144
  closeAfterLogin,
148
- loginWithSiwe,
149
145
  source: "requestPermissions",
150
146
  });
151
147
  }, [
152
148
  chain,
153
149
  closeAfterLogin,
154
- loginWithSiwe,
155
150
  onError,
156
151
  onLoginSuccess,
157
152
  onSessionKeySuccess,
@@ -161,19 +156,8 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
161
156
  strategies,
162
157
  ]);
163
158
  const handleLoginSuccess = (0, react_2.useCallback)(async (account) => {
164
- debug("Authenticating with B3 via SIWE");
165
- setIsConnected(true);
166
- if (loginWithSiwe) {
167
- debug("setIsAuthenticating:true:1");
168
- setIsAuthenticating(true);
169
- const userAuth = await authenticate(account, partnerId);
170
- setUser(userAuth.user);
171
- }
172
- debug("handleLoginSuccess:account", account);
173
159
  onLoginSuccess?.(account);
174
- debug("setIsAuthenticating:false:1");
175
- setIsAuthenticating(false);
176
- }, [loginWithSiwe, onLoginSuccess, authenticate, partnerId, setUser, setIsConnected, setIsAuthenticating]);
160
+ }, [onLoginSuccess]);
177
161
  (0, react_2.useEffect)(() => {
178
162
  if (step === "permissions") {
179
163
  setB3ModalContentType({
@@ -195,14 +179,14 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
195
179
  if (step === "login") {
196
180
  // Custom strategy
197
181
  if (strategies?.[0] === "privy") {
198
- return (0, jsx_runtime_1.jsx)(SignInWithB3Privy_1.SignInWithB3Privy, { onSuccess: handleLoginSuccess, partnerId: partnerId, chain: chain });
182
+ return (0, jsx_runtime_1.jsx)(SignInWithB3Privy_1.SignInWithB3Privy, { onSuccess: handleLoginSuccess, chain: chain });
199
183
  }
200
184
  // Strategies are explicitly provided
201
185
  if (strategies) {
202
- return ((0, jsx_runtime_1.jsx)(LoginStepCustom_1.LoginStepCustom, { strategies: strategies, partnerId: partnerId, chain: chain, onSuccess: handleLoginSuccess, onError: onError, automaticallySetFirstEoa: !!automaticallySetFirstEoa }));
186
+ return ((0, jsx_runtime_1.jsx)(LoginStepCustom_1.LoginStepCustom, { strategies: strategies, chain: chain, onSuccess: handleLoginSuccess, onError: onError, automaticallySetFirstEoa: !!automaticallySetFirstEoa }));
203
187
  }
204
188
  // Default to handle all strategies we support
205
- return (0, jsx_runtime_1.jsx)(LoginStep_1.LoginStep, { partnerId: partnerId, chain: chain, onSuccess: handleLoginSuccess, onError: onError });
189
+ return (0, jsx_runtime_1.jsx)(LoginStep_1.LoginStep, { chain: chain, onSuccess: handleLoginSuccess, onError: onError });
206
190
  }
207
191
  return null;
208
192
  }
@@ -4,8 +4,7 @@ interface SignInWithB3PrivyProps {
4
4
  onError?: (error: Error) => Promise<void>;
5
5
  onSuccess: (account: Account) => Promise<void>;
6
6
  accessToken?: string;
7
- partnerId: string;
8
7
  chain: Chain;
9
8
  }
10
- export declare function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }: SignInWithB3PrivyProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps): import("react/jsx-runtime").JSX.Element;
11
10
  export {};
@@ -6,8 +6,9 @@ const react_1 = require("../../../../global-account/react");
6
6
  const debug_1 = require("../../../../shared/utils/debug");
7
7
  const react_2 = require("react");
8
8
  const debug = (0, debug_1.debugB3React)("SignInWithB3Privy");
9
- function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }) {
10
- const { isLoading, connectTw, fullToken } = (0, react_1.useHandleConnectWithPrivy)(partnerId, chain, onSuccess);
9
+ function SignInWithB3Privy({ onSuccess, onError, chain }) {
10
+ const { partnerId } = (0, react_1.useB3)();
11
+ const { isLoading, connectTw, fullToken } = (0, react_1.useHandleConnectWithPrivy)(chain, onSuccess);
11
12
  const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
12
13
  const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
13
14
  const { logout } = (0, react_1.useAuthentication)(partnerId);
@@ -9,7 +9,6 @@ interface LoginStepProps {
9
9
  /** Optional callback function called when an error occurs */
10
10
  onError?: (error: Error) => Promise<void>;
11
11
  /** Partner ID used for authentication */
12
- partnerId: string;
13
12
  /** Blockchain chain information */
14
13
  chain: Chain;
15
14
  /** Optional authentication strategy options */
@@ -20,5 +19,5 @@ interface LoginStepContainerProps {
20
19
  partnerId?: string;
21
20
  }
22
21
  export declare function LoginStepContainer({ children, partnerId }: LoginStepContainerProps): import("react/jsx-runtime").JSX.Element;
23
- export declare function LoginStep({ onSuccess, onError, partnerId, chain }: LoginStepProps): import("react/jsx-runtime").JSX.Element;
22
+ export declare function LoginStep({ onSuccess, chain }: LoginStepProps): import("react/jsx-runtime").JSX.Element;
24
23
  export {};
@@ -5,7 +5,6 @@ exports.LoginStep = LoginStep;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const react_1 = require("../../../../../global-account/react");
7
7
  const constants_1 = require("../../../../../shared/constants");
8
- const debug_1 = require("../../../../../shared/utils/debug");
9
8
  const thirdweb_1 = require("../../../../../shared/utils/thirdweb");
10
9
  const react_2 = require("thirdweb/react");
11
10
  const wallets_1 = require("thirdweb/wallets");
@@ -19,14 +18,12 @@ function LoginStepContainer({ children, partnerId }) {
19
18
  const partnerLogo = partner?.data?.[0]?.loginCustomization?.logoUrl;
20
19
  return ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col items-center justify-center pt-6", children: [partnerLogo && ((0, jsx_runtime_1.jsx)("img", { src: partnerLogo, alt: "Partner Logo", className: "partner-logo mb-6 h-12 w-auto object-contain" })), children, (0, jsx_runtime_1.jsxs)("h2", { className: "mt-6 flex items-center gap-2 text-lg font-bold", children: ["Powered by", (0, jsx_runtime_1.jsx)("img", { alt: "B3 Logo", className: "h-5", src: "https://cdn.b3.fun/b3_logo.svg" }), "Connect"] })] }));
21
20
  }
22
- function LoginStep({ onSuccess, onError, partnerId, chain }) {
21
+ function LoginStep({ onSuccess, chain }) {
22
+ const { partnerId, theme } = (0, react_1.useB3)();
23
23
  const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
24
24
  partnerId: partnerId,
25
25
  });
26
- const { theme } = (0, react_1.useB3)();
27
- const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
28
- const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
29
- const { logout } = (0, react_1.useAuthentication)(partnerId);
26
+ const { onConnect } = (0, react_1.useAuthentication)(partnerId);
30
27
  return ((0, jsx_runtime_1.jsx)(LoginStepContainer, { partnerId: partnerId, children: (0, jsx_runtime_1.jsx)(react_2.ConnectEmbed, { showThirdwebBranding: false, client: thirdweb_1.client, chain: chain, wallets: [wallet], theme: theme === "light"
31
28
  ? (0, react_2.lightTheme)({
32
29
  colors: {
@@ -37,50 +34,18 @@ function LoginStep({ onSuccess, onError, partnerId, chain }) {
37
34
  colors: {
38
35
  modalBg: "hsl(var(--b3-react-background))",
39
36
  },
40
- }), autoConnect: true, style: {
37
+ }), style: {
41
38
  width: "100%",
42
39
  height: "100%",
43
40
  border: 0,
44
- },
45
- // TODO: Integrate with SIWE in useSIWE
46
- // auth={{
47
- // isLoggedIn: async (address) => {
48
- // console.log("checking if logged in!", { address });
49
- // return await isLoggedIn();
50
- // },
51
- // doLogin: async (params) => {
52
- // console.log("logging in!");
53
- // await login(params);
54
- // },
55
- // getLoginPayload: async ({ address }) =>
56
- // generatePayload({ address }),
57
- // doLogout: async () => {
58
- // console.log("logging out!");
59
- // await logout();
60
- // },
61
- // }}
62
- header: {
41
+ }, header: {
63
42
  title: "Sign in with B3",
64
43
  titleIcon: "https://cdn.b3.fun/b3_logo.svg",
65
44
  }, className: "b3-login-step", onConnect: async (wallet) => {
66
- try {
67
- setIsAuthenticating(true);
68
- (0, debug_1.debug)("setIsAuthenticating:true:6");
69
- const account = wallet.getAccount();
70
- if (!account)
71
- throw new Error("No account found");
72
- await onSuccess(account);
73
- setIsAuthenticated(true);
74
- console.log("connected!", wallet.id);
75
- }
76
- catch (error) {
77
- await onError?.(error);
78
- await logout();
79
- setIsAuthenticated(false);
80
- }
81
- finally {
82
- (0, debug_1.debug)("setIsAuthenticating:false:6");
83
- setIsAuthenticating(false);
84
- }
45
+ await onConnect(wallet);
46
+ const account = wallet.getAccount();
47
+ if (!account)
48
+ throw new Error("No account found");
49
+ await onSuccess(account);
85
50
  } }) }));
86
51
  }
@@ -5,10 +5,9 @@ interface LoginStepCustomProps {
5
5
  automaticallySetFirstEoa: boolean;
6
6
  onSuccess: (account: Account) => Promise<void>;
7
7
  onError?: (error: Error) => Promise<void>;
8
- partnerId: string;
9
8
  chain: Chain;
10
9
  strategies: AllowedStrategy[];
11
10
  maxInitialWallets?: number;
12
11
  }
13
- export declare function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategies, maxInitialWallets, automaticallySetFirstEoa, }: LoginStepCustomProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function LoginStepCustom({ onSuccess, onError, chain, strategies, maxInitialWallets, automaticallySetFirstEoa, }: LoginStepCustomProps): import("react/jsx-runtime").JSX.Element;
14
13
  export {};
@@ -9,7 +9,8 @@ const react_2 = require("react");
9
9
  const react_3 = require("thirdweb/react");
10
10
  const wallets_1 = require("thirdweb/wallets");
11
11
  const debug = (0, debug_1.debugB3React)("LoginStepCustom");
12
- function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategies, maxInitialWallets = 2, automaticallySetFirstEoa, }) {
12
+ function LoginStepCustom({ onSuccess, onError, chain, strategies, maxInitialWallets = 2, automaticallySetFirstEoa, }) {
13
+ const { partnerId } = (0, react_1.useB3)();
13
14
  const [isLoading, setIsLoading] = (0, react_2.useState)(false);
14
15
  const [showAllWallets, setShowAllWallets] = (0, react_2.useState)(false);
15
16
  const { connect } = (0, react_1.useConnect)(partnerId, chain);
@@ -5,8 +5,9 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("../../../../global-account/react");
6
6
  const utils_1 = require("../../../../shared/utils");
7
7
  function ManageAccountButton(props) {
8
+ const { partnerId } = (0, react_1.useB3)();
8
9
  const { setB3ModalOpen, setB3ModalContentType } = (0, react_1.useModalStore)();
9
- const { isConnected } = (0, react_1.useAuthentication)(props.partnerId, props.loginWithSiwe);
10
+ const { isConnected } = (0, react_1.useAuthentication)(partnerId);
10
11
  const handleClickManageAccount = () => {
11
12
  setB3ModalContentType({
12
13
  ...props,
@@ -1,5 +1,6 @@
1
+ import { Wallet } from "thirdweb/wallets";
1
2
  import { preAuthenticate } from "thirdweb/wallets/in-app";
2
- export declare function useAuthentication(partnerId: string, loginWithSiwe?: boolean): {
3
+ export declare function useAuthentication(partnerId: string): {
3
4
  logout: (callback?: () => void) => Promise<void>;
4
5
  isAuthenticated: boolean;
5
6
  isReady: boolean;
@@ -7,6 +8,54 @@ export declare function useAuthentication(partnerId: string, loginWithSiwe?: boo
7
8
  isConnected: boolean;
8
9
  wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
9
10
  preAuthenticate: typeof preAuthenticate;
10
- connect: (strategyOptions?: import("thirdweb/wallets").SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
11
+ connect: (wallet: Wallet) => Promise<void>;
11
12
  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;
12
61
  };
@@ -8,116 +8,158 @@ 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");
12
11
  const debug_1 = require("../../../shared/utils/debug");
13
12
  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 useConnect_1 = require("./useConnect");
19
- const useSiwe_1 = require("./useSiwe");
18
+ const wagmi_1 = require("wagmi");
19
+ const useUserQuery_1 = require("./useUserQuery");
20
+ const useWagmiConfig_1 = require("./useWagmiConfig");
20
21
  const debug = (0, debug_1.debugB3React)("useAuthentication");
21
- function useAuthentication(partnerId, loginWithSiwe) {
22
+ function useAuthentication(partnerId) {
22
23
  const { disconnect } = (0, react_3.useDisconnect)();
23
24
  const wallets = (0, react_3.useConnectedWallets)();
24
25
  const activeWallet = (0, react_3.useActiveWallet)();
25
- const { authenticate } = (0, useSiwe_1.useSiwe)();
26
- const { setUser } = (0, react_1.useB3)();
27
26
  const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
28
27
  const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
29
- const setIsConnecting = (0, react_1.useAuthStore)(state => state.setIsConnecting);
30
28
  const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
31
29
  const isConnecting = (0, react_1.useAuthStore)(state => state.isConnecting);
32
30
  const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
33
- const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
34
- const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
35
31
  const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
36
- const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
32
+ const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
37
33
  const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
38
- const { connect } = (0, useConnect_1.useConnect)(partnerId, supported_1.b3MainnetThirdWeb);
34
+ const setActiveWallet = (0, react_3.useSetActiveWallet)();
35
+ 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
+ const { switchAccount } = (0, wagmi_1.useSwitchAccount)();
43
+ debug("@@activeWagmiAccount", activeWagmiAccount);
39
44
  const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
40
45
  partnerId: partnerId,
41
46
  });
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);
47
+ const syncWagmi = (0, react_2.useCallback)(async () => {
48
+ function syncWagmiFunc() {
49
+ const connectors = (0, core_1.getConnectors)(wagmiConfig);
50
+ debug("@@syncWagmi", {
51
+ connectors,
52
+ wallets,
53
+ });
54
+ // For each that matchs a TW wallet on wallets, connect to the wagmi connector
55
+ // or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
56
+ connectors.forEach(async (connector) => {
57
+ const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
58
+ // If no TW wallet, do not prompt the user to connect
59
+ if (!twWallet) {
53
60
  return;
54
61
  }
55
- debug("setIsAuthenticating:true:4");
56
- const account = await wallet.getAccount();
57
- if (!account) {
58
- throw new Error("No account found during auto-connect");
62
+ // Metamask will prompt to connect, we can just switch accounts here.
63
+ if (connector.id === "io.metamask") {
64
+ return switchAccount({ connector });
59
65
  }
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);
66
+ if (
67
+ // If it's not an in-app wallet or it is the ecosystem wallet, connect
68
+ connector.id !== "in-app-wallet" ||
69
+ (connector.id === "in-app-wallet" && twWallet.id === constants_1.ecosystemWalletId)) {
70
+ try {
71
+ const options = {
72
+ wallet: twWallet, // the connected wallet
73
+ };
74
+ debug("@@syncWagmi:connecting", { twWallet, connector });
75
+ connect({
76
+ connector,
77
+ ...options,
78
+ });
79
+ }
80
+ catch (error) {
81
+ console.error("@@syncWagmi:error", error);
82
+ }
70
83
  }
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);
84
+ else {
85
+ debug("@@syncWagmi:not-connecting", connector);
82
86
  }
83
- }
84
- catch (error) {
85
- debug("Auto-connect authentication failed", { error });
86
- setIsAuthenticated(false);
87
- debug("setIsAuthenticating:false:4");
88
- setUser();
89
- }
90
- setIsAuthenticating(false);
91
- },
92
- });
93
- /**
94
- * useAutoConnectLoading starts as false
95
- */
87
+ });
88
+ }
89
+ syncWagmiFunc();
90
+ // wagmi config shouldn't change
91
+ // eslint-disable-next-line react-hooks/exhaustive-deps
92
+ }, [partnerId, wallets]);
96
93
  (0, react_2.useEffect)(() => {
97
- if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
94
+ syncWagmi();
95
+ }, [wallets, syncWagmi]);
96
+ const authenticateUser = (0, react_2.useCallback)(async (wallet) => {
97
+ setHasStartedConnecting(true);
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
+ // Try to re-authenticate first
106
+ try {
107
+ const userAuth = await app_1.default.reAuthenticate();
108
+ setUser(userAuth.user);
109
+ setIsAuthenticated(true);
98
110
  setIsAuthenticating(false);
111
+ debug("Re-authenticated successfully", { userAuth });
112
+ // Authenticate on BSMNT with B3 JWT
113
+ const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
114
+ debug("@@b3Jwt", b3Jwt);
99
115
  }
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);
116
+ catch (error) {
117
+ // If re-authentication fails, try fresh authentication
118
+ debug("Re-authentication failed, attempting fresh authentication");
119
+ const userAuth = await authenticate(account, partnerId);
120
+ setUser(userAuth.user);
121
+ setIsAuthenticated(true);
122
+ setIsAuthenticating(false);
123
+ debug("Fresh authentication successful", { userAuth });
124
+ // Authenticate on BSMNT with B3 JWT
125
+ const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
126
+ debug("@@b3Jwt", b3Jwt);
127
+ }
128
+ }, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
129
+ const onConnect = (0, react_2.useCallback)(async (wallet) => {
130
+ debug("@@useAuthentication:onConnect", { wallet });
131
+ try {
132
+ setHasStartedConnecting(true);
133
+ setIsConnected(true);
134
+ setIsAuthenticating(true);
135
+ await setActiveWallet(wallet);
136
+ await authenticateUser(wallet);
106
137
  }
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);
138
+ catch (error) {
139
+ debug("@@useAuthentication:onConnect:failed", { error });
140
+ setIsAuthenticated(false);
141
+ setUser(undefined);
115
142
  }
116
- else {
117
- debug("setIsAuthenticating:false:5b");
118
- setIsConnecting(false);
143
+ finally {
144
+ setIsAuthenticating(false);
119
145
  }
120
- }, [useAutoConnectLoading, isAuthenticated, setIsConnecting, setIsConnected]);
146
+ debug({
147
+ isAuthenticated,
148
+ isAuthenticating,
149
+ isConnected,
150
+ });
151
+ }, [
152
+ authenticateUser,
153
+ isAuthenticated,
154
+ isAuthenticating,
155
+ isConnected,
156
+ setActiveWallet,
157
+ setHasStartedConnecting,
158
+ setIsAuthenticated,
159
+ setIsAuthenticating,
160
+ setIsConnected,
161
+ setUser,
162
+ ]);
121
163
  const logout = async (callback) => {
122
164
  if (activeWallet) {
123
165
  debug("@@logout:activeWallet", activeWallet);
@@ -143,7 +185,21 @@ function useAuthentication(partnerId, loginWithSiwe) {
143
185
  setUser();
144
186
  callback?.();
145
187
  };
146
- const isReady = isAuthenticated && !useAutoConnectLoading && !isAuthenticating;
188
+ const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
189
+ client: thirdweb_1.client,
190
+ wallets: [wallet],
191
+ onConnect: onConnect,
192
+ });
193
+ /**
194
+ * useAutoConnectLoading starts as false
195
+ */
196
+ (0, react_2.useEffect)(() => {
197
+ if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
198
+ setIsAuthenticating(false);
199
+ }
200
+ useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
201
+ }, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
202
+ const isReady = isAuthenticated && !isAuthenticating;
147
203
  return {
148
204
  logout,
149
205
  isAuthenticated,
@@ -152,7 +208,11 @@ function useAuthentication(partnerId, loginWithSiwe) {
152
208
  isConnected,
153
209
  wallet,
154
210
  preAuthenticate: in_app_1.preAuthenticate,
155
- connect,
211
+ connect: onConnect,
156
212
  isAuthenticating,
213
+ onConnect,
214
+ user,
215
+ refetchUser: authenticateUser,
216
+ setUser,
157
217
  };
158
218
  }
@@ -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(partnerId: string, chain?: Chain, onSuccess?: (account: Account) => void): {
7
+ export declare function useHandleConnectWithPrivy(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,7 +10,8 @@ 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(partnerId, chain, onSuccess) {
13
+ function useHandleConnectWithPrivy(chain, onSuccess) {
14
+ const { partnerId } = (0, react_1.useB3)();
14
15
  if (!chain) {
15
16
  throw new Error("Chain is required");
16
17
  }