@b3dotfun/sdk 0.0.62 → 0.0.63-test.0-alpha.0

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 (150) 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/AnySpendCustomExactIn.d.ts +34 -0
  4. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +275 -0
  5. package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +5 -4
  6. package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
  7. package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.js +288 -0
  8. package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
  9. package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.js +33 -0
  10. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +4 -4
  11. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +4 -6
  12. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +9 -17
  13. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
  14. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +11 -1
  15. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +66 -147
  16. package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
  17. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
  18. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +39 -15
  19. package/dist/cjs/anyspend/react/components/common/PaySection.js +1 -1
  20. package/dist/cjs/anyspend/react/components/common/TokenBalance.js +1 -1
  21. package/dist/cjs/anyspend/react/components/index.d.ts +5 -1
  22. package/dist/cjs/anyspend/react/components/index.js +11 -3
  23. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
  24. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +42 -19
  25. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
  26. package/dist/cjs/anyspend/react/hooks/useAnyspendQuote.js +1 -1
  27. package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
  28. package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +56 -0
  29. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  30. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +73 -0
  31. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
  32. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +57 -0
  33. package/dist/cjs/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
  34. package/dist/cjs/anyspend/react/hooks/usePhantomTransfer.js +211 -0
  35. package/dist/cjs/anyspend/types/api.d.ts +665 -3
  36. package/dist/cjs/anyspend/utils/orderPayload.js +4 -0
  37. package/dist/cjs/global-account/react/components/B3DynamicModal.js +10 -1
  38. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +3 -1
  39. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
  40. package/dist/cjs/global-account/react/hooks/index.d.ts +2 -1
  41. package/dist/cjs/global-account/react/hooks/index.js +5 -3
  42. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
  43. package/dist/cjs/global-account/react/hooks/useAuthentication.js +7 -2
  44. package/dist/cjs/global-account/react/hooks/useSimBalance.d.ts +1 -1
  45. package/dist/cjs/global-account/react/hooks/useSimBalance.js +6 -5
  46. package/dist/cjs/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
  47. package/dist/cjs/global-account/react/hooks/useTokenBalanceDirect.js +62 -0
  48. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +4 -3
  49. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +31 -1
  50. package/dist/esm/anyspend/react/components/AnySpend.js +62 -24
  51. package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -0
  52. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
  53. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +269 -0
  54. package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +7 -6
  55. package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
  56. package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.js +285 -0
  57. package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
  58. package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.js +30 -0
  59. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +4 -4
  60. package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +5 -7
  61. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +9 -17
  62. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
  63. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +11 -1
  64. package/dist/esm/anyspend/react/components/common/OrderDetails.js +67 -148
  65. package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
  66. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
  67. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +40 -16
  68. package/dist/esm/anyspend/react/components/common/PaySection.js +1 -1
  69. package/dist/esm/anyspend/react/components/common/TokenBalance.js +2 -2
  70. package/dist/esm/anyspend/react/components/index.d.ts +5 -1
  71. package/dist/esm/anyspend/react/components/index.js +5 -1
  72. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
  73. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +42 -19
  74. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
  75. package/dist/esm/anyspend/react/hooks/useAnyspendQuote.js +1 -1
  76. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
  77. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +53 -0
  78. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  79. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +70 -0
  80. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
  81. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +54 -0
  82. package/dist/esm/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
  83. package/dist/esm/anyspend/react/hooks/usePhantomTransfer.js +208 -0
  84. package/dist/esm/anyspend/types/api.d.ts +665 -3
  85. package/dist/esm/anyspend/utils/orderPayload.js +4 -0
  86. package/dist/esm/global-account/react/components/B3DynamicModal.js +11 -2
  87. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +3 -1
  88. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
  89. package/dist/esm/global-account/react/hooks/index.d.ts +2 -1
  90. package/dist/esm/global-account/react/hooks/index.js +2 -1
  91. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
  92. package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -2
  93. package/dist/esm/global-account/react/hooks/useSimBalance.d.ts +1 -1
  94. package/dist/esm/global-account/react/hooks/useSimBalance.js +6 -5
  95. package/dist/esm/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
  96. package/dist/esm/global-account/react/hooks/useTokenBalanceDirect.js +59 -0
  97. package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +4 -3
  98. package/dist/esm/global-account/react/stores/useModalStore.d.ts +31 -1
  99. package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
  100. package/dist/types/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
  101. package/dist/types/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
  102. package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
  103. package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
  104. package/dist/types/anyspend/react/components/index.d.ts +5 -1
  105. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
  106. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
  107. package/dist/types/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
  108. package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  109. package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
  110. package/dist/types/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
  111. package/dist/types/anyspend/types/api.d.ts +665 -3
  112. package/dist/types/global-account/react/hooks/index.d.ts +2 -1
  113. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
  114. package/dist/types/global-account/react/hooks/useSimBalance.d.ts +1 -1
  115. package/dist/types/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
  116. package/dist/types/global-account/react/stores/useModalStore.d.ts +31 -1
  117. package/package.json +3 -2
  118. package/src/anyspend/react/components/AnySpend.tsx +73 -22
  119. package/src/anyspend/react/components/AnySpendCustom.tsx +4 -0
  120. package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +595 -0
  121. package/src/anyspend/react/components/AnySpendStakeB3.tsx +8 -11
  122. package/src/anyspend/react/components/AnySpendStakeB3ExactIn.tsx +522 -0
  123. package/src/anyspend/react/components/AnySpendStakeUpsideExactIn.tsx +73 -0
  124. package/src/anyspend/react/components/AnyspendDepositHype.tsx +7 -3
  125. package/src/anyspend/react/components/common/CryptoPaySection.tsx +5 -7
  126. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +9 -18
  127. package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +22 -0
  128. package/src/anyspend/react/components/common/OrderDetails.tsx +76 -190
  129. package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +2 -3
  130. package/src/anyspend/react/components/common/OrderTokenAmount.tsx +48 -17
  131. package/src/anyspend/react/components/common/PaySection.tsx +1 -0
  132. package/src/anyspend/react/components/common/TokenBalance.tsx +2 -2
  133. package/src/anyspend/react/components/index.ts +5 -1
  134. package/src/anyspend/react/hooks/useAnyspendFlow.ts +51 -18
  135. package/src/anyspend/react/hooks/useAnyspendQuote.ts +1 -1
  136. package/src/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.ts +72 -0
  137. package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +80 -0
  138. package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +69 -0
  139. package/src/anyspend/react/hooks/usePhantomTransfer.ts +301 -0
  140. package/src/anyspend/types/api.ts +669 -1
  141. package/src/anyspend/utils/orderPayload.ts +5 -1
  142. package/src/global-account/react/components/B3DynamicModal.tsx +11 -1
  143. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +3 -1
  144. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +2 -2
  145. package/src/global-account/react/hooks/index.ts +2 -1
  146. package/src/global-account/react/hooks/useAuthentication.ts +10 -2
  147. package/src/global-account/react/hooks/useSimBalance.ts +6 -5
  148. package/src/global-account/react/hooks/useTokenBalanceDirect.tsx +84 -0
  149. package/src/global-account/react/hooks/useTokenFromUrl.tsx +6 -5
  150. package/src/global-account/react/stores/useModalStore.ts +34 -0
