@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.
- 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
|
@@ -9,10 +9,10 @@ import { useConnectedWallets, useSetActiveWallet, useWalletInfo } from "thirdweb
|
|
|
9
9
|
import { ManageAccountButton } from "../custom/ManageAccountButton.js";
|
|
10
10
|
export function SignIn(props) {
|
|
11
11
|
const { className } = props;
|
|
12
|
-
const { automaticallySetFirstEoa } = useB3();
|
|
12
|
+
const { automaticallySetFirstEoa, partnerId } = useB3();
|
|
13
13
|
const { wallet, address: globalAddress, ensName, connectedSmartWallet, connectedEOAWallet, isActiveSmartWallet, isActiveEOAWallet, smartWalletIcon, eoaWalletIcon, } = useAccountWallet();
|
|
14
14
|
const isMobile = useIsMobile();
|
|
15
|
-
const { logout } = useAuthentication(
|
|
15
|
+
const { logout } = useAuthentication(partnerId);
|
|
16
16
|
const onDisconnect = async () => {
|
|
17
17
|
await logout();
|
|
18
18
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Button, StyleRoot,
|
|
2
|
+
import { Button, StyleRoot, useAuthStore, useB3, useIsMobile, useModalStore, } from "../../../../global-account/react/index.js";
|
|
3
3
|
import { useEffect } from "react";
|
|
4
4
|
import { ManageAccountButton } from "../custom/ManageAccountButton.js";
|
|
5
5
|
import { Loading } from "../ui/Loading.js";
|
|
6
6
|
export function SignInWithB3(props) {
|
|
7
7
|
const { setB3ModalOpen, setB3ModalContentType, setEcoSystemAccountAddress } = useModalStore();
|
|
8
8
|
const { account } = useB3();
|
|
9
|
-
const { isAuthenticating, isAuthenticated } =
|
|
9
|
+
const { isAuthenticating, isAuthenticated } = useAuthStore();
|
|
10
10
|
const isMobile = useIsMobile();
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
if (account) {
|
|
@@ -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,
|
|
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,
|
|
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,
|
|
16
|
-
const {
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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, {
|
|
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,
|
|
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,
|
|
7
|
-
const {
|
|
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,
|
|
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,
|
|
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,
|
|
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 {
|
|
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
|
-
}),
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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,
|
|
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,
|
|
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(
|
|
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
|
|
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: (
|
|
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,
|
|
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 {
|
|
9
|
-
import {
|
|
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 "
|
|
13
|
-
import {
|
|
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
|
|
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
|
|
26
|
+
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
31
27
|
const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
|
|
32
|
-
const
|
|
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
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
66
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
setIsConnecting(false);
|
|
137
|
+
finally {
|
|
138
|
+
setIsAuthenticating(false);
|
|
113
139
|
}
|
|
114
|
-
|
|
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
|
|
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
|
}
|