@b3dotfun/sdk 0.0.47 → 0.0.48
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.
- package/README.md +225 -6
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +5 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -64
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +26 -21
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/cjs/global-account/react/components/B3Provider/types.js +2 -0
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
- package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +6 -22
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +10 -45
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -1
- package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +141 -81
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -1
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/cjs/global-account/react/hooks/useUserQuery.js +86 -0
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +42 -0
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/cjs/notifications/index.d.ts +3 -0
- package/dist/cjs/notifications/index.js +25 -0
- package/dist/cjs/notifications/react/hooks/index.d.ts +1 -0
- package/dist/cjs/notifications/react/hooks/index.js +17 -0
- package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/cjs/notifications/react/hooks/useNotifications.js +148 -0
- package/dist/cjs/notifications/react/index.d.ts +1 -0
- package/dist/cjs/notifications/react/index.js +17 -0
- package/dist/cjs/notifications/services/api.d.ts +67 -0
- package/dist/cjs/notifications/services/api.js +184 -0
- package/dist/cjs/notifications/services/index.d.ts +1 -0
- package/dist/cjs/notifications/services/index.js +17 -0
- package/dist/cjs/notifications/types/index.d.ts +51 -0
- package/dist/cjs/notifications/types/index.js +2 -0
- package/dist/cjs/shared/utils/auth-token.d.ts +7 -0
- package/dist/cjs/shared/utils/auth-token.js +17 -0
- package/dist/cjs/shared/utils/index.d.ts +1 -0
- package/dist/cjs/shared/utils/index.js +1 -0
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -3
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -68
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +24 -19
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/esm/global-account/react/components/B3Provider/types.js +2 -0
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +7 -23
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +4 -3
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +11 -46
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
- package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +3 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +144 -84
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +3 -2
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/esm/global-account/react/hooks/useUserQuery.js +83 -0
- package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/esm/global-account/react/hooks/useWagmiConfig.js +39 -0
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/esm/notifications/index.d.ts +3 -0
- package/dist/esm/notifications/index.js +7 -0
- package/dist/esm/notifications/react/hooks/index.d.ts +1 -0
- package/dist/esm/notifications/react/hooks/index.js +1 -0
- package/dist/esm/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/esm/notifications/react/hooks/useNotifications.js +145 -0
- package/dist/esm/notifications/react/index.d.ts +1 -0
- package/dist/esm/notifications/react/index.js +1 -0
- package/dist/esm/notifications/services/api.d.ts +67 -0
- package/dist/esm/notifications/services/api.js +179 -0
- package/dist/esm/notifications/services/index.d.ts +1 -0
- package/dist/esm/notifications/services/index.js +1 -0
- package/dist/esm/notifications/types/index.d.ts +51 -0
- package/dist/esm/shared/utils/auth-token.d.ts +7 -0
- package/dist/esm/shared/utils/auth-token.js +11 -0
- package/dist/esm/shared/utils/index.d.ts +1 -0
- package/dist/esm/shared/utils/index.js +1 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/types/notifications/index.d.ts +3 -0
- package/dist/types/notifications/react/hooks/index.d.ts +1 -0
- package/dist/types/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/types/notifications/react/index.d.ts +1 -0
- package/dist/types/notifications/services/api.d.ts +67 -0
- package/dist/types/notifications/services/index.d.ts +1 -0
- package/dist/types/notifications/types/index.d.ts +51 -0
- package/dist/types/shared/utils/auth-token.d.ts +7 -0
- package/dist/types/shared/utils/index.d.ts +1 -0
- package/package.json +23 -3
- package/src/anyspend/react/components/AnySpendCustom.tsx +5 -3
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +51 -35
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +28 -72
- package/src/global-account/react/components/B3Provider/types.ts +4 -0
- package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +2 -3
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +4 -23
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +4 -3
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +8 -46
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
- package/src/global-account/react/components/custom/ManageAccountButton.tsx +3 -2
- package/src/global-account/react/hooks/useAuthentication.ts +170 -89
- package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +3 -2
- package/src/global-account/react/hooks/useUserQuery.ts +95 -0
- package/src/global-account/react/hooks/useWagmiConfig.tsx +44 -0
- package/src/global-account/react/stores/useModalStore.ts +0 -2
- package/src/notifications/index.ts +9 -0
- package/src/notifications/react/hooks/index.ts +1 -0
- package/src/notifications/react/hooks/useNotifications.ts +153 -0
- package/src/notifications/react/index.ts +1 -0
- package/src/notifications/services/api.ts +217 -0
- package/src/notifications/services/index.ts +1 -0
- package/src/notifications/types/index.ts +58 -0
- package/src/shared/utils/auth-token.ts +13 -0
- package/src/shared/utils/index.ts +1 -0
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -245
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -243
- package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
- /package/dist/{cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts → esm/notifications/types/index.js} +0 -0
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
useB3,
|
|
6
6
|
useGetAllTWSigners,
|
|
7
7
|
useModalStore,
|
|
8
|
-
useSiwe,
|
|
9
8
|
} from "@b3dotfun/sdk/global-account/react";
|
|
10
9
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
11
10
|
import { useCallback, useEffect, useState } from "react";
|
|
@@ -31,19 +30,16 @@ export function SignInWithB3Flow({
|
|
|
31
30
|
sessionKeyAddress,
|
|
32
31
|
partnerId,
|
|
33
32
|
closeAfterLogin = false,
|
|
34
|
-
loginWithSiwe = false,
|
|
35
33
|
source = "signInWithB3Button",
|
|
36
34
|
signersEnabled = false,
|
|
37
35
|
}: SignInWithB3ModalProps) {
|
|
38
|
-
const {
|
|
36
|
+
const { automaticallySetFirstEoa } = useB3();
|
|
39
37
|
const [step, setStep] = useState<"login" | "permissions" | null>(source === "requestPermissions" ? null : "login");
|
|
40
38
|
const [sessionKeyAdded, setSessionKeyAdded] = useState(source === "requestPermissions" ? true : false);
|
|
41
39
|
const { setB3ModalContentType, setB3ModalOpen, isOpen } = useModalStore();
|
|
42
40
|
const account = useActiveAccount();
|
|
43
|
-
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
44
41
|
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
45
42
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
46
|
-
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
47
43
|
const [refetchCount, setRefetchCount] = useState(0);
|
|
48
44
|
const [refetchError, setRefetchError] = useState<string | null>(null);
|
|
49
45
|
const {
|
|
@@ -57,7 +53,6 @@ export function SignInWithB3Flow({
|
|
|
57
53
|
enabled: signersEnabled,
|
|
58
54
|
},
|
|
59
55
|
});
|
|
60
|
-
const { authenticate } = useSiwe();
|
|
61
56
|
const [refetchQueued, setRefetchQueued] = useState(false);
|
|
62
57
|
|
|
63
58
|
// Enhanced refetchSigners function that tracks number of attempts
|
|
@@ -175,13 +170,11 @@ export function SignInWithB3Flow({
|
|
|
175
170
|
sessionKeyAddress,
|
|
176
171
|
partnerId,
|
|
177
172
|
closeAfterLogin,
|
|
178
|
-
loginWithSiwe,
|
|
179
173
|
source: "requestPermissions",
|
|
180
174
|
});
|
|
181
175
|
}, [
|
|
182
176
|
chain,
|
|
183
177
|
closeAfterLogin,
|
|
184
|
-
loginWithSiwe,
|
|
185
178
|
onError,
|
|
186
179
|
onLoginSuccess,
|
|
187
180
|
onSessionKeySuccess,
|
|
@@ -193,20 +186,9 @@ export function SignInWithB3Flow({
|
|
|
193
186
|
|
|
194
187
|
const handleLoginSuccess = useCallback(
|
|
195
188
|
async (account: Account) => {
|
|
196
|
-
debug("Authenticating with B3 via SIWE");
|
|
197
|
-
setIsConnected(true);
|
|
198
|
-
if (loginWithSiwe) {
|
|
199
|
-
debug("setIsAuthenticating:true:1");
|
|
200
|
-
setIsAuthenticating(true);
|
|
201
|
-
const userAuth = await authenticate(account, partnerId);
|
|
202
|
-
setUser(userAuth.user);
|
|
203
|
-
}
|
|
204
|
-
debug("handleLoginSuccess:account", account);
|
|
205
189
|
onLoginSuccess?.(account);
|
|
206
|
-
debug("setIsAuthenticating:false:1");
|
|
207
|
-
setIsAuthenticating(false);
|
|
208
190
|
},
|
|
209
|
-
[
|
|
191
|
+
[onLoginSuccess],
|
|
210
192
|
);
|
|
211
193
|
|
|
212
194
|
useEffect(() => {
|
|
@@ -243,7 +225,7 @@ export function SignInWithB3Flow({
|
|
|
243
225
|
if (step === "login") {
|
|
244
226
|
// Custom strategy
|
|
245
227
|
if (strategies?.[0] === "privy") {
|
|
246
|
-
return <SignInWithB3Privy onSuccess={handleLoginSuccess}
|
|
228
|
+
return <SignInWithB3Privy onSuccess={handleLoginSuccess} chain={chain} />;
|
|
247
229
|
}
|
|
248
230
|
|
|
249
231
|
// Strategies are explicitly provided
|
|
@@ -251,7 +233,6 @@ export function SignInWithB3Flow({
|
|
|
251
233
|
return (
|
|
252
234
|
<LoginStepCustom
|
|
253
235
|
strategies={strategies}
|
|
254
|
-
partnerId={partnerId}
|
|
255
236
|
chain={chain}
|
|
256
237
|
onSuccess={handleLoginSuccess}
|
|
257
238
|
onError={onError}
|
|
@@ -261,7 +242,7 @@ export function SignInWithB3Flow({
|
|
|
261
242
|
}
|
|
262
243
|
|
|
263
244
|
// Default to handle all strategies we support
|
|
264
|
-
return <LoginStep
|
|
245
|
+
return <LoginStep chain={chain} onSuccess={handleLoginSuccess} onError={onError} />;
|
|
265
246
|
}
|
|
266
247
|
|
|
267
248
|
return null;
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Loading,
|
|
3
3
|
useAuthentication,
|
|
4
4
|
useAuthStore,
|
|
5
|
+
useB3,
|
|
5
6
|
useHandleConnectWithPrivy,
|
|
6
7
|
} from "@b3dotfun/sdk/global-account/react";
|
|
7
8
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
@@ -14,12 +15,12 @@ interface SignInWithB3PrivyProps {
|
|
|
14
15
|
onError?: (error: Error) => Promise<void>;
|
|
15
16
|
onSuccess: (account: Account) => Promise<void>;
|
|
16
17
|
accessToken?: string;
|
|
17
|
-
partnerId: string;
|
|
18
18
|
chain: Chain;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function SignInWithB3Privy({ onSuccess, onError,
|
|
22
|
-
const {
|
|
21
|
+
export function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps) {
|
|
22
|
+
const { partnerId } = useB3();
|
|
23
|
+
const { isLoading, connectTw, fullToken } = useHandleConnectWithPrivy(chain, onSuccess);
|
|
23
24
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
24
25
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
25
26
|
const { logout } = useAuthentication(partnerId);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useAuthentication,
|
|
1
|
+
import { useAuthentication, useB3, useQueryB3 } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
3
|
-
import { debug } from "@b3dotfun/sdk/shared/utils/debug";
|
|
4
3
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
5
4
|
import { Chain } from "thirdweb";
|
|
6
5
|
import { ConnectEmbed, darkTheme, lightTheme } from "thirdweb/react";
|
|
@@ -14,7 +13,6 @@ interface LoginStepProps {
|
|
|
14
13
|
/** Optional callback function called when an error occurs */
|
|
15
14
|
onError?: (error: Error) => Promise<void>;
|
|
16
15
|
/** Partner ID used for authentication */
|
|
17
|
-
partnerId: string;
|
|
18
16
|
/** Blockchain chain information */
|
|
19
17
|
chain: Chain;
|
|
20
18
|
/** Optional authentication strategy options */
|
|
@@ -56,15 +54,12 @@ export function LoginStepContainer({ children, partnerId }: LoginStepContainerPr
|
|
|
56
54
|
);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
export function LoginStep({ onSuccess,
|
|
57
|
+
export function LoginStep({ onSuccess, chain }: LoginStepProps) {
|
|
58
|
+
const { partnerId, theme } = useB3();
|
|
60
59
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
61
60
|
partnerId: partnerId,
|
|
62
61
|
});
|
|
63
|
-
|
|
64
|
-
const { theme } = useB3();
|
|
65
|
-
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
66
|
-
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
67
|
-
const { logout } = useAuthentication(partnerId);
|
|
62
|
+
const { onConnect } = useAuthentication(partnerId);
|
|
68
63
|
|
|
69
64
|
return (
|
|
70
65
|
<LoginStepContainer partnerId={partnerId}>
|
|
@@ -86,54 +81,21 @@ export function LoginStep({ onSuccess, onError, partnerId, chain }: LoginStepPro
|
|
|
86
81
|
},
|
|
87
82
|
})
|
|
88
83
|
}
|
|
89
|
-
autoConnect
|
|
90
84
|
style={{
|
|
91
85
|
width: "100%",
|
|
92
86
|
height: "100%",
|
|
93
87
|
border: 0,
|
|
94
88
|
}}
|
|
95
|
-
// TODO: Integrate with SIWE in useSIWE
|
|
96
|
-
// auth={{
|
|
97
|
-
// isLoggedIn: async (address) => {
|
|
98
|
-
// console.log("checking if logged in!", { address });
|
|
99
|
-
// return await isLoggedIn();
|
|
100
|
-
// },
|
|
101
|
-
// doLogin: async (params) => {
|
|
102
|
-
// console.log("logging in!");
|
|
103
|
-
// await login(params);
|
|
104
|
-
// },
|
|
105
|
-
// getLoginPayload: async ({ address }) =>
|
|
106
|
-
// generatePayload({ address }),
|
|
107
|
-
// doLogout: async () => {
|
|
108
|
-
// console.log("logging out!");
|
|
109
|
-
// await logout();
|
|
110
|
-
// },
|
|
111
|
-
// }}
|
|
112
89
|
header={{
|
|
113
90
|
title: "Sign in with B3",
|
|
114
91
|
titleIcon: "https://cdn.b3.fun/b3_logo.svg",
|
|
115
92
|
}}
|
|
116
93
|
className="b3-login-step"
|
|
117
94
|
onConnect={async wallet => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const account = wallet.getAccount();
|
|
123
|
-
if (!account) throw new Error("No account found");
|
|
124
|
-
|
|
125
|
-
await onSuccess(account);
|
|
126
|
-
setIsAuthenticated(true);
|
|
127
|
-
|
|
128
|
-
console.log("connected!", wallet.id);
|
|
129
|
-
} catch (error) {
|
|
130
|
-
await onError?.(error as Error);
|
|
131
|
-
await logout();
|
|
132
|
-
setIsAuthenticated(false);
|
|
133
|
-
} finally {
|
|
134
|
-
debug("setIsAuthenticating:false:6");
|
|
135
|
-
setIsAuthenticating(false);
|
|
136
|
-
}
|
|
95
|
+
await onConnect(wallet);
|
|
96
|
+
const account = wallet.getAccount();
|
|
97
|
+
if (!account) throw new Error("No account found");
|
|
98
|
+
await onSuccess(account);
|
|
137
99
|
}}
|
|
138
100
|
/>
|
|
139
101
|
</LoginStepContainer>
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
LoginStepContainer,
|
|
8
8
|
useAuthentication,
|
|
9
9
|
useAuthStore,
|
|
10
|
+
useB3,
|
|
10
11
|
useConnect,
|
|
11
12
|
WalletRow,
|
|
12
13
|
} from "@b3dotfun/sdk/global-account/react";
|
|
@@ -21,7 +22,6 @@ interface LoginStepCustomProps {
|
|
|
21
22
|
automaticallySetFirstEoa: boolean;
|
|
22
23
|
onSuccess: (account: Account) => Promise<void>;
|
|
23
24
|
onError?: (error: Error) => Promise<void>;
|
|
24
|
-
partnerId: string;
|
|
25
25
|
chain: Chain;
|
|
26
26
|
strategies: AllowedStrategy[];
|
|
27
27
|
maxInitialWallets?: number;
|
|
@@ -32,12 +32,12 @@ const debug = debugB3React("LoginStepCustom");
|
|
|
32
32
|
export function LoginStepCustom({
|
|
33
33
|
onSuccess,
|
|
34
34
|
onError,
|
|
35
|
-
partnerId,
|
|
36
35
|
chain,
|
|
37
36
|
strategies,
|
|
38
37
|
maxInitialWallets = 2,
|
|
39
38
|
automaticallySetFirstEoa,
|
|
40
39
|
}: LoginStepCustomProps) {
|
|
40
|
+
const { partnerId } = useB3();
|
|
41
41
|
const [isLoading, setIsLoading] = useState(false);
|
|
42
42
|
const [showAllWallets, setShowAllWallets] = useState(false);
|
|
43
43
|
const { connect } = useConnect(partnerId, chain);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Button, StyleRoot, useAuthentication, useModalStore } from "@b3dotfun/sdk/global-account/react";
|
|
1
|
+
import { Button, StyleRoot, useAuthentication, useB3, useModalStore } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { cn } from "@b3dotfun/sdk/shared/utils";
|
|
3
3
|
import { SignInWithB3Props } from "../SignInWithB3/SignInWithB3";
|
|
4
4
|
|
|
5
5
|
export function ManageAccountButton(props: SignInWithB3Props & { className?: string }) {
|
|
6
|
+
const { partnerId } = useB3();
|
|
6
7
|
const { setB3ModalOpen, setB3ModalContentType } = useModalStore();
|
|
7
|
-
const { isConnected } = useAuthentication(
|
|
8
|
+
const { isConnected } = useAuthentication(partnerId);
|
|
8
9
|
|
|
9
10
|
const handleClickManageAccount = () => {
|
|
10
11
|
setB3ModalContentType({
|
|
@@ -1,124 +1,185 @@
|
|
|
1
1
|
import app from "@b3dotfun/sdk/global-account/app";
|
|
2
2
|
import { authenticateWithB3JWT } from "@b3dotfun/sdk/global-account/bsmnt";
|
|
3
|
-
import { useAuthStore,
|
|
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 {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
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 "
|
|
13
|
-
import {
|
|
19
|
+
import { useAccount, useConnect, useSwitchAccount } 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
|
|
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
|
|
35
|
+
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
33
36
|
const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
|
|
34
|
-
const
|
|
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
|
+
const { switchAccount } = useSwitchAccount();
|
|
46
|
+
debug("@@activeWagmiAccount", activeWagmiAccount);
|
|
35
47
|
|
|
36
48
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
37
49
|
partnerId: partnerId,
|
|
38
50
|
});
|
|
39
51
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
const syncWagmi = useCallback(async () => {
|
|
53
|
+
function syncWagmiFunc() {
|
|
54
|
+
const connectors = getConnectors(wagmiConfig);
|
|
55
|
+
debug("@@syncWagmi", {
|
|
56
|
+
connectors,
|
|
57
|
+
wallets,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// For each that matchs a TW wallet on wallets, connect to the wagmi connector
|
|
61
|
+
// or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
|
|
62
|
+
connectors.forEach(async connector => {
|
|
63
|
+
const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
|
|
64
|
+
|
|
65
|
+
// If no TW wallet, do not prompt the user to connect
|
|
66
|
+
if (!twWallet) {
|
|
53
67
|
return;
|
|
54
68
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
69
|
+
|
|
70
|
+
// Metamask will prompt to connect, we can just switch accounts here.
|
|
71
|
+
if (connector.id === "io.metamask") {
|
|
72
|
+
return switchAccount({ connector });
|
|
59
73
|
}
|
|
60
74
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
debug("
|
|
80
|
-
|
|
81
|
-
// Authenticate on BSMNT with B3 JWT
|
|
82
|
-
const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
|
|
83
|
-
console.log("@@b3Jwt", b3Jwt);
|
|
75
|
+
if (
|
|
76
|
+
// If it's not an in-app wallet or it is the ecosystem wallet, connect
|
|
77
|
+
connector.id !== "in-app-wallet" ||
|
|
78
|
+
(connector.id === "in-app-wallet" && twWallet.id === ecosystemWalletId)
|
|
79
|
+
) {
|
|
80
|
+
try {
|
|
81
|
+
const options = {
|
|
82
|
+
wallet: twWallet, // the connected wallet
|
|
83
|
+
} satisfies ConnectionOptions;
|
|
84
|
+
debug("@@syncWagmi:connecting", { twWallet, connector });
|
|
85
|
+
connect({
|
|
86
|
+
connector,
|
|
87
|
+
...options,
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error("@@syncWagmi:error", error);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
debug("@@syncWagmi:not-connecting", connector);
|
|
84
94
|
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
syncWagmiFunc();
|
|
98
|
+
// wagmi config shouldn't change
|
|
99
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
|
+
}, [partnerId, wallets]);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
syncWagmi();
|
|
104
|
+
}, [wallets, syncWagmi]);
|
|
105
|
+
|
|
106
|
+
const authenticateUser = useCallback(
|
|
107
|
+
async (wallet?: Wallet) => {
|
|
108
|
+
setHasStartedConnecting(true);
|
|
109
|
+
|
|
110
|
+
const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
|
|
111
|
+
if (!account) {
|
|
112
|
+
throw new Error("No account found during auto-connect");
|
|
113
|
+
}
|
|
114
|
+
if (!account) {
|
|
115
|
+
throw new Error("No account found during auto-connect");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Try to re-authenticate first
|
|
119
|
+
try {
|
|
120
|
+
const userAuth = await app.reAuthenticate();
|
|
121
|
+
setUser(userAuth.user);
|
|
122
|
+
setIsAuthenticated(true);
|
|
123
|
+
setIsAuthenticating(false);
|
|
124
|
+
debug("Re-authenticated successfully", { userAuth });
|
|
125
|
+
|
|
126
|
+
// Authenticate on BSMNT with B3 JWT
|
|
127
|
+
const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
|
|
128
|
+
debug("@@b3Jwt", b3Jwt);
|
|
85
129
|
} catch (error) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
setUser();
|
|
130
|
+
// If re-authentication fails, try fresh authentication
|
|
131
|
+
debug("Re-authentication failed, attempting fresh authentication");
|
|
132
|
+
const userAuth = await authenticate(account, partnerId);
|
|
133
|
+
setUser(userAuth.user);
|
|
134
|
+
setIsAuthenticated(true);
|
|
135
|
+
setIsAuthenticating(false);
|
|
136
|
+
debug("Fresh authentication successful", { userAuth });
|
|
137
|
+
|
|
138
|
+
// Authenticate on BSMNT with B3 JWT
|
|
139
|
+
const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
|
|
140
|
+
debug("@@b3Jwt", b3Jwt);
|
|
90
141
|
}
|
|
91
|
-
setIsAuthenticating(false);
|
|
92
142
|
},
|
|
93
|
-
|
|
143
|
+
[activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting],
|
|
144
|
+
);
|
|
94
145
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
|
|
100
|
-
setIsAuthenticating(false);
|
|
101
|
-
}
|
|
102
|
-
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
103
|
-
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
|
|
146
|
+
const onConnect = useCallback(
|
|
147
|
+
async (wallet: Wallet) => {
|
|
148
|
+
debug("@@useAuthentication:onConnect", { wallet });
|
|
104
149
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
150
|
+
try {
|
|
151
|
+
setHasStartedConnecting(true);
|
|
152
|
+
setIsConnected(true);
|
|
153
|
+
setIsAuthenticating(true);
|
|
154
|
+
await setActiveWallet(wallet);
|
|
155
|
+
await authenticateUser(wallet);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
debug("@@useAuthentication:onConnect:failed", { error });
|
|
158
|
+
setIsAuthenticated(false);
|
|
159
|
+
setUser(undefined);
|
|
160
|
+
} finally {
|
|
161
|
+
setIsAuthenticating(false);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
debug({
|
|
165
|
+
isAuthenticated,
|
|
166
|
+
isAuthenticating,
|
|
167
|
+
isConnected,
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
[
|
|
171
|
+
authenticateUser,
|
|
172
|
+
isAuthenticated,
|
|
173
|
+
isAuthenticating,
|
|
174
|
+
isConnected,
|
|
175
|
+
setActiveWallet,
|
|
176
|
+
setHasStartedConnecting,
|
|
177
|
+
setIsAuthenticated,
|
|
178
|
+
setIsAuthenticating,
|
|
179
|
+
setIsConnected,
|
|
180
|
+
setUser,
|
|
181
|
+
],
|
|
182
|
+
);
|
|
122
183
|
|
|
123
184
|
const logout = async (callback?: () => void) => {
|
|
124
185
|
if (activeWallet) {
|
|
@@ -150,7 +211,23 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
150
211
|
callback?.();
|
|
151
212
|
};
|
|
152
213
|
|
|
153
|
-
const
|
|
214
|
+
const { isLoading: useAutoConnectLoading } = useAutoConnect({
|
|
215
|
+
client,
|
|
216
|
+
wallets: [wallet],
|
|
217
|
+
onConnect: onConnect,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* useAutoConnectLoading starts as false
|
|
222
|
+
*/
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
|
|
225
|
+
setIsAuthenticating(false);
|
|
226
|
+
}
|
|
227
|
+
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
228
|
+
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
|
|
229
|
+
|
|
230
|
+
const isReady = isAuthenticated && !isAuthenticating;
|
|
154
231
|
|
|
155
232
|
return {
|
|
156
233
|
logout,
|
|
@@ -160,7 +237,11 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
160
237
|
isConnected,
|
|
161
238
|
wallet,
|
|
162
239
|
preAuthenticate,
|
|
163
|
-
connect,
|
|
240
|
+
connect: onConnect,
|
|
164
241
|
isAuthenticating,
|
|
242
|
+
onConnect,
|
|
243
|
+
user,
|
|
244
|
+
refetchUser: authenticateUser,
|
|
245
|
+
setUser,
|
|
165
246
|
};
|
|
166
247
|
}
|
|
@@ -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(
|
|
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
|
}
|