@b3dotfun/sdk 0.0.62-alpha.1 → 0.0.62-alpha.3

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 (88) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +61 -23
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -0
  3. package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +5 -4
  4. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +4 -4
  5. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +4 -6
  6. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +9 -17
  7. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
  8. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +11 -1
  9. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +56 -145
  10. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
  11. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +39 -15
  12. package/dist/cjs/anyspend/react/components/common/PaySection.js +1 -1
  13. package/dist/cjs/anyspend/react/components/common/TokenBalance.js +1 -1
  14. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +12 -11
  15. package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
  16. package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +56 -0
  17. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  18. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +73 -0
  19. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
  20. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +57 -0
  21. package/dist/cjs/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
  22. package/dist/cjs/anyspend/react/hooks/usePhantomTransfer.js +211 -0
  23. package/dist/cjs/global-account/react/hooks/index.d.ts +2 -1
  24. package/dist/cjs/global-account/react/hooks/index.js +5 -3
  25. package/dist/cjs/global-account/react/hooks/useSimBalance.d.ts +1 -1
  26. package/dist/cjs/global-account/react/hooks/useSimBalance.js +6 -5
  27. package/dist/cjs/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
  28. package/dist/cjs/global-account/react/hooks/useTokenBalanceDirect.js +62 -0
  29. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +4 -3
  30. package/dist/esm/anyspend/react/components/AnySpend.js +62 -24
  31. package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -0
  32. package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +7 -6
  33. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +4 -4
  34. package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +5 -7
  35. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +9 -17
  36. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
  37. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +11 -1
  38. package/dist/esm/anyspend/react/components/common/OrderDetails.js +57 -146
  39. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
  40. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +40 -16
  41. package/dist/esm/anyspend/react/components/common/PaySection.js +1 -1
  42. package/dist/esm/anyspend/react/components/common/TokenBalance.js +2 -2
  43. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +12 -11
  44. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
  45. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +53 -0
  46. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  47. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +70 -0
  48. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
  49. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +54 -0
  50. package/dist/esm/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
  51. package/dist/esm/anyspend/react/hooks/usePhantomTransfer.js +208 -0
  52. package/dist/esm/global-account/react/hooks/index.d.ts +2 -1
  53. package/dist/esm/global-account/react/hooks/index.js +2 -1
  54. package/dist/esm/global-account/react/hooks/useSimBalance.d.ts +1 -1
  55. package/dist/esm/global-account/react/hooks/useSimBalance.js +6 -5
  56. package/dist/esm/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
  57. package/dist/esm/global-account/react/hooks/useTokenBalanceDirect.js +59 -0
  58. package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +4 -3
  59. package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
  60. package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
  61. package/dist/types/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
  62. package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  63. package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
  64. package/dist/types/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
  65. package/dist/types/global-account/react/hooks/index.d.ts +2 -1
  66. package/dist/types/global-account/react/hooks/useSimBalance.d.ts +1 -1
  67. package/dist/types/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
  68. package/package.json +1 -1
  69. package/src/anyspend/react/components/AnySpend.tsx +73 -22
  70. package/src/anyspend/react/components/AnySpendCustom.tsx +4 -0
  71. package/src/anyspend/react/components/AnySpendStakeB3.tsx +8 -11
  72. package/src/anyspend/react/components/AnyspendDepositHype.tsx +7 -3
  73. package/src/anyspend/react/components/common/CryptoPaySection.tsx +5 -7
  74. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +9 -18
  75. package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +22 -0
  76. package/src/anyspend/react/components/common/OrderDetails.tsx +66 -188
  77. package/src/anyspend/react/components/common/OrderTokenAmount.tsx +48 -17
  78. package/src/anyspend/react/components/common/PaySection.tsx +1 -0
  79. package/src/anyspend/react/components/common/TokenBalance.tsx +2 -2
  80. package/src/anyspend/react/hooks/useAnyspendFlow.ts +13 -10
  81. package/src/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.ts +72 -0
  82. package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +80 -0
  83. package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +69 -0
  84. package/src/anyspend/react/hooks/usePhantomTransfer.ts +301 -0
  85. package/src/global-account/react/hooks/index.ts +2 -1
  86. package/src/global-account/react/hooks/useSimBalance.ts +6 -5
  87. package/src/global-account/react/hooks/useTokenBalanceDirect.tsx +84 -0
  88. package/src/global-account/react/hooks/useTokenFromUrl.tsx +6 -5
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { getDefaultToken, USDC_BASE } from "../../../anyspend/index.js";
4
4
  import { useAnyspendCreateOnrampOrder, useAnyspendCreateOrder, useAnyspendOrderAndTransactions, useAnyspendQuote, useGeoOnrampOptions, } from "../../../anyspend/react/index.js";
