@b3dotfun/sdk 0.1.68-alpha.0 → 0.1.68-alpha.10
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/platform/client.d.ts +35 -0
- package/dist/cjs/anyspend/platform/client.js +158 -0
- package/dist/cjs/anyspend/platform/errors.d.ts +38 -0
- package/dist/cjs/anyspend/platform/errors.js +77 -0
- package/dist/cjs/anyspend/platform/index.d.ts +87 -0
- package/dist/cjs/anyspend/platform/index.js +85 -0
- package/dist/cjs/anyspend/platform/resources/analytics.d.ts +7 -0
- package/dist/cjs/anyspend/platform/resources/analytics.js +12 -0
- package/dist/cjs/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
- package/dist/cjs/anyspend/platform/resources/checkout-sessions.js +27 -0
- package/dist/cjs/anyspend/platform/resources/customers.d.ts +19 -0
- package/dist/cjs/anyspend/platform/resources/customers.js +34 -0
- package/dist/cjs/anyspend/platform/resources/discount-codes.d.ts +29 -0
- package/dist/cjs/anyspend/platform/resources/discount-codes.js +31 -0
- package/dist/cjs/anyspend/platform/resources/events.d.ts +14 -0
- package/dist/cjs/anyspend/platform/resources/events.js +16 -0
- package/dist/cjs/anyspend/platform/resources/notifications.d.ts +18 -0
- package/dist/cjs/anyspend/platform/resources/notifications.js +27 -0
- package/dist/cjs/anyspend/platform/resources/organization.d.ts +17 -0
- package/dist/cjs/anyspend/platform/resources/organization.js +15 -0
- package/dist/cjs/anyspend/platform/resources/payment-links.d.ts +21 -0
- package/dist/cjs/anyspend/platform/resources/payment-links.js +49 -0
- package/dist/cjs/anyspend/platform/resources/products.d.ts +27 -0
- package/dist/cjs/anyspend/platform/resources/products.js +31 -0
- package/dist/cjs/anyspend/platform/resources/transactions.d.ts +11 -0
- package/dist/cjs/anyspend/platform/resources/transactions.js +25 -0
- package/dist/cjs/anyspend/platform/resources/webhooks.d.ts +14 -0
- package/dist/cjs/anyspend/platform/resources/webhooks.js +33 -0
- package/dist/cjs/anyspend/platform/resources/widgets.d.ts +38 -0
- package/dist/cjs/anyspend/platform/resources/widgets.js +31 -0
- package/dist/cjs/anyspend/platform/types.d.ts +478 -0
- package/dist/cjs/anyspend/platform/types.js +5 -0
- package/dist/cjs/anyspend/platform/utils/idempotency.d.ts +4 -0
- package/dist/cjs/anyspend/platform/utils/idempotency.js +17 -0
- package/dist/cjs/anyspend/platform/utils/pagination.d.ts +12 -0
- package/dist/cjs/anyspend/platform/utils/pagination.js +22 -0
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +5 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +123 -12
- package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
- package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
- package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +2 -2
- package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
- package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -2
- package/dist/cjs/anyspend/react/components/checkout/CryptoPayPanel.js +1 -1
- package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
- package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.js +48 -16
- package/dist/cjs/anyspend/react/components/checkout/KycGate.d.ts +11 -0
- package/dist/cjs/anyspend/react/components/checkout/KycGate.js +203 -0
- package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
- package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.js +145 -0
- package/dist/cjs/anyspend/react/components/index.d.ts +1 -1
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +14 -0
- package/dist/cjs/anyspend/react/hooks/useKycStatus.d.ts +47 -0
- package/dist/cjs/anyspend/react/hooks/useKycStatus.js +124 -0
- package/dist/cjs/anyspend/services/anyspend.d.ts +4 -1
- package/dist/cjs/anyspend/services/anyspend.js +3 -1
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/cjs/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -5
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +21 -24
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
- package/dist/cjs/global-account/react/hooks/useAuth.js +1 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +3 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +82 -24
- package/dist/cjs/global-account/react/hooks/useGetAllTWSigners.js +2 -1
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/cjs/global-account/react/stores/useModalStore.js +2 -0
- package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +18 -0
- package/dist/cjs/global-account/react/utils/createWagmiConfig.js +17 -0
- package/dist/esm/anyspend/platform/client.d.ts +35 -0
- package/dist/esm/anyspend/platform/client.js +153 -0
- package/dist/esm/anyspend/platform/errors.d.ts +38 -0
- package/dist/esm/anyspend/platform/errors.js +67 -0
- package/dist/esm/anyspend/platform/index.d.ts +87 -0
- package/dist/esm/anyspend/platform/index.js +75 -0
- package/dist/esm/anyspend/platform/resources/analytics.d.ts +7 -0
- package/dist/esm/anyspend/platform/resources/analytics.js +8 -0
- package/dist/esm/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
- package/dist/esm/anyspend/platform/resources/checkout-sessions.js +23 -0
- package/dist/esm/anyspend/platform/resources/customers.d.ts +19 -0
- package/dist/esm/anyspend/platform/resources/customers.js +30 -0
- package/dist/esm/anyspend/platform/resources/discount-codes.d.ts +29 -0
- package/dist/esm/anyspend/platform/resources/discount-codes.js +27 -0
- package/dist/esm/anyspend/platform/resources/events.d.ts +14 -0
- package/dist/esm/anyspend/platform/resources/events.js +12 -0
- package/dist/esm/anyspend/platform/resources/notifications.d.ts +18 -0
- package/dist/esm/anyspend/platform/resources/notifications.js +23 -0
- package/dist/esm/anyspend/platform/resources/organization.d.ts +17 -0
- package/dist/esm/anyspend/platform/resources/organization.js +11 -0
- package/dist/esm/anyspend/platform/resources/payment-links.d.ts +21 -0
- package/dist/esm/anyspend/platform/resources/payment-links.js +45 -0
- package/dist/esm/anyspend/platform/resources/products.d.ts +27 -0
- package/dist/esm/anyspend/platform/resources/products.js +27 -0
- package/dist/esm/anyspend/platform/resources/transactions.d.ts +11 -0
- package/dist/esm/anyspend/platform/resources/transactions.js +21 -0
- package/dist/esm/anyspend/platform/resources/webhooks.d.ts +14 -0
- package/dist/esm/anyspend/platform/resources/webhooks.js +29 -0
- package/dist/esm/anyspend/platform/resources/widgets.d.ts +38 -0
- package/dist/esm/anyspend/platform/resources/widgets.js +27 -0
- package/dist/esm/anyspend/platform/types.d.ts +478 -0
- package/dist/esm/anyspend/platform/types.js +4 -0
- package/dist/esm/anyspend/platform/utils/idempotency.d.ts +4 -0
- package/dist/esm/anyspend/platform/utils/idempotency.js +14 -0
- package/dist/esm/anyspend/platform/utils/pagination.d.ts +12 -0
- package/dist/esm/anyspend/platform/utils/pagination.js +19 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +5 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +124 -13
- package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
- package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
- package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
- package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +2 -2
- package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
- package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -2
- package/dist/esm/anyspend/react/components/checkout/CryptoPayPanel.js +1 -1
- package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
- package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.js +50 -18
- package/dist/esm/anyspend/react/components/checkout/KycGate.d.ts +11 -0
- package/dist/esm/anyspend/react/components/checkout/KycGate.js +167 -0
- package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
- package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.js +142 -0
- package/dist/esm/anyspend/react/components/index.d.ts +1 -1
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +14 -0
- package/dist/esm/anyspend/react/hooks/useKycStatus.d.ts +47 -0
- package/dist/esm/anyspend/react/hooks/useKycStatus.js +117 -0
- package/dist/esm/anyspend/services/anyspend.d.ts +4 -1
- package/dist/esm/anyspend/services/anyspend.js +3 -1
- package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/esm/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -5
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +21 -24
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
- package/dist/esm/global-account/react/hooks/useAuth.js +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +3 -1
- package/dist/esm/global-account/react/hooks/useAuthentication.js +82 -24
- package/dist/esm/global-account/react/hooks/useGetAllTWSigners.js +2 -1
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/esm/global-account/react/stores/useModalStore.js +2 -0
- package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +18 -0
- package/dist/esm/global-account/react/utils/createWagmiConfig.js +16 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/platform/client.d.ts +35 -0
- package/dist/types/anyspend/platform/errors.d.ts +38 -0
- package/dist/types/anyspend/platform/index.d.ts +87 -0
- package/dist/types/anyspend/platform/resources/analytics.d.ts +7 -0
- package/dist/types/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
- package/dist/types/anyspend/platform/resources/customers.d.ts +19 -0
- package/dist/types/anyspend/platform/resources/discount-codes.d.ts +29 -0
- package/dist/types/anyspend/platform/resources/events.d.ts +14 -0
- package/dist/types/anyspend/platform/resources/notifications.d.ts +18 -0
- package/dist/types/anyspend/platform/resources/organization.d.ts +17 -0
- package/dist/types/anyspend/platform/resources/payment-links.d.ts +21 -0
- package/dist/types/anyspend/platform/resources/products.d.ts +27 -0
- package/dist/types/anyspend/platform/resources/transactions.d.ts +11 -0
- package/dist/types/anyspend/platform/resources/webhooks.d.ts +14 -0
- package/dist/types/anyspend/platform/resources/widgets.d.ts +38 -0
- package/dist/types/anyspend/platform/types.d.ts +478 -0
- package/dist/types/anyspend/platform/utils/idempotency.d.ts +4 -0
- package/dist/types/anyspend/platform/utils/pagination.d.ts +12 -0
- package/dist/types/anyspend/react/components/AnySpend.d.ts +5 -1
- package/dist/types/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
- package/dist/types/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
- package/dist/types/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
- package/dist/types/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
- package/dist/types/anyspend/react/components/checkout/KycGate.d.ts +11 -0
- package/dist/types/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
- package/dist/types/anyspend/react/components/index.d.ts +1 -1
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
- package/dist/types/anyspend/react/hooks/useKycStatus.d.ts +47 -0
- package/dist/types/anyspend/services/anyspend.d.ts +4 -1
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +3 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +18 -0
- package/package.json +7 -1
- package/src/anyspend/docs/checkout-sessions.md +20 -3
- package/src/anyspend/platform/client.ts +198 -0
- package/src/anyspend/platform/errors.ts +92 -0
- package/src/anyspend/platform/index.ts +129 -0
- package/src/anyspend/platform/resources/analytics.ts +10 -0
- package/src/anyspend/platform/resources/checkout-sessions.ts +36 -0
- package/src/anyspend/platform/resources/customers.ts +54 -0
- package/src/anyspend/platform/resources/discount-codes.ts +63 -0
- package/src/anyspend/platform/resources/events.ts +22 -0
- package/src/anyspend/platform/resources/notifications.ts +37 -0
- package/src/anyspend/platform/resources/organization.ts +24 -0
- package/src/anyspend/platform/resources/payment-links.ts +74 -0
- package/src/anyspend/platform/resources/products.ts +59 -0
- package/src/anyspend/platform/resources/transactions.ts +33 -0
- package/src/anyspend/platform/resources/webhooks.ts +47 -0
- package/src/anyspend/platform/resources/widgets.ts +63 -0
- package/src/anyspend/platform/types.ts +532 -0
- package/src/anyspend/platform/utils/idempotency.ts +15 -0
- package/src/anyspend/platform/utils/pagination.ts +32 -0
- package/src/anyspend/react/components/AnySpend.tsx +148 -14
- package/src/anyspend/react/components/checkout/AnySpendCheckout.tsx +81 -18
- package/src/anyspend/react/components/checkout/AnySpendCheckoutTrigger.tsx +4 -0
- package/src/anyspend/react/components/checkout/CheckoutPaymentPanel.tsx +8 -0
- package/src/anyspend/react/components/checkout/CryptoPayPanel.tsx +4 -13
- package/src/anyspend/react/components/checkout/FiatCheckoutPanel.tsx +86 -17
- package/src/anyspend/react/components/checkout/KycGate.tsx +387 -0
- package/src/anyspend/react/components/checkout/VariablePricingInput.tsx +247 -0
- package/src/anyspend/react/components/index.ts +1 -0
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +17 -0
- package/src/anyspend/react/hooks/useKycStatus.ts +150 -0
- package/src/anyspend/services/anyspend.ts +7 -0
- package/src/global-account/react/components/B3DynamicModal.tsx +0 -2
- package/src/global-account/react/components/ManageAccount/BottomNavigation.tsx +7 -7
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +13 -5
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +35 -25
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +1 -1
- package/src/global-account/react/hooks/useAuth.ts +2 -2
- package/src/global-account/react/hooks/useAuthentication.ts +80 -27
- package/src/global-account/react/hooks/useGetAllTWSigners.tsx +2 -1
- package/src/global-account/react/stores/useModalStore.ts +6 -0
- package/src/global-account/react/utils/createWagmiConfig.tsx +18 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ANYSPEND_MAINNET_BASE_URL } from "../../../anyspend/constants/index.js";
|
|
3
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { useCallback } from "react";
|
|
5
|
+
import { useAccount, useSignMessage } from "wagmi";
|
|
6
|
+
function buildWalletAuthMessage(walletAddress, timestamp) {
|
|
7
|
+
return `AnySpend wants to verify your identity for card payments.\n\nThis signature does not trigger a blockchain transaction or cost any gas.\n\nWallet: ${walletAddress.toLowerCase()}\nNonce: ${timestamp}`;
|
|
8
|
+
}
|
|
9
|
+
/** Module-level signature cache to avoid repeated wallet prompts within the 5-minute window. */
|
|
10
|
+
const headerCache = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* Returns cached wallet auth headers without triggering a wallet signature prompt.
|
|
13
|
+
* Returns undefined if no valid cache exists for the given address.
|
|
14
|
+
*/
|
|
15
|
+
export function getCachedWalletHeaders(address) {
|
|
16
|
+
const cached = headerCache.get(address.toLowerCase());
|
|
17
|
+
if (cached && Date.now() < cached.expiresAt)
|
|
18
|
+
return cached.headers;
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns a function that builds the wallet-signature auth headers.
|
|
23
|
+
* Caches signatures for 4 minutes (server allows 5-minute window).
|
|
24
|
+
*/
|
|
25
|
+
export function useWalletAuthHeaders() {
|
|
26
|
+
const { address } = useAccount();
|
|
27
|
+
const { signMessageAsync } = useSignMessage();
|
|
28
|
+
const getHeaders = useCallback(async () => {
|
|
29
|
+
if (!address)
|
|
30
|
+
throw new Error("No wallet connected");
|
|
31
|
+
const walletAddress = address.toLowerCase();
|
|
32
|
+
const cached = headerCache.get(walletAddress);
|
|
33
|
+
if (cached && Date.now() < cached.expiresAt)
|
|
34
|
+
return cached.headers;
|
|
35
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
36
|
+
const message = buildWalletAuthMessage(walletAddress, timestamp);
|
|
37
|
+
const signature = await signMessageAsync({ message });
|
|
38
|
+
const headers = {
|
|
39
|
+
"X-Wallet-Address": walletAddress,
|
|
40
|
+
"X-Wallet-Signature": signature,
|
|
41
|
+
"X-Wallet-Timestamp": String(timestamp),
|
|
42
|
+
};
|
|
43
|
+
// Cache for 4 minutes so repeated fetches don't re-prompt the user
|
|
44
|
+
headerCache.set(walletAddress, { headers, expiresAt: Date.now() + 4 * 60 * 1000 });
|
|
45
|
+
return headers;
|
|
46
|
+
}, [address, signMessageAsync]);
|
|
47
|
+
return { address, getHeaders };
|
|
48
|
+
}
|
|
49
|
+
export function useKycStatus(enabled = true) {
|
|
50
|
+
const { address, getHeaders } = useWalletAuthHeaders();
|
|
51
|
+
const { data, isLoading, error, refetch } = useQuery({
|
|
52
|
+
queryKey: ["kyc-status", address],
|
|
53
|
+
queryFn: async () => {
|
|
54
|
+
const headers = await getHeaders();
|
|
55
|
+
const response = await fetch(`${ANYSPEND_MAINNET_BASE_URL}/kyc/status`, { headers });
|
|
56
|
+
const json = await response.json();
|
|
57
|
+
if (!response.ok)
|
|
58
|
+
throw new Error(json.message || "Failed to fetch KYC status");
|
|
59
|
+
return json.data;
|
|
60
|
+
},
|
|
61
|
+
enabled: enabled && !!address,
|
|
62
|
+
staleTime: 30000,
|
|
63
|
+
retry: 0,
|
|
64
|
+
refetchOnWindowFocus: false,
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
kycStatus: data || null,
|
|
68
|
+
isLoadingKycStatus: isLoading,
|
|
69
|
+
kycStatusError: error,
|
|
70
|
+
refetchKycStatus: refetch,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function useCreateKycInquiry() {
|
|
74
|
+
const { address, getHeaders } = useWalletAuthHeaders();
|
|
75
|
+
const { mutateAsync, isPending } = useMutation({
|
|
76
|
+
mutationFn: async () => {
|
|
77
|
+
if (!address)
|
|
78
|
+
throw new Error("No wallet connected");
|
|
79
|
+
const headers = await getHeaders();
|
|
80
|
+
const response = await fetch(`${ANYSPEND_MAINNET_BASE_URL}/kyc/inquiry`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
83
|
+
});
|
|
84
|
+
const json = await response.json();
|
|
85
|
+
if (!response.ok)
|
|
86
|
+
throw new Error(json.message || "Failed to create KYC inquiry");
|
|
87
|
+
return json.data;
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
createInquiry: mutateAsync,
|
|
92
|
+
isCreatingInquiry: isPending,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export function useVerifyKyc() {
|
|
96
|
+
const { address, getHeaders } = useWalletAuthHeaders();
|
|
97
|
+
const { mutateAsync, isPending } = useMutation({
|
|
98
|
+
mutationFn: async (inquiryId) => {
|
|
99
|
+
if (!address)
|
|
100
|
+
throw new Error("No wallet connected");
|
|
101
|
+
const headers = await getHeaders();
|
|
102
|
+
const response = await fetch(`${ANYSPEND_MAINNET_BASE_URL}/kyc/verify`, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
105
|
+
body: JSON.stringify({ inquiryId }),
|
|
106
|
+
});
|
|
107
|
+
const json = await response.json();
|
|
108
|
+
if (!response.ok)
|
|
109
|
+
throw new Error(json.message || "Failed to verify KYC");
|
|
110
|
+
return json.data;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
verifyKyc: mutateAsync,
|
|
115
|
+
isVerifying: isPending,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -6,7 +6,7 @@ export declare const anyspendService: {
|
|
|
6
6
|
getTokenList: (chainId: number, query: string) => Promise<components["schemas"]["Token"][]>;
|
|
7
7
|
getToken: (chainId: number, tokenAddress: string) => Promise<components["schemas"]["Token"]>;
|
|
8
8
|
getQuote: (req: GetQuoteRequest, partnerId?: string) => Promise<GetQuoteResponse>;
|
|
9
|
-
createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, callbackMetadata, }: {
|
|
9
|
+
createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, callbackMetadata, feeOnTop, kycWalletHeaders, }: {
|
|
10
10
|
recipientAddress: string;
|
|
11
11
|
type: string;
|
|
12
12
|
srcChain: number;
|
|
@@ -22,6 +22,9 @@ export declare const anyspendService: {
|
|
|
22
22
|
clientReferenceId?: string;
|
|
23
23
|
visitorData?: VisitorData;
|
|
24
24
|
callbackMetadata?: Record<string, unknown>;
|
|
25
|
+
feeOnTop?: boolean;
|
|
26
|
+
/** Wallet signature auth headers for KYC lookup (stripe-web2 orders only). */
|
|
27
|
+
kycWalletHeaders?: Record<string, string>;
|
|
25
28
|
}) => Promise<{
|
|
26
29
|
success: boolean;
|
|
27
30
|
message: string;
|
|
@@ -37,7 +37,7 @@ export const anyspendService = {
|
|
|
37
37
|
return data;
|
|
38
38
|
},
|
|
39
39
|
// Order related
|
|
40
|
-
createOrder: async ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, callbackMetadata, }) => {
|
|
40
|
+
createOrder: async ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, callbackMetadata, feeOnTop, kycWalletHeaders, }) => {
|
|
41
41
|
const accessToken = await app.authentication.getAccessToken();
|
|
42
42
|
const response = await fetch(`${ANYSPEND_MAINNET_BASE_URL}/orders`, {
|
|
43
43
|
method: "POST",
|
|
@@ -46,6 +46,7 @@ export const anyspendService = {
|
|
|
46
46
|
...(visitorData?.requestId && { "X-Fingerprint-Request-Id": visitorData.requestId }),
|
|
47
47
|
...(visitorData?.visitorId && { "X-Fingerprint-Visitor-Id": visitorData.visitorId }),
|
|
48
48
|
...(accessToken && { Authorization: `Bearer ${accessToken}` }),
|
|
49
|
+
...kycWalletHeaders,
|
|
49
50
|
},
|
|
50
51
|
body: JSON.stringify({
|
|
51
52
|
recipientAddress,
|
|
@@ -62,6 +63,7 @@ export const anyspendService = {
|
|
|
62
63
|
partnerId,
|
|
63
64
|
...(clientReferenceId && { clientReferenceId }),
|
|
64
65
|
...(callbackMetadata && { callbackMetadata }),
|
|
66
|
+
...(feeOnTop != null && { feeOnTop }),
|
|
65
67
|
}),
|
|
66
68
|
});
|
|
67
69
|
const data = await response.json();
|
|
@@ -162,7 +162,7 @@ export function B3DynamicModal() {
|
|
|
162
162
|
contentType?.type === "send" ||
|
|
163
163
|
contentType?.type === "avatarEditor" ||
|
|
164
164
|
contentType?.type === "notifications") &&
|
|
165
|
-
"p-0", "mx-auto w-full max-w-md sm:max-w-lg"), hideCloseButton: hideCloseButton, hideGABranding: isAnySpendType, onEscapeKeyDown: !isClosable ? e => e.preventDefault() : undefined,
|
|
165
|
+
"p-0", "mx-auto w-full max-w-md sm:max-w-lg"), hideCloseButton: hideCloseButton, hideGABranding: isAnySpendType, onEscapeKeyDown: !isClosable ? e => e.preventDefault() : undefined, children: [_jsx(ModalTitle, { className: "sr-only hidden", children: contentType?.type || "Modal" }), _jsx(ModalDescription, { className: "sr-only hidden", children: contentType?.type || "Modal Body" }), _jsxs("div", { className: cn("b3-modal-content no-scrollbar dark:bg-b3-background flex max-h-[90dvh] flex-col overflow-auto sm:max-h-[80dvh]"), children: [!hideCloseButton && (_jsxs("button", { onClick: navigateBack, className: "flex items-center gap-2 px-6 py-4 text-gray-600 transition-colors hover:text-gray-900 dark:text-gray-400 dark:hover:text-white", children: [_jsxs("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("path", { d: "M15.8337 10H4.16699", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M10.0003 15.8334L4.16699 10L10.0003 4.16669", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] }), _jsx("span", { className: "font-inter text-sm font-semibold", children: "Back" })] })), _jsx("div", { className: "flex-1", children: renderContent() }), _jsx(AnimatePresence, { children: toasts.length > 0 && (_jsx(motion.div, { initial: { height: 0 }, animate: { height: "auto" }, exit: { height: 0 }, transition: { duration: 0.3, ease: "easeInOut" }, className: "toast-section relative z-10 overflow-hidden bg-white dark:border-neutral-800 dark:bg-neutral-900", children: _jsx(motion.div, { initial: { opacity: 0, y: -10 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -10 }, transition: { duration: 0.2, delay: 0.1 }, className: "p-4 pt-0", children: _jsx(ToastContainer, { toasts: toasts, onDismiss: removeToast, theme: theme }) }) })) })] })] }), isOpen && !isAnySpendType && (_jsx("style", { children: `
|
|
166
166
|
.modal-inner-content {
|
|
167
167
|
transition: margin-bottom 0.3s ease-in-out;
|
|
168
168
|
margin-bottom: ${toasts.length > 0 ? "0px" : "23px"} !important;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { TabsListPrimitive, TabTriggerPrimitive, useModalStore } from "../../../../global-account/react/index.js";
|
|
3
3
|
const HomeIcon = () => {
|
|
4
|
-
return (_jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", {
|
|
4
|
+
return (_jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M12.5227 1.33636C12.1804 1.24368 11.8196 1.24368 11.4773 1.33636C11.08 1.44395 10.7454 1.7066 10.4784 1.91623L10.4038 1.97465L3.54376 7.31012C3.16713 7.6024 2.83532 7.85991 2.58806 8.19421C2.37107 8.48759 2.20942 8.8181 2.11106 9.1695C1.99898 9.56992 1.99943 9.98993 1.99995 10.4667L2.00002 17.8385C2 18.3657 1.99998 18.8204 2.03059 19.195C2.06289 19.5904 2.1342 19.9836 2.327 20.362C2.61462 20.9264 3.07356 21.3854 3.63805 21.673C4.01643 21.8658 4.40964 21.9371 4.80499 21.9694C5.17956 22 5.63431 22 6.16145 22H17.8386C18.3657 22 18.8205 22 19.195 21.9694C19.5904 21.9371 19.9836 21.8658 20.362 21.673C20.9265 21.3854 21.3854 20.9264 21.673 20.362C21.8658 19.9836 21.9371 19.5904 21.9694 19.195C22.0001 18.8204 22 18.3657 22 17.8386L22.0001 10.4667C22.0006 9.98993 22.0011 9.56992 21.889 9.1695C21.7906 8.8181 21.629 8.48759 21.412 8.19421C21.1647 7.8599 20.8329 7.6024 20.4563 7.31011L13.5963 1.97465L13.5216 1.91623C13.2546 1.7066 12.9201 1.44395 12.5227 1.33636ZM8.00003 16C7.44775 16 7.00003 16.4477 7.00003 17C7.00003 17.5523 7.44775 18 8.00003 18H16C16.5523 18 17 17.5523 17 17C17 16.4477 16.5523 16 16 16H8.00003Z", fill: "currentColor" }) }));
|
|
5
5
|
};
|
|
6
6
|
const SwapIcon = () => {
|
|
7
|
-
return (_jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M20.4533 12.893C20.1755 15.5029 18.6968 17.9487 16.2498 19.3614C12.1843 21.7086 6.98576 20.3157 4.63855 16.2502L4.38855 15.8172M3.5465 11.107C3.8243 8.49711 5.30309 6.05138 7.75007 4.63862C11.8156 2.29141 17.0141 3.68434 19.3613 7.74983L19.6113 8.18285M3.49353 18.0661L4.22558 15.334L6.95763 16.0661M17.0428 7.93401L19.7748 8.66606L20.5069 5.93401", stroke: "currentColor",
|
|
7
|
+
return (_jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M20.4533 12.893C20.1755 15.5029 18.6968 17.9487 16.2498 19.3614C12.1843 21.7086 6.98576 20.3157 4.63855 16.2502L4.38855 15.8172M3.5465 11.107C3.8243 8.49711 5.30309 6.05138 7.75007 4.63862C11.8156 2.29141 17.0141 3.68434 19.3613 7.74983L19.6113 8.18285M3.49353 18.0661L4.22558 15.334L6.95763 16.0661M17.0428 7.93401L19.7748 8.66606L20.5069 5.93401", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
8
8
|
};
|
|
9
9
|
const SettingsIcon = () => {
|
|
10
|
-
return (_jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", {
|
|
10
|
+
return (_jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M19.286 15.9606C19.2272 15.6362 19.2669 15.3016 19.4 15C19.5268 14.7042 19.7372 14.452 20.0055 14.2743C20.2738 14.0966 20.5882 14.0013 20.91 14H21C21.5304 14 22.0391 13.7893 22.4142 13.4142C22.7893 13.0391 23 12.5304 23 12C23 11.4696 22.7893 10.9609 22.4142 10.5858C22.0391 10.2107 21.5304 10 21 10H20.83C20.5082 9.99872 20.1938 9.90337 19.9255 9.72569C19.6572 9.54802 19.4468 9.29577 19.32 9V8.92C19.1869 8.61838 19.1472 8.28381 19.206 7.95941C19.2648 7.63502 19.4195 7.33568 19.65 7.1L19.71 7.04C19.896 6.85425 20.0435 6.63368 20.1441 6.39088C20.2448 6.14808 20.2966 5.88783 20.2966 5.625C20.2966 5.36217 20.2448 5.10192 20.1441 4.85912C20.0435 4.61632 19.896 4.39575 19.71 4.21C19.5243 4.02405 19.3037 3.87653 19.0609 3.77588C18.8181 3.67523 18.5578 3.62343 18.295 3.62343C18.0322 3.62343 17.7719 3.67523 17.5291 3.77588C17.2863 3.87653 17.0657 4.02405 16.88 4.21L16.82 4.27C16.5843 4.50054 16.285 4.65519 15.9606 4.714C15.6362 4.77282 15.3016 4.73312 15 4.6C14.7042 4.47324 14.452 4.26276 14.2743 3.99447C14.0966 3.72618 14.0013 3.41179 14 3.09V3C14 2.46957 13.7893 1.96086 13.4142 1.58579C13.0391 1.21071 12.5304 1 12 1C11.4696 1 10.9609 1.21071 10.5858 1.58579C10.2107 1.96086 10 2.46957 10 3V3.17C9.99872 3.49179 9.90337 3.80618 9.72569 4.07447C9.54802 4.34276 9.29577 4.55324 9 4.68H8.92C8.61838 4.81312 8.28381 4.85282 7.95941 4.794C7.63502 4.73519 7.33568 4.58054 7.1 4.35L7.04 4.29C6.85425 4.10405 6.63368 3.95653 6.39088 3.85588C6.14808 3.75523 5.88783 3.70343 5.625 3.70343C5.36217 3.70343 5.10192 3.75523 4.85912 3.85588C4.61632 3.95653 4.39575 4.10405 4.21 4.29C4.02405 4.47575 3.87653 4.69632 3.77588 4.93912C3.67523 5.18192 3.62343 5.44217 3.62343 5.705C3.62343 5.96783 3.67523 6.22808 3.77588 6.47088C3.87653 6.71368 4.02405 6.93425 4.21 7.12L4.27 7.18C4.50054 7.41568 4.65519 7.71502 4.714 8.03941C4.77282 8.36381 4.73312 8.69838 4.6 9C4.48572 9.31074 4.28059 9.5799 4.0113 9.77251C3.742 9.96512 3.42099 10.0723 3.09 10.08H3C2.46957 10.08 1.96086 10.2907 1.58579 10.6658C1.21071 11.0409 1 11.5496 1 12.08C1 12.6104 1.21071 13.1191 1.58579 13.4942C1.96086 13.8693 2.46957 14.08 3 14.08H3.17C3.49179 14.0813 3.80618 14.1766 4.07447 14.3543C4.34276 14.532 4.55324 14.7842 4.68 15.08C4.81312 15.3816 4.85282 15.7162 4.794 16.0406C4.73519 16.365 4.58054 16.6643 4.35 16.9L4.29 16.96C4.10405 17.1457 3.95653 17.3663 3.85588 17.6091C3.75523 17.8519 3.70343 18.1122 3.70343 18.375C3.70343 18.6378 3.75523 18.8981 3.85588 19.1409C3.95653 19.3837 4.10405 19.6043 4.29 19.79C4.47575 19.976 4.69632 20.1235 4.93912 20.2241C5.18192 20.3248 5.44217 20.3766 5.705 20.3766C5.96783 20.3766 6.22808 20.3248 6.47088 20.2241C6.71368 20.1235 6.93425 19.976 7.12 19.79L7.18 19.73C7.41568 19.4995 7.71502 19.3448 8.03941 19.286C8.36381 19.2272 8.69838 19.2669 9 19.4C9.31074 19.5143 9.5799 19.7194 9.77251 19.9887C9.96512 20.258 10.0723 20.579 10.08 20.91V21C10.08 21.5304 10.2907 22.0391 10.6658 22.4142C11.0409 22.7893 11.5496 23 12.08 23C12.6104 23 13.1191 22.7893 13.4942 22.4142C13.8693 22.0391 14.08 21.5304 14.08 21V20.83C14.0813 20.5082 14.1766 20.1938 14.3543 19.9255C14.532 19.6572 14.7842 19.4468 15.08 19.32C15.3816 19.1869 15.7162 19.1472 16.0406 19.206C16.365 19.2648 16.6643 19.4195 16.9 19.65L16.96 19.71C17.1457 19.896 17.3663 20.0435 17.6091 20.1441C17.8519 20.2448 18.1122 20.2966 18.375 20.2966C18.6378 20.2966 18.8981 20.2448 19.1409 20.1441C19.3837 20.0435 19.6043 19.896 19.79 19.71C19.976 19.5243 20.1235 19.3037 20.2241 19.0609C20.3248 18.8181 20.3766 18.5578 20.3766 18.295C20.3766 18.0322 20.3248 17.7719 20.2241 17.5291C20.1235 17.2863 19.976 17.0657 19.79 16.88L19.73 16.82C19.4995 16.5843 19.3448 16.285 19.286 15.9606ZM15 12C15 13.6569 13.6569 15 12 15C10.3431 15 9 13.6569 9 12C9 10.3431 10.3431 9 12 9C13.6569 9 15 10.3431 15 12Z", fill: "currentColor" }) }));
|
|
11
11
|
};
|
|
12
12
|
const BottomNavigation = () => {
|
|
13
13
|
const setB3ModalContentType = useModalStore(state => state.setB3ModalContentType);
|
|
@@ -13,7 +13,7 @@ export function SignIn(props) {
|
|
|
13
13
|
const { address: globalAddress, ensName, connectedSmartWallet, connectedEOAWallet, isActiveSmartWallet, isActiveEOAWallet, smartWalletIcon, } = useAccountWallet();
|
|
14
14
|
const { data: walletImage } = useWalletImage(connectedEOAWallet?.id);
|
|
15
15
|
const isMobile = useIsMobile();
|
|
16
|
-
const { logout } = useAuthentication(partnerId);
|
|
16
|
+
const { logout } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
17
17
|
const onDisconnect = async () => {
|
|
18
18
|
await logout();
|
|
19
19
|
};
|
|
@@ -14,16 +14,23 @@ const MAX_REFETCH_ATTEMPTS = 20;
|
|
|
14
14
|
*/
|
|
15
15
|
export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, source = "signInWithB3Button", signersEnabled = false, }) {
|
|
16
16
|
const { automaticallySetFirstEoa } = useB3Config();
|
|
17
|
-
|
|
18
|
-
//
|
|
17
|
+
// skipAutoConnect: this component intentionally logs out on mount to show a fresh login screen.
|
|
18
|
+
// AuthenticationProvider is the sole owner of useAutoConnect to avoid competing auth cycles.
|
|
19
|
+
const { user, logout } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
20
|
+
// Tracks whether the pre-login logout has finished.
|
|
21
|
+
// We must not render ConnectEmbed until logout (wallet disconnect) completes,
|
|
22
|
+
// otherwise the wallet state disrupts ConnectEmbed causing a blank modal.
|
|
23
|
+
const [readyToShowLogin, setReadyToShowLogin] = useState(source === "requestPermissions");
|
|
19
24
|
const hasLoggedOutRef = useRef(false);
|
|
20
25
|
useEffect(() => {
|
|
21
26
|
if (hasLoggedOutRef.current)
|
|
22
27
|
return;
|
|
23
28
|
if (source !== "requestPermissions") {
|
|
24
29
|
debug("Logging out before login");
|
|
25
|
-
logout();
|
|
26
30
|
hasLoggedOutRef.current = true;
|
|
31
|
+
logout().finally(() => {
|
|
32
|
+
setReadyToShowLogin(true);
|
|
33
|
+
});
|
|
27
34
|
}
|
|
28
35
|
}, [source, logout]);
|
|
29
36
|
const [step, setStep] = useState(source === "requestPermissions" ? null : "login");
|
|
@@ -228,8 +235,9 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
228
235
|
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx("div", { className: "p-4 text-center text-red-500", children: refetchError }) }));
|
|
229
236
|
}
|
|
230
237
|
else if (step === "login") {
|
|
231
|
-
// Show loading spinner
|
|
232
|
-
|
|
238
|
+
// Show loading spinner while: authenticating, waiting for pre-login logout to finish,
|
|
239
|
+
// or fetching signers.
|
|
240
|
+
if (!readyToShowLogin || isAuthenticating || isFetchingSigners) {
|
|
233
241
|
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx("div", { className: "my-8 flex min-h-[350px] items-center justify-center", children: _jsx(Loading, { variant: "white", size: "lg" }) }) }));
|
|
234
242
|
}
|
|
235
243
|
else {
|
|
@@ -8,7 +8,7 @@ export function SignInWithB3Privy({ onSuccess, onError, chain }) {
|
|
|
8
8
|
const { isLoading, connectTw, fullToken } = useHandleConnectWithPrivy(chain, onSuccess);
|
|
9
9
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
10
10
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
11
|
-
const { logout } = useAuthentication(partnerId);
|
|
11
|
+
const { logout } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
12
12
|
debug("@@SignInWithB3Privy", {
|
|
13
13
|
isLoading,
|
|
14
14
|
fullToken,
|
|
@@ -19,5 +19,5 @@ interface LoginStepContainerProps {
|
|
|
19
19
|
partnerId?: string;
|
|
20
20
|
}
|
|
21
21
|
export declare function LoginStepContainer({ children, partnerId }: LoginStepContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
-
export declare function LoginStep({ onSuccess, chain }: LoginStepProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare function LoginStep({ onSuccess, chain }: LoginStepProps): import("react/jsx-runtime").JSX.Element | null;
|
|
23
23
|
export {};
|
|
@@ -3,6 +3,7 @@ import { useAuthentication, useB3Config, useQueryB3 } from "../../../../../globa
|
|
|
3
3
|
import { ecosystemWalletId } from "../../../../../shared/constants/index.js";
|
|
4
4
|
import { client } from "../../../../../shared/utils/thirdweb.js";
|
|
5
5
|
import { ConnectEmbed, darkTheme, lightTheme } from "thirdweb/react";
|
|
6
|
+
import { useMemo } from "react";
|
|
6
7
|
import { ecosystemWallet } from "thirdweb/wallets";
|
|
7
8
|
export function LoginStepContainer({ children, partnerId }) {
|
|
8
9
|
const { data: partner } = useQueryB3("global-accounts-partners", "find", {
|
|
@@ -14,30 +15,17 @@ export function LoginStepContainer({ children, partnerId }) {
|
|
|
14
15
|
const partnerLogo = partner?.data?.[0]?.loginCustomization?.logoUrl;
|
|
15
16
|
return (_jsxs("div", { className: "bg-b3-react-background 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] }));
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
: darkTheme({
|
|
30
|
-
colors: {
|
|
31
|
-
modalBg: "hsl(var(--b3-react-background))",
|
|
32
|
-
},
|
|
33
|
-
}), style: {
|
|
34
|
-
width: "100%",
|
|
35
|
-
height: "100%",
|
|
36
|
-
border: 0,
|
|
37
|
-
}, header: {
|
|
38
|
-
title: "Sign in with B3",
|
|
39
|
-
titleIcon: "https://cdn.b3.fun/b3_logo.svg",
|
|
40
|
-
}, className: "b3-login-step", onConnect: async (wallet, allConnectedWallets) => {
|
|
18
|
+
/** Inner component that only mounts when partnerId is a non-empty string.
|
|
19
|
+
* Keeps all hooks unconditional without calling useAuthentication(""). */
|
|
20
|
+
function LoginStepContent({ onSuccess, chain, partnerId, theme, }) {
|
|
21
|
+
const wallet = useMemo(() => ecosystemWallet(ecosystemWalletId, { partnerId }), [partnerId]);
|
|
22
|
+
// skipAutoConnect: AuthenticationProvider already owns the auto-connect instance.
|
|
23
|
+
// Creating another here would cause a second authentication cycle (another 401 attempt)
|
|
24
|
+
// that makes the modal flash between spinner and blank before finally showing the login form.
|
|
25
|
+
const { onConnect } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
26
|
+
return (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx(ConnectEmbed, { showThirdwebBranding: false, autoConnect: false, client: client, chain: chain, wallets: [wallet], theme: theme === "light"
|
|
27
|
+
? lightTheme({ colors: { modalBg: "hsl(var(--b3-react-background))" } })
|
|
28
|
+
: darkTheme({ colors: { modalBg: "hsl(var(--b3-react-background))" } }), style: { width: "100%", height: "100%", border: 0 }, header: { title: "Sign in with B3", titleIcon: "https://cdn.b3.fun/b3_logo.svg" }, className: "b3-login-step", onConnect: async (wallet, allConnectedWallets) => {
|
|
41
29
|
await onConnect(wallet, allConnectedWallets);
|
|
42
30
|
const account = wallet.getAccount();
|
|
43
31
|
if (!account)
|
|
@@ -45,3 +33,12 @@ export function LoginStep({ onSuccess, chain }) {
|
|
|
45
33
|
await onSuccess(account);
|
|
46
34
|
} }) }));
|
|
47
35
|
}
|
|
36
|
+
export function LoginStep({ onSuccess, chain }) {
|
|
37
|
+
const { partnerId, theme } = useB3Config();
|
|
38
|
+
// partnerId may be undefined during the brief B3Provider hydration window.
|
|
39
|
+
// Return null rather than rendering ConnectEmbed with an invalid ecosystem
|
|
40
|
+
// wallet config (which causes a blank screen).
|
|
41
|
+
if (!partnerId)
|
|
42
|
+
return null;
|
|
43
|
+
return _jsx(LoginStepContent, { onSuccess: onSuccess, chain: chain, partnerId: partnerId, theme: theme });
|
|
44
|
+
}
|
|
@@ -13,7 +13,7 @@ export function LoginStepCustom({ onSuccess, onError, chain, strategies, maxInit
|
|
|
13
13
|
const { connect } = useConnect(partnerId, chain);
|
|
14
14
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
15
15
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
16
|
-
const { logout } = useAuthentication(partnerId);
|
|
16
|
+
const { logout } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
17
17
|
const { connect: connectTW } = useConnectTW();
|
|
18
18
|
// Split strategies into auth and wallet types
|
|
19
19
|
const authStrategies = strategies.filter(s => !isWalletType(s));
|
|
@@ -11,7 +11,7 @@ import { ecosystemWallet } from "thirdweb/wallets";
|
|
|
11
11
|
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
12
12
|
import { useAccount, useConnect, useSwitchAccount } from "wagmi";
|
|
13
13
|
import { LocalSDKContext } from "../components/B3Provider/LocalSDKProvider.js";
|
|
14
|
-
import {
|
|
14
|
+
import { getCachedWagmiConfig } from "../utils/createWagmiConfig.js";
|
|
15
15
|
import { useSearchParam } from "./useSearchParamsSSR.js";
|
|
16
16
|
import { useUserQuery } from "./useUserQuery.js";
|
|
17
17
|
const debug = debugB3React("useAuth");
|
|
@@ -38,7 +38,7 @@ export function useAuth() {
|
|
|
38
38
|
const useAutoConnectLoadingPrevious = useRef(false);
|
|
39
39
|
const referralCode = useSearchParam("referralCode");
|
|
40
40
|
const { partnerId } = useB3Config();
|
|
41
|
-
const wagmiConfig =
|
|
41
|
+
const wagmiConfig = getCachedWagmiConfig({ partnerId });
|
|
42
42
|
const { connect } = useConnect();
|
|
43
43
|
const activeWagmiAccount = useAccount();
|
|
44
44
|
const { switchAccount } = useSwitchAccount();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Wallet } from "thirdweb/wallets";
|
|
2
2
|
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
3
|
-
export declare function useAuthentication(partnerId: string
|
|
3
|
+
export declare function useAuthentication(partnerId: string, { skipAutoConnect }?: {
|
|
4
|
+
skipAutoConnect?: boolean;
|
|
5
|
+
}): {
|
|
4
6
|
logout: (callback?: () => void) => Promise<void>;
|
|
5
7
|
isAuthenticated: boolean;
|
|
6
8
|
isReady: boolean;
|
|
@@ -15,11 +15,26 @@ import { createWagmiConfig } from "../utils/createWagmiConfig.js";
|
|
|
15
15
|
import { useTWAuth } from "./useTWAuth.js";
|
|
16
16
|
import { useUserQuery } from "./useUserQuery.js";
|
|
17
17
|
const debug = debugB3React("useAuthentication");
|
|
18
|
-
export function useAuthentication(partnerId) {
|
|
18
|
+
export function useAuthentication(partnerId, { skipAutoConnect = false } = {}) {
|
|
19
19
|
const { onConnectCallback, onLogoutCallback } = useContext(LocalSDKContext);
|
|
20
20
|
const { disconnect } = useDisconnect();
|
|
21
21
|
const wallets = useConnectedWallets();
|
|
22
|
+
// Keep refs so logout() always disconnects current wallets, not stale closure values.
|
|
23
|
+
// autoConnectCore captures onConnect (and thus logout) from the first render before wallets
|
|
24
|
+
// are populated — without these refs, logout() would capture wallets=[] and disconnect nothing.
|
|
25
|
+
const walletsRef = useRef(wallets);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
walletsRef.current = wallets;
|
|
28
|
+
}, [wallets]);
|
|
22
29
|
const activeWallet = useActiveWallet();
|
|
30
|
+
// Track the active wallet by ref so logout() can disconnect the exact reference
|
|
31
|
+
// stored in thirdweb's activeWalletStore. walletsRef.current (from useConnectedWallets)
|
|
32
|
+
// may hold a different object reference than what thirdweb considers "active",
|
|
33
|
+
// causing the identity check in onWalletDisconnect to fail silently.
|
|
34
|
+
const activeWalletRef = useRef(activeWallet);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
activeWalletRef.current = activeWallet;
|
|
37
|
+
}, [activeWallet]);
|
|
23
38
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
24
39
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
25
40
|
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
@@ -126,21 +141,29 @@ export function useAuthentication(partnerId) {
|
|
|
126
141
|
}
|
|
127
142
|
}, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
|
|
128
143
|
const logout = useCallback(async (callback) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
144
|
+
// Only disconnect ecosystem/smart wallets, preserve EOA wallets (e.g. MetaMask)
|
|
145
|
+
// so they remain available after re-login.
|
|
146
|
+
// Use walletsRef.current (not the stale closure value) so we always get current wallets —
|
|
147
|
+
// autoConnectCore captures logout from the first render when wallets is still [].
|
|
148
|
+
walletsRef.current.forEach(wallet => {
|
|
149
|
+
debug("@@logout:wallet", wallet.id);
|
|
150
|
+
if (wallet.id.startsWith("ecosystem.") || wallet.id === "smart") {
|
|
151
|
+
disconnect(wallet);
|
|
152
|
+
}
|
|
138
153
|
});
|
|
139
|
-
//
|
|
140
|
-
//
|
|
154
|
+
// Always disconnect the active wallet to clear thirdweb's activeAccountStore.
|
|
155
|
+
// Without this, any auto-reconnected wallet (e.g. Coinbase Wallet, MetaMask)
|
|
156
|
+
// keeps activeAccount set, and ConnectEmbed renders show=false (blank modal).
|
|
157
|
+
// We use the exact reference from activeWalletRef because thirdweb's
|
|
158
|
+
// onWalletDisconnect uses strict identity (===) to decide whether to clear
|
|
159
|
+
// activeAccountStore.
|
|
160
|
+
if (activeWalletRef.current) {
|
|
161
|
+
debug("@@logout:disconnecting active wallet", activeWalletRef.current.id);
|
|
162
|
+
disconnect(activeWalletRef.current);
|
|
163
|
+
}
|
|
164
|
+
// Clear user-specific storage but preserve wallet connection state
|
|
165
|
+
// so EOA wallets (e.g. MetaMask) can auto-reconnect on next login
|
|
141
166
|
if (typeof localStorage !== "undefined") {
|
|
142
|
-
localStorage.removeItem("thirdweb:connected-wallet-ids");
|
|
143
|
-
localStorage.removeItem("wagmi.store");
|
|
144
167
|
localStorage.removeItem("lastAuthProvider");
|
|
145
168
|
localStorage.removeItem("b3-user");
|
|
146
169
|
}
|
|
@@ -148,33 +171,58 @@ export function useAuthentication(partnerId) {
|
|
|
148
171
|
debug("@@logout:loggedOut");
|
|
149
172
|
setIsAuthenticated(false);
|
|
150
173
|
setIsConnected(false);
|
|
174
|
+
// Reset isAuthenticating so any in-flight page-load auto-connect that set it true
|
|
175
|
+
// does not keep the login modal spinner stuck after logout() is called.
|
|
176
|
+
setIsAuthenticating(false);
|
|
151
177
|
setUser();
|
|
152
178
|
callback?.();
|
|
153
179
|
if (onLogoutCallback) {
|
|
154
180
|
await onLogoutCallback();
|
|
155
181
|
}
|
|
156
|
-
},
|
|
182
|
+
},
|
|
183
|
+
// wallets intentionally omitted — we use walletsRef.current so this callback stays stable
|
|
184
|
+
// and always operates on current wallets even when captured in stale closures.
|
|
185
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
186
|
+
[disconnect, setIsAuthenticated, setIsAuthenticating, setUser, setIsConnected, onLogoutCallback]);
|
|
157
187
|
const onConnect = useCallback(async (_walleAutoConnectedWith, allConnectedWallets) => {
|
|
158
188
|
debug("@@useAuthentication:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
|
|
189
|
+
const ecosystemWalletToDisconnect = allConnectedWallets.find(w => w.id.startsWith("ecosystem."));
|
|
159
190
|
try {
|
|
160
|
-
|
|
161
|
-
if (!wallet) {
|
|
191
|
+
if (!ecosystemWalletToDisconnect) {
|
|
162
192
|
throw new Error("No smart wallet found during auto-connect");
|
|
163
193
|
}
|
|
164
|
-
debug("@@useAuthentication:onConnect", { wallet });
|
|
194
|
+
debug("@@useAuthentication:onConnect", { wallet: ecosystemWalletToDisconnect });
|
|
165
195
|
setHasStartedConnecting(true);
|
|
166
196
|
setIsConnected(true);
|
|
167
197
|
setIsAuthenticating(true);
|
|
168
|
-
await setActiveWallet(
|
|
169
|
-
const userAuth = await authenticateUser(
|
|
198
|
+
await setActiveWallet(ecosystemWalletToDisconnect);
|
|
199
|
+
const userAuth = await authenticateUser(ecosystemWalletToDisconnect);
|
|
170
200
|
if (userAuth && onConnectCallback) {
|
|
171
|
-
await onConnectCallback(
|
|
201
|
+
await onConnectCallback(ecosystemWalletToDisconnect, userAuth.accessToken);
|
|
172
202
|
}
|
|
173
203
|
}
|
|
174
204
|
catch (error) {
|
|
175
205
|
debug("@@useAuthentication:onConnect:failed", { error });
|
|
176
206
|
setIsAuthenticated(false);
|
|
177
207
|
setUser(undefined);
|
|
208
|
+
// Directly disconnect the ecosystem wallet we set active above.
|
|
209
|
+
// We can't rely on logout()'s activeWalletRef here because it's updated
|
|
210
|
+
// via useEffect (deferred until after paint), but this callback may run
|
|
211
|
+
// entirely within a single React commit cycle — before the ref updates.
|
|
212
|
+
if (ecosystemWalletToDisconnect) {
|
|
213
|
+
debug("@@useAuthentication:onConnect:disconnecting ecosystem wallet", ecosystemWalletToDisconnect.id);
|
|
214
|
+
disconnect(ecosystemWalletToDisconnect);
|
|
215
|
+
}
|
|
216
|
+
// Also disconnect the wallet that autoConnectCore set as active.
|
|
217
|
+
// When only a non-ecosystem wallet (e.g. MetaMask) auto-reconnects,
|
|
218
|
+
// ecosystemWalletToDisconnect is undefined, so the block above is skipped.
|
|
219
|
+
// But autoConnectCore already set this wallet as thirdweb's activeWallet,
|
|
220
|
+
// leaving activeAccount set. ConnectEmbed checks show = !activeAccount,
|
|
221
|
+
// so if we don't clear it, the login form renders blank.
|
|
222
|
+
if (_walleAutoConnectedWith && _walleAutoConnectedWith !== ecosystemWalletToDisconnect) {
|
|
223
|
+
debug("@@useAuthentication:onConnect:disconnecting auto-connected wallet", _walleAutoConnectedWith.id);
|
|
224
|
+
disconnect(_walleAutoConnectedWith);
|
|
225
|
+
}
|
|
178
226
|
await logout();
|
|
179
227
|
}
|
|
180
228
|
finally {
|
|
@@ -189,6 +237,7 @@ export function useAuthentication(partnerId) {
|
|
|
189
237
|
isAuthenticated,
|
|
190
238
|
isAuthenticating,
|
|
191
239
|
isConnected,
|
|
240
|
+
disconnect,
|
|
192
241
|
setHasStartedConnecting,
|
|
193
242
|
setIsConnected,
|
|
194
243
|
setIsAuthenticating,
|
|
@@ -201,23 +250,32 @@ export function useAuthentication(partnerId) {
|
|
|
201
250
|
]);
|
|
202
251
|
const { isLoading: useAutoConnectLoading } = useAutoConnect({
|
|
203
252
|
client,
|
|
204
|
-
|
|
253
|
+
// When skipAutoConnect is true (e.g. LoginStepContent, SignInWithB3Flow), pass an empty
|
|
254
|
+
// wallets array so useAutoConnect completes immediately without firing onConnect.
|
|
255
|
+
// Only AuthenticationProvider (the primary instance) should own auto-connect.
|
|
256
|
+
wallets: skipAutoConnect ? [] : [wallet],
|
|
205
257
|
onConnect,
|
|
206
258
|
onTimeout: () => {
|
|
259
|
+
if (skipAutoConnect)
|
|
260
|
+
return;
|
|
207
261
|
logout().catch(error => {
|
|
208
262
|
debug("@@useAuthentication:logout on timeout failed", { error });
|
|
209
263
|
});
|
|
210
264
|
},
|
|
211
265
|
});
|
|
212
266
|
/**
|
|
213
|
-
* useAutoConnectLoading starts as false
|
|
267
|
+
* useAutoConnectLoading starts as false.
|
|
268
|
+
* Only the primary (non-skip) instance manages isAuthenticating via this effect
|
|
269
|
+
* to avoid race conditions when multiple useAuthentication instances are mounted.
|
|
214
270
|
*/
|
|
215
271
|
useEffect(() => {
|
|
272
|
+
if (skipAutoConnect)
|
|
273
|
+
return;
|
|
216
274
|
if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
|
|
217
275
|
setIsAuthenticating(false);
|
|
218
276
|
}
|
|
219
277
|
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
220
|
-
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
|
|
278
|
+
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating, skipAutoConnect]);
|
|
221
279
|
const isReady = isAuthenticated && !isAuthenticating;
|
|
222
280
|
return {
|
|
223
281
|
logout,
|
|
@@ -62,7 +62,8 @@ export function useGetAllTWSigners({ chain, accountAddress, queryOptions }) {
|
|
|
62
62
|
});
|
|
63
63
|
return result;
|
|
64
64
|
},
|
|
65
|
-
enabled
|
|
65
|
+
// Respect queryOptions.enabled if explicitly set (e.g. signersEnabled=false from SignInWithB3Flow)
|
|
66
|
+
enabled: queryOptions?.enabled !== false && Boolean(chain && accountAddress),
|
|
66
67
|
refetchOnMount: true,
|
|
67
68
|
refetchOnWindowFocus: true,
|
|
68
69
|
refetchOnReconnect: true,
|
|
@@ -657,6 +657,10 @@ interface ModalState {
|
|
|
657
657
|
setLinkingState: (isLinking: boolean, method?: string | null) => void;
|
|
658
658
|
/** Function to update closable property of current content without adding to history */
|
|
659
659
|
setClosable: (closable: boolean) => void;
|
|
660
|
+
/** Whether a third-party iframe (e.g. Persona KYC) is currently active over the modal */
|
|
661
|
+
personaActive: boolean;
|
|
662
|
+
/** Function to mark a third-party iframe as active/inactive */
|
|
663
|
+
setPersonaActive: (active: boolean) => void;
|
|
660
664
|
}
|
|
661
665
|
/**
|
|
662
666
|
* Zustand store for managing modal state
|
|
@@ -36,4 +36,6 @@ export const useModalStore = create(set => ({
|
|
|
36
36
|
setClosable: (closable) => set(state => ({
|
|
37
37
|
contentType: state.contentType ? { ...state.contentType, closable } : null,
|
|
38
38
|
})),
|
|
39
|
+
personaActive: false,
|
|
40
|
+
setPersonaActive: (active) => set({ personaActive: active }),
|
|
39
41
|
}));
|