@b3dotfun/sdk 0.0.47-alpha.1 → 0.0.47-alpha.3

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