@b3dotfun/sdk 0.0.28-alpha.0 → 0.0.28-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/cjs/anyspend/abis/escrow.d.ts +987 -0
  2. package/dist/cjs/anyspend/abis/escrow.js +1275 -0
  3. package/dist/cjs/anyspend/react/components/AnySpend.js +10 -168
  4. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +2 -2
  5. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +10 -0
  6. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +263 -0
  7. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +17 -0
  8. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +53 -0
  9. package/dist/cjs/anyspend/react/components/common/ErrorSection.d.ts +6 -0
  10. package/dist/cjs/anyspend/react/components/common/ErrorSection.js +12 -0
  11. package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
  12. package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +2 -2
  13. package/dist/cjs/anyspend/react/components/common/PaySection.d.ts +20 -0
  14. package/dist/cjs/anyspend/react/components/common/PaySection.js +58 -0
  15. package/dist/cjs/anyspend/react/components/common/TabSection.d.ts +10 -0
  16. package/dist/cjs/anyspend/react/components/common/TabSection.js +18 -0
  17. package/dist/cjs/anyspend/react/components/index.d.ts +2 -0
  18. package/dist/cjs/anyspend/react/components/index.js +5 -1
  19. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +165 -0
  20. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +184 -0
  21. package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +2 -2
  22. package/dist/cjs/global-account/react/components/B3DynamicModal.js +3 -0
  23. package/dist/cjs/global-account/react/components/custom/Button.d.ts +1 -1
  24. package/dist/cjs/global-account/react/components/ui/button.d.ts +1 -1
  25. package/dist/cjs/global-account/react/components/ui/command.d.ts +2 -2
  26. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +17 -1
  27. package/dist/cjs/shared/constants/chains/b3Chain.d.ts +1 -1
  28. package/dist/cjs/shared/constants/chains/supported.d.ts +3 -3
  29. package/dist/esm/anyspend/abis/escrow.d.ts +987 -0
  30. package/dist/esm/anyspend/abis/escrow.js +1272 -0
  31. package/dist/esm/anyspend/react/components/AnySpend.js +12 -170
  32. package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -3
  33. package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +10 -0
  34. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +257 -0
  35. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +17 -0
  36. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +50 -0
  37. package/dist/esm/anyspend/react/components/common/ErrorSection.d.ts +6 -0
  38. package/dist/esm/anyspend/react/components/common/ErrorSection.js +9 -0
  39. package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
  40. package/dist/esm/anyspend/react/components/common/PanelOnramp.js +2 -2
  41. package/dist/esm/anyspend/react/components/common/PaySection.d.ts +20 -0
  42. package/dist/esm/anyspend/react/components/common/PaySection.js +55 -0
  43. package/dist/esm/anyspend/react/components/common/TabSection.d.ts +10 -0
  44. package/dist/esm/anyspend/react/components/common/TabSection.js +15 -0
  45. package/dist/esm/anyspend/react/components/index.d.ts +2 -0
  46. package/dist/esm/anyspend/react/components/index.js +2 -0
  47. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +165 -0
  48. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +180 -0
  49. package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +2 -2
  50. package/dist/esm/global-account/react/components/B3DynamicModal.js +3 -0
  51. package/dist/esm/global-account/react/components/custom/Button.d.ts +1 -1
  52. package/dist/esm/global-account/react/components/ui/button.d.ts +1 -1
  53. package/dist/esm/global-account/react/components/ui/command.d.ts +2 -2
  54. package/dist/esm/global-account/react/stores/useModalStore.d.ts +17 -1
  55. package/dist/esm/shared/constants/chains/b3Chain.d.ts +1 -1
  56. package/dist/esm/shared/constants/chains/supported.d.ts +3 -3
  57. package/dist/styles/index.css +1 -1
  58. package/dist/types/anyspend/abis/escrow.d.ts +987 -0
  59. package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +10 -0
  60. package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +17 -0
  61. package/dist/types/anyspend/react/components/common/ErrorSection.d.ts +6 -0
  62. package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
  63. package/dist/types/anyspend/react/components/common/PaySection.d.ts +20 -0
  64. package/dist/types/anyspend/react/components/common/TabSection.d.ts +10 -0
  65. package/dist/types/anyspend/react/components/index.d.ts +2 -0
  66. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +165 -0
  67. package/dist/types/anyspend/react/hooks/useSigMint.d.ts +2 -2
  68. package/dist/types/global-account/react/components/custom/Button.d.ts +1 -1
  69. package/dist/types/global-account/react/components/ui/button.d.ts +1 -1
  70. package/dist/types/global-account/react/components/ui/command.d.ts +2 -2
  71. package/dist/types/global-account/react/stores/useModalStore.d.ts +17 -1
  72. package/dist/types/shared/constants/chains/b3Chain.d.ts +1 -1
  73. package/dist/types/shared/constants/chains/supported.d.ts +3 -3
  74. package/package.json +1 -1
  75. package/src/anyspend/abis/escrow.ts +1272 -0
  76. package/src/anyspend/react/components/AnySpend.tsx +48 -389
  77. package/src/anyspend/react/components/AnySpendCustom.tsx +2 -10
  78. package/src/anyspend/react/components/AnyspendDepositHype.tsx +525 -0
  79. package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +152 -0
  80. package/src/anyspend/react/components/common/ErrorSection.tsx +21 -0
  81. package/src/anyspend/react/components/common/PanelOnramp.tsx +4 -2
  82. package/src/anyspend/react/components/common/PaySection.tsx +222 -0
  83. package/src/anyspend/react/components/common/TabSection.tsx +58 -0
  84. package/src/anyspend/react/components/index.ts +2 -0
  85. package/src/anyspend/react/hooks/useAnyspendFlow.ts +226 -0
  86. package/src/global-account/react/components/B3DynamicModal.tsx +3 -0
  87. package/src/global-account/react/stores/useModalStore.ts +19 -1
@@ -3,12 +3,10 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  import { getDefaultToken, USDC_BASE } from "../../../anyspend/index.js";
4
4
  import { useAnyspendCreateOnrampOrder, useAnyspendCreateOrder, useAnyspendOrderAndTransactions, useAnyspendQuote, useGeoOnrampOptions, } from "../../../anyspend/react/index.js";
5
5
  import { Button, ShinyButton, StyleRoot, TransitionPanel, useAccountWallet, useProfile, useRouter, useSearchParamsSSR, useTokenData, useTokenFromUrl, } from "../../../global-account/react/index.js";
6
- import { formatUsername } from "../../../shared/utils/index.js";
7
6
  import { cn } from "../../../shared/utils/cn.js";
8
- import { shortenAddress } from "../../../shared/utils/formatAddress.js";
9
- import { formatDisplayNumber, formatTokenAmount } from "../../../shared/utils/number.js";
7
+ import { formatTokenAmount } from "../../../shared/utils/number.js";
10
8
  import invariant from "invariant";
11
- import { ArrowDown, ChevronRight, CircleAlert, HistoryIcon } from "lucide-react";
9
+ import { ArrowDown, HistoryIcon } from "lucide-react";
12
10
  import { motion } from "motion/react";
13
11
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
14
12
  import { toast } from "sonner";
@@ -16,15 +14,17 @@ import { parseUnits } from "viem";
16
14
  import { base, mainnet } from "viem/chains";
17
15
  import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
18
16
  import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod.js";
17
+ import { CryptoReceiveSection } from "./common/CryptoReceiveSection.js";
18
+ import { ErrorSection } from "./common/ErrorSection.js";
19
19
  import { FiatPaymentMethod, FiatPaymentMethodComponent } from "./common/FiatPaymentMethod.js";
20
20
  import { OrderDetails, OrderDetailsLoadingView } from "./common/OrderDetails.js";
21
21
  import { OrderHistory } from "./common/OrderHistory.js";
22
22
  import { OrderStatus } from "./common/OrderStatus.js";
23
- import { OrderTokenAmount } from "./common/OrderTokenAmount.js";
24
23
  import { PanelOnramp } from "./common/PanelOnramp.js";
25
24
  import { PanelOnrampPayment } from "./common/PanelOnrampPayment.js";
25
+ import { PaySection } from "./common/PaySection.js";
26
26
  import { RecipientSelection } from "./common/RecipientSelection.js";
27
- import { TokenBalance } from "./common/TokenBalance.js";
27
+ import { TabSection } from "./common/TabSection.js";
28
28
  export var PanelView;
29
29
  (function (PanelView) {
30
30
  PanelView[PanelView["MAIN"] = 0] = "MAIN";
@@ -284,8 +284,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
284
284
  // );
285
285
  // State for recipient selection
286
286
  const [recipientAddress, setRecipientAddress] = useState();
287
- const { address: globalAddress, wallet: globalWallet, ensName: connectedName } = useAccountWallet();
288
- const connectedAddress = globalWallet?.address;
287
+ const { address: globalAddress, wallet: globalWallet } = useAccountWallet();
289
288
  const recipientProfile = useProfile({ address: recipientAddress, fresh: true });
290
289
  const recipientName = recipientProfile.data?.name;
291
290
  // Set default recipient address when wallet changes
@@ -357,113 +356,6 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
357
356
  }
358
357
  // Only run this effect once on mount
359
358
  }, [globalAddress, recipientAddress, customRecipients.length]);
360
- // Available recipient options
361
- // const recipientOptions = useMemo<RecipientOption[]>(() => {
362
- // const options: RecipientOption[] = [];
363
- // // Add current wallet if connected
364
- // if (globalAddress) {
365
- // options.push({
366
- // address: globalAddress,
367
- // icon: "https://gradvatar.com/" + globalAddress,
368
- // label: "Current Wallet",
369
- // ensName: walletName
370
- // });
371
- // }
372
- // // Add custom recipients with their onchain names
373
- // customRecipients.forEach((recipient, index) => {
374
- // options.push({
375
- // ...recipient,
376
- // ensName: customRecipientNames[index] || undefined
377
- // });
378
- // });
379
- // // Add current recipientAddress if it exists and isn't already in options
380
- // if (
381
- // recipientAddress &&
382
- // !options.some(opt => normalizeAddress(opt.address) === normalizeAddress(recipientAddress))
383
- // ) {
384
- // options.push({
385
- // address: recipientAddress,
386
- // label: `Custom (${centerTruncate(recipientAddress, 6)})`,
387
- // ensName: recipientName
388
- // });
389
- // }
390
- // return options;
391
- // }, [globalAddress, customRecipients, recipientAddress, recipientName, walletName, customRecipientNames]);
392
- // const handleCreateOrder = async (recipientAddress: string) => {
393
- // try {
394
- // invariant(anyspendPrice, "Relay price is not found");
395
- // const srcAmountBigInt = parseUnits(srcAmount.replace(/,/g, ""), selectedSrcToken.decimals);
396
- // createOrder({
397
- // recipientAddress,
398
- // orderType: "swap",
399
- // srcChain: selectedSrcChainId,
400
- // dstChain: selectedDstChainId,
401
- // srcToken: selectedSrcToken,
402
- // dstToken: selectedDstToken,
403
- // srcAmount: srcAmountBigInt.toString(),
404
- // expectedDstAmount: anyspendPrice?.data?.currencyOut?.amount || "0"
405
- // });
406
- // } catch (err) {
407
- // console.error(err);
408
- // toast.error((err as Error).message);
409
- // throw err; // Re-throw to handle in the calling function
410
- // }
411
- // };
412
- // const handleSaveRecipient = async () => {
413
- // if (!newRecipientAddress) {
414
- // toast.error("Please enter an address");
415
- // recipientInputRef.current?.focus();
416
- // return;
417
- // }
418
- // let normalizedAddress: string;
419
- // try {
420
- // // Handle ENS name
421
- // if (
422
- // newRecipientAddress.toLowerCase().endsWith(".eth") ||
423
- // newRecipientAddress.startsWith("@") ||
424
- // newRecipientAddress.includes(".b3")
425
- // ) {
426
- // if (!resolvedAddress) {
427
- // toast.error("Could not resolve ENS name");
428
- // return;
429
- // }
430
- // normalizedAddress = getAddress(resolvedAddress);
431
- // }
432
- // // Handle regular address
433
- // else {
434
- // if (!isEvmOrSolanaAddress(newRecipientAddress)) {
435
- // toast.error("Please enter a valid address or ENS name");
436
- // recipientInputRef.current?.focus();
437
- // return;
438
- // }
439
- // normalizedAddress = normalizeAddress(newRecipientAddress);
440
- // }
441
- // // Check for duplicate address
442
- // if (!customRecipients.some(r => normalizeAddress(r.address) === normalizedAddress)) {
443
- // // Add to custom recipients
444
- // const newRecipient = {
445
- // address: normalizedAddress,
446
- // label:
447
- // newRecipientAddress.toLowerCase().endsWith(".eth") ||
448
- // newRecipientAddress.startsWith("@") ||
449
- // newRecipientAddress.includes(".b3")
450
- // ? newRecipientAddress // Keep ENS name as label
451
- // : `Custom (${centerTruncate(normalizedAddress, 6)})`
452
- // };
453
- // setCustomRecipients(prev => [...prev, newRecipient]);
454
- // }
455
- // setRecipientAddress(normalizedAddress);
456
- // // Handle based on login state
457
- // if (!globalAddress) {
458
- // await handleCreateOrder(normalizedAddress);
459
- // } else {
460
- // setActivePanel(PanelView.MAIN);
461
- // }
462
- // } catch (err) {
463
- // // Error handling is done in handleCreateOrder
464
- // console.error("Error in handleSaveRecipient:", err);
465
- // }
466
- // };
467
359
  // Update dependent amount when relay price changes
468
360
  useEffect(() => {
469
361
  if (anyspendQuote?.data &&
@@ -757,49 +649,13 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
757
649
  useEffect(() => {
758
650
  window.scrollTo({ top: 0, behavior: "smooth" });
759
651
  }, [activePanel]);
760
- const calculatePriceImpact = (inputUsd, outputUsd) => {
761
- if (!inputUsd || !outputUsd) {
762
- return { percentage: "0.00", isNegative: false };
763
- }
764
- const input = Number(inputUsd);
765
- const output = Number(outputUsd);
766
- // Handle edge cases
767
- if (input === 0 || isNaN(input) || isNaN(output) || input <= output) {
768
- return { percentage: "0.00", isNegative: false };
769
- }
770
- const percentageValue = ((output - input) / input) * 100;
771
- // Handle the -0.00% case
772
- if (percentageValue > -0.005 && percentageValue < 0) {
773
- return { percentage: "0.00", isNegative: false };
774
- }
775
- return {
776
- percentage: Math.abs(percentageValue).toFixed(2),
777
- isNegative: percentageValue < 0,
778
- };
779
- };
780
- // Add state for rate details toggle
781
- // const [showRateDetails, setShowRateDetails] = useState(false);
782
652
  const historyView = (_jsx("div", { className: "mx-auto flex w-[560px] max-w-full flex-col items-center", children: _jsx(OrderHistory, { mode: mode, onBack: () => setActivePanel(PanelView.MAIN), onSelectOrder: onSelectOrder }) }));
783
653
  const orderDetailsView = (_jsx("div", { className: "mx-auto w-[460px] max-w-full", children: _jsx("div", { className: "relative flex flex-col gap-4", children: oat && (_jsxs(_Fragment, { children: [_jsx(OrderStatus, { order: oat.data.order }), _jsx(OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTx: oat.data.relayTx, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, onBack: () => {
784
654
  setOrderId(undefined);
785
655
  setActivePanel(PanelView.MAIN);
786
656
  setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE); // Reset payment method when going back
787
657
  } })] })) }) }));
788
- const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [isBuyMode && (_jsxs("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: [selectedDstToken.metadata?.logoURI && (_jsx("div", { className: "relative", children: _jsx("img", { src: selectedDstToken.metadata.logoURI, alt: selectedDstToken.symbol, className: "border-as-stroke h-12 w-12 rounded-full border-2 shadow-md" }) })), _jsx("div", { children: _jsxs("h1", { className: "text-as-primary text-xl font-bold", children: ["Buy ", selectedDstToken.symbol] }) })] })), _jsx("div", { className: "w-full", children: _jsxs("div", { className: "bg-as-surface-secondary relative mb-4 grid h-10 grid-cols-2 rounded-xl", children: [_jsx("div", { className: cn("bg-as-brand absolute bottom-0 left-0 top-0 z-0 rounded-xl transition-transform duration-100", "h-full w-1/2", activeTab === "fiat" ? "translate-x-full" : "translate-x-0"), style: { willChange: "transform" } }), _jsx("button", { className: cn("relative z-10 h-full w-full rounded-xl px-3 text-sm font-medium transition-colors duration-100", activeTab === "crypto" ? "text-white" : "text-as-primary/70 hover:bg-as-on-surface-2 bg-transparent"), onClick: () => {
789
- setActiveTab("crypto");
790
- setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE); // Reset payment method when switching to crypto
791
- setSelectedFiatPaymentMethod(FiatPaymentMethod.NONE); // Reset fiat payment method when switching to crypto
792
- }, children: "Pay with crypto" }), _jsx("button", { className: cn("relative z-10 h-full w-full rounded-xl px-3 text-sm font-medium transition-colors duration-100", activeTab === "fiat" ? "text-white" : "text-as-primary/70 hover:bg-as-on-surface-2 bg-transparent"), onClick: () => {
793
- setActiveTab("fiat");
794
- setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE); // Reset crypto payment method when switching to fiat
795
- setSelectedFiatPaymentMethod(FiatPaymentMethod.NONE); // Reset fiat payment method when switching to fiat
796
- }, children: "Pay with Fiat" })] }) }), _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [activeTab === "crypto" ? (_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: "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", onClick: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), children: selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (_jsxs(_Fragment, { children: [connectedAddress ? (_jsx(_Fragment, { children: _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.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: globalAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
797
- setIsSrcInputDirty(true);
798
- setSrcAmount(value);
799
- }, 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, { style: "currency", fallback: "" }) }), _jsx(TokenBalance, { token: selectedSrcToken, walletAddress: globalAddress, onChangeInput: value => {
800
- setIsSrcInputDirty(true);
801
- setSrcAmount(value);
802
- } })] })] })) : (_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: srcAmountOnRamp, setSrcAmountOnRamp: setSrcAmountOnRamp, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: recipientAddress, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, destinationAmount: dstAmount, onDestinationTokenChange: setSelectedDstToken, onDestinationChainChange: setSelectedDstChainId }) })), _jsx(Button, { variant: "ghost", className: cn("border-as-stroke bg-as-surface-primary absolute left-1/2 top-1/2 z-10 h-10 w-10 -translate-x-1/2 -translate-y-1/2 rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl", isBuyMode && "top-[calc(50%+56px)] cursor-default", activeTab === "fiat" && "hidden"), onClick: () => {
658
+ const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [isBuyMode && (_jsxs("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: [selectedDstToken.metadata?.logoURI && (_jsx("div", { className: "relative", children: _jsx("img", { src: selectedDstToken.metadata.logoURI, alt: selectedDstToken.symbol, className: "border-as-stroke h-12 w-12 rounded-full border-2 shadow-md" }) })), _jsx("div", { children: _jsxs("h1", { className: "text-as-primary text-xl font-bold", children: ["Buy ", selectedDstToken.symbol] }) })] })), _jsx(TabSection, { activeTab: activeTab, setActiveTab: setActiveTab, setSelectedCryptoPaymentMethod: setSelectedCryptoPaymentMethod, setSelectedFiatPaymentMethod: setSelectedFiatPaymentMethod }), _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [activeTab === "crypto" ? (_jsx(PaySection, { paymentType: "crypto", selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, selectedFiatPaymentMethod: selectedFiatPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), onSelectFiatPaymentMethod: () => setActivePanel(PanelView.FIAT_PAYMENT_METHOD), anyspendQuote: anyspendQuote })) : (_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: srcAmountOnRamp, setSrcAmountOnRamp: setSrcAmountOnRamp, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: recipientAddress, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, destinationAmount: dstAmount, onDestinationTokenChange: setSelectedDstToken, onDestinationChainChange: setSelectedDstChainId, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD }) })), _jsx(Button, { variant: "ghost", className: cn("border-as-stroke bg-as-surface-primary absolute left-1/2 top-1/2 z-10 h-10 w-10 -translate-x-1/2 -translate-y-1/2 rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl", isBuyMode && "top-[calc(50%+56px)] cursor-default", activeTab === "fiat" && "hidden"), onClick: () => {
803
659
  if (activeTab === "fiat" || isBuyMode) {
804
660
  return;
805
661
  }
@@ -818,24 +674,10 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
818
674
  const tempDstAmount = dstAmount;
819
675
  setSrcAmount(tempDstAmount);
820
676
  setDstAmount(tempSrcAmount);
821
- }, 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 !== "fiat" && (_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: "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: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Receive" }), recipientAddress ? (_jsx("button", { className: cn("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: _jsxs(_Fragment, { children: [recipientAddress ? (_jsx(_Fragment, { children: _jsx("span", { className: "text-as-tertiarry flex items-center gap-1 text-sm", children: recipientName ? formatUsername(recipientName) : shortenAddress(recipientAddress || "") }) })) : ("Connect wallet"), _jsx(ChevronRight, { className: "h-4 w-4" })] }) })) : (_jsx("button", { className: "text-as-primary/70 flex items-center gap-1 rounded-lg", onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: _jsx("div", { className: "text-sm font-medium", children: "Select recipient" }) }))] }), isBuyMode ? (
822
- // Fixed destination token display in buy mode
823
- _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: [selectedDstToken.metadata?.logoURI && (_jsx("img", { src: selectedDstToken.metadata.logoURI, alt: selectedDstToken.symbol, className: "h-8 w-8 rounded-full" })), _jsx("span", { className: "text-as-brand text-lg font-bold", children: selectedDstToken.symbol })] })] })) : (_jsx(OrderTokenAmount, { address: recipientAddress, context: "to", inputValue: dstAmount, onChangeInput: value => {
824
- setIsSrcInputDirty(false);
825
- setDstAmount(value);
826
- }, chainId: selectedDstChainId, setChainId: setSelectedDstChainId, token: selectedDstToken, setToken: setSelectedDstToken })), _jsxs("div", { className: "text-as-primary/50 flex h-5 items-center text-sm", children: [formatDisplayNumber(anyspendQuote?.data?.currencyOut?.amountUsd, { style: "currency", fallback: "" }), anyspendQuote?.data?.currencyIn?.amountUsd &&
827
- anyspendQuote?.data?.currencyOut?.amountUsd &&
828
- (() => {
829
- const { percentage, isNegative } = calculatePriceImpact(anyspendQuote.data.currencyIn.amountUsd, anyspendQuote.data.currencyOut.amountUsd);
830
- // Parse the percentage as a number for comparison
831
- const percentageNum = parseFloat(percentage);
832
- // Don't show if less than 1%
833
- if (percentageNum < 1) {
834
- return null;
835
- }
836
- // Using inline style to ensure color displays
837
- return (_jsxs("span", { className: "ml-2", style: { color: percentageNum >= 10 ? "red" : "#FFD700" }, children: ["(", isNegative ? "-" : "", percentage, "%)"] }));
838
- })()] })] }))] }), getAnyspendQuoteError && (_jsxs("div", { className: "bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl px-4 py-2", children: [_jsx(CircleAlert, { className: "bg-as-red h-4 min-h-4 w-4 min-w-4 rounded-full p-0 text-sm font-medium text-white" }), _jsx("div", { className: "text-as-red text-sm", children: getAnyspendQuoteError.message })] })), _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", getAnyspendQuoteError && "mt-0"), 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: 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] })] }));
677
+ }, 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: () => setActivePanel(PanelView.RECIPIENT_SELECTION), dstAmount: dstAmount, dstToken: selectedDstToken, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: setSelectedDstChainId, setSelectedDstToken: setSelectedDstToken, onChangeDstAmount: value => {
678
+ setIsSrcInputDirty(false);
679
+ setDstAmount(value);
680
+ }, anyspendQuote: anyspendQuote }))] }), _jsx(ErrorSection, { error: getAnyspendQuoteError }), _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", getAnyspendQuoteError && "mt-0"), 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: 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] })] }));
839
681
  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 => {
840
682
  setOrderId(orderId);
841
683
  setActivePanel(PanelView.ORDER_DETAILS);
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { eqci, getDefaultToken, roundUpUSDCBaseAmountToNearest } from "../../../anyspend/index.js";
3
3
  import { RELAY_ETH_ADDRESS, USDC_BASE } from "../../../anyspend/constants/index.js";
4
4
  import { useAnyspendCreateOnrampOrder, useAnyspendCreateOrder, useAnyspendOrderAndTransactions, useAnyspendQuote, useAnyspendTokenList, useConnectedUserProfile, useGeoOnrampOptions, } from "../../../anyspend/react/index.js";
@@ -409,11 +409,11 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
409
409
  ? "Receive NFT at"
410
410
  : orderType === "join_tournament"
411
411
  ? "Join for"
412
- : "Recipient" }), _jsxs("div", { className: "flex items-center gap-2", children: [recipientAddress ? (_jsx("button", { className: cn("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: _jsxs(_Fragment, { children: [recipientProfile && (_jsx("img", { src: recipientProfile.data?.avatar || "", alt: recipientProfile.data?.name || "", className: "bg-b3-react-foreground size-6 rounded-full object-cover opacity-100" })), _jsxs("div", { className: "text-as-tertiarry flex items-center gap-1 text-sm", children: [recipientName && _jsx("span", { children: formatUsername(recipientName) }), _jsx("span", { children: shortenAddress(recipientAddress) })] })] }) })) : (_jsx("button", { className: "text-as-primary/70 flex items-center gap-1 rounded-lg", onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: _jsx("div", { className: "text-sm font-medium", children: "Select recipient" }) })), _jsx(ChevronRight, { className: "h-4 w-4" })] })] }, recipientAddress)) : null;
412
+ : "Recipient" }), _jsxs("div", { className: "flex items-center gap-2", children: [recipientAddress ? (_jsx("button", { className: cn("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: _jsx(_Fragment, { children: _jsx("div", { className: "text-as-tertiarry flex items-center gap-1 text-sm", children: _jsx("span", { children: recipientName ? formatUsername(recipientName) : shortenAddress(recipientAddress) }) }) }) })) : (_jsx("button", { className: "text-as-primary/70 flex items-center gap-1 rounded-lg", onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: _jsx("div", { className: "text-sm font-medium", children: "Select recipient" }) })), _jsx(ChevronRight, { className: "h-4 w-4" })] })] }, recipientAddress)) : null;
413
413
  const historyView = (_jsx("div", { className: cn("mx-auto flex w-full max-w-2xl flex-col items-center p-5", mode === "modal" && "bg-b3-react-background"), children: _jsx(OrderHistory, { mode: mode, onBack: () => {
414
414
  setActivePanel(PanelView.HISTORY);
415
415
  }, onSelectOrder: onSelectOrder }) }));
416
- const orderDetailsView = (_jsxs("div", { className: cn("mx-auto flex w-full flex-col items-center gap-4 p-5", mode === "modal" && "bg-b3-react-background rounded-xl"), children: [oat && (_jsxs(_Fragment, { children: [_jsx(OrderStatusDisplay, { order: oat.data.order }), _jsx(OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTx: oat.data.relayTx, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, cryptoPaymentMethod: activeTab === "fiat" ? CryptoPaymentMethodType.NONE : selectedCryptoPaymentMethod, onBack: () => {
416
+ const orderDetailsView = (_jsxs("div", { className: cn("mx-auto flex w-full flex-col items-center gap-4", mode === "modal" && "bg-b3-react-background rounded-xl"), children: [oat && (_jsxs(_Fragment, { children: [_jsx(OrderStatusDisplay, { order: oat.data.order }), _jsx(OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTx: oat.data.relayTx, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, cryptoPaymentMethod: activeTab === "fiat" ? CryptoPaymentMethodType.NONE : selectedCryptoPaymentMethod, onBack: () => {
417
417
  setOrderId(undefined);
418
418
  setActivePanel(PanelView.CONFIRM_ORDER);
419
419
  // Remove orderId from URL when canceling
@@ -0,0 +1,10 @@
1
+ export declare function AnySpendDepositHype(props: {
2
+ loadOrder?: string;
3
+ mode?: "modal" | "page";
4
+ recipientAddress: string;
5
+ paymentType?: "crypto" | "fiat";
6
+ sourceTokenAddress?: string;
7
+ sourceTokenChainId?: number;
8
+ onSuccess?: () => void;
9
+ depositContractAddress?: string;
10
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,257 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { B3_TOKEN } from "../../../anyspend/index.js";
3
+ import { Button, ShinyButton, StyleRoot, TransitionPanel } from "../../../global-account/react/index.js";
4
+ import { cn } from "../../../shared/utils/cn.js";
5
+ import invariant from "invariant";
6
+ import { motion } from "motion/react";
7
+ import { useMemo } from "react";
8
+ import { toast } from "sonner";
9
+ import { encodeFunctionData } from "viem";
10
+ import { base } from "viem/chains";
11
+ import { PanelView, useAnyspendFlow } from "../hooks/useAnyspendFlow.js";
12
+ import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
13
+ import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod.js";
14
+ import { CryptoReceiveSection } from "./common/CryptoReceiveSection.js";
15
+ import { ErrorSection } from "./common/ErrorSection.js";
16
+ import { FiatPaymentMethod, FiatPaymentMethodComponent } from "./common/FiatPaymentMethod.js";
17
+ import { OrderDetails } from "./common/OrderDetails.js";
18
+ import { OrderStatus } from "./common/OrderStatus.js";
19
+ import { PaySection } from "./common/PaySection.js";
20
+ import { RecipientSelection } from "./common/RecipientSelection.js";
21
+ import { ESCROW_ABI } from "../../../anyspend/abis/escrow.js";
22
+ import { ArrowDown } from "lucide-react";
23
+ import { PanelOnramp } from "./common/PanelOnramp.js";
24
+ function generateEncodedDataForDepositHype(amount, beneficiary) {
25
+ invariant(BigInt(amount) > 0, "Amount must be greater than zero");
26
+ const encodedData = encodeFunctionData({
27
+ abi: ESCROW_ABI,
28
+ functionName: "depositFor",
29
+ args: [beneficiary, B3_TOKEN.address, BigInt(amount)],
30
+ });
31
+ return encodedData;
32
+ }
33
+ export function AnySpendDepositHype(props) {
34
+ const fingerprintConfig = getFingerprintConfig();
35
+ return (_jsx(AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: _jsx(AnySpendDepositHypeInner, { ...props }) }));
36
+ }
37
+ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, onSuccess, depositContractAddress, }) {
38
+ // Use shared flow hook
39
+ const { activePanel, setActivePanel, orderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, dstAmount, setIsSrcInputDirty, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, anyspendQuote, isLoadingAnyspendQuote, getAnyspendQuoteError, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = useAnyspendFlow({
40
+ paymentType,
41
+ recipientAddress,
42
+ loadOrder,
43
+ isDepositMode: true,
44
+ onTransactionSuccess: onSuccess,
45
+ sourceTokenAddress,
46
+ sourceTokenChainId,
47
+ });
48
+ // Button state logic
49
+ const btnInfo = useMemo(() => {
50
+ if (activeInputAmountInWei === "0")
51
+ return { text: "Enter an amount", disable: true, error: false };
52
+ if (isLoadingAnyspendQuote)
53
+ return { text: "Loading quote...", disable: true, error: false };
54
+ if (isCreatingOrder || isCreatingOnrampOrder)
55
+ return { text: "Creating order...", disable: true, error: false };
56
+ if (!selectedRecipientAddress)
57
+ return { text: "Select recipient", disable: false, error: false };
58
+ if (!anyspendQuote || !anyspendQuote.success)
59
+ return { text: "Get quote error", disable: true, error: true };
60
+ if (!dstAmount)
61
+ return { text: "No quote available", disable: true, error: true };
62
+ // Check minimum deposit amount (10 HYPE)
63
+ // Use the raw amount from the quote instead of the formatted display string
64
+ if (anyspendQuote.data?.currencyOut?.amount && anyspendQuote.data.currencyOut.currency?.decimals) {
65
+ const rawAmountInWei = anyspendQuote.data.currencyOut.amount;
66
+ const decimals = anyspendQuote.data.currencyOut.currency.decimals;
67
+ const actualAmount = parseFloat(rawAmountInWei) / Math.pow(10, decimals);
68
+ if (actualAmount < 10) {
69
+ return { text: "Minimum 10 HYPE deposit", disable: true, error: true };
70
+ }
71
+ }
72
+ if (paymentType === "crypto") {
73
+ if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
74
+ return { text: "Choose payment method", disable: false, error: false };
75
+ }
76
+ return { text: "Continue to deposit", disable: false, error: false };
77
+ }
78
+ if (paymentType === "fiat") {
79
+ if (selectedFiatPaymentMethod === FiatPaymentMethod.NONE) {
80
+ return { text: "Select payment method", disable: false, error: false };
81
+ }
82
+ return { text: "Buy", disable: false, error: false };
83
+ }
84
+ return { text: "Continue to deposit", disable: false, error: false };
85
+ }, [
86
+ activeInputAmountInWei,
87
+ isLoadingAnyspendQuote,
88
+ isCreatingOrder,
89
+ isCreatingOnrampOrder,
90
+ selectedRecipientAddress,
91
+ anyspendQuote,
92
+ dstAmount,
93
+ paymentType,
94
+ selectedCryptoPaymentMethod,
95
+ selectedFiatPaymentMethod,
96
+ ]);
97
+ const onMainButtonClick = async () => {
98
+ if (btnInfo.disable)
99
+ return;
100
+ if (!selectedRecipientAddress) {
101
+ setActivePanel(PanelView.RECIPIENT_SELECTION);
102
+ return;
103
+ }
104
+ if (paymentType === "crypto") {
105
+ if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
106
+ setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD);
107
+ return;
108
+ }
109
+ await handleCryptoOrder();
110
+ }
111
+ else if (paymentType === "fiat") {
112
+ if (selectedFiatPaymentMethod === FiatPaymentMethod.NONE) {
113
+ setActivePanel(PanelView.FIAT_PAYMENT_METHOD);
114
+ return;
115
+ }
116
+ await handleFiatOrder();
117
+ }
118
+ };
119
+ // Handle crypto order creation
120
+ const handleCryptoOrder = async () => {
121
+ try {
122
+ invariant(anyspendQuote, "Relay price is not found");
123
+ invariant(selectedRecipientAddress, "Recipient address is not found");
124
+ invariant(depositContractAddress, "Deposit contract address is not found");
125
+ const srcAmountBigInt = BigInt(activeInputAmountInWei);
126
+ const depositAmountWei = anyspendQuote.data?.currencyOut?.amount || "0";
127
+ const encodedData = generateEncodedDataForDepositHype(depositAmountWei, selectedRecipientAddress);
128
+ createOrder({
129
+ recipientAddress: selectedRecipientAddress,
130
+ orderType: "custom",
131
+ srcChain: selectedSrcChainId,
132
+ dstChain: base.id,
133
+ srcToken: selectedSrcToken,
134
+ dstToken: B3_TOKEN,
135
+ srcAmount: srcAmountBigInt.toString(),
136
+ creatorAddress: globalAddress,
137
+ payload: {
138
+ amount: depositAmountWei,
139
+ data: encodedData,
140
+ to: depositContractAddress,
141
+ action: "deposit HYPE",
142
+ },
143
+ });
144
+ }
145
+ catch (err) {
146
+ console.error(err);
147
+ toast.error("Failed to create order: " + err.message);
148
+ }
149
+ };
150
+ // Handle fiat order creation
151
+ const handleFiatOrder = async () => {
152
+ try {
153
+ invariant(anyspendQuote, "Relay price is not found");
154
+ invariant(selectedRecipientAddress, "Recipient address is not found");
155
+ invariant(depositContractAddress, "Deposit contract address is not found");
156
+ if (!srcAmount || parseFloat(srcAmount) <= 0) {
157
+ toast.error("Please enter a valid amount");
158
+ return;
159
+ }
160
+ // Determine vendor and payment method string
161
+ let vendor;
162
+ let paymentMethodString = "";
163
+ if (selectedFiatPaymentMethod === FiatPaymentMethod.COINBASE_PAY) {
164
+ if (coinbaseAvailablePaymentMethods.length === 0) {
165
+ toast.error("Coinbase Pay not available");
166
+ return;
167
+ }
168
+ vendor = "coinbase";
169
+ paymentMethodString = coinbaseAvailablePaymentMethods[0]?.id || "";
170
+ }
171
+ else if (selectedFiatPaymentMethod === FiatPaymentMethod.STRIPE) {
172
+ if (!stripeWeb2Support || !stripeWeb2Support.isSupport) {
173
+ toast.error("Stripe not available");
174
+ return;
175
+ }
176
+ vendor = "stripe-web2";
177
+ paymentMethodString = "";
178
+ }
179
+ else {
180
+ toast.error("Please select a payment method");
181
+ return;
182
+ }
183
+ const depositAmountWei = anyspendQuote.data?.currencyOut?.amount || "0";
184
+ const encodedData = generateEncodedDataForDepositHype(depositAmountWei, selectedRecipientAddress);
185
+ createOnrampOrder({
186
+ recipientAddress: selectedRecipientAddress,
187
+ orderType: "custom",
188
+ dstChain: base.id,
189
+ dstToken: B3_TOKEN,
190
+ srcFiatAmount: srcAmount,
191
+ onramp: {
192
+ vendor: vendor,
193
+ paymentMethod: paymentMethodString,
194
+ country: geoData?.country || "US",
195
+ redirectUrl: window.location.origin,
196
+ },
197
+ expectedDstAmount: anyspendQuote?.data?.currencyOut?.amount?.toString() || "0",
198
+ creatorAddress: globalAddress,
199
+ payload: {
200
+ amount: depositAmountWei,
201
+ data: encodedData,
202
+ to: depositContractAddress,
203
+ action: "deposit HYPE",
204
+ },
205
+ });
206
+ }
207
+ catch (err) {
208
+ console.error(err);
209
+ toast.error("Failed to create order: " + err.message);
210
+ }
211
+ };
212
+ // Order details view
213
+ const orderDetailsView = (_jsx("div", { className: "mx-auto w-[460px] max-w-full", children: _jsx("div", { className: "relative flex flex-col gap-4", children: oat && (_jsxs(_Fragment, { children: [_jsx(OrderStatus, { order: oat.data.order }), _jsx(OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTx: oat.data.relayTx, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, cryptoPaymentMethod: paymentType === "fiat" ? CryptoPaymentMethodType.NONE : selectedCryptoPaymentMethod, onBack: () => {
214
+ setActivePanel(PanelView.MAIN);
215
+ onSuccess?.();
216
+ } })] })) }) }));
217
+ // Loading view
218
+ const loadingView = (_jsx("div", { className: "mx-auto flex w-full flex-col items-center gap-4 p-5", children: _jsx("div", { className: "text-as-primary", children: "Loading order details..." }) }));
219
+ // Panel views
220
+ const recipientSelectionView = (_jsx(RecipientSelection, { initialValue: selectedRecipientAddress || "", onBack: () => setActivePanel(PanelView.MAIN), onConfirm: address => {
221
+ setSelectedRecipientAddress(address);
222
+ setActivePanel(PanelView.MAIN);
223
+ } }));
224
+ const cryptoPaymentMethodView = (_jsx(CryptoPaymentMethod, { globalAddress: globalAddress, globalWallet: undefined, selectedPaymentMethod: selectedCryptoPaymentMethod, setSelectedPaymentMethod: setSelectedCryptoPaymentMethod, isCreatingOrder: isCreatingOrder, onBack: () => setActivePanel(PanelView.MAIN), onSelectPaymentMethod: (method) => {
225
+ setSelectedCryptoPaymentMethod(method);
226
+ setActivePanel(PanelView.MAIN);
227
+ } }));
228
+ const fiatPaymentMethodView = (_jsx(FiatPaymentMethodComponent, { selectedPaymentMethod: selectedFiatPaymentMethod, setSelectedPaymentMethod: setSelectedFiatPaymentMethod, onBack: () => setActivePanel(PanelView.MAIN), onSelectPaymentMethod: (method) => {
229
+ setSelectedFiatPaymentMethod(method);
230
+ setActivePanel(PanelView.MAIN);
231
+ }, srcAmountOnRamp: srcAmount }));
232
+ // If showing token selection, render with panel transitions
233
+ return (_jsx(StyleRoot, { children: _jsx("div", { className: cn("anyspend-container font-inter mx-auto w-full max-w-[460px]", mode === "page" &&
234
+ "bg-as-surface-primary border-as-border-secondary overflow-hidden rounded-2xl border shadow-xl"), children: _jsx(TransitionPanel, { activeIndex: orderId
235
+ ? oat
236
+ ? PanelView.ORDER_DETAILS
237
+ : PanelView.LOADING
238
+ : activePanel === PanelView.ORDER_DETAILS
239
+ ? PanelView.MAIN
240
+ : activePanel, className: cn("rounded-2xl", {
241
+ "mt-0": mode === "modal",
242
+ }), variants: {
243
+ enter: { x: 300, opacity: 0 },
244
+ center: { x: 0, opacity: 1 },
245
+ exit: { x: -300, opacity: 0 },
246
+ }, transition: { type: "spring", stiffness: 300, damping: 30 }, children: [
247
+ _jsx("div", { className: cn(mode === "page" && "p-6"), children: _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(PaySection, { paymentType: "crypto", selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, selectedFiatPaymentMethod: selectedFiatPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), onSelectFiatPaymentMethod: () => setActivePanel(PanelView.FIAT_PAYMENT_METHOD), anyspendQuote: anyspendQuote })) : (_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, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD }) })), _jsx(Button, { variant: "ghost", className: cn("swap-direction-button border-as-stroke bg-as-surface-primary absolute left-1/2 top-[calc(50%+56px)] z-10 h-10 w-10 -translate-x-1/2 -translate-y-1/2 cursor-default rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl", paymentType === "fiat" && "hidden"), 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, selectedDstChainId: base.id, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, onChangeDstAmount: value => {
248
+ setIsSrcInputDirty(false);
249
+ setSrcAmount(value);
250
+ }, anyspendQuote: anyspendQuote }))] }) }), _jsx(ErrorSection, { error: getAnyspendQuoteError }), _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", getAnyspendQuoteError && "mt-0"), 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: btnInfo.text }) })] }) }, "main-view"),
251
+ _jsx("div", { className: cn(mode === "page" && "p-6"), children: cryptoPaymentMethodView }, "crypto-payment-method-view"),
252
+ _jsx("div", { className: cn(mode === "page" && "p-6"), children: fiatPaymentMethodView }, "fiat-payment-method-view"),
253
+ _jsx("div", { className: cn(mode === "page" && "p-6"), children: recipientSelectionView }, "recipient-selection-view"),
254
+ _jsx("div", { className: cn(mode === "page" && "p-6"), children: orderDetailsView }, "order-details-view"),
255
+ _jsx("div", { className: cn(mode === "page" && "p-6"), children: loadingView }, "loading-view"),
256
+ ] }) }) }));
257
+ }
@@ -0,0 +1,17 @@
1
+ import { components } from "../../../types/api";
2
+ interface CryptoReceiveSectionProps {
3
+ isDepositMode?: boolean;
4
+ isBuyMode?: boolean;
5
+ selectedRecipientAddress?: string;
6
+ recipientName?: string;
7
+ onSelectRecipient: () => void;
8
+ dstAmount: string;
9
+ dstToken: components["schemas"]["Token"];
10
+ selectedDstChainId?: number;
11
+ setSelectedDstChainId?: (chainId: number) => void;
12
+ setSelectedDstToken?: (token: components["schemas"]["Token"]) => void;
13
+ onChangeDstAmount?: (value: string) => void;
14
+ anyspendQuote?: any;
15
+ }
16
+ export declare function CryptoReceiveSection({ isDepositMode, isBuyMode, selectedRecipientAddress, recipientName, onSelectRecipient, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, onChangeDstAmount, anyspendQuote, }: CryptoReceiveSectionProps): import("react/jsx-runtime").JSX.Element;
17
+ export {};