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