@b3dotfun/sdk 0.0.64 → 0.0.65-alpha.1

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 (58) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +37 -23
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +22 -9
  3. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +7 -11
  4. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +1 -5
  5. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +0 -4
  6. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
  7. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +15 -9
  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/anyspend/utils/index.d.ts +0 -1
  13. package/dist/cjs/anyspend/utils/index.js +0 -1
  14. package/dist/cjs/global-account/react/components/B3DynamicModal.js +4 -7
  15. package/dist/cjs/global-account/react/hooks/useAuthentication.js +0 -11
  16. package/dist/cjs/global-account/react/hooks/useGlobalAccount.d.ts +1 -0
  17. package/dist/cjs/global-account/react/hooks/useGlobalAccount.js +3 -0
  18. package/dist/esm/anyspend/react/components/AnySpend.js +37 -23
  19. package/dist/esm/anyspend/react/components/AnySpendCustom.js +22 -9
  20. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +8 -12
  21. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +2 -6
  22. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +1 -5
  23. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
  24. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +15 -9
  25. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
  26. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +13 -9
  27. package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
  28. package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.js +48 -0
  29. package/dist/esm/anyspend/utils/index.d.ts +0 -1
  30. package/dist/esm/anyspend/utils/index.js +0 -1
  31. package/dist/esm/global-account/react/components/B3DynamicModal.js +5 -8
  32. package/dist/esm/global-account/react/hooks/useAuthentication.js +0 -11
  33. package/dist/esm/global-account/react/hooks/useGlobalAccount.d.ts +1 -0
  34. package/dist/esm/global-account/react/hooks/useGlobalAccount.js +3 -0
  35. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
  36. package/dist/types/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
  37. package/dist/types/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
  38. package/dist/types/anyspend/utils/index.d.ts +0 -1
  39. package/dist/types/global-account/react/hooks/useGlobalAccount.d.ts +1 -0
  40. package/package.json +1 -1
  41. package/src/anyspend/react/components/AnySpend.tsx +49 -28
  42. package/src/anyspend/react/components/AnySpendCustom.tsx +28 -15
  43. package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +9 -12
  44. package/src/anyspend/react/components/AnyspendDepositHype.tsx +2 -6
  45. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +1 -6
  46. package/src/anyspend/react/hooks/useAnyspendFlow.ts +23 -11
  47. package/src/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.ts +20 -12
  48. package/src/anyspend/react/hooks/useCryptoPaymentMethodState.ts +71 -0
  49. package/src/anyspend/utils/index.ts +0 -1
  50. package/src/global-account/react/components/B3DynamicModal.tsx +5 -9
  51. package/src/global-account/react/hooks/useAuthentication.ts +0 -12
  52. package/src/global-account/react/hooks/useGlobalAccount.tsx +3 -1
  53. package/dist/cjs/anyspend/utils/accountStore.d.ts +0 -7
  54. package/dist/cjs/anyspend/utils/accountStore.js +0 -8
  55. package/dist/esm/anyspend/utils/accountStore.d.ts +0 -7
  56. package/dist/esm/anyspend/utils/accountStore.js +0 -5
  57. package/dist/types/anyspend/utils/accountStore.d.ts +0 -7
  58. package/src/anyspend/utils/accountStore.ts +0 -12
@@ -7,8 +7,7 @@ import { ArrowDown, Loader2 } from "lucide-react";
7
7
  import { motion } from "motion/react";
8
8
  import { useEffect, useMemo, useRef } from "react";
9
9
  import { toast } from "sonner";
10
- import { useActiveWallet, useSetActiveWallet } from "thirdweb/react";
11
- import { useGlobalWalletState } from "../../utils/index.js";
10
+ import { useSetActiveWallet } from "thirdweb/react";
12
11
  import { PanelView, useAnyspendFlow } from "../hooks/useAnyspendFlow.js";
13
12
  import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
14
13
  import { CryptoPaySection } from "./common/CryptoPaySection.js";