@@ -3,27 +3,55 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { ChevronsUpDown } from "lucide-react";
4
4
  import { useEffect, useRef } from "react";
5
5
  import { NumericFormat } from "react-number-format";
6
+ import { formatUnits } from "viem";
6
7
  import { ALL_CHAINS, RELAY_SOLANA_MAINNET_CHAIN_ID } from "../../../../anyspend/index.js";
7
- import { Button } from "../../../../global-account/react/index.js";
8
+ import { getNativeRequired } from "../../../../anyspend/utils/chain.js";
9
+ import { isNativeToken } from "../../../../anyspend/utils/token.js";
10
+ import { Button, useTokenBalance } from "../../../../global-account/react/index.js";
8
11
  import { cn } from "../../../../shared/utils/index.js";
9
12
  import { TokenSelector } from "@relayprotocol/relay-kit-ui";
10
13
  import { ChainTokenIcon } from "./ChainTokenIcon.js";
11
- export function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, address, chainId, setChainId, token, setToken, hideTokenSelect = false, canEditAmount = true, className, innerClassName, amountClassName, tokenSelectClassName, onTokenSelect, }) {
14
+ export function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, address, chainId, setChainId, token, setToken, hideTokenSelect = false, canEditAmount = true, className, innerClassName, amountClassName, tokenSelectClassName, onTokenSelect, walletAddress, }) {
12
15
  // Track previous token to detect changes
13
16
  const prevTokenRef = useRef(token.address);
17
+ // Track if initial balance has been set
18
+ const initialBalanceSetRef = useRef(false);
19
+ // Only get token balance when context is "from" (for setting max amount)
20
+ const { rawBalance } = useTokenBalance({
21
+ token,
22
+ address: context === "from" && walletAddress ? walletAddress : undefined,
23
+ });
24
+ // Reset balance ref when token address or chain changes
14
25
  useEffect(() => {
15
- // Only trigger when token actually changes
16
- if (prevTokenRef.current !== token.address) {
17
- console.log(`Token changed from ${prevTokenRef.current} to ${token.address}`);
18
- // For "from" context, reset to default value when token changes
19
- if (context === "from") {
20
- // Reset input to default for new token
21
- onChangeInput("0.01");
26
+ initialBalanceSetRef.current = false;
27
+ }, [token.address, token.chainId]);
28
+ useEffect(() => {
29
+ // Only handle "from" context
30
+ if (context !== "from")
31
+ return;
32
+ // Check if token changed or if this is the initial load with balance
33
+ const isTokenChanged = prevTokenRef.current !== token.address;
34
+ const isInitialLoad = !initialBalanceSetRef.current && rawBalance;
35
+ if ((isTokenChanged || isInitialLoad) && rawBalance) {
36
+ console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}, Initial: ${isInitialLoad}`);
37
+ // Calculate max amount with gas reserve for native tokens
38
+ let maxAmount;
39
+ if (isNativeToken(token.address)) {
40
+ const gasReserve = getNativeRequired(token.chainId);
41
+ // Ensure we don't go negative
42
+ maxAmount = rawBalance > gasReserve ? rawBalance - gasReserve : BigInt(0);
43
+ }
44
+ else {
45
+ // For ERC20 tokens, use full balance
46
+ maxAmount = rawBalance;
22
47
  }
23
- // Update ref to current token
48
+ // Set the max amount as input value
49
+ onChangeInput(formatUnits(maxAmount, token.decimals));
50
+ // Update refs
24
51
  prevTokenRef.current = token.address;
52
+ initialBalanceSetRef.current = true;
25
53
  }
26
- }, [token.address, chainId, context, onChangeInput]);
54
+ }, [token.address, token.chainId, token.decimals, chainId, context, onChangeInput, rawBalance]);
27
55
  const handleTokenSelect = (newToken) => {
28
56
  const token = {
29
57
  address: newToken.address,
@@ -50,12 +78,8 @@ export function OrderTokenAmount({ disabled, inputValue, onChangeInput, context,
50
78
  prevTokenRef.current = "changing"; // Temporary value to force effect
51
79
  // Set the chain ID first
52
80
  setChainId(newToken.chainId);
53
- // Then set the new token
81
+ // Then set the new token - the useEffect will handle setting the max balance
54
82
  setToken(token);
55
- // If this is the source token, reset the amount immediately
56
- if (context === "from") {
57
- onChangeInput("0.01");
58
- }
59
83
  };
60
84
  return (_jsx("div", { className: cn("border-as-stroke flex w-full flex-col gap-2 rounded-xl", className), children: _jsxs("div", { className: cn("flex items-center justify-between gap-3", innerClassName), children: [!canEditAmount ? (_jsx("h2", { className: cn("text-3xl font-medium text-white", amountClassName), children: inputValue || "--" })) : (_jsx(NumericFormat, { decimalSeparator: ".", allowedDecimalSeparators: [","], thousandSeparator: true, inputMode: "decimal", autoComplete: "off", autoCorrect: "off", type: "text", placeholder: "0.00", minLength: 1, maxLength: 30, spellCheck: "false", className: cn("placeholder:text-as-primary/70 disabled:text-as-primary/70 text-as-primary w-full bg-transparent text-4xl font-semibold leading-[42px] outline-none sm:text-[30px]", amountClassName), pattern: "^[0-9]*[.,]?[0-9]*$", disabled: disabled, value: inputValue, allowNegative: false, onChange: e => onChangeInput(e.currentTarget.value) }, `input-${token.address}-${chainId}`)), !hideTokenSelect && (_jsx(TokenSelector, { address: address, chainIdsFilter: Object.values(ALL_CHAINS).map(chain => chain.id), context: context, fromChainWalletVMSupported: true, isValidAddress: true, lockedChainIds: Object.values(ALL_CHAINS).map(chain => chain.id), multiWalletSupportEnabled: true, onAnalyticEvent: undefined, popularChainIds: [1, 8453, RELAY_SOLANA_MAINNET_CHAIN_ID], setToken: handleTokenSelect, supportedWalletVMs: ["evm", "svm"], token: undefined, trigger: _jsxs(Button, { variant: "outline", role: "combobox", className: cn("token-selector-button bg-b3-react-background border-as-stroke flex h-auto w-fit shrink-0 items-center justify-center gap-2 rounded-xl border-2 px-2 py-1 pr-2 text-center", tokenSelectClassName), children: [token.metadata.logoURI ? (_jsx(ChainTokenIcon, { chainUrl: ALL_CHAINS[chainId].logoUrl, tokenUrl: token.metadata.logoURI, className: "h-8 min-h-8 w-8 min-w-8" })) : (_jsx("div", { className: "h-8 w-8 rounded-full bg-gray-700" })), _jsxs("div", { className: "flex flex-col items-start gap-0", children: [_jsx("div", { className: "text-as-primary font-semibold", children: token.symbol }), _jsx("div", { className: "text-as-primary/70 text-xs", children: ALL_CHAINS[chainId].name })] }), _jsx(ChevronsUpDown, { className: "h-4 w-4 shrink-0 opacity-70" })] }) }, `selector-${context}-${token.address}-${chainId}`))] }) }, `${context}-${token.address}-${chainId}`));
61
85
  }
@@ -39,7 +39,7 @@ export function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, se
39
39
  useEffect(() => {
40
40
  appliedSrcMetadataRef.current = false;
41
41
  }, [selectedSrcToken.address, selectedSrcToken.chainId]);
42
- 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: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Pay" }), _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: [isConnected ? (_jsx("div", { className: "flex items-center gap-1", children: connectedName ? formatUsername(connectedName) : shortenAddress(connectedAddress || "") })) : ("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: connectedAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
42
+ 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: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Pay" }), _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: [isConnected ? (_jsx("div", { className: "flex items-center gap-1", children: connectedName ? formatUsername(connectedName) : shortenAddress(connectedAddress || "") })) : ("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: connectedAddress, walletAddress: connectedAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
43
43
  setIsSrcInputDirty(true);
44
44
  setSrcAmount(value);
45
45
  }, chainId: selectedSrcChainId, setChainId: setSelectedSrcChainId, token: selectedSrcToken, setToken: setSelectedSrcToken }), _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, {
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { getNativeRequired } from "../../../../anyspend/utils/chain.js";
3
3
  import { isNativeToken } from "../../../../anyspend/utils/token.js";
4
- import { useTokenBalance } from "../../../../global-account/react/index.js";
4
+ import { useTokenBalanceDirect } from "../../../../global-account/react/index.js";
5
5
  import { formatUnits } from "viem";
6
6
  export function TokenBalance({ token, walletAddress, onChangeInput, }) {
7
- const { rawBalance, formattedBalance, isLoading } = useTokenBalance({
7
+ const { rawBalance, formattedBalance, isLoading } = useTokenBalanceDirect({
8
8
  token,
9
9
  address: walletAddress,
10
10
  });
@@ -2,11 +2,15 @@ export { AnySpend } from "./AnySpend";
2
2
  export { AnySpendBondKit } from "./AnySpendBondKit";
3
3
  export { AnySpendBuySpin } from "./AnySpendBuySpin";
4
4
  export { AnySpendCustom } from "./AnySpendCustom";
5
+ export { AnySpendCustomExactIn } from "./AnySpendCustomExactIn";
5
6
  export * from "./AnySpendFingerprintWrapper";
6
7
  export { AnySpendNFT } from "./AnySpendNFT";
8
+ export { AnyspendSignatureMint } from "./AnyspendSignatureMint";
7
9
  export { AnySpendStakeB3 } from "./AnySpendStakeB3";
10
+ export { AnySpendStakeB3ExactIn } from "./AnySpendStakeB3ExactIn";
11
+ export { AnySpendStakeUpside } from "./AnySpendStakeUpside";
12
+ export { AnySpendStakeUpsideExactIn } from "./AnySpendStakeUpsideExactIn";
8
13
  export { AnySpendTournament } from "./AnySpendTournament";
9
- export { AnyspendSignatureMint } from "./AnyspendSignatureMint";
10
14
  export { AnySpendNFTButton } from "./common/AnySpendNFTButton";
11
15
  export { ChainTokenIcon } from "./common/ChainTokenIcon";
12
16
  export { CryptoPaySection } from "./common/CryptoPaySection";
@@ -3,11 +3,15 @@ export { AnySpend } from "./AnySpend.js";
3
3
  export { AnySpendBondKit } from "./AnySpendBondKit.js";
4
4
  export { AnySpendBuySpin } from "./AnySpendBuySpin.js";
5
5
  export { AnySpendCustom } from "./AnySpendCustom.js";
6
+ export { AnySpendCustomExactIn } from "./AnySpendCustomExactIn.js";
6
7
  export * from "./AnySpendFingerprintWrapper.js";
7
8
  export { AnySpendNFT } from "./AnySpendNFT.js";
9
+ export { AnyspendSignatureMint } from "./AnyspendSignatureMint.js";
8
10
  export { AnySpendStakeB3 } from "./AnySpendStakeB3.js";
11
+ export { AnySpendStakeB3ExactIn } from "./AnySpendStakeB3ExactIn.js";
12
+ export { AnySpendStakeUpside } from "./AnySpendStakeUpside.js";
13
+ export { AnySpendStakeUpsideExactIn } from "./AnySpendStakeUpsideExactIn.js";
9
14
  export { AnySpendTournament } from "./AnySpendTournament.js";
10
- export { AnyspendSignatureMint } from "./AnyspendSignatureMint.js";
11
15
  export { AnySpendNFTButton } from "./common/AnySpendNFTButton.js";
12
16
  // Common Components
13
17
  export { ChainTokenIcon } from "./common/ChainTokenIcon.js";
@@ -17,13 +17,16 @@ interface UseAnyspendFlowProps {
17
17
  loadOrder?: string;
18
18
  isDepositMode?: boolean;
19
19
  onOrderSuccess?: (orderId: string) => void;
20
- onTransactionSuccess?: (amount?: string) => void;
20
+ onTransactionSuccess?: (amount: string) => void;
21
21
  sourceTokenAddress?: string;
22
22
  sourceTokenChainId?: number;
23
+ destinationTokenAddress?: string;
24
+ destinationTokenChainId?: number;
23
25
  slippage?: number;
24
26
  disableUrlParamManagement?: boolean;
27
+ orderType?: "hype_duel" | "custom_exact_in";
25
28
  }
26
- export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrder, isDepositMode, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, slippage, disableUrlParamManagement, }: UseAnyspendFlowProps): {
29
+ export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrder, isDepositMode, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, destinationTokenAddress, destinationTokenChainId, slippage, disableUrlParamManagement, orderType, }: UseAnyspendFlowProps): {
27
30
  activePanel: PanelView;
28
31
  setActivePanel: import("react").Dispatch<import("react").SetStateAction<PanelView>>;
29
32
  orderId: string | undefined;
@@ -44,7 +47,6 @@ export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrd
44
47
  selectedSrcChainId: number;
45
48
  setSelectedSrcChainId: import("react").Dispatch<import("react").SetStateAction<number>>;
46
49
  selectedDstChainId: number;
47
- setSelectedDstChainId: import("react").Dispatch<import("react").SetStateAction<number>>;
48
50
  selectedSrcToken: {
49
51
  chainId: number;
50
52
  address: string;
@@ -65,6 +67,26 @@ export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrd
65
67
  logoURI?: string;
66
68
  };
67
69
  }>>;
70
+ selectedDstToken: {
71
+ chainId: number;
72
+ address: string;
73
+ symbol: string;
74
+ name: string;
75
+ decimals: number;
76
+ metadata: {
77
+ logoURI?: string;
78
+ };
79
+ };
80
+ setSelectedDstToken: import("react").Dispatch<import("react").SetStateAction<{
81
+ chainId: number;
82
+ address: string;
83
+ symbol: string;
84
+ name: string;
85
+ decimals: number;
86
+ metadata: {
87
+ logoURI?: string;
88
+ };
89
+ }>>;
68
90
  srcAmount: string;
69
91
  setSrcAmount: import("react").Dispatch<import("react").SetStateAction<string>>;
70
92
  dstAmount: string;
@@ -10,6 +10,8 @@ import { base, mainnet } from "viem/chains";
10
10
  import { useAccount } from "wagmi";
11
11
  import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod.js";
12
12
  import { FiatPaymentMethod } from "../components/common/FiatPaymentMethod.js";
13
+ import { useAutoSelectCryptoPaymentMethod } from "./useAutoSelectCryptoPaymentMethod.js";
14
+ import { useAutoSetActiveWalletFromWagmi } from "./useAutoSetActiveWalletFromWagmi.js";
13
15
  export var PanelView;
14
16
  (function (PanelView) {
15
17
  PanelView[PanelView["MAIN"] = 0] = "MAIN";
@@ -21,21 +23,25 @@ export var PanelView;
21
23
  PanelView[PanelView["POINTS_DETAIL"] = 6] = "POINTS_DETAIL";
22
24
  PanelView[PanelView["FEE_DETAIL"] = 7] = "FEE_DETAIL";
23
25
  })(PanelView || (PanelView = {}));
24
- export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, slippage = 0, disableUrlParamManagement = false, }) {
26
+ // This hook serves for order hype_duel and custom_exact_in
27
+ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, destinationTokenAddress, destinationTokenChainId, slippage = 0, disableUrlParamManagement = false, orderType = "hype_duel", }) {
25
28
  const searchParams = useSearchParamsSSR();
26
29
  const router = useRouter();
27
30
  // Panel and order state
28
31
  const [activePanel, setActivePanel] = useState(loadOrder ? PanelView.ORDER_DETAILS : PanelView.MAIN);
29
32
  const [orderId, setOrderId] = useState(loadOrder);
30
33
  const { orderAndTransactions: oat } = useAnyspendOrderAndTransactions(orderId);
31
- // Token selection state - use provided sourceTokenChainId if available
34
+ // Token selection state - use provided sourceTokenChainId and destinationTokenChainId if available
32
35
  const [selectedSrcChainId, setSelectedSrcChainId] = useState(sourceTokenChainId || (paymentType === "fiat" ? base.id : mainnet.id));
33
- const [selectedDstChainId, setSelectedDstChainId] = useState(base.id); // Default to Base for cross-chain swaps
34
36
  const defaultSrcToken = paymentType === "fiat" ? USDC_BASE : getDefaultToken(selectedSrcChainId);
37
+ const defaultDstToken = B3_TOKEN; // Default destination token
35
38
  const [selectedSrcToken, setSelectedSrcToken] = useState(defaultSrcToken);
39
+ const [selectedDstToken, setSelectedDstToken] = useState(defaultDstToken);
36
40
  const [srcAmount, setSrcAmount] = useState(paymentType === "fiat" ? "5" : "0.1");
37
41
  const [dstAmount, setDstAmount] = useState("");
38
42
  const [isSrcInputDirty, setIsSrcInputDirty] = useState(true);
43
+ // Derive destination chain ID from token or prop (cannot change)
44
+ const selectedDstChainId = destinationTokenChainId || selectedDstToken.chainId;
39
45
  // Payment method state
40
46
  const [selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod] = useState(CryptoPaymentMethodType.NONE);
41
47
  const [selectedFiatPaymentMethod, setSelectedFiatPaymentMethod] = useState(FiatPaymentMethod.NONE);
@@ -45,6 +51,8 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
45
51
  const [selectedRecipientAddress, setSelectedRecipientAddress] = useState(recipientAddress);
46
52
  const recipientProfile = useProfile({ address: selectedRecipientAddress, fresh: true });
47
53
  const recipientName = recipientProfile.data?.name;
54
+ // Auto-set active wallet from wagmi
55
+ useAutoSetActiveWalletFromWagmi();
48
56
  // Set default recipient address when wallet changes
49
57
  useEffect(() => {
50
58
  if (!selectedRecipientAddress && globalAddress) {
@@ -68,17 +76,14 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
68
76
  return false;
69
77
  }
70
78
  }, [rawBalance, srcAmount, selectedSrcToken.decimals, isBalanceLoading, paymentType]);
71
- // Auto-set crypto payment method based on balance
72
- useEffect(() => {
73
- if (paymentType === "crypto" && !isBalanceLoading) {
74
- if (hasEnoughBalance) {
75
- setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
76
- }
77
- else {
78
- setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
79
- }
80
- }
81
- }, [paymentType, hasEnoughBalance, isBalanceLoading]);
79
+ // Auto-select crypto payment method based on available wallets and balance
80
+ useAutoSelectCryptoPaymentMethod({
81
+ paymentType,
82
+ selectedCryptoPaymentMethod,
83
+ setSelectedCryptoPaymentMethod,
84
+ hasEnoughBalance,
85
+ isBalanceLoading,
86
+ });
82
87
  // Fetch specific token when sourceTokenAddress and sourceTokenChainId are provided
83
88
  useEffect(() => {
84
89
  const fetchSourceToken = async () => {
@@ -96,6 +101,23 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
96
101
  };
97
102
  fetchSourceToken();
98
103
  }, [sourceTokenAddress, sourceTokenChainId]);
104
+ // Fetch specific token when destinationTokenAddress and destinationTokenChainId are provided
105
+ useEffect(() => {
106
+ const fetchDestinationToken = async () => {
107
+ if (destinationTokenAddress && destinationTokenChainId) {
108
+ try {
109
+ const token = await anyspendService.getToken(destinationTokenChainId, destinationTokenAddress);
110
+ setSelectedDstToken(token);
111
+ }
112
+ catch (error) {
113
+ console.error("Failed to fetch destination token:", error);
114
+ toast.error(`Failed to load token ${destinationTokenAddress} on chain ${destinationTokenChainId}`);
115
+ // Keep the default token on error
116
+ }
117
+ }
118
+ };
119
+ fetchDestinationToken();
120
+ }, [destinationTokenAddress, destinationTokenChainId]);
99
121
  // Helper function for onramp vendor mapping
100
122
  const getOnrampVendor = (paymentMethod) => {
101
123
  switch (paymentMethod) {
@@ -115,8 +137,8 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
115
137
  srcChain: paymentType === "fiat" ? base.id : selectedSrcChainId,
116
138
  dstChain: isDepositMode ? base.id : selectedDstChainId, // For deposits, always Base; for swaps, use selected destination
117
139
  srcTokenAddress: paymentType === "fiat" ? USDC_BASE.address : selectedSrcToken.address,
118
- dstTokenAddress: isDepositMode ? B3_TOKEN.address : selectedSrcToken.address, // For deposits, always B3
119
- type: "hype_duel",
140
+ dstTokenAddress: selectedDstToken.address,
141
+ type: orderType,
120
142
  amount: activeInputAmountInWei,
121
143
  recipientAddress: selectedRecipientAddress,
122
144
  onrampVendor: paymentType === "fiat" ? getOnrampVendor(selectedFiatPaymentMethod) : undefined,
@@ -194,7 +216,7 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
194
216
  const formattedActualDstAmount = amount
195
217
  ? formatTokenAmount(BigInt(amount), oat.data.order.metadata.dstToken.decimals)
196
218
  : undefined;
197
- onTransactionSuccess?.(formattedActualDstAmount);
219
+ onTransactionSuccess?.(formattedActualDstAmount ?? "");
198
220
  }
199
221
  }, [
200
222
  oat?.data?.order.status,
@@ -212,10 +234,11 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
212
234
  // Token state
213
235
  selectedSrcChainId,
214
236
  setSelectedSrcChainId,
215
- selectedDstChainId,
216
- setSelectedDstChainId,
237
+ selectedDstChainId, // Derived, not stateful
217
238
  selectedSrcToken,
218
239
  setSelectedSrcToken,
240
+ selectedDstToken,
241
+ setSelectedDstToken,
219
242
  srcAmount,
220
243
  setSrcAmount,
221
244
  dstAmount,
@@ -53,6 +53,35 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
53
53
  relay?: Record<string, never>;
54
54
  } | null;
55
55
  fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
56
+ } & {
57
+ type: "x402_swap";
58
+ payload: import("../..").components["schemas"]["X402SwapPayload"];
59
+ metadata: import("../..").components["schemas"]["X402SwapMetadata"];
60
+ }) | ({
61
+ id: string;
62
+ recipientAddress: string;
63
+ globalAddress: string;
64
+ srcChain: number;
65
+ dstChain: number;
66
+ srcTokenAddress: string;
67
+ dstTokenAddress: string;
68
+ srcAmount: string;
69
+ status: "scanning_deposit_transaction" | "waiting_stripe_payment" | "expired" | "sending_token_from_vault" | "relay" | "executing" | "executed" | "refunding" | "refunded" | "failure";
70
+ errorDetails: string | null;
71
+ createdAt: number;
72
+ expiredAt: number;
73
+ filledAt: number | null;
74
+ receivedDepositAt: number | null;
75
+ creatorAddress: string | null;
76
+ partnerId: string | null;
77
+ onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
78
+ oneClickBuyUrl: string | null;
79
+ stripePaymentIntentId: string | null;
80
+ settlement: {
81
+ actualDstAmount?: string;
82
+ relay?: Record<string, never>;
83
+ } | null;
84
+ fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
56
85
  } & {
57
86
  type: "hype_duel";
58
87
  payload: import("../..").components["schemas"]["HypeDuelPayload"];
@@ -111,6 +140,35 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
111
140
  relay?: Record<string, never>;
112
141
  } | null;
113
142
  fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
143
+ } & {
144
+ type: "custom_exact_in";
145
+ payload: import("../..").components["schemas"]["CustomExactInPayload"];
146
+ metadata: import("../..").components["schemas"]["CustomMetadata"];
147
+ }) | ({
148
+ id: string;
149
+ recipientAddress: string;
150
+ globalAddress: string;
151
+ srcChain: number;
152
+ dstChain: number;
153
+ srcTokenAddress: string;
154
+ dstTokenAddress: string;
155
+ srcAmount: string;
156
+ status: "scanning_deposit_transaction" | "waiting_stripe_payment" | "expired" | "sending_token_from_vault" | "relay" | "executing" | "executed" | "refunding" | "refunded" | "failure";
157
+ errorDetails: string | null;
158
+ createdAt: number;
159
+ expiredAt: number;
160
+ filledAt: number | null;
161
+ receivedDepositAt: number | null;
162
+ creatorAddress: string | null;
163
+ partnerId: string | null;
164
+ onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
165
+ oneClickBuyUrl: string | null;
166
+ stripePaymentIntentId: string | null;
167
+ settlement: {
168
+ actualDstAmount?: string;
169
+ relay?: Record<string, never>;
170
+ } | null;
171
+ fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
114
172
  } & {
115
173
  type: "mint_nft";
116
174
  payload: import("../..").components["schemas"]["MintNftPayload"];
@@ -230,6 +288,35 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
230
288
  relay?: Record<string, never>;
231
289
  } | null;
232
290
  fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
291
+ } & {
292
+ type: "x402_swap";
293
+ payload: import("../..").components["schemas"]["X402SwapPayload"];
294
+ metadata: import("../..").components["schemas"]["X402SwapMetadata"];
295
+ }) | ({
296
+ id: string;
297
+ recipientAddress: string;
298
+ globalAddress: string;
299
+ srcChain: number;
300
+ dstChain: number;
301
+ srcTokenAddress: string;
302
+ dstTokenAddress: string;
303
+ srcAmount: string;
304
+ status: "scanning_deposit_transaction" | "waiting_stripe_payment" | "expired" | "sending_token_from_vault" | "relay" | "executing" | "executed" | "refunding" | "refunded" | "failure";
305
+ errorDetails: string | null;
306
+ createdAt: number;
307
+ expiredAt: number;
308
+ filledAt: number | null;
309
+ receivedDepositAt: number | null;
310
+ creatorAddress: string | null;
311
+ partnerId: string | null;
312
+ onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
313
+ oneClickBuyUrl: string | null;
314
+ stripePaymentIntentId: string | null;
315
+ settlement: {
316
+ actualDstAmount?: string;
317
+ relay?: Record<string, never>;
318
+ } | null;
319
+ fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
233
320
  } & {
234
321
  type: "hype_duel";
235
322
  payload: import("../..").components["schemas"]["HypeDuelPayload"];
@@ -288,6 +375,35 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
288
375
  relay?: Record<string, never>;
289
376
  } | null;
290
377
  fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
378
+ } & {
379
+ type: "custom_exact_in";
380
+ payload: import("../..").components["schemas"]["CustomExactInPayload"];
381
+ metadata: import("../..").components["schemas"]["CustomMetadata"];
382
+ }) | ({
383
+ id: string;
384
+ recipientAddress: string;
385
+ globalAddress: string;
386
+ srcChain: number;
387
+ dstChain: number;
388
+ srcTokenAddress: string;
389
+ dstTokenAddress: string;
390
+ srcAmount: string;
391
+ status: "scanning_deposit_transaction" | "waiting_stripe_payment" | "expired" | "sending_token_from_vault" | "relay" | "executing" | "executed" | "refunding" | "refunded" | "failure";
392
+ errorDetails: string | null;
393
+ createdAt: number;
394
+ expiredAt: number;
395
+ filledAt: number | null;
396
+ receivedDepositAt: number | null;
397
+ creatorAddress: string | null;
398
+ partnerId: string | null;
399
+ onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
400
+ oneClickBuyUrl: string | null;
401
+ stripePaymentIntentId: string | null;
402
+ settlement: {
403
+ actualDstAmount?: string;
404
+ relay?: Record<string, never>;
405
+ } | null;
406
+ fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
291
407
  } & {
292
408
  type: "mint_nft";
293
409
  payload: import("../..").components["schemas"]["MintNftPayload"];
@@ -11,7 +11,7 @@ export function useAnyspendQuote(req) {
11
11
  req.dstChain &&
12
12
  req.srcTokenAddress &&
13
13
  req.dstTokenAddress &&
14
- BigInt(req.type === "swap" || req.type === "hype_duel"
14
+ BigInt(req.type === "swap" || req.type === "hype_duel" || req.type === "x402_swap" || req.type === "custom_exact_in"
15
15
  ? req.amount
16
16
  : req.type === "mint_nft"
17
17
  ? req.price
@@ -0,0 +1,26 @@
1
+ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
2
+ interface UseAutoSelectCryptoPaymentMethodParams {
3
+ /** Current payment type (crypto or fiat) */
4
+ paymentType?: "crypto" | "fiat";
5
+ /** Currently selected payment method */
6
+ selectedCryptoPaymentMethod: CryptoPaymentMethodType;
7
+ /** Function to update the selected payment method */
8
+ setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
9
+ /** Whether user has enough balance to pay */
10
+ hasEnoughBalance: boolean;
11
+ /** Whether balance is still loading */
12
+ isBalanceLoading: boolean;
13
+ }
14
+ /**
15
+ * Custom hook to automatically select appropriate crypto payment method
16
+ * based on available wallets and balance.
17
+ *
18
+ * Auto-selection logic:
19
+ * - Only auto-selects when payment method is NONE (doesn't override user choices)
20
+ * - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
21
+ * - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
22
+ * - If only Global wallet available → GLOBAL_WALLET
23
+ * - If no wallets → remains NONE
24
+ */
25
+ export declare function useAutoSelectCryptoPaymentMethod({ paymentType, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }: UseAutoSelectCryptoPaymentMethodParams): void;
26
+ export {};
@@ -0,0 +1,53 @@
1
+ import { useEffect } from "react";
2
+ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod.js";
3
+ import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay.js";
4
+ /**
5
+ * Custom hook to automatically select appropriate crypto payment method
6
+ * based on available wallets and balance.
7
+ *
8
+ * Auto-selection logic:
9
+ * - Only auto-selects when payment method is NONE (doesn't override user choices)
10
+ * - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
11
+ * - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
12
+ * - If only Global wallet available → GLOBAL_WALLET
13
+ * - If no wallets → remains NONE
14
+ */
15
+ export function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto", selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }) {
16
+ // Get suggested payment method based on available wallets
17
+ const { suggestedPaymentMethod } = useConnectedWalletDisplay(selectedCryptoPaymentMethod);
18
+ useEffect(() => {
19
+ // Only auto-select when on crypto payment type and payment method is NONE
20
+ if (paymentType !== "crypto" || selectedCryptoPaymentMethod !== CryptoPaymentMethodType.NONE) {
21
+ return;
22
+ }
23
+ // If we have a suggested payment method (wallet is connected), use it
24
+ if (suggestedPaymentMethod !== CryptoPaymentMethodType.NONE) {
25
+ // If we have balance info and enough balance, use CONNECT_WALLET
26
+ // Otherwise, default to TRANSFER_CRYPTO if balance is insufficient
27
+ if (!isBalanceLoading) {
28
+ if (hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
29
+ setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
30
+ }
31
+ else if (!hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
32
+ // Wallet connected but insufficient balance - suggest transfer
33
+ setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
34
+ }
35
+ else {
36
+ // Use suggested method (e.g., GLOBAL_WALLET)
37
+ setSelectedCryptoPaymentMethod(suggestedPaymentMethod);
38
+ }
39
+ }
40
+ else {
41
+ // Balance still loading, use suggested method
42
+ setSelectedCryptoPaymentMethod(suggestedPaymentMethod);
43
+ }
44
+ }
45
+ }, [
46
+ paymentType,
47
+ selectedCryptoPaymentMethod,
48
+ suggestedPaymentMethod,
49
+ hasEnoughBalance,
50
+ isBalanceLoading,
51
+ setSelectedCryptoPaymentMethod,
52
+ ]);
53
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
3
+ *
4
+ * This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
5
+ * ensuring that when users connect via wagmi, the active wallet is properly set.
6
+ *
7
+ * Place this hook in components that stay mounted throughout the user flow
8
+ * (not in components that unmount during navigation).
9
+ */
10
+ export declare function useAutoSetActiveWalletFromWagmi(): void;