@b3dotfun/sdk 0.0.19-alpha.0 → 0.0.19-alpha.2
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/dist/cjs/anyspend/react/components/AnySpend.js +0 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +0 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnrampPayment.js +0 -1
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +0 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +0 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +0 -4
- package/dist/cjs/anyspend/react/hooks/useGeoOnrampOptions.js +1 -1
- package/dist/cjs/anyspend/react/hooks/useStripeSupport.d.ts +1 -1
- package/dist/cjs/anyspend/react/hooks/useStripeSupport.js +4 -4
- package/dist/cjs/anyspend/services/anyspend.d.ts +1 -1
- package/dist/cjs/anyspend/services/anyspend.js +1 -2
- package/dist/cjs/anyspend/types/api.d.ts +1 -16
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +18 -11
- package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -0
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +12 -1
- package/dist/cjs/global-account/react/stores/useAuthStore.d.ts +4 -0
- package/dist/cjs/global-account/react/stores/useAuthStore.js +4 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +0 -1
- package/dist/esm/anyspend/react/components/common/PanelOnrampPayment.js +0 -1
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +0 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +0 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +0 -4
- package/dist/esm/anyspend/react/hooks/useGeoOnrampOptions.js +1 -1
- package/dist/esm/anyspend/react/hooks/useStripeSupport.d.ts +1 -1
- package/dist/esm/anyspend/react/hooks/useStripeSupport.js +4 -4
- package/dist/esm/anyspend/services/anyspend.d.ts +1 -1
- package/dist/esm/anyspend/services/anyspend.js +1 -2
- package/dist/esm/anyspend/types/api.d.ts +1 -16
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +19 -12
- package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -0
- package/dist/esm/global-account/react/hooks/useAuthentication.js +12 -1
- package/dist/esm/global-account/react/stores/useAuthStore.d.ts +4 -0
- package/dist/esm/global-account/react/stores/useAuthStore.js +4 -0
- package/dist/types/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +0 -1
- package/dist/types/anyspend/react/hooks/useStripeSupport.d.ts +1 -1
- package/dist/types/anyspend/services/anyspend.d.ts +1 -1
- package/dist/types/anyspend/types/api.d.ts +1 -16
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -0
- package/dist/types/global-account/react/stores/useAuthStore.d.ts +4 -0
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +0 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +0 -1
- package/src/anyspend/react/components/common/PanelOnrampPayment.tsx +0 -1
- package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +0 -1
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +0 -6
- package/src/anyspend/react/hooks/useGeoOnrampOptions.ts +0 -1
- package/src/anyspend/react/hooks/useStripeSupport.ts +3 -4
- package/src/anyspend/services/anyspend.ts +0 -2
- package/src/anyspend/types/api.ts +1 -16
- package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +19 -11
- package/src/global-account/react/components/custom/ManageAccountButton.tsx +2 -2
- package/src/global-account/react/hooks/useAuthentication.ts +12 -1
- package/src/global-account/react/stores/useAuthStore.ts +8 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Loading, useB3, useGetAllTWSigners, useModalStore, useSiwe, } from "../../../../global-account/react/index.js";
|
|
2
|
+
import { Loading, useAuthStore, useB3, useGetAllTWSigners, useModalStore, useSiwe, } 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";
|
|
@@ -16,9 +16,12 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
16
16
|
const { setUser, automaticallySetFirstEoa } = useB3();
|
|
17
17
|
const [step, setStep] = useState(source === "requestPermissions" ? null : "login");
|
|
18
18
|
const [sessionKeyAdded, setSessionKeyAdded] = useState(source === "requestPermissions" ? true : false);
|
|
19
|
-
const { setB3ModalContentType, setB3ModalOpen } = useModalStore();
|
|
19
|
+
const { setB3ModalContentType, setB3ModalOpen, isOpen } = useModalStore();
|
|
20
20
|
const account = useActiveAccount();
|
|
21
|
-
const
|
|
21
|
+
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
22
|
+
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
23
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
24
|
+
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
22
25
|
const [refetchCount, setRefetchCount] = useState(0);
|
|
23
26
|
const [refetchError, setRefetchError] = useState(null);
|
|
24
27
|
const { data: signers, refetch: refetchSigners, isFetching: isFetchingSigners, } = useGetAllTWSigners({
|
|
@@ -29,7 +32,6 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
29
32
|
},
|
|
30
33
|
});
|
|
31
34
|
const { authenticate } = useSiwe();
|
|
32
|
-
const [authenticatingWithB3, setAuthenticatingWithB3] = useState(false);
|
|
33
35
|
const [refetchQueued, setRefetchQueued] = useState(false);
|
|
34
36
|
// Enhanced refetchSigners function that tracks number of attempts
|
|
35
37
|
const handleRefetchSigners = useCallback(() => {
|
|
@@ -55,11 +57,14 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
55
57
|
// Handle post-login flow after signers are loaded
|
|
56
58
|
useEffect(() => {
|
|
57
59
|
debug("@@SignInWithB3Flow:useEffect", {
|
|
58
|
-
|
|
60
|
+
isConnected,
|
|
61
|
+
isAuthenticating,
|
|
59
62
|
isFetchingSigners,
|
|
63
|
+
closeAfterLogin,
|
|
64
|
+
isOpen,
|
|
60
65
|
source,
|
|
61
66
|
});
|
|
62
|
-
if (
|
|
67
|
+
if (isConnected) {
|
|
63
68
|
// Check if we already have a signer for this partner
|
|
64
69
|
const hasExistingSigner = signers?.some(signer => signer.partner.id === partnerId);
|
|
65
70
|
if (hasExistingSigner) {
|
|
@@ -99,7 +104,6 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
99
104
|
signers,
|
|
100
105
|
isFetchingSigners,
|
|
101
106
|
partnerId,
|
|
102
|
-
loginComplete,
|
|
103
107
|
handleRefetchSigners,
|
|
104
108
|
source,
|
|
105
109
|
closeAfterLogin,
|
|
@@ -108,6 +112,9 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
108
112
|
onSessionKeySuccess,
|
|
109
113
|
setB3ModalOpen,
|
|
110
114
|
signersEnabled,
|
|
115
|
+
isConnected,
|
|
116
|
+
isAuthenticating,
|
|
117
|
+
isOpen,
|
|
111
118
|
]);
|
|
112
119
|
debug("render", {
|
|
113
120
|
step,
|
|
@@ -152,16 +159,16 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
152
159
|
]);
|
|
153
160
|
const handleLoginSuccess = useCallback(async (account) => {
|
|
154
161
|
debug("Authenticating with B3 via SIWE");
|
|
162
|
+
setIsConnected(true);
|
|
155
163
|
if (loginWithSiwe) {
|
|
156
|
-
|
|
164
|
+
setIsAuthenticating(true);
|
|
157
165
|
const userAuth = await authenticate(account, partnerId);
|
|
158
166
|
setUser(userAuth.user);
|
|
159
167
|
}
|
|
160
168
|
debug("handleLoginSuccess:account", account);
|
|
161
169
|
onLoginSuccess?.(account);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}, [authenticate, loginWithSiwe, onLoginSuccess, setUser, partnerId]);
|
|
170
|
+
setIsAuthenticating(false);
|
|
171
|
+
}, [loginWithSiwe, onLoginSuccess, setIsAuthenticating, authenticate, partnerId, setUser, setIsConnected]);
|
|
165
172
|
useEffect(() => {
|
|
166
173
|
if (step === "permissions") {
|
|
167
174
|
setB3ModalContentType({
|
|
@@ -177,7 +184,7 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
177
184
|
if (refetchError) {
|
|
178
185
|
return (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx("div", { className: "p-4 text-center text-red-500", children: refetchError }) }));
|
|
179
186
|
}
|
|
180
|
-
if (
|
|
187
|
+
if (isAuthenticating || (isFetchingSigners && step === "login") || source === "requestPermissions") {
|
|
181
188
|
return (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx("div", { className: "mt-8 flex items-center justify-center", children: _jsx(Loading, { variant: "white", size: "lg" }) }) }));
|
|
182
189
|
}
|
|
183
190
|
if (step === "login") {
|
|
@@ -3,7 +3,7 @@ import { Button, StyleRoot, useAuthentication, useModalStore } from "../../../..
|
|
|
3
3
|
import { cn } from "../../../../shared/utils/index.js";
|
|
4
4
|
export function ManageAccountButton(props) {
|
|
5
5
|
const { setB3ModalOpen, setB3ModalContentType } = useModalStore();
|
|
6
|
-
const {
|
|
6
|
+
const { isConnected } = useAuthentication(props.partnerId, props.loginWithSiwe);
|
|
7
7
|
const handleClickManageAccount = () => {
|
|
8
8
|
setB3ModalContentType({
|
|
9
9
|
...props,
|
|
@@ -11,7 +11,7 @@ export function ManageAccountButton(props) {
|
|
|
11
11
|
});
|
|
12
12
|
setB3ModalOpen(true);
|
|
13
13
|
};
|
|
14
|
-
if (!
|
|
14
|
+
if (!isConnected)
|
|
15
15
|
return null;
|
|
16
16
|
return (_jsx(StyleRoot, { children: _jsxs(Button, { onClick: handleClickManageAccount, style: { backgroundColor: "#3368ef" }, className: cn("b3-manage-account-button flex items-center gap-2 text-white", props.className), children: [props.withLogo !== false && (_jsx("img", { src: "https://cdn.b3.fun/b3_logo_white.svg", alt: "B3 Logo", className: "h-5 w-5" })), props.loggedInButtonText || "Manage Account"] }) }));
|
|
17
17
|
}
|
|
@@ -4,6 +4,8 @@ export declare function useAuthentication(partnerId: string, loginWithSiwe?: boo
|
|
|
4
4
|
isAuthenticating: boolean;
|
|
5
5
|
isAuthenticated: boolean;
|
|
6
6
|
isReady: boolean;
|
|
7
|
+
isConnecting: boolean;
|
|
8
|
+
isConnected: boolean;
|
|
7
9
|
wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
|
|
8
10
|
preAuthenticate: typeof preAuthenticate;
|
|
9
11
|
connect: (strategyOptions?: import("thirdweb/wallets").SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
|
|
@@ -21,6 +21,10 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
21
21
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
22
22
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
23
23
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
24
|
+
const setIsConnecting = useAuthStore(state => state.setIsConnecting);
|
|
25
|
+
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
26
|
+
const isConnecting = useAuthStore(state => state.isConnecting);
|
|
27
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
24
28
|
const { connect } = useConnect(partnerId, b3MainnetThirdWeb);
|
|
25
29
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
26
30
|
partnerId: partnerId,
|
|
@@ -30,6 +34,7 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
30
34
|
wallets: [wallet],
|
|
31
35
|
onConnect: async (wallet) => {
|
|
32
36
|
try {
|
|
37
|
+
setIsConnected(true);
|
|
33
38
|
if (!loginWithSiwe) {
|
|
34
39
|
debug("Skipping SIWE login", { loginWithSiwe });
|
|
35
40
|
setIsAuthenticated(true);
|
|
@@ -67,19 +72,22 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
67
72
|
useEffect(() => {
|
|
68
73
|
if (useAutoConnectLoading) {
|
|
69
74
|
setIsAuthenticating(true);
|
|
75
|
+
setIsConnecting(true);
|
|
70
76
|
}
|
|
71
77
|
else if (!isAuthenticated) {
|
|
72
78
|
// Only set isAuthenticating to false if we're not authenticated
|
|
73
79
|
// This prevents the flicker state where both isAuthenticating and isAuthenticated are false
|
|
74
80
|
const timeout = setTimeout(() => {
|
|
75
81
|
setIsAuthenticating(false);
|
|
82
|
+
setIsConnecting(false);
|
|
76
83
|
}, 100); // Add a small delay to prevent quick flickers
|
|
77
84
|
return () => clearTimeout(timeout);
|
|
78
85
|
}
|
|
79
86
|
else {
|
|
80
87
|
setIsAuthenticating(false);
|
|
88
|
+
setIsConnecting(false);
|
|
81
89
|
}
|
|
82
|
-
}, [useAutoConnectLoading, isAuthenticated, setIsAuthenticating]);
|
|
90
|
+
}, [useAutoConnectLoading, isAuthenticated, setIsAuthenticating, setIsConnecting, setIsConnected]);
|
|
83
91
|
const logout = async (callback) => {
|
|
84
92
|
if (activeWallet) {
|
|
85
93
|
debug("@@logout:activeWallet", activeWallet);
|
|
@@ -102,6 +110,7 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
102
110
|
app.logout();
|
|
103
111
|
debug("@@logout:loggedOut");
|
|
104
112
|
setIsAuthenticated(false);
|
|
113
|
+
setIsConnected(false);
|
|
105
114
|
setUser();
|
|
106
115
|
callback?.();
|
|
107
116
|
};
|
|
@@ -111,6 +120,8 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
111
120
|
isAuthenticating: useAutoConnectLoading || isAuthenticating,
|
|
112
121
|
isAuthenticated,
|
|
113
122
|
isReady,
|
|
123
|
+
isConnecting,
|
|
124
|
+
isConnected,
|
|
114
125
|
wallet,
|
|
115
126
|
preAuthenticate,
|
|
116
127
|
connect,
|
|
@@ -7,10 +7,14 @@ interface AuthState {
|
|
|
7
7
|
chain?: Chain;
|
|
8
8
|
isAuthenticating: boolean;
|
|
9
9
|
isAuthenticated: boolean;
|
|
10
|
+
isConnecting: boolean;
|
|
11
|
+
isConnected: boolean;
|
|
10
12
|
onSuccess?: (account: any) => void;
|
|
11
13
|
onError?: (error: Error) => void;
|
|
12
14
|
setB3ModalOpen: (isOpen: boolean) => void;
|
|
13
15
|
setStep: (step: "login" | "permissions") => void;
|
|
16
|
+
setIsConnecting: (isConnecting: boolean) => void;
|
|
17
|
+
setIsConnected: (isConnected: boolean) => void;
|
|
14
18
|
setIsAuthenticating: (isAuthenticating: boolean) => void;
|
|
15
19
|
setIsAuthenticated: (isAuthenticated: boolean) => void;
|
|
16
20
|
startAuth: (params: {
|
|
@@ -7,10 +7,14 @@ export const useAuthStore = create(set => ({
|
|
|
7
7
|
chain: undefined,
|
|
8
8
|
isAuthenticating: false,
|
|
9
9
|
isAuthenticated: false,
|
|
10
|
+
isConnecting: false,
|
|
11
|
+
isConnected: false,
|
|
10
12
|
onSuccess: undefined,
|
|
11
13
|
onError: undefined,
|
|
12
14
|
setB3ModalOpen: isOpen => set({ isOpen }),
|
|
13
15
|
setStep: step => set({ step }),
|
|
16
|
+
setIsConnecting: isConnecting => set({ isConnecting }),
|
|
17
|
+
setIsConnected: isConnected => set({ isConnected }),
|
|
14
18
|
setIsAuthenticating: isAuthenticating => set({ isAuthenticating }),
|
|
15
19
|
setIsAuthenticated: isAuthenticated => set({ isAuthenticated }),
|
|
16
20
|
startAuth: params => set({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VisitorData } from "@b3dotfun/sdk/anyspend/types/fingerprint";
|
|
2
|
-
export declare function useStripeSupport(isMainnet: boolean,
|
|
2
|
+
export declare function useStripeSupport(isMainnet: boolean, usdAmount?: string, visitorData?: VisitorData, isLoadingVisitorData?: boolean): {
|
|
3
3
|
isStripeOnrampSupported: boolean;
|
|
4
4
|
stripeWeb2Support: {
|
|
5
5
|
isSupport: false;
|
|
@@ -30,7 +30,7 @@ export declare const anyspendService: {
|
|
|
30
30
|
getOrderAndTransactions: (isMainnet: boolean, orderId: string | undefined) => Promise<GetOrderAndTxsResponse>;
|
|
31
31
|
getOrderHistory: (isMainnet: boolean, creatorAddress: string | undefined, limit?: number, offset?: number) => Promise<GetOrderHistoryResponse>;
|
|
32
32
|
getCoinbaseOnrampOptions: (isMainnet: boolean, country: string, visitorData?: VisitorData) => Promise<GetCoinbaseOnrampOptionsResponse>;
|
|
33
|
-
checkStripeSupport: (isMainnet: boolean,
|
|
33
|
+
checkStripeSupport: (isMainnet: boolean, usdAmount?: string, visitorData?: VisitorData) => Promise<{
|
|
34
34
|
stripeOnramp: boolean;
|
|
35
35
|
stripeWeb2: components["schemas"]["StripeWeb2Support"];
|
|
36
36
|
}>;
|
|
@@ -238,12 +238,7 @@ export interface paths {
|
|
|
238
238
|
*/
|
|
239
239
|
get: {
|
|
240
240
|
parameters: {
|
|
241
|
-
query
|
|
242
|
-
/**
|
|
243
|
-
* @description IP address to check location-based support
|
|
244
|
-
* @example 192.168.1.1
|
|
245
|
-
*/
|
|
246
|
-
ipAddress: string;
|
|
241
|
+
query?: {
|
|
247
242
|
/**
|
|
248
243
|
* @description Optional USD amount for transaction limit checks
|
|
249
244
|
* @example 100.00
|
|
@@ -903,11 +898,6 @@ export interface components {
|
|
|
903
898
|
* @example
|
|
904
899
|
*/
|
|
905
900
|
paymentMethod?: string;
|
|
906
|
-
/**
|
|
907
|
-
* @description User's IP address
|
|
908
|
-
* @example 96.225.86.216
|
|
909
|
-
*/
|
|
910
|
-
ipAddress?: string;
|
|
911
901
|
/**
|
|
912
902
|
* @description Redirect URL after payment
|
|
913
903
|
* @example https://www.anyspend.com
|
|
@@ -936,11 +926,6 @@ export interface components {
|
|
|
936
926
|
* @example SG
|
|
937
927
|
*/
|
|
938
928
|
country?: string;
|
|
939
|
-
/**
|
|
940
|
-
* @description User's IP address
|
|
941
|
-
* @example 149.88.23.87
|
|
942
|
-
*/
|
|
943
|
-
ipAddress?: string;
|
|
944
929
|
/**
|
|
945
930
|
* @description URL to redirect after payment
|
|
946
931
|
* @example https://www.anyspend.com
|
|
@@ -4,6 +4,8 @@ export declare function useAuthentication(partnerId: string, loginWithSiwe?: boo
|
|
|
4
4
|
isAuthenticating: boolean;
|
|
5
5
|
isAuthenticated: boolean;
|
|
6
6
|
isReady: boolean;
|
|
7
|
+
isConnecting: boolean;
|
|
8
|
+
isConnected: boolean;
|
|
7
9
|
wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
|
|
8
10
|
preAuthenticate: typeof preAuthenticate;
|
|
9
11
|
connect: (strategyOptions?: import("thirdweb/wallets").SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
|
|
@@ -7,10 +7,14 @@ interface AuthState {
|
|
|
7
7
|
chain?: Chain;
|
|
8
8
|
isAuthenticating: boolean;
|
|
9
9
|
isAuthenticated: boolean;
|
|
10
|
+
isConnecting: boolean;
|
|
11
|
+
isConnected: boolean;
|
|
10
12
|
onSuccess?: (account: any) => void;
|
|
11
13
|
onError?: (error: Error) => void;
|
|
12
14
|
setB3ModalOpen: (isOpen: boolean) => void;
|
|
13
15
|
setStep: (step: "login" | "permissions") => void;
|
|
16
|
+
setIsConnecting: (isConnecting: boolean) => void;
|
|
17
|
+
setIsConnected: (isConnected: boolean) => void;
|
|
14
18
|
setIsAuthenticating: (isAuthenticating: boolean) => void;
|
|
15
19
|
setIsAuthenticated: (isAuthenticated: boolean) => void;
|
|
16
20
|
startAuth: (params: {
|
package/package.json
CHANGED
|
@@ -878,7 +878,6 @@ function AnySpendInner({
|
|
|
878
878
|
vendor: vendor,
|
|
879
879
|
paymentMethod: paymentMethodString,
|
|
880
880
|
country: geoData?.country || "US",
|
|
881
|
-
ipAddress: geoData?.ip,
|
|
882
881
|
redirectUrl:
|
|
883
882
|
window.location.origin === "https://basement.fun" ? "https://basement.fun/deposit" : window.location.origin,
|
|
884
883
|
},
|
|
@@ -440,7 +440,6 @@ export function AnySpendCustom({
|
|
|
440
440
|
vendor: onramp.vendor,
|
|
441
441
|
paymentMethod: onramp.paymentMethod,
|
|
442
442
|
country: geoData?.country || "US",
|
|
443
|
-
ipAddress: geoData?.ip,
|
|
444
443
|
redirectUrl:
|
|
445
444
|
window.location.origin === "https://basement.fun"
|
|
446
445
|
? "https://basement.fun/deposit"
|
|
@@ -143,7 +143,6 @@ function PanelOnrampPaymentInner(props: PanelOnrampPaymentProps) {
|
|
|
143
143
|
vendor: vendor,
|
|
144
144
|
paymentMethod: paymentMethod || "",
|
|
145
145
|
country: geoData?.country || "US",
|
|
146
|
-
ipAddress: geoData?.ip,
|
|
147
146
|
redirectUrl:
|
|
148
147
|
window.location.origin === "https://basement.fun" ? "https://basement.fun/deposit" : window.location.origin,
|
|
149
148
|
},
|
|
@@ -213,7 +213,6 @@ function WebviewOnrampPaymentInner({
|
|
|
213
213
|
vendor: "stripe-web2",
|
|
214
214
|
paymentMethod: "",
|
|
215
215
|
country: geoData.country || "US",
|
|
216
|
-
ipAddress: geoData.ip,
|
|
217
216
|
redirectUrl: `${window.location.origin}${userId ? `?userId=${userId}` : ""}`,
|
|
218
217
|
},
|
|
219
218
|
expectedDstAmount: anyspendQuote.data?.currencyOut?.amount?.toString() || "0",
|
|
@@ -16,7 +16,6 @@ export type OnrampOptions = {
|
|
|
16
16
|
paymentMethod: string;
|
|
17
17
|
country: string;
|
|
18
18
|
redirectUrl: string;
|
|
19
|
-
ipAddress?: string; // Required for Stripe
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
export type CreateOnrampOrderParams = Omit<CreateOrderParams, "srcChain" | "srcToken" | "srcAmount"> & {
|
|
@@ -60,11 +59,6 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError }: UseAnyspend
|
|
|
60
59
|
} = params;
|
|
61
60
|
|
|
62
61
|
try {
|
|
63
|
-
// Validate Stripe onramp options
|
|
64
|
-
if (onramp.vendor === "stripe" && !onramp.ipAddress) {
|
|
65
|
-
throw new Error("IP address is required for Stripe onramp");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
62
|
// Validate required onramp fields
|
|
69
63
|
if (!onramp.vendor || !onramp.country) {
|
|
70
64
|
throw new Error("Missing required onramp fields: vendor, country");
|
|
@@ -22,7 +22,6 @@ export function useGeoOnrampOptions(isMainnet: boolean, srcFiatAmount: string) {
|
|
|
22
22
|
useCoinbaseOnrampOptions(isMainnet, geoData?.country, visitorData);
|
|
23
23
|
const { isStripeOnrampSupported, stripeWeb2Support, isLoadingStripeSupport, stripeSupportError } = useStripeSupport(
|
|
24
24
|
isMainnet,
|
|
25
|
-
geoData?.ip || "",
|
|
26
25
|
srcFiatAmount,
|
|
27
26
|
visitorData,
|
|
28
27
|
);
|
|
@@ -5,15 +5,14 @@ import { useMemo } from "react";
|
|
|
5
5
|
|
|
6
6
|
export function useStripeSupport(
|
|
7
7
|
isMainnet: boolean,
|
|
8
|
-
ipAddress: string,
|
|
9
8
|
usdAmount?: string,
|
|
10
9
|
visitorData?: VisitorData,
|
|
11
10
|
isLoadingVisitorData?: boolean,
|
|
12
11
|
) {
|
|
13
12
|
const { data, isLoading, error, refetch } = useQuery({
|
|
14
|
-
queryKey: ["useStripeSupport", isMainnet,
|
|
15
|
-
queryFn: () => anyspendService.checkStripeSupport(isMainnet,
|
|
16
|
-
enabled:
|
|
13
|
+
queryKey: ["useStripeSupport", isMainnet, usdAmount, visitorData?.requestId, visitorData?.visitorId],
|
|
14
|
+
queryFn: () => anyspendService.checkStripeSupport(isMainnet, usdAmount, visitorData),
|
|
15
|
+
enabled: !isLoadingVisitorData,
|
|
17
16
|
});
|
|
18
17
|
|
|
19
18
|
return useMemo(
|
|
@@ -170,12 +170,10 @@ export const anyspendService = {
|
|
|
170
170
|
|
|
171
171
|
checkStripeSupport: async (
|
|
172
172
|
isMainnet: boolean,
|
|
173
|
-
ipAddress: string,
|
|
174
173
|
usdAmount?: string,
|
|
175
174
|
visitorData?: VisitorData,
|
|
176
175
|
): Promise<{ stripeOnramp: boolean; stripeWeb2: components["schemas"]["StripeWeb2Support"] }> => {
|
|
177
176
|
const params = new URLSearchParams({
|
|
178
|
-
ipAddress,
|
|
179
177
|
usdAmount: usdAmount || "",
|
|
180
178
|
});
|
|
181
179
|
const response = await fetch(
|
|
@@ -239,12 +239,7 @@ export interface paths {
|
|
|
239
239
|
*/
|
|
240
240
|
get: {
|
|
241
241
|
parameters: {
|
|
242
|
-
query
|
|
243
|
-
/**
|
|
244
|
-
* @description IP address to check location-based support
|
|
245
|
-
* @example 192.168.1.1
|
|
246
|
-
*/
|
|
247
|
-
ipAddress: string;
|
|
242
|
+
query?: {
|
|
248
243
|
/**
|
|
249
244
|
* @description Optional USD amount for transaction limit checks
|
|
250
245
|
* @example 100.00
|
|
@@ -909,11 +904,6 @@ export interface components {
|
|
|
909
904
|
* @example
|
|
910
905
|
*/
|
|
911
906
|
paymentMethod?: string;
|
|
912
|
-
/**
|
|
913
|
-
* @description User's IP address
|
|
914
|
-
* @example 96.225.86.216
|
|
915
|
-
*/
|
|
916
|
-
ipAddress?: string;
|
|
917
907
|
/**
|
|
918
908
|
* @description Redirect URL after payment
|
|
919
909
|
* @example https://www.anyspend.com
|
|
@@ -942,11 +932,6 @@ export interface components {
|
|
|
942
932
|
* @example SG
|
|
943
933
|
*/
|
|
944
934
|
country?: string;
|
|
945
|
-
/**
|
|
946
|
-
* @description User's IP address
|
|
947
|
-
* @example 149.88.23.87
|
|
948
|
-
*/
|
|
949
|
-
ipAddress?: string;
|
|
950
935
|
/**
|
|
951
936
|
* @description URL to redirect after payment
|
|
952
937
|
* @example https://www.anyspend.com
|
|
@@ -21,7 +21,7 @@ export type SignInWithB3Props = Omit<SignInWithB3ModalProps, "type" | "showBackB
|
|
|
21
21
|
export function SignInWithB3(props: SignInWithB3Props) {
|
|
22
22
|
const { setB3ModalOpen, setB3ModalContentType, setEcoSystemAccountAddress } = useModalStore();
|
|
23
23
|
const { account } = useB3();
|
|
24
|
-
const { isAuthenticating,
|
|
24
|
+
const { isAuthenticating, isConnected } = useAuthentication(props.partnerId, props.loginWithSiwe);
|
|
25
25
|
const isMobile = useIsMobile();
|
|
26
26
|
|
|
27
27
|
useEffect(() => {
|
|
@@ -39,7 +39,7 @@ export function SignInWithB3(props: SignInWithB3Props) {
|
|
|
39
39
|
setB3ModalOpen(true);
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
if (
|
|
42
|
+
if (isConnected) {
|
|
43
43
|
return <ManageAccountButton {...props} />;
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Loading,
|
|
3
3
|
SignInWithB3ModalProps,
|
|
4
|
+
useAuthStore,
|
|
4
5
|
useB3,
|
|
5
6
|
useGetAllTWSigners,
|
|
6
7
|
useModalStore,
|
|
@@ -37,9 +38,12 @@ export function SignInWithB3Flow({
|
|
|
37
38
|
const { setUser, automaticallySetFirstEoa } = useB3();
|
|
38
39
|
const [step, setStep] = useState<"login" | "permissions" | null>(source === "requestPermissions" ? null : "login");
|
|
39
40
|
const [sessionKeyAdded, setSessionKeyAdded] = useState(source === "requestPermissions" ? true : false);
|
|
40
|
-
const { setB3ModalContentType, setB3ModalOpen } = useModalStore();
|
|
41
|
+
const { setB3ModalContentType, setB3ModalOpen, isOpen } = useModalStore();
|
|
41
42
|
const account = useActiveAccount();
|
|
42
|
-
const
|
|
43
|
+
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
44
|
+
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
45
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
46
|
+
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
43
47
|
const [refetchCount, setRefetchCount] = useState(0);
|
|
44
48
|
const [refetchError, setRefetchError] = useState<string | null>(null);
|
|
45
49
|
const {
|
|
@@ -54,7 +58,6 @@ export function SignInWithB3Flow({
|
|
|
54
58
|
},
|
|
55
59
|
});
|
|
56
60
|
const { authenticate } = useSiwe();
|
|
57
|
-
const [authenticatingWithB3, setAuthenticatingWithB3] = useState(false);
|
|
58
61
|
const [refetchQueued, setRefetchQueued] = useState(false);
|
|
59
62
|
|
|
60
63
|
// Enhanced refetchSigners function that tracks number of attempts
|
|
@@ -86,12 +89,15 @@ export function SignInWithB3Flow({
|
|
|
86
89
|
// Handle post-login flow after signers are loaded
|
|
87
90
|
useEffect(() => {
|
|
88
91
|
debug("@@SignInWithB3Flow:useEffect", {
|
|
89
|
-
|
|
92
|
+
isConnected,
|
|
93
|
+
isAuthenticating,
|
|
90
94
|
isFetchingSigners,
|
|
95
|
+
closeAfterLogin,
|
|
96
|
+
isOpen,
|
|
91
97
|
source,
|
|
92
98
|
});
|
|
93
99
|
|
|
94
|
-
if (
|
|
100
|
+
if (isConnected) {
|
|
95
101
|
// Check if we already have a signer for this partner
|
|
96
102
|
const hasExistingSigner = signers?.some(signer => signer.partner.id === partnerId);
|
|
97
103
|
if (hasExistingSigner) {
|
|
@@ -128,7 +134,6 @@ export function SignInWithB3Flow({
|
|
|
128
134
|
signers,
|
|
129
135
|
isFetchingSigners,
|
|
130
136
|
partnerId,
|
|
131
|
-
loginComplete,
|
|
132
137
|
handleRefetchSigners,
|
|
133
138
|
source,
|
|
134
139
|
closeAfterLogin,
|
|
@@ -137,6 +142,9 @@ export function SignInWithB3Flow({
|
|
|
137
142
|
onSessionKeySuccess,
|
|
138
143
|
setB3ModalOpen,
|
|
139
144
|
signersEnabled,
|
|
145
|
+
isConnected,
|
|
146
|
+
isAuthenticating,
|
|
147
|
+
isOpen,
|
|
140
148
|
]);
|
|
141
149
|
|
|
142
150
|
debug("render", {
|
|
@@ -186,17 +194,17 @@ export function SignInWithB3Flow({
|
|
|
186
194
|
const handleLoginSuccess = useCallback(
|
|
187
195
|
async (account: Account) => {
|
|
188
196
|
debug("Authenticating with B3 via SIWE");
|
|
197
|
+
setIsConnected(true);
|
|
189
198
|
if (loginWithSiwe) {
|
|
190
|
-
|
|
199
|
+
setIsAuthenticating(true);
|
|
191
200
|
const userAuth = await authenticate(account, partnerId);
|
|
192
201
|
setUser(userAuth.user);
|
|
193
202
|
}
|
|
194
203
|
debug("handleLoginSuccess:account", account);
|
|
195
204
|
onLoginSuccess?.(account);
|
|
196
|
-
|
|
197
|
-
setAuthenticatingWithB3(false);
|
|
205
|
+
setIsAuthenticating(false);
|
|
198
206
|
},
|
|
199
|
-
[
|
|
207
|
+
[loginWithSiwe, onLoginSuccess, setIsAuthenticating, authenticate, partnerId, setUser, setIsConnected],
|
|
200
208
|
);
|
|
201
209
|
|
|
202
210
|
useEffect(() => {
|
|
@@ -220,7 +228,7 @@ export function SignInWithB3Flow({
|
|
|
220
228
|
);
|
|
221
229
|
}
|
|
222
230
|
|
|
223
|
-
if (
|
|
231
|
+
if (isAuthenticating || (isFetchingSigners && step === "login") || source === "requestPermissions") {
|
|
224
232
|
return (
|
|
225
233
|
<LoginStepContainer partnerId={partnerId}>
|
|
226
234
|
<div className="mt-8 flex items-center justify-center">
|
|
@@ -4,7 +4,7 @@ import { SignInWithB3Props } from "../SignInWithB3/SignInWithB3";
|
|
|
4
4
|
|
|
5
5
|
export function ManageAccountButton(props: SignInWithB3Props & { className?: string }) {
|
|
6
6
|
const { setB3ModalOpen, setB3ModalContentType } = useModalStore();
|
|
7
|
-
const {
|
|
7
|
+
const { isConnected } = useAuthentication(props.partnerId, props.loginWithSiwe);
|
|
8
8
|
|
|
9
9
|
const handleClickManageAccount = () => {
|
|
10
10
|
setB3ModalContentType({
|
|
@@ -14,7 +14,7 @@ export function ManageAccountButton(props: SignInWithB3Props & { className?: str
|
|
|
14
14
|
setB3ModalOpen(true);
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
if (!
|
|
17
|
+
if (!isConnected) return null;
|
|
18
18
|
|
|
19
19
|
return (
|
|
20
20
|
<StyleRoot>
|
|
@@ -23,6 +23,10 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
23
23
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
24
24
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
25
25
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
26
|
+
const setIsConnecting = useAuthStore(state => state.setIsConnecting);
|
|
27
|
+
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
28
|
+
const isConnecting = useAuthStore(state => state.isConnecting);
|
|
29
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
26
30
|
const { connect } = useConnect(partnerId, b3MainnetThirdWeb);
|
|
27
31
|
|
|
28
32
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
@@ -34,6 +38,7 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
34
38
|
wallets: [wallet],
|
|
35
39
|
onConnect: async wallet => {
|
|
36
40
|
try {
|
|
41
|
+
setIsConnected(true);
|
|
37
42
|
if (!loginWithSiwe) {
|
|
38
43
|
debug("Skipping SIWE login", { loginWithSiwe });
|
|
39
44
|
setIsAuthenticated(true);
|
|
@@ -72,17 +77,20 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
72
77
|
useEffect(() => {
|
|
73
78
|
if (useAutoConnectLoading) {
|
|
74
79
|
setIsAuthenticating(true);
|
|
80
|
+
setIsConnecting(true);
|
|
75
81
|
} else if (!isAuthenticated) {
|
|
76
82
|
// Only set isAuthenticating to false if we're not authenticated
|
|
77
83
|
// This prevents the flicker state where both isAuthenticating and isAuthenticated are false
|
|
78
84
|
const timeout = setTimeout(() => {
|
|
79
85
|
setIsAuthenticating(false);
|
|
86
|
+
setIsConnecting(false);
|
|
80
87
|
}, 100); // Add a small delay to prevent quick flickers
|
|
81
88
|
return () => clearTimeout(timeout);
|
|
82
89
|
} else {
|
|
83
90
|
setIsAuthenticating(false);
|
|
91
|
+
setIsConnecting(false);
|
|
84
92
|
}
|
|
85
|
-
}, [useAutoConnectLoading, isAuthenticated, setIsAuthenticating]);
|
|
93
|
+
}, [useAutoConnectLoading, isAuthenticated, setIsAuthenticating, setIsConnecting, setIsConnected]);
|
|
86
94
|
|
|
87
95
|
const logout = async (callback?: () => void) => {
|
|
88
96
|
if (activeWallet) {
|
|
@@ -110,6 +118,7 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
110
118
|
debug("@@logout:loggedOut");
|
|
111
119
|
|
|
112
120
|
setIsAuthenticated(false);
|
|
121
|
+
setIsConnected(false);
|
|
113
122
|
setUser();
|
|
114
123
|
callback?.();
|
|
115
124
|
};
|
|
@@ -121,6 +130,8 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
121
130
|
isAuthenticating: useAutoConnectLoading || isAuthenticating,
|
|
122
131
|
isAuthenticated,
|
|
123
132
|
isReady,
|
|
133
|
+
isConnecting,
|
|
134
|
+
isConnected,
|
|
124
135
|
wallet,
|
|
125
136
|
preAuthenticate,
|
|
126
137
|
connect,
|