@@ -31,7 +30,7 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
31
30
  SYMBOL: destinationToken.symbol ?? "TOKEN",
32
31
  LOGO_URI: destinationToken.metadata?.logoURI ?? "",
33
32
  };
34
- const { activePanel, setActivePanel, orderId, setOrderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, selectedDstToken, selectedDstChainId, srcAmount, setSrcAmount, dstAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, hasEnoughBalance, isBalanceLoading, anyspendQuote, isLoadingAnyspendQuote, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = useAnyspendFlow({
33
+ const { activePanel, setActivePanel, orderId, setOrderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, selectedDstToken, selectedDstChainId, srcAmount, setSrcAmount, dstAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, effectiveCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, hasEnoughBalance, isBalanceLoading, anyspendQuote, isLoadingAnyspendQuote, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = useAnyspendFlow({
35
34
  paymentType,
36
35
  recipientAddress,
37
36
  loadOrder,
@@ -47,18 +46,15 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
47
46
  });
48
47
  const { connectedEOAWallet } = useAccountWallet();
49
48
  const setActiveWallet = useSetActiveWallet();
50
- const activeWallet = useActiveWallet();
51
- const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
52
49
  const appliedPreferEoa = useRef(false);
53
50
  useEffect(() => {
54
51
  if (preferEoa && !appliedPreferEoa.current) {
55
52
  if (connectedEOAWallet) {
56
53
  appliedPreferEoa.current = true;
57
- setGlobalAccountWallet(activeWallet);
58
54
  setActiveWallet(connectedEOAWallet);
59
55
  }
60
56
  }
61
- }, [preferEoa, connectedEOAWallet, setActiveWallet, activeWallet, setGlobalAccountWallet]);
57
+ }, [preferEoa, connectedEOAWallet, setActiveWallet]);
62
58
  const selectedRecipientOrDefault = selectedRecipientAddress ?? recipientAddress;
63
59
  const expectedDstAmountRaw = anyspendQuote?.data?.currencyOut?.amount ?? "0";
64
60
  const buildCustomPayload = (_recipient) => {
@@ -87,12 +83,12 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
87
83
  if (!anyspendQuote || !anyspendQuote.success)
88
84
  return { text: "Get quote error", disable: true, error: true, loading: false };
89
85
  if (paymentType === "crypto") {
90
- if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
86
+ if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
91
87
  return { text: "Choose payment method", disable: false, error: false, loading: false };
92
88
  }
93
89
  if (!hasEnoughBalance &&
94
90
  !isBalanceLoading &&
95
- selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
91
+ effectiveCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
96
92
  return { text: "Insufficient balance", disable: true, error: true, loading: false };
97
93
  }
98
94
  return { text: `Execute ${actionLabel}`, disable: false, error: false, loading: false };
@@ -112,7 +108,7 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
112
108
  selectedRecipientOrDefault,
113
109
  anyspendQuote,
114
110
  paymentType,
115
- selectedCryptoPaymentMethod,
111
+ effectiveCryptoPaymentMethod,
116
112
  selectedFiatPaymentMethod,
117
113
  hasEnoughBalance,
118
114
  isBalanceLoading,
@@ -141,7 +137,7 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
141
137
  }
142
138
  };
143
139
  const headerContent = header ? (header({ anyspendPrice: anyspendQuote, isLoadingAnyspendPrice: isLoadingAnyspendQuote })) : (_jsx("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: _jsxs("div", { children: [_jsx("h1", { className: "text-as-primary text-xl font-bold", children: actionLabel }), _jsx("p", { className: "text-as-secondary text-sm", children: "Pay from any token to execute a custom exact-in transaction." })] }) }));
144
- const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [headerContent, _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: selectedRecipientOrDefault, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, dstTokenSymbol: DESTINATION_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: selectedRecipientOrDefault, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(PanelView.RECIPIENT_SELECTION), dstAmount: dstAmount, dstToken: selectedDstToken, dstTokenSymbol: DESTINATION_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: DESTINATION_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
140
+ const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [headerContent, _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: selectedRecipientOrDefault, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, dstTokenSymbol: DESTINATION_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: selectedRecipientOrDefault, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(PanelView.RECIPIENT_SELECTION), dstAmount: dstAmount, dstToken: selectedDstToken, dstTokenSymbol: DESTINATION_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: DESTINATION_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
145
141
  setIsSrcInputDirty(false);
146
142
  setSrcAmount(value);
147
143
  }, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(PanelView.FEE_DETAIL) }))] }) }), _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] }));
@@ -221,7 +217,7 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
221
217
  toast.error("Failed to create order: " + err.message);
222
218
  }
223
219
  };
224
- const orderDetailsView = (_jsx("div", { className: "mx-auto w-[460px] max-w-full", children: _jsx("div", { className: "relative flex flex-col gap-4", children: oat && (_jsx(OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTxs: oat.data.relayTxs, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, cryptoPaymentMethod: paymentType === "fiat" ? CryptoPaymentMethodType.NONE : selectedCryptoPaymentMethod, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onPaymentMethodChange: setSelectedCryptoPaymentMethod, onBack: () => {
220
+ const orderDetailsView = (_jsx("div", { className: "mx-auto w-[460px] max-w-full", children: _jsx("div", { className: "relative flex flex-col gap-4", children: oat && (_jsx(OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTxs: oat.data.relayTxs, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, cryptoPaymentMethod: paymentType === "fiat" ? CryptoPaymentMethodType.NONE : effectiveCryptoPaymentMethod, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod, onPaymentMethodChange: setSelectedCryptoPaymentMethod, onBack: () => {
225
221
  setOrderId(undefined);
226
222
  setActivePanel(PanelView.MAIN);
227
223
  }, disableUrlParamManagement: true, points: oat.data.points || undefined })) }) }));
@@ -6,7 +6,7 @@ import invariant from "invariant";
6
6
  import { motion } from "motion/react";
7
7
  import { useEffect, useMemo, useRef } from "react";
8
8
  import { toast } from "sonner";
9
- import { useActiveWallet, useSetActiveWallet } from "thirdweb/react";
9
+ import { useSetActiveWallet } from "thirdweb/react";
10
10
  import { base } from "viem/chains";
11
11
  import { PanelView, useAnyspendFlow } from "../hooks/useAnyspendFlow.js";
12
12
  import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
@@ -19,7 +19,6 @@ import { OrderDetails } from "./common/OrderDetails.js";
19
19
  import { PointsDetailPanel } from "./common/PointsDetailPanel.js";
20
20
  import { RecipientSelection } from "./common/RecipientSelection.js";
21
21
  import { ArrowDown, Loader2 } from "lucide-react";
22
- import { useGlobalWalletState } from "../../utils/index.js";
23
22
  import { PanelOnramp } from "./common/PanelOnramp.js";
24
23
  const SLIPPAGE_PERCENT = 3;
25
24
  export const HYPE_TOKEN_DETAILS = {
@@ -45,18 +44,15 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
45
44
  });
46
45
  const { connectedEOAWallet: connectedEOAWallet } = useAccountWallet();
47
46
  const setActiveWallet = useSetActiveWallet();
48
- const activeWallet = useActiveWallet();
49
- const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
50
47
  const appliedPreferEoa = useRef(false);
51
48
  useEffect(() => {
52
49
  if (preferEoa && !appliedPreferEoa.current) {
53
50
  if (connectedEOAWallet) {
54
51
  appliedPreferEoa.current = true;
55
- setGlobalAccountWallet(activeWallet);
56
52
  setActiveWallet(connectedEOAWallet);
57
53
  }
58
54
  }
59
- }, [preferEoa, connectedEOAWallet, setActiveWallet, activeWallet, setGlobalAccountWallet]);
55
+ }, [preferEoa, connectedEOAWallet, setActiveWallet]);
60
56
  // Button state logic
61
57
  const btnInfo = useMemo(() => {
62
58
  if (activeInputAmountInWei === "0")
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useGlobalWalletState } from "../../../../anyspend/utils/index.js";
4
3
  import { useAccountWallet } from "../../../../global-account/react/index.js";
5
4
  import { cn } from "../../../../shared/utils/cn.js";
6
5
  import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
@@ -10,7 +9,7 @@ import { ChevronLeft, ChevronRightCircle, Wallet, X, ZapIcon } from "lucide-reac
10
9
  import { useState } from "react";
11
10
  import { createPortal } from "react-dom";
12
11
  import { toast } from "sonner";
13
- import { useActiveWallet, useSetActiveWallet, useWalletInfo } from "thirdweb/react";
12
+ import { useSetActiveWallet, useWalletInfo } from "thirdweb/react";
14
13
  import { createWallet } from "thirdweb/wallets";
15
14
  import { useAccount, useConnect, useDisconnect, useWalletClient } from "wagmi";
16
15
  import { useConnectedWalletDisplay } from "../../hooks/useConnectedWalletDisplay.js";
@@ -30,8 +29,6 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
30
29
  const [showWalletModal, setShowWalletModal] = useState(false);
31
30
  const setActiveWallet = useSetActiveWallet();
32
31
  const { data: eoaWalletInfo } = useWalletInfo(connectedEOAWallet?.id);
33
- const activeWallet = useActiveWallet();
34
- const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
35
32
  const isConnected = !!connectedEOAWallet;
36
33
  const globalAddress = connectedSmartWallet?.getAccount()?.address;
37
34
  // Use custom hook to determine wallet display logic
@@ -162,7 +159,6 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
162
159
  return (_jsxs("div", { className: "crypto-payment-method mx-auto h-fit w-[460px] max-w-full", children: [_jsxs("div", { className: cn("relative flex flex-col gap-10"), children: [_jsx("button", { onClick: onBack, className: "text-as-quaternary hover:text-as-primary absolute flex h-8 w-8 items-center justify-center rounded-lg transition-colors", children: _jsx(ChevronLeft, { className: "h-6 w-6" }) }), _jsx("div", { className: "flex items-center justify-around gap-4", children: _jsx("div", { className: "flex-1 text-center", children: _jsx("h2", { className: "text-as-primary text-lg font-semibold", children: "Select a payment method" }) }) }), _jsxs("div", { className: "crypto-payment-methods flex flex-col gap-4", children: [(shouldShowConnectedEOA || shouldShowWagmiWallet || globalAddress) && (_jsxs("div", { className: "installed-wallets", children: [_jsx("h3", { className: "text-as-primary/80 mb-3 text-sm font-medium", children: "Connected wallets" }), _jsxs("div", { className: "space-y-2", children: [shouldShowConnectedEOA && (_jsx("button", { onClick: () => {
163
160
  setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
164
161
  onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
165
- setGlobalAccountWallet(activeWallet);
166
162
  if (connectedEOAWallet) {
167
163
  setActiveWallet(connectedEOAWallet);
168
164
  }
@@ -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";
@@ -42,12 +43,12 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
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
+ }
@@ -1,4 +1,3 @@
1
- export * from "./accountStore";
2
1
  export * from "./address";
3
2
  export * from "./chain";
4
3
  export * from "./format";
@@ -1,4 +1,3 @@
1
- export * from "./accountStore.js";
2
1
  export * from "./address.js";
3
2
  export * from "./chain.js";
4
3
  export * from "./format.js";
@@ -3,8 +3,7 @@ import { AnySpend, AnySpendBondKit, AnySpendBuySpin, AnySpendNFT, AnyspendSignat
3
3
  import { AnySpendDepositHype } from "../../../anyspend/react/components/AnyspendDepositHype.js";
4
4
  import { AnySpendStakeUpside } from "../../../anyspend/react/components/AnySpendStakeUpside.js";
5
5
  import { AnySpendStakeUpsideExactIn } from "../../../anyspend/react/components/AnySpendStakeUpsideExactIn.js";
6
- import { useGlobalWalletState } from "../../../anyspend/utils/index.js";
7
- import { useIsMobile, useModalStore } from "../../../global-account/react/index.js";
6
+ import { useGlobalAccount, useIsMobile, useModalStore } from "../../../global-account/react/index.js";
8
7
  import { cn } from "../../../shared/utils/cn.js";
9
8
  import { debugB3React } from "../../../shared/utils/debug.js";
10
9
  import { useEffect, useRef } from "react";
@@ -24,19 +23,17 @@ export function B3DynamicModal() {
24
23
  const { theme } = useB3();
25
24
  const isMobile = useIsMobile();
26
25
  const prevIsOpenRef = useRef(isOpen);
27
- const globalAccountWallet = useGlobalWalletState(state => state.globalAccountWallet);
28
- const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
26
+ const { wallet } = useGlobalAccount();
29
27
  const setActiveWallet = useSetActiveWallet();
30
28
  // anyspend cleanup global account chnages by setting account back
31
29
  useEffect(() => {
32
30
  if (prevIsOpenRef.current && !isOpen) {
33
- if (globalAccountWallet) {
34
- setActiveWallet(globalAccountWallet);
35
- setGlobalAccountWallet(undefined);
31
+ if (wallet) {
32
+ setActiveWallet(wallet);
36
33
  }
37
34
  }
38
35
  prevIsOpenRef.current = isOpen;
39
- }, [isOpen, globalAccountWallet, setActiveWallet, setGlobalAccountWallet]);
36
+ }, [isOpen, wallet, setActiveWallet]);
40
37
  // Define arrays for different modal type groups
41
38
  const fullWidthTypes = [
42
39
  "anySpend",
@@ -38,17 +38,6 @@ export function useAuthentication(partnerId) {
38
38
  const activeWagmiAccount = useAccount();
39
39
  const { switchAccount } = useSwitchAccount();
40
40
  debug("@@activeWagmiAccount", activeWagmiAccount);
41
- // Check localStorage version and clear if not found or mismatched
42
- useEffect(() => {
43
- if (typeof localStorage !== "undefined") {
44
- const version = localStorage.getItem("version");
45
- if (version !== "1") {
46
- debug("@@localStorage:clearing due to version mismatch", { version });
47
- localStorage.clear();
48
- localStorage.setItem("version", "1");
49
- }
50
- }
51
- }, []);
52
41
  const wallet = ecosystemWallet(ecosystemWalletId, {
53
42
  partnerId: partnerId,
54
43
  });
@@ -3,4 +3,5 @@ export declare function useGlobalAccount(): {
3
3
  account: Wallet | undefined;
4
4
  address: string | undefined;
5
5
  info: import("@tanstack/react-query").UseQueryResult<import("thirdweb/wallets").WalletInfo, Error>;
6
+ wallet: Wallet | undefined;
6
7
  };
@@ -7,6 +7,7 @@ export function useGlobalAccount() {
7
7
  const wallets = useConnectedWallets();
8
8
  const isConnected = useAuthStore(state => state.isConnected);
9
9
  const [globalAccount, setGlobalAccount] = useState(undefined);
10
+ const [globalAccountWallet, setGlobalAccountWallet] = useState(undefined);
10
11
  const [address, setAddress] = useState(undefined);
11
12
  const walletInfo = useWalletInfo(globalAccount?.id);
12
13
  useEffect(() => {
@@ -17,6 +18,7 @@ export function useGlobalAccount() {
17
18
  return;
18
19
  }
19
20
  const globalAccountWallet = wallets.find(wallet => wallet.id.startsWith("ecosystem."));
21
+ setGlobalAccountWallet(globalAccountWallet);
20
22
  const account = globalAccountWallet?.getAccount();
21
23
  setGlobalAccount(globalAccountWallet);
22
24
  setAddress(account?.address);
@@ -25,5 +27,6 @@ export function useGlobalAccount() {
25
27
  account: globalAccount,
26
28
  address,
27
29
  info: walletInfo,
30
+ wallet: globalAccountWallet,
28
31
  };
29
32
  }
@@ -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 {};