5
- import { Button, ShinyButton, StyleRoot, TransitionPanel, useAccountWallet, useProfile, useRouter, useSearchParamsSSR, useTokenData, useTokenFromUrl, } from "../../../global-account/react/index.js";
5
+ import { Button, ShinyButton, StyleRoot, TransitionPanel, useAccountWallet, useProfile, useRouter, useSearchParamsSSR, useTokenBalanceDirect, useTokenData, useTokenFromUrl, } from "../../../global-account/react/index.js";
6
6
  import { cn } from "../../../shared/utils/cn.js";
7
7
  import { formatTokenAmount } from "../../../shared/utils/number.js";
8
8
  import invariant from "invariant";
@@ -12,17 +12,19 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
12
12
  import { toast } from "sonner";
13
13
  import { parseUnits } from "viem";
14
14
  import { base, mainnet } from "viem/chains";
15
+ import { useAutoSelectCryptoPaymentMethod } from "../hooks/useAutoSelectCryptoPaymentMethod.js";
16
+ import { useAutoSetActiveWalletFromWagmi } from "../hooks/useAutoSetActiveWalletFromWagmi.js";
15
17
  import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
16
18
  import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod.js";
17
19
  import { CryptoPaySection } from "./common/CryptoPaySection.js";
18
20
  import { CryptoReceiveSection } from "./common/CryptoReceiveSection.js";
21
+ import { FeeDetailPanel } from "./common/FeeDetailPanel.js";
19
22
  import { FiatPaymentMethod, FiatPaymentMethodComponent } from "./common/FiatPaymentMethod.js";
20
23
  import { OrderDetails, OrderDetailsLoadingView } from "./common/OrderDetails.js";
21
24
  import { OrderHistory } from "./common/OrderHistory.js";
22
25
  import { PanelOnramp } from "./common/PanelOnramp.js";
23
26
  import { PanelOnrampPayment } from "./common/PanelOnrampPayment.js";
24
27
  import { PointsDetailPanel } from "./common/PointsDetailPanel.js";
25
- import { FeeDetailPanel } from "./common/FeeDetailPanel.js";
26
28
  import { RecipientSelection } from "./common/RecipientSelection.js";
27
29
  import { TabSection } from "./common/TabSection.js";
28
30
  export var PanelView;
@@ -304,13 +306,36 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
304
306
  // );
305
307
  // State for recipient selection
306
308
  const [recipientAddress, setRecipientAddress] = useState();
307
- const { address: globalAddress, wallet: globalWallet } = useAccountWallet();
309
+ const { address: globalAddress, wallet: globalWallet, connectedEOAWallet } = useAccountWallet();
308
310
  const recipientProfile = useProfile({ address: recipientAddress, fresh: true });
309
311
  const recipientName = recipientProfile.data?.name;
310
- // Set default recipient address when wallet changes
311
- useEffect(() => {
312
- setRecipientAddress(recipientAddressFromProps || globalAddress);
313
- }, [recipientAddressFromProps, globalAddress]);
312
+ // Auto-set active wallet from wagmi
313
+ useAutoSetActiveWalletFromWagmi();
314
+ // Check token balance for crypto payments
315
+ const { rawBalance, isLoading: isBalanceLoading } = useTokenBalanceDirect({
316
+ token: selectedSrcToken,
317
+ address: connectedEOAWallet?.getAccount()?.address,
318
+ });
319
+ // Check if user has enough balanceuseAutoSetActiveWalletFromWagmi
320
+ const hasEnoughBalance = useMemo(() => {
321
+ if (!rawBalance || isBalanceLoading || activeTab !== "crypto")
322
+ return false;
323
+ try {
324
+ const requiredAmount = parseUnits(srcAmount.replace(/,/g, ""), selectedSrcToken.decimals);
325
+ return rawBalance >= requiredAmount;
326
+ }
327
+ catch {
328
+ return false;
329
+ }
330
+ }, [rawBalance, srcAmount, selectedSrcToken.decimals, isBalanceLoading, activeTab]);
331
+ // Auto-select crypto payment method based on available wallets and balance
332
+ useAutoSelectCryptoPaymentMethod({
333
+ paymentType: activeTab,
334
+ selectedCryptoPaymentMethod,
335
+ setSelectedCryptoPaymentMethod,
336
+ hasEnoughBalance,
337
+ isBalanceLoading,
338
+ });
314
339
  // Get geo-based onramp options for fiat payments
315
340
  const { geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support } = useGeoOnrampOptions(srcAmountOnRamp);
316
341
  // Helper function to map payment method to onramp vendor
@@ -474,17 +499,30 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
474
499
  return { text: "Select a different token or chain", disable: true, error: false, loading: false };
475
500
  if (isLoadingAnyspendQuote)
476
501
  return { text: "Loading quote...", disable: true, error: false, loading: true };
477
- if (!recipientAddress)
478
- return { text: "Select recipient", disable: false, error: false, loading: false };
479
502
  if (isCreatingOrder || isCreatingOnrampOrder)
480
503
  return { text: "Creating order...", disable: true, error: false, loading: true };
481
504
  if (!anyspendQuote || !anyspendQuote.success)
482
505
  return { text: "No quote found", disable: true, error: false, loading: false };
506
+ if (activeTab === "fiat") {
507
+ // For fiat: check recipient first, then payment method
508
+ if (!recipientAddress)
509
+ return { text: "Select recipient", disable: false, error: false, loading: false };
510
+ // If no fiat payment method selected, show "Select payment method"
511
+ if (selectedFiatPaymentMethod === FiatPaymentMethod.NONE) {
512
+ return { text: "Select payment method", disable: false, error: false, loading: false };
513
+ }
514
+ // If payment method is selected, show "Buy"
515
+ return { text: "Buy", disable: false, error: false, loading: false };
516
+ }
483
517
  if (activeTab === "crypto") {
518
+ // For crypto: check payment method first, then recipient
484
519
  // If no payment method selected, show "Choose payment method"
485
520
  if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
486
521
  return { text: "Choose payment method", disable: false, error: false, loading: false };
487
522
  }
523
+ // Check recipient after payment method
524
+ if (!recipientAddress)
525
+ return { text: "Select recipient", disable: false, error: false, loading: false };
488
526
  // If payment method selected, show appropriate action
489
527
  if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ||
490
528
  selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET) {
@@ -494,14 +532,6 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
494
532
  return { text: "Continue to payment", disable: false, error: false, loading: false };
495
533
  }
496
534
  }
497
- if (activeTab === "fiat") {
498
- // If no fiat payment method selected, show "Select payment method"
499
- if (selectedFiatPaymentMethod === FiatPaymentMethod.NONE) {
500
- return { text: "Select payment method", disable: false, error: false, loading: false };
501
- }
502
- // If payment method is selected, show "Buy"
503
- return { text: "Buy", disable: false, error: false, loading: false };
504
- }
505
535
  return { text: "Buy", disable: false, error: false, loading: false };
506
536
  }, [
507
537
  activeInputAmountInWei,
@@ -519,14 +549,15 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
519
549
  const onMainButtonClick = async () => {
520
550
  if (btnInfo.disable)
521
551
  return;
522
- if (!recipientAddress) {
523
- navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward");
524
- return;
525
- }
526
552
  try {
527
553
  invariant(anyspendQuote, "Relay price is not found");
528
- invariant(recipientAddress, "Recipient address is not found");
529
554
  if (activeTab === "fiat") {
555
+ // For fiat: check recipient first
556
+ if (!recipientAddress) {
557
+ navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward");
558
+ return;
559
+ }
560
+ invariant(recipientAddress, "Recipient address is not found");
530
561
  // If no fiat payment method selected, show payment method selection
531
562
  if (selectedFiatPaymentMethod === FiatPaymentMethod.NONE) {
532
563
  navigateToPanel(PanelView.FIAT_PAYMENT_METHOD, "forward");
@@ -537,12 +568,19 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
537
568
  return;
538
569
  }
539
570
  if (activeTab === "crypto") {
571
+ // For crypto: check payment method first, then recipient
540
572
  // If no payment method selected, show payment method selection
541
573
  if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
542
574
  console.log("No payment method selected, showing selection panel");
543
575
  navigateToPanel(PanelView.CRYPTO_PAYMENT_METHOD, "forward");
544
576
  return;
545
577
  }
578
+ // Check recipient after payment method
579
+ if (!recipientAddress) {
580
+ navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward");
581
+ return;
582
+ }
583
+ invariant(recipientAddress, "Recipient address is not found");
546
584
  // If payment method is selected, create order with payment method info
547
585
  if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ||
548
586
  selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ||
@@ -755,10 +793,10 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
755
793
  const tempDstAmount = dstAmount;
756
794
  setSrcAmount(tempDstAmount);
757
795
  setDstAmount(tempSrcAmount);
758
- }, children: _jsx("div", { className: "relative flex items-center justify-center transition-opacity", children: _jsx(ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }), activeTab === "crypto" && (_jsx(CryptoReceiveSection, { isDepositMode: false, isBuyMode: isBuyMode, selectedRecipientAddress: recipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward"), dstAmount: dstAmount, dstToken: selectedDstToken, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: setSelectedDstChainId, setSelectedDstToken: setSelectedDstToken, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
796
+ }, children: _jsx("div", { className: "relative flex items-center justify-center transition-opacity", children: _jsx(ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }), activeTab === "crypto" && (_jsx(CryptoReceiveSection, { isDepositMode: false, isBuyMode: isBuyMode, selectedRecipientAddress: recipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward"), setRecipientAddress: setRecipientAddress, recipientAddressFromProps: recipientAddressFromProps, globalAddress: globalAddress, dstAmount: dstAmount, dstToken: selectedDstToken, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: setSelectedDstChainId, setSelectedDstToken: setSelectedDstToken, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
759
797
  setIsSrcInputDirty(false);
760
798
  setDstAmount(value);
761
- }, anyspendQuote: anyspendQuote, onShowPointsDetail: () => navigateToPanel(PanelView.POINTS_DETAIL, "forward"), onShowFeeDetail: () => navigateToPanel(PanelView.FEE_DETAIL, "forward") }))] }), _jsxs(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] }) }), !hideTransactionHistoryButton && (globalAddress || recipientAddress) ? (_jsxs(Button, { variant: "link", onClick: onClickHistory, className: "text-as-primary/50 hover:text-as-primary flex items-center gap-1 transition-colors", children: [_jsx(HistoryIcon, { className: "h-4 w-4" }), " ", _jsx("span", { className: "pr-4", children: "Transaction History" })] })) : null] })] }));
799
+ }, anyspendQuote: anyspendQuote, onShowPointsDetail: () => navigateToPanel(PanelView.POINTS_DETAIL, "forward"), onShowFeeDetail: () => navigateToPanel(PanelView.FEE_DETAIL, "forward"), selectedCryptoPaymentMethod: selectedCryptoPaymentMethod }))] }), _jsxs(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] }) }), !hideTransactionHistoryButton && (globalAddress || recipientAddress) ? (_jsxs(Button, { variant: "link", onClick: onClickHistory, className: "text-as-primary/50 hover:text-as-primary flex items-center gap-1 transition-colors", children: [_jsx(HistoryIcon, { className: "h-4 w-4" }), " ", _jsx("span", { className: "pr-4", children: "Transaction History" })] })) : null] })] }));
762
800
  const onrampPaymentView = (_jsx(PanelOnrampPayment, { srcAmountOnRamp: srcAmountOnRamp, recipientName: recipientName || undefined, recipientAddress: recipientAddress, isBuyMode: isBuyMode, destinationTokenChainId: destinationTokenChainId, destinationTokenAddress: destinationTokenAddress, selectedDstChainId: selectedDstChainId, selectedDstToken: selectedDstToken, orderType: "swap", anyspendQuote: anyspendQuote, globalAddress: globalAddress, onOrderCreated: orderId => {
763
801
  setOrderId(orderId);
764
802
  navigateToPanel(PanelView.ORDER_DETAILS, "forward");
@@ -14,6 +14,7 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
14
14
  import { toast } from "sonner";
15
15
  import { base } from "viem/chains";
16
16
  import { useFeatureFlags } from "../contexts/FeatureFlagsContext.js";
17
+ import { useAutoSetActiveWalletFromWagmi } from "../hooks/useAutoSetActiveWalletFromWagmi.js";
17
18
  import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
18
19
  import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod.js";
19
20
  import { FeeBreakDown } from "./common/FeeBreakDown.js";
@@ -110,6 +111,8 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
110
111
  const featureFlags = useFeatureFlags();
111
112
  const searchParams = useSearchParamsSSR();
112
113
  const router = useRouter();
114
+ // Auto-set active wallet from wagmi
115
+ useAutoSetActiveWalletFromWagmi();
113
116
  const [activePanel, setActivePanel] = useState(loadOrder ? PanelView.ORDER_DETAILS : PanelView.CONFIRM_ORDER);
114
117
  const [activeTab, setActiveTab] = useState(activeTabProps);
115
118
  // Add state for selected payment methods
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { ABI_ERC20_STAKING, B3_TOKEN } from "../../../anyspend/index.js";
3
- import { Button, GlareCardRounded, Input, StyleRoot, TextLoop, useHasMounted, useModalStore, useTokenBalance, useUnifiedChainSwitchAndExecute, } from "../../../global-account/react/index.js";
2
+ import { ABI_ERC20_STAKING, B3_TOKEN, eqci } from "../../../anyspend/index.js";
3
+ import { Button, GlareCardRounded, Input, StyleRoot, TextLoop, useHasMounted, useModalStore, useSimBalance, useUnifiedChainSwitchAndExecute, } from "../../../global-account/react/index.js";
4
4
  import { PUBLIC_BASE_RPC_URL } from "../../../shared/constants/index.js";
5
5
  import { formatTokenAmount } from "../../../shared/utils/number.js";
6
6
  import invariant from "invariant";
@@ -32,13 +32,14 @@ function generateEncodedDataForStakingB3(amount, beneficiary) {
32
32
  export function AnySpendStakeB3({ loadOrder, mode = "modal", recipientAddress, stakeAmount, onSuccess, }) {
33
33
  const hasMounted = useHasMounted();
34
34
  const { setB3ModalOpen } = useModalStore();
35
- // Fetch B3 token balance
36
- const { formattedBalance: b3Balance, isLoading: isBalanceLoading, rawBalance: b3RawBalance, } = useTokenBalance({
37
- token: B3_TOKEN,
38
- });
39
35
  // Wagmi hooks for direct staking
40
36
  const { address } = useAccount();
41
37
  const { switchChainAndExecute, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
38
+ // Fetch B3 token balance
39
+ const { data: simBalance, isLoading: isBalanceLoading } = useSimBalance(address, [base.id]);
40
+ const b3RawBalanceStr = simBalance?.balances.find(b => eqci(b.address, B3_TOKEN.address))?.amount || "0";
41
+ const b3RawBalance = BigInt(b3RawBalanceStr);
42
+ const b3Balance = formatTokenAmount(b3RawBalance, B3_TOKEN.decimals);
42
43
  // State for direct staking flow
43
44
  const [isStaking, setIsStaking] = useState(false);
44
45
  const [stakingTxHash, setStakingTxHash] = useState("");
@@ -6,6 +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
10
  import { base } from "viem/chains";
10
11
  import { PanelView, useAnyspendFlow } from "../hooks/useAnyspendFlow.js";
11
12
  import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
@@ -17,10 +18,9 @@ import { FiatPaymentMethod, FiatPaymentMethodComponent } from "./common/FiatPaym
17
18
  import { OrderDetails } from "./common/OrderDetails.js";
18
19
  import { PointsDetailPanel } from "./common/PointsDetailPanel.js";
19
20
  import { RecipientSelection } from "./common/RecipientSelection.js";
20
- import { useActiveWallet, useSetActiveWallet } from "thirdweb/react";
21
21
  import { ArrowDown, Loader2 } from "lucide-react";
22
- import { PanelOnramp } from "./common/PanelOnramp.js";
23
22
  import { useGlobalWalletState } from "../../utils/index.js";
23
+ import { PanelOnramp } from "./common/PanelOnramp.js";
24
24
  const SLIPPAGE_PERCENT = 3;
25
25
  export const HYPE_TOKEN_DETAILS = {
26
26
  SYMBOL: "HYPE",
@@ -128,10 +128,10 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
128
128
  await handleFiatOrder();
129
129
  }
130
130
  };
131
- 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: recipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(PanelView.RECIPIENT_SELECTION), 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 => {
131
+ 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 => {
132
132
  setIsSrcInputDirty(false);
133
133
  setSrcAmount(value);
134
- }, 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] }));
134
+ }, 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] }));
135
135
  // Handle crypto order creation
136
136
  const handleCryptoOrder = async () => {
137
137
  try {
@@ -1,21 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useAccountWallet, useProfile, useTokenData } from "../../../../global-account/react/index.js";
2
+ import { useProfile, useTokenData } from "../../../../global-account/react/index.js";
3
3
  import { formatUsername } from "../../../../shared/utils/index.js";
4
4
  import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
5
5
  import { formatDisplayNumber } from "../../../../shared/utils/number.js";
6
6
  import { ChevronRight, Info } from "lucide-react";
7
7
  import { motion } from "motion/react";
8
8
  import { useEffect, useRef } from "react";
9
+ import { useConnectedWalletDisplay } from "../../hooks/useConnectedWalletDisplay.js";
9
10
  import { CryptoPaymentMethodType } from "./CryptoPaymentMethod.js";
10
11
  import { OrderTokenAmount } from "./OrderTokenAmount.js";
11
12
  import { TokenBalance } from "./TokenBalance.js";
12
13
  export function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod, anyspendQuote, onTokenSelect, onShowFeeDetail, }) {
13
- const { connectedSmartWallet, connectedEOAWallet } = useAccountWallet();
14
14
  const { data: srcTokenMetadata } = useTokenData(selectedSrcToken?.chainId, selectedSrcToken?.address);
15
- // Determine which address to use based on payment method
16
- const walletAddress = selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET
17
- ? connectedSmartWallet?.getAccount()?.address
18
- : connectedEOAWallet?.getAccount()?.address;
15
+ // Use custom hook to determine wallet address based on payment method
16
+ const { walletAddress } = useConnectedWalletDisplay(selectedCryptoPaymentMethod);
19
17
  const { data: profileData } = useProfile({ address: walletAddress });
20
18
  const connectedName = profileData?.displayName;
21
19
  // Add ref to track if we've applied metadata
@@ -42,7 +40,7 @@ export function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, se
42
40
  useEffect(() => {
43
41
  appliedSrcMetadataRef.current = false;
44
42
  }, [selectedSrcToken.address, selectedSrcToken.chainId]);
45
- return (_jsxs(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" }, className: "pay-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: ["Pay", !isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && (_jsx("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: _jsx(Info, { className: "h-4 w-4" }) }))] }), _jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none", onClick: onSelectCryptoPaymentMethod, children: selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (_jsxs(_Fragment, { children: [walletAddress ? (_jsx("div", { className: "flex items-center gap-1", children: connectedName ? formatUsername(connectedName) : shortenAddress(walletAddress || "") })) : ("Connect wallet"), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? (_jsxs(_Fragment, { children: ["Global Account", _jsx(ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (_jsxs(_Fragment, { children: ["Transfer crypto", _jsx(ChevronRight, { className: "h-4 w-4" })] })) : (_jsxs(_Fragment, { children: ["Select payment method", _jsx(ChevronRight, { className: "h-4 w-4" })] })) })] }), _jsx(OrderTokenAmount, { address: walletAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
43
+ return (_jsxs(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" }, className: "pay-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: ["Pay", !isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && (_jsx("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: _jsx(Info, { className: "h-4 w-4" }) }))] }), _jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none", onClick: onSelectCryptoPaymentMethod, children: selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (_jsxs(_Fragment, { children: [walletAddress ? (_jsx("div", { className: "flex items-center gap-1", children: connectedName ? formatUsername(connectedName) : shortenAddress(walletAddress || "") })) : ("Connect wallet"), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? (_jsxs(_Fragment, { children: ["Global Account", _jsx(ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (_jsxs(_Fragment, { children: ["Transfer crypto", _jsx(ChevronRight, { className: "h-4 w-4" })] })) : (_jsxs(_Fragment, { children: ["Select payment method", _jsx(ChevronRight, { className: "h-4 w-4" })] })) })] }), _jsx(OrderTokenAmount, { address: walletAddress, walletAddress: walletAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
46
44
  setIsSrcInputDirty(true);
47
45
  setSrcAmount(value);
48
46
  }, chainId: selectedSrcChainId, setChainId: setSelectedSrcChainId, token: selectedSrcToken, setToken: setSelectedSrcToken, onTokenSelect: onTokenSelect }), _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-as-primary/50 flex h-5 items-center text-sm", children: formatDisplayNumber(anyspendQuote?.data?.currencyIn?.amountUsd, {
@@ -13,6 +13,7 @@ import { toast } from "sonner";
13
13
  import { useActiveWallet, useSetActiveWallet, useWalletInfo } from "thirdweb/react";
14
14
  import { createWallet } from "thirdweb/wallets";
15
15
  import { useAccount, useConnect, useDisconnect, useWalletClient } from "wagmi";
16
+ import { useConnectedWalletDisplay } from "../../hooks/useConnectedWalletDisplay.js";
16
17
  export var CryptoPaymentMethodType;
17
18
  (function (CryptoPaymentMethodType) {
18
19
  CryptoPaymentMethodType["NONE"] = "none";
@@ -22,7 +23,7 @@ export var CryptoPaymentMethodType;
22
23
  })(CryptoPaymentMethodType || (CryptoPaymentMethodType = {}));
23
24
  export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod, isCreatingOrder, onBack, onSelectPaymentMethod, }) {
24
25
  const { wallet: globalWallet, connectedEOAWallet: connectedEOAWallet, connectedSmartWallet: connectedSmartWallet, } = useAccountWallet();
25
- const { connector, address, isConnected: wagmiWalletIsConnected } = useAccount();
26
+ const { connector, address } = useAccount();
26
27
  const { connect, connectors, isPending } = useConnect();
27
28
  const { disconnect } = useDisconnect();
28
29
  const { data: walletClient } = useWalletClient();
@@ -33,19 +34,8 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
33
34
  const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
34
35
  const isConnected = !!connectedEOAWallet;
35
36
  const globalAddress = connectedSmartWallet?.getAccount()?.address;
36
- // Helper function to check if two addresses are the same
37
- const isSameAddress = (addr1, addr2) => {
38
- if (!addr1 || !addr2)
39
- return false;
40
- return addr1.toLowerCase() === addr2.toLowerCase();
41
- };
42
- // Check if connectedEOAWallet and wagmi wallet represent the same wallet
43
- const connectedEOAAddress = connectedEOAWallet?.getAccount()?.address;
44
- const wagmiAddress = address;
45
- const isWalletDuplicated = isSameAddress(connectedEOAAddress, wagmiAddress);
46
- // Determine which wallet to show (prefer connectedEOAWallet if both exist and are the same)
47
- const shouldShowConnectedEOA = !!connectedEOAWallet;
48
- const shouldShowWagmiWallet = wagmiWalletIsConnected && (!isWalletDuplicated || !connectedEOAWallet);
37
+ // Use custom hook to determine wallet display logic
38
+ const { shouldShowConnectedEOA, shouldShowWagmiWallet } = useConnectedWalletDisplay(selectedPaymentMethod);
49
39
  // Map wagmi connector names to thirdweb wallet IDs
50
40
  const getThirdwebWalletId = (connectorName) => {
51
41
  const walletMap = {
@@ -173,9 +163,11 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
173
163
  setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
174
164
  onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
175
165
  setGlobalAccountWallet(activeWallet);
176
- setActiveWallet(connectedEOAWallet);
166
+ if (connectedEOAWallet) {
167
+ setActiveWallet(connectedEOAWallet);
168
+ }
177
169
  toast.success(`Selected ${eoaWalletInfo?.name || connector?.name || "wallet"}`);
178
- }, className: cn("crypto-payment-method-connect-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
170
+ }, className: cn("crypto-payment-method-connect-wallet eoa-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
179
171
  ? "connected-wallet border-as-brand bg-as-brand/5"
180
172
  : "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: _jsx(Wallet, { className: "h-5 w-5 text-blue-600" }) }), _jsxs("div", { className: "flex flex-col", children: [_jsx("span", { className: "text-as-primary font-semibold", children: eoaWalletInfo?.name || connector?.name || "Connected Wallet" }), _jsx("span", { className: "text-as-primary/60 text-sm", children: shortenAddress(connectedEOAWallet?.getAccount()?.address || "") })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && (_jsx("div", { className: "h-2 w-2 rounded-full bg-green-500" })), _jsx("button", { onClick: e => {
181
173
  e.stopPropagation();
@@ -195,7 +187,7 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
195
187
  }
196
188
  }
197
189
  toast.success(`Selected ${connector?.name || "wallet"}`);
198
- }, className: cn("crypto-payment-method-connect-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
190
+ }, className: cn("crypto-payment-method-connect-wallet wagmi-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
199
191
  ? "connected-wallet border-as-brand bg-as-brand/5"
200
192
  : "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: _jsx(Wallet, { className: "h-5 w-5 text-blue-600" }) }), _jsxs("div", { className: "flex flex-col", children: [_jsx("span", { className: "text-as-primary font-semibold", children: connector?.name || "Connected Wallet" }), _jsx("span", { className: "text-as-primary/60 text-sm", children: shortenAddress(address || "") })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && (_jsx("div", { className: "h-2 w-2 rounded-full bg-green-500" })), _jsx("button", { onClick: e => {
201
193
  e.stopPropagation();
@@ -1,10 +1,14 @@
1
1
  import { components } from "../../../types/api";
2
+ import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
2
3
  interface CryptoReceiveSectionProps {
3
4
  isDepositMode?: boolean;
4
5
  isBuyMode?: boolean;
5
6
  selectedRecipientAddress?: string;
6
7
  recipientName?: string;
7
8
  onSelectRecipient: () => void;
9
+ setRecipientAddress?: (address: string | undefined) => void;
10
+ recipientAddressFromProps?: string;
11
+ globalAddress?: string;
8
12
  dstAmount: string;
9
13
  dstToken: components["schemas"]["Token"];
10
14
  selectedDstChainId?: number;
@@ -17,6 +21,7 @@ interface CryptoReceiveSectionProps {
17
21
  dstTokenLogoURI?: string;
18
22
  onShowPointsDetail?: () => void;
19
23
  onShowFeeDetail?: () => void;
24
+ selectedCryptoPaymentMethod?: CryptoPaymentMethodType;
20
25
  }
21
- export declare function CryptoReceiveSection({ isDepositMode, isBuyMode, selectedRecipientAddress, recipientName, onSelectRecipient, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, isSrcInputDirty, onChangeDstAmount, anyspendQuote, dstTokenSymbol, dstTokenLogoURI, onShowPointsDetail, onShowFeeDetail, }: CryptoReceiveSectionProps): import("react/jsx-runtime").JSX.Element;
26
+ export declare function CryptoReceiveSection({ isDepositMode, isBuyMode, selectedRecipientAddress, recipientName, onSelectRecipient, setRecipientAddress, recipientAddressFromProps, globalAddress, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, isSrcInputDirty, onChangeDstAmount, anyspendQuote, dstTokenSymbol, dstTokenLogoURI, onShowPointsDetail, onShowFeeDetail, selectedCryptoPaymentMethod, }: CryptoReceiveSectionProps): import("react/jsx-runtime").JSX.Element;
22
27
  export {};
@@ -5,11 +5,21 @@ import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
5
5
  import { formatDisplayNumber } from "../../../../shared/utils/number.js";
6
6
  import { ChevronRight, Info } from "lucide-react";
7
7
  import { motion } from "motion/react";
8
+ import { useEffect } from "react";
8
9
  import { useFeatureFlags } from "../../contexts/FeatureFlagsContext.js";
10
+ import { useConnectedWalletDisplay } from "../../hooks/useConnectedWalletDisplay.js";
9
11
  import { OrderTokenAmount } from "./OrderTokenAmount.js";
10
12
  import { PointsBadge } from "./PointsBadge.js";
11
- export function CryptoReceiveSection({ isDepositMode = false, isBuyMode = false, selectedRecipientAddress, recipientName, onSelectRecipient, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, isSrcInputDirty, onChangeDstAmount, anyspendQuote, dstTokenSymbol, dstTokenLogoURI, onShowPointsDetail, onShowFeeDetail, }) {
13
+ export function CryptoReceiveSection({ isDepositMode = false, isBuyMode = false, selectedRecipientAddress, recipientName, onSelectRecipient, setRecipientAddress, recipientAddressFromProps, globalAddress, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, isSrcInputDirty, onChangeDstAmount, anyspendQuote, dstTokenSymbol, dstTokenLogoURI, onShowPointsDetail, onShowFeeDetail, selectedCryptoPaymentMethod, }) {
12
14
  const featureFlags = useFeatureFlags();
15
+ // Get wallet address based on selected payment method
16
+ const { walletAddress } = useConnectedWalletDisplay(selectedCryptoPaymentMethod);
17
+ // Set default recipient address when wallet changes
18
+ useEffect(() => {
19
+ if (setRecipientAddress) {
20
+ setRecipientAddress(recipientAddressFromProps || walletAddress || globalAddress);
21
+ }
22
+ }, [recipientAddressFromProps, walletAddress, globalAddress, setRecipientAddress]);
13
23
  return (_jsxs(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, className: "receive-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [_jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: [isDepositMode ? "Deposit" : "Receive", isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && (_jsx("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: _jsx(Info, { className: "h-4 w-4" }) }))] }), selectedRecipientAddress ? (_jsx("button", { className: cn("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: onSelectRecipient, children: _jsxs(_Fragment, { children: [_jsx("span", { className: "text-as-tertiarry flex items-center gap-1 text-sm", children: recipientName ? formatUsername(recipientName) : shortenAddress(selectedRecipientAddress || "") }), _jsx(ChevronRight, { className: "h-4 w-4" })] }) })) : (_jsx("button", { className: "text-as-primary/70 flex items-center gap-1 rounded-lg", onClick: onSelectRecipient, children: _jsx("div", { className: "text-sm font-medium", children: "Select recipient" }) }))] }), isBuyMode || isDepositMode ? (
14
24
  // Fixed destination token display for buy mode and deposit mode
15
25
  _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-as-primary text-2xl font-bold", children: dstAmount || "0" }), _jsxs("div", { className: "bg-as-brand/10 border-as-brand/30 flex items-center gap-3 rounded-xl border px-4 py-3", children: [(dstTokenLogoURI || dstToken.metadata?.logoURI) && (_jsx("img", { src: dstTokenLogoURI || dstToken.metadata?.logoURI, alt: dstTokenSymbol || dstToken.symbol, className: "h-8 w-8 rounded-full" })), _jsx("span", { className: "text-as-brand text-lg font-bold", children: dstTokenSymbol || dstToken.symbol })] })] })) : (