@b3dotfun/sdk 0.0.65-alpha.0 → 0.0.65-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.
Files changed (37) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +38 -24
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +22 -9
  3. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +7 -7
  4. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +5 -5
  5. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +2 -10
  6. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
  7. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +16 -10
  8. package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
  9. package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +13 -9
  10. package/dist/cjs/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
  11. package/dist/cjs/anyspend/react/hooks/useCryptoPaymentMethodState.js +51 -0
  12. package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
  13. package/dist/esm/anyspend/react/components/AnySpend.js +38 -24
  14. package/dist/esm/anyspend/react/components/AnySpendCustom.js +22 -9
  15. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +7 -7
  16. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +5 -5
  17. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -10
  18. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
  19. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +16 -10
  20. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
  21. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +13 -9
  22. package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
  23. package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.js +48 -0
  24. package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
  25. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
  26. package/dist/types/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
  27. package/dist/types/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
  28. package/package.json +1 -1
  29. package/src/anyspend/react/components/AnySpend.tsx +50 -29
  30. package/src/anyspend/react/components/AnySpendCustom.tsx +28 -15
  31. package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +8 -7
  32. package/src/anyspend/react/components/AnyspendDepositHype.tsx +5 -4
  33. package/src/anyspend/react/components/common/OrderTokenAmount.tsx +2 -13
  34. package/src/anyspend/react/hooks/useAnyspendFlow.ts +24 -12
  35. package/src/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.ts +20 -12
  36. package/src/anyspend/react/hooks/useCryptoPaymentMethodState.ts +71 -0
  37. package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +6 -12
@@ -31,7 +31,7 @@ export function AnySpendDepositHype(props) {
31
31
  }
32
32
  function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, onSuccess, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, }) {
33
33
  // Use shared flow hook
34
- const { activePanel, setActivePanel, orderId, setOrderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, dstAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, anyspendQuote, isLoadingAnyspendQuote, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = useAnyspendFlow({
34
+ const { activePanel, setActivePanel, orderId, setOrderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, dstAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, effectiveCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, anyspendQuote, isLoadingAnyspendQuote, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = useAnyspendFlow({
35
35
  paymentType,
36
36
  recipientAddress,
37
37
  loadOrder,
@@ -78,7 +78,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
78
78
  }
79
79
  }
80
80
  if (paymentType === "crypto") {
81
- if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
81
+ if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
82
82
  return { text: "Choose payment method", disable: false, error: false, loading: false };
83
83
  }
84
84
  return { text: "Continue to deposit", disable: false, error: false, loading: false };
@@ -92,6 +92,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
92
92
  return { text: "Continue to deposit", disable: false, error: false, loading: false };
93
93
  }, [
94
94
  activeInputAmountInWei,
95
+ effectiveCryptoPaymentMethod,
95
96
  isLoadingAnyspendQuote,
96
97
  isCreatingOrder,
97
98
  isCreatingOnrampOrder,
@@ -99,7 +100,6 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
99
100
  anyspendQuote,
100
101
  dstAmount,
101
102
  paymentType,
102
- selectedCryptoPaymentMethod,
103
103
  selectedFiatPaymentMethod,
104
104
  ]);
105
105
  const onMainButtonClick = async () => {
@@ -110,7 +110,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
110
110
  return;
111
111
  }
112
112
  if (paymentType === "crypto") {
113
- if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
113
+ if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
114
114
  setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD);
115
115
  return;
116
116
  }
@@ -124,7 +124,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
124
124
  await handleFiatOrder();
125
125
  }
126
126
  };
127
- const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [_jsx("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: _jsx("div", { children: _jsx("h1", { className: "text-as-primary text-xl font-bold", children: paymentType === "crypto" ? "Deposit Crypto" : "Fund with Fiat" }) }) }), _jsx("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [paymentType === "crypto" ? (_jsx(CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : (_jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, children: _jsx(PanelOnramp, { srcAmountOnRamp: srcAmount, setSrcAmountOnRamp: setSrcAmount, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: recipientAddress, destinationToken: B3_TOKEN, destinationChainId: base.id, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, hideDstToken: true, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: PanelView.RECIPIENT_SELECTION, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(PanelView.FEE_DETAIL), customUsdInputValues: customUsdInputValues }) })), _jsx("div", { className: cn("relative -my-1 flex h-0 items-center justify-center", paymentType === "fiat" && "hidden"), children: _jsx(Button, { variant: "ghost", className: cn("swap-direction-button border-as-stroke bg-as-surface-primary z-10 h-10 w-10 cursor-default rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl"), children: _jsx("div", { className: "relative flex items-center justify-center transition-opacity", children: _jsx(ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }) }), paymentType === "crypto" && (_jsx(CryptoReceiveSection, { isDepositMode: false, isBuyMode: true, selectedRecipientAddress: selectedRecipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(PanelView.RECIPIENT_SELECTION), setRecipientAddress: setSelectedRecipientAddress, recipientAddressFromProps: recipientAddress, globalAddress: globalAddress, dstAmount: dstAmount, dstToken: B3_TOKEN, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: HYPE_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: base.id, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
127
+ const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [_jsx("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: _jsx("div", { children: _jsx("h1", { className: "text-as-primary text-xl font-bold", children: paymentType === "crypto" ? "Deposit Crypto" : "Fund with Fiat" }) }) }), _jsx("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [paymentType === "crypto" ? (_jsx(CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : (_jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, children: _jsx(PanelOnramp, { srcAmountOnRamp: srcAmount, setSrcAmountOnRamp: setSrcAmount, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: recipientAddress, destinationToken: B3_TOKEN, destinationChainId: base.id, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, hideDstToken: true, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: PanelView.RECIPIENT_SELECTION, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(PanelView.FEE_DETAIL), customUsdInputValues: customUsdInputValues }) })), _jsx("div", { className: cn("relative -my-1 flex h-0 items-center justify-center", paymentType === "fiat" && "hidden"), children: _jsx(Button, { variant: "ghost", className: cn("swap-direction-button border-as-stroke bg-as-surface-primary z-10 h-10 w-10 cursor-default rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl"), children: _jsx("div", { className: "relative flex items-center justify-center transition-opacity", children: _jsx(ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }) }), paymentType === "crypto" && (_jsx(CryptoReceiveSection, { isDepositMode: false, isBuyMode: true, selectedRecipientAddress: selectedRecipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(PanelView.RECIPIENT_SELECTION), setRecipientAddress: setSelectedRecipientAddress, recipientAddressFromProps: recipientAddress, globalAddress: globalAddress, dstAmount: dstAmount, dstToken: B3_TOKEN, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: HYPE_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: base.id, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
128
128
  setIsSrcInputDirty(false);
129
129
  setSrcAmount(value);
130
130
  }, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(PanelView.FEE_DETAIL), selectedCryptoPaymentMethod: selectedCryptoPaymentMethod }))] }) }), _jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: cn("mt-4 flex w-full max-w-[460px] flex-col gap-2"), children: _jsx(ShinyButton, { accentColor: "hsl(var(--as-brand))", disabled: btnInfo.disable, onClick: onMainButtonClick, className: cn("as-main-button relative w-full", btnInfo.error ? "!bg-as-red" : btnInfo.disable ? "!bg-as-on-surface-2" : "!bg-as-brand"), textClassName: cn(btnInfo.error ? "text-white" : btnInfo.disable ? "text-as-secondary" : "text-white"), children: _jsxs("div", { className: "flex items-center justify-center gap-2", children: [btnInfo.loading && _jsx(Loader2, { className: "h-4 w-4 animate-spin" }), btnInfo.text] }) }) }), mainFooter ? mainFooter : null] }));
@@ -14,26 +14,19 @@ import { ChainTokenIcon } from "./ChainTokenIcon.js";
14
14
  export function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, address, chainId, setChainId, token, setToken, hideTokenSelect = false, canEditAmount = true, className, innerClassName, amountClassName, tokenSelectClassName, onTokenSelect, walletAddress, }) {
15
15
  // Track previous token to detect changes
16
16
  const prevTokenRef = useRef(token.address);
17
- // Track if initial balance has been set
18
- const initialBalanceSetRef = useRef(false);
19
17
  // Only get token balance when context is "from" (for setting max amount)
20
18
  const { rawBalance } = useTokenBalance({
21
19
  token,
22
20
  address: context === "from" && walletAddress ? walletAddress : undefined,
23
21
  });
24
- // Reset balance ref when token address or chain changes
25
- useEffect(() => {
26
- initialBalanceSetRef.current = false;
27
- }, [token.address, token.chainId]);
28
22
  useEffect(() => {
29
23
  // Only handle "from" context
30
24
  if (context !== "from")
31
25
  return;
32
26
  // Check if token changed or if this is the initial load with balance
33
27
  const isTokenChanged = prevTokenRef.current !== token.address;
34
- const isInitialLoad = !initialBalanceSetRef.current && rawBalance;
35
- if ((isTokenChanged || isInitialLoad) && rawBalance) {
36
- console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}, Initial: ${isInitialLoad}`);
28
+ if (isTokenChanged && rawBalance) {
29
+ console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}`);
37
30
  // Calculate max amount with gas reserve for native tokens
38
31
  let maxAmount;
39
32
  if (isNativeToken(token.address)) {
@@ -49,7 +42,6 @@ export function OrderTokenAmount({ disabled, inputValue, onChangeInput, context,
49
42
  onChangeInput(formatUnits(maxAmount, token.decimals));
50
43
  // Update refs
51
44
  prevTokenRef.current = token.address;
52
- initialBalanceSetRef.current = true;
53
45
  }
54
46
  }, [token.address, token.chainId, token.decimals, chainId, context, onChangeInput, rawBalance]);
55
47
  const handleTokenSelect = (newToken) => {
@@ -93,8 +93,12 @@ export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrd
93
93
  setDstAmount: import("react").Dispatch<import("react").SetStateAction<string>>;
94
94
  isSrcInputDirty: boolean;
95
95
  setIsSrcInputDirty: import("react").Dispatch<import("react").SetStateAction<boolean>>;
96
+ cryptoPaymentMethod: CryptoPaymentMethodType;
97
+ setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
96
98
  selectedCryptoPaymentMethod: CryptoPaymentMethodType;
97
- setSelectedCryptoPaymentMethod: import("react").Dispatch<import("react").SetStateAction<CryptoPaymentMethodType>>;
99
+ setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
100
+ effectiveCryptoPaymentMethod: CryptoPaymentMethodType;
101
+ resetPaymentMethods: () => void;
98
102
  selectedFiatPaymentMethod: FiatPaymentMethod;
99
103
  setSelectedFiatPaymentMethod: import("react").Dispatch<import("react").SetStateAction<FiatPaymentMethod>>;
100
104
  selectedRecipientAddress: string | undefined;
@@ -7,11 +7,12 @@ import { useEffect, useMemo, useState } from "react";
7
7
  import { toast } from "sonner";
8
8
  import { parseUnits } from "viem";
9
9
  import { base, mainnet } from "viem/chains";
10
- import { useAccount } from "wagmi";
11
10
  import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod.js";
12
11
  import { FiatPaymentMethod } from "../components/common/FiatPaymentMethod.js";
13
12
  import { useAutoSelectCryptoPaymentMethod } from "./useAutoSelectCryptoPaymentMethod.js";
14
13
  import { useAutoSetActiveWalletFromWagmi } from "./useAutoSetActiveWalletFromWagmi.js";
14
+ import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay.js";
15
+ import { useCryptoPaymentMethodState } from "./useCryptoPaymentMethodState.js";
15
16
  export var PanelView;
16
17
  (function (PanelView) {
17
18
  PanelView[PanelView["MAIN"] = 0] = "MAIN";
@@ -37,17 +38,17 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
37
38
  const defaultDstToken = B3_TOKEN; // Default destination token
38
39
  const [selectedSrcToken, setSelectedSrcToken] = useState(defaultSrcToken);
39
40
  const [selectedDstToken, setSelectedDstToken] = useState(defaultDstToken);
40
- const [srcAmount, setSrcAmount] = useState(paymentType === "fiat" ? "5" : "0.1");
41
+ const [srcAmount, setSrcAmount] = useState(paymentType === "fiat" ? "5" : "0");
41
42
  const [dstAmount, setDstAmount] = useState("");
42
43
  const [isSrcInputDirty, setIsSrcInputDirty] = useState(true);
43
44
  // Derive destination chain ID from token or prop (cannot change)
44
45
  const selectedDstChainId = destinationTokenChainId || selectedDstToken.chainId;
45
- // Payment method state
46
- const [selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod] = useState(CryptoPaymentMethodType.NONE);
46
+ // Payment method state with dual-state system (auto + explicit user selection)
47
+ const { cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, effectiveCryptoPaymentMethod, resetPaymentMethods, } = useCryptoPaymentMethodState();
47
48
  const [selectedFiatPaymentMethod, setSelectedFiatPaymentMethod] = useState(FiatPaymentMethod.NONE);
48
49
  // Recipient state
49
50
  const { address: globalAddress } = useAccountWallet();
50
- const { address: wagmiAddress } = useAccount();
51
+ const { walletAddress } = useConnectedWalletDisplay(effectiveCryptoPaymentMethod);
51
52
  const [selectedRecipientAddress, setSelectedRecipientAddress] = useState(recipientAddress);
52
53
  const recipientProfile = useProfile({ address: selectedRecipientAddress, fresh: true });
53
54
  const recipientName = recipientProfile.data?.name;
@@ -62,7 +63,7 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
62
63
  // Check token balance for crypto payments
63
64
  const { rawBalance, isLoading: isBalanceLoading } = useTokenBalance({
64
65
  token: selectedSrcToken,
65
- address: wagmiAddress,
66
+ address: walletAddress,
66
67
  });
67
68
  // Check if user has enough balance
68
69
  const hasEnoughBalance = useMemo(() => {
@@ -79,8 +80,9 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
79
80
  // Auto-select crypto payment method based on available wallets and balance
80
81
  useAutoSelectCryptoPaymentMethod({
81
82
  paymentType,
83
+ cryptoPaymentMethod,
84
+ setCryptoPaymentMethod,
82
85
  selectedCryptoPaymentMethod,
83
- setSelectedCryptoPaymentMethod,
84
86
  hasEnoughBalance,
85
87
  isBalanceLoading,
86
88
  });
@@ -180,9 +182,9 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
180
182
  if (!disableUrlParamManagement) {
181
183
  const params = new URLSearchParams(searchParams.toString()); // Preserve existing params
182
184
  params.set("orderId", newOrderId);
183
- if (selectedCryptoPaymentMethod !== CryptoPaymentMethodType.NONE) {
184
- console.log("Setting cryptoPaymentMethod in URL:", selectedCryptoPaymentMethod);
185
- params.set("cryptoPaymentMethod", selectedCryptoPaymentMethod);
185
+ if (effectiveCryptoPaymentMethod !== CryptoPaymentMethodType.NONE) {
186
+ console.log("Setting cryptoPaymentMethod in URL:", effectiveCryptoPaymentMethod);
187
+ params.set("cryptoPaymentMethod", effectiveCryptoPaymentMethod);
186
188
  }
187
189
  else {
188
190
  console.log("Payment method is NONE, not setting in URL");
@@ -246,8 +248,12 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
246
248
  isSrcInputDirty,
247
249
  setIsSrcInputDirty,
248
250
  // Payment methods
251
+ cryptoPaymentMethod,
252
+ setCryptoPaymentMethod,
249
253
  selectedCryptoPaymentMethod,
250
254
  setSelectedCryptoPaymentMethod,
255
+ effectiveCryptoPaymentMethod,
256
+ resetPaymentMethods,
251
257
  selectedFiatPaymentMethod,
252
258
  setSelectedFiatPaymentMethod,
253
259
  // Recipient
@@ -2,10 +2,12 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
2
2
  interface UseAutoSelectCryptoPaymentMethodParams {
3
3
  /** Current payment type (crypto or fiat) */
4
4
  paymentType?: "crypto" | "fiat";
5
- /** Currently selected payment method */
5
+ /** Auto-selected payment method based on balance (not used in hook logic, but part of state management) */
6
+ cryptoPaymentMethod: CryptoPaymentMethodType;
7
+ /** Function to update the auto-selected payment method */
8
+ setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
9
+ /** User explicitly selected payment method (NONE means no explicit selection) */
6
10
  selectedCryptoPaymentMethod: CryptoPaymentMethodType;
7
- /** Function to update the selected payment method */
8
- setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
9
11
  /** Whether user has enough balance to pay */
10
12
  hasEnoughBalance: boolean;
11
13
  /** Whether balance is still loading */
@@ -16,11 +18,11 @@ interface UseAutoSelectCryptoPaymentMethodParams {
16
18
  * based on available wallets and balance.
17
19
  *
18
20
  * Auto-selection logic:
19
- * - Only auto-selects when payment method is NONE (doesn't override user choices)
21
+ * - Only auto-selects when selectedCryptoPaymentMethod is NONE (user hasn't explicitly chosen)
20
22
  * - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
21
23
  * - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
22
24
  * - If only Global wallet available → GLOBAL_WALLET
23
25
  * - If no wallets → remains NONE
24
26
  */
25
- export declare function useAutoSelectCryptoPaymentMethod({ paymentType, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }: UseAutoSelectCryptoPaymentMethodParams): void;
27
+ export declare function useAutoSelectCryptoPaymentMethod({ paymentType, cryptoPaymentMethod: _cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }: UseAutoSelectCryptoPaymentMethodParams): void;
26
28
  export {};
@@ -6,18 +6,22 @@ import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay.js";
6
6
  * based on available wallets and balance.
7
7
  *
8
8
  * Auto-selection logic:
9
- * - Only auto-selects when payment method is NONE (doesn't override user choices)
9
+ * - Only auto-selects when selectedCryptoPaymentMethod is NONE (user hasn't explicitly chosen)
10
10
  * - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
11
11
  * - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
12
12
  * - If only Global wallet available → GLOBAL_WALLET
13
13
  * - If no wallets → remains NONE
14
14
  */
15
- export function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto", selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }) {
15
+ export function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto", cryptoPaymentMethod: _cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }) {
16
16
  // Get suggested payment method based on available wallets
17
17
  const { suggestedPaymentMethod } = useConnectedWalletDisplay(selectedCryptoPaymentMethod);
18
18
  useEffect(() => {
19
- // Only auto-select when on crypto payment type and payment method is NONE
20
- if (paymentType !== "crypto" || selectedCryptoPaymentMethod !== CryptoPaymentMethodType.NONE) {
19
+ // Only auto-select when on crypto payment type
20
+ if (paymentType !== "crypto") {
21
+ return;
22
+ }
23
+ // Only auto-switch if user hasn't explicitly selected a payment method
24
+ if (selectedCryptoPaymentMethod !== CryptoPaymentMethodType.NONE) {
21
25
  return;
22
26
  }
23
27
  // If we have a suggested payment method (wallet is connected), use it
@@ -26,28 +30,28 @@ export function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto", selec
26
30
  // Otherwise, default to TRANSFER_CRYPTO if balance is insufficient
27
31
  if (!isBalanceLoading) {
28
32
  if (hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
29
- setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
33
+ setCryptoPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
30
34
  }
31
35
  else if (!hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
32
36
  // Wallet connected but insufficient balance - suggest transfer
33
- setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
37
+ setCryptoPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
34
38
  }
35
39
  else {
36
40
  // Use suggested method (e.g., GLOBAL_WALLET)
37
- setSelectedCryptoPaymentMethod(suggestedPaymentMethod);
41
+ setCryptoPaymentMethod(suggestedPaymentMethod);
38
42
  }
39
43
  }
40
44
  else {
41
45
  // Balance still loading, use suggested method
42
- setSelectedCryptoPaymentMethod(suggestedPaymentMethod);
46
+ setCryptoPaymentMethod(suggestedPaymentMethod);
43
47
  }
44
48
  }
45
49
  }, [
46
50
  paymentType,
51
+ setCryptoPaymentMethod,
47
52
  selectedCryptoPaymentMethod,
48
53
  suggestedPaymentMethod,
49
54
  hasEnoughBalance,
50
55
  isBalanceLoading,
51
- setSelectedCryptoPaymentMethod,
52
56
  ]);
53
57
  }
@@ -0,0 +1,42 @@
1
+ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
2
+ interface UseCryptoPaymentMethodStateResult {
3
+ /** Auto-selected payment method based on balance */
4
+ cryptoPaymentMethod: CryptoPaymentMethodType;
5
+ /** Function to update the auto-selected payment method */
6
+ setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
7
+ /** User explicitly selected payment method (NONE means no explicit selection) */
8
+ selectedCryptoPaymentMethod: CryptoPaymentMethodType;
9
+ /** Function to update the user-selected payment method */
10
+ setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
11
+ /** Effective payment method (user selection takes priority over auto-selection) */
12
+ effectiveCryptoPaymentMethod: CryptoPaymentMethodType;
13
+ /** Reset both payment method states to NONE */
14
+ resetPaymentMethods: () => void;
15
+ }
16
+ /**
17
+ * Custom hook to manage crypto payment method state with dual-state system:
18
+ *
19
+ * - `cryptoPaymentMethod`: Auto-selected based on wallet availability and balance
20
+ * - `selectedCryptoPaymentMethod`: Explicitly selected by user
21
+ * - `effectiveCryptoPaymentMethod`: User selection takes priority over auto-selection
22
+ *
23
+ * This allows automatic payment method suggestions while respecting explicit user choices.
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * const {
28
+ * cryptoPaymentMethod,
29
+ * setCryptoPaymentMethod,
30
+ * selectedCryptoPaymentMethod,
31
+ * setSelectedCryptoPaymentMethod,
32
+ * effectiveCryptoPaymentMethod,
33
+ * resetPaymentMethods
34
+ * } = useCryptoPaymentMethodState();
35
+ *
36
+ * // Use effectiveCryptoPaymentMethod for display
37
+ * // Use setSelectedCryptoPaymentMethod when user explicitly selects
38
+ * // Call resetPaymentMethods when switching tabs or going back
39
+ * ```
40
+ */
41
+ export declare function useCryptoPaymentMethodState(): UseCryptoPaymentMethodStateResult;
42
+ export {};
@@ -0,0 +1,48 @@
1
+ import { useState } from "react";
2
+ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod.js";
3
+ /**
4
+ * Custom hook to manage crypto payment method state with dual-state system:
5
+ *
6
+ * - `cryptoPaymentMethod`: Auto-selected based on wallet availability and balance
7
+ * - `selectedCryptoPaymentMethod`: Explicitly selected by user
8
+ * - `effectiveCryptoPaymentMethod`: User selection takes priority over auto-selection
9
+ *
10
+ * This allows automatic payment method suggestions while respecting explicit user choices.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const {
15
+ * cryptoPaymentMethod,
16
+ * setCryptoPaymentMethod,
17
+ * selectedCryptoPaymentMethod,
18
+ * setSelectedCryptoPaymentMethod,
19
+ * effectiveCryptoPaymentMethod,
20
+ * resetPaymentMethods
21
+ * } = useCryptoPaymentMethodState();
22
+ *
23
+ * // Use effectiveCryptoPaymentMethod for display
24
+ * // Use setSelectedCryptoPaymentMethod when user explicitly selects
25
+ * // Call resetPaymentMethods when switching tabs or going back
26
+ * ```
27
+ */
28
+ export function useCryptoPaymentMethodState() {
29
+ // cryptoPaymentMethod: auto-selected based on balance
30
+ const [cryptoPaymentMethod, setCryptoPaymentMethod] = useState(CryptoPaymentMethodType.NONE);
31
+ // selectedCryptoPaymentMethod: explicitly selected by user (NONE means no explicit selection)
32
+ const [selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod] = useState(CryptoPaymentMethodType.NONE);
33
+ // The effective payment method (user selection takes priority over auto-selection)
34
+ const effectiveCryptoPaymentMethod = selectedCryptoPaymentMethod !== CryptoPaymentMethodType.NONE ? selectedCryptoPaymentMethod : cryptoPaymentMethod;
35
+ // Helper function to reset both states
36
+ const resetPaymentMethods = () => {
37
+ setCryptoPaymentMethod(CryptoPaymentMethodType.NONE);
38
+ setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE);
39
+ };
40
+ return {
41
+ cryptoPaymentMethod,
42
+ setCryptoPaymentMethod,
43
+ selectedCryptoPaymentMethod,
44
+ setSelectedCryptoPaymentMethod,
45
+ effectiveCryptoPaymentMethod,
46
+ resetPaymentMethods,
47
+ };
48
+ }
@@ -6,7 +6,6 @@ import invariant from "invariant";
6
6
  import { useCallback, useState } from "react";
7
7
  import { toast } from "sonner";
8
8
  import { prepareTransaction, sendTransaction as twSendTransaction } from "thirdweb";
9
- import { useActiveWallet } from "thirdweb/react";
10
9
  import { isAddress } from "viem";
11
10
  import { useSwitchChain } from "wagmi";
12
11
  import { useB3 } from "../components/index.js";
@@ -19,7 +18,6 @@ invariant(partnerId, "Partner ID is required");
19
18
  export function useUnifiedChainSwitchAndExecute() {
20
19
  const { switchChainAsync } = useSwitchChain();
21
20
  const [isSwitchingOrExecuting, setIsSwitchingOrExecuting] = useState(false);
22
- const activeWallet = useActiveWallet();
23
21
  const { isActiveSmartWallet, isActiveEOAWallet, connectedEOAWallet } = useAccountWallet();
24
22
  const { account: aaAccount } = useB3();
25
23
  // Handle EOA wallet chain switch and execute transaction
@@ -34,18 +32,18 @@ export function useUnifiedChainSwitchAndExecute() {
34
32
  toast.error(`Chain ${targetChainId} is not supported`);
35
33
  return;
36
34
  }
37
- const currentChainId = activeWallet?.getChain()?.id;
35
+ const currentChainId = connectedEOAWallet?.getChain()?.id;
38
36
  const onCorrectChain = currentChainId === targetChainId;
39
37
  // Helper function to execute the transaction
40
38
  const executeTransaction = async () => {
41
- const signer = activeWallet?.getAccount();
39
+ const signer = connectedEOAWallet?.getAccount();
42
40
  if (!signer) {
43
41
  throw new Error("No account connected");
44
42
  }
45
43
  // Coinbase Smart Wallet specific chain switching (different behavior from other wallets)
46
44
  const walletChain = connectedEOAWallet.getChain();
47
45
  if (walletChain?.id !== targetChainId) {
48
- activeWallet?.switchChain(getThirdwebChain(targetChainId));
46
+ connectedEOAWallet?.switchChain(getThirdwebChain(targetChainId));
49
47
  }
50
48
  invariant(isAddress(params.to), "params.to is not a valid address");
51
49
  const result = await signer.sendTransaction({
@@ -97,7 +95,7 @@ export function useUnifiedChainSwitchAndExecute() {
97
95
  finally {
98
96
  setIsSwitchingOrExecuting(false);
99
97
  }
100
- }, [connectedEOAWallet, activeWallet, switchChainAsync]);
98
+ }, [connectedEOAWallet, switchChainAsync]);
101
99
  // Handle AA wallet transaction (no chain switch needed for AA)
102
100
  const handleAASendTransaction = useCallback(async (targetChainId, params) => {
103
101
  if (!aaAccount) {
@@ -153,14 +151,8 @@ export function useUnifiedChainSwitchAndExecute() {
153
151
  if (isActiveSmartWallet) {
154
152
  return handleAASendTransaction(targetChainId, params);
155
153
  }
156
- else if (isActiveEOAWallet) {
157
- return handleEOASwitchChainAndSendTransaction(targetChainId, params);
158
- }
159
- else {
160
- toast.error("No wallet connected");
161
- return undefined;
162
- }
163
- }, [isActiveSmartWallet, isActiveEOAWallet, handleAASendTransaction, handleEOASwitchChainAndSendTransaction]);
154
+ return handleEOASwitchChainAndSendTransaction(targetChainId, params);
155
+ }, [isActiveSmartWallet, handleAASendTransaction, handleEOASwitchChainAndSendTransaction]);
164
156
  return {
165
157
  switchChainAndExecute,
166
158
  switchChainAndExecuteWithEOA: handleEOASwitchChainAndSendTransaction,
@@ -93,8 +93,12 @@ export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrd
93
93
  setDstAmount: import("react").Dispatch<import("react").SetStateAction<string>>;
94
94
  isSrcInputDirty: boolean;
95
95
  setIsSrcInputDirty: import("react").Dispatch<import("react").SetStateAction<boolean>>;
96
+ cryptoPaymentMethod: CryptoPaymentMethodType;
97
+ setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
96
98
  selectedCryptoPaymentMethod: CryptoPaymentMethodType;
97
- setSelectedCryptoPaymentMethod: import("react").Dispatch<import("react").SetStateAction<CryptoPaymentMethodType>>;
99
+ setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
100
+ effectiveCryptoPaymentMethod: CryptoPaymentMethodType;
101
+ resetPaymentMethods: () => void;
98
102
  selectedFiatPaymentMethod: FiatPaymentMethod;
99
103
  setSelectedFiatPaymentMethod: import("react").Dispatch<import("react").SetStateAction<FiatPaymentMethod>>;
100
104
  selectedRecipientAddress: string | undefined;
@@ -2,10 +2,12 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
2
2
  interface UseAutoSelectCryptoPaymentMethodParams {
3
3
  /** Current payment type (crypto or fiat) */
4
4
  paymentType?: "crypto" | "fiat";
5
- /** Currently selected payment method */
5
+ /** Auto-selected payment method based on balance (not used in hook logic, but part of state management) */
6
+ cryptoPaymentMethod: CryptoPaymentMethodType;
7
+ /** Function to update the auto-selected payment method */
8
+ setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
9
+ /** User explicitly selected payment method (NONE means no explicit selection) */
6
10
  selectedCryptoPaymentMethod: CryptoPaymentMethodType;
7
- /** Function to update the selected payment method */
8
- setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
9
11
  /** Whether user has enough balance to pay */
10
12
  hasEnoughBalance: boolean;
11
13
  /** Whether balance is still loading */
@@ -16,11 +18,11 @@ interface UseAutoSelectCryptoPaymentMethodParams {
16
18
  * based on available wallets and balance.
17
19
  *
18
20
  * Auto-selection logic:
19
- * - Only auto-selects when payment method is NONE (doesn't override user choices)
21
+ * - Only auto-selects when selectedCryptoPaymentMethod is NONE (user hasn't explicitly chosen)
20
22
  * - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
21
23
  * - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
22
24
  * - If only Global wallet available → GLOBAL_WALLET
23
25
  * - If no wallets → remains NONE
24
26
  */
25
- export declare function useAutoSelectCryptoPaymentMethod({ paymentType, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }: UseAutoSelectCryptoPaymentMethodParams): void;
27
+ export declare function useAutoSelectCryptoPaymentMethod({ paymentType, cryptoPaymentMethod: _cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }: UseAutoSelectCryptoPaymentMethodParams): void;
26
28
  export {};
@@ -0,0 +1,42 @@
1
+ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
2
+ interface UseCryptoPaymentMethodStateResult {
3
+ /** Auto-selected payment method based on balance */
4
+ cryptoPaymentMethod: CryptoPaymentMethodType;
5
+ /** Function to update the auto-selected payment method */
6
+ setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
7
+ /** User explicitly selected payment method (NONE means no explicit selection) */
8
+ selectedCryptoPaymentMethod: CryptoPaymentMethodType;
9
+ /** Function to update the user-selected payment method */
10
+ setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
11
+ /** Effective payment method (user selection takes priority over auto-selection) */
12
+ effectiveCryptoPaymentMethod: CryptoPaymentMethodType;
13
+ /** Reset both payment method states to NONE */
14
+ resetPaymentMethods: () => void;
15
+ }
16
+ /**
17
+ * Custom hook to manage crypto payment method state with dual-state system:
18
+ *
19
+ * - `cryptoPaymentMethod`: Auto-selected based on wallet availability and balance
20
+ * - `selectedCryptoPaymentMethod`: Explicitly selected by user
21
+ * - `effectiveCryptoPaymentMethod`: User selection takes priority over auto-selection
22
+ *
23
+ * This allows automatic payment method suggestions while respecting explicit user choices.
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * const {
28
+ * cryptoPaymentMethod,
29
+ * setCryptoPaymentMethod,
30
+ * selectedCryptoPaymentMethod,
31
+ * setSelectedCryptoPaymentMethod,
32
+ * effectiveCryptoPaymentMethod,
33
+ * resetPaymentMethods
34
+ * } = useCryptoPaymentMethodState();
35
+ *
36
+ * // Use effectiveCryptoPaymentMethod for display
37
+ * // Use setSelectedCryptoPaymentMethod when user explicitly selects
38
+ * // Call resetPaymentMethods when switching tabs or going back
39
+ * ```
40
+ */
41
+ export declare function useCryptoPaymentMethodState(): UseCryptoPaymentMethodStateResult;
42
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.65-alpha.0",
3
+ "version": "0.0.65-alpha.2",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",