@b3dotfun/sdk 0.0.87-alpha.0 → 0.0.87-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.
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +5 -0
- package/dist/cjs/anyspend/react/components/AnySpend.js +59 -49
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +1 -2
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.d.ts +122 -0
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.js +190 -0
- package/dist/cjs/anyspend/react/components/QRDeposit.d.ts +43 -0
- package/dist/cjs/anyspend/react/components/QRDeposit.js +146 -0
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +17 -12
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +12 -5
- package/dist/cjs/anyspend/react/components/common/OrderStatus.js +2 -2
- package/dist/cjs/anyspend/react/components/common/WarningText.d.ts +32 -0
- package/dist/cjs/anyspend/react/components/common/WarningText.js +36 -0
- package/dist/cjs/anyspend/react/components/icons/CreditCardIcon.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/icons/CreditCardIcon.js +6 -0
- package/dist/cjs/anyspend/react/components/icons/QrCodeIcon.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/icons/QrCodeIcon.js +6 -0
- package/dist/cjs/anyspend/react/components/index.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/index.js +3 -1
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -2
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +35 -11
- package/dist/cjs/anyspend/react/hooks/useCreateDepositFirstOrder.d.ts +24 -0
- package/dist/cjs/anyspend/react/hooks/useCreateDepositFirstOrder.js +86 -0
- package/dist/cjs/anyspend/utils/format.js +28 -5
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +5 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +59 -49
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +1 -2
- package/dist/esm/anyspend/react/components/AnySpendDeposit.d.ts +122 -0
- package/dist/esm/anyspend/react/components/AnySpendDeposit.js +187 -0
- package/dist/esm/anyspend/react/components/QRDeposit.d.ts +43 -0
- package/dist/esm/anyspend/react/components/QRDeposit.js +143 -0
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +17 -12
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +12 -5
- package/dist/esm/anyspend/react/components/common/OrderStatus.js +2 -2
- package/dist/esm/anyspend/react/components/common/WarningText.d.ts +32 -0
- package/dist/esm/anyspend/react/components/common/WarningText.js +32 -0
- package/dist/esm/anyspend/react/components/icons/CreditCardIcon.d.ts +6 -0
- package/dist/esm/anyspend/react/components/icons/CreditCardIcon.js +2 -0
- package/dist/esm/anyspend/react/components/icons/QrCodeIcon.d.ts +6 -0
- package/dist/esm/anyspend/react/components/icons/QrCodeIcon.js +2 -0
- package/dist/esm/anyspend/react/components/index.d.ts +2 -0
- package/dist/esm/anyspend/react/components/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +35 -11
- package/dist/esm/anyspend/react/hooks/useCreateDepositFirstOrder.d.ts +24 -0
- package/dist/esm/anyspend/react/hooks/useCreateDepositFirstOrder.js +83 -0
- package/dist/esm/anyspend/utils/format.js +28 -5
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpend.d.ts +5 -0
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -1
- package/dist/types/anyspend/react/components/AnySpendDeposit.d.ts +122 -0
- package/dist/types/anyspend/react/components/QRDeposit.d.ts +43 -0
- package/dist/types/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
- package/dist/types/anyspend/react/components/common/WarningText.d.ts +32 -0
- package/dist/types/anyspend/react/components/icons/CreditCardIcon.d.ts +6 -0
- package/dist/types/anyspend/react/components/icons/QrCodeIcon.d.ts +6 -0
- package/dist/types/anyspend/react/components/index.d.ts +2 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -2
- package/dist/types/anyspend/react/hooks/useCreateDepositFirstOrder.d.ts +24 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +4 -0
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +68 -45
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +2 -3
- package/src/anyspend/react/components/AnySpendDeposit.tsx +578 -0
- package/src/anyspend/react/components/QRDeposit.tsx +348 -0
- package/src/anyspend/react/components/common/OrderDetails.tsx +26 -8
- package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +20 -8
- package/src/anyspend/react/components/common/OrderStatus.tsx +2 -2
- package/src/anyspend/react/components/common/WarningText.tsx +52 -0
- package/src/anyspend/react/components/icons/CreditCardIcon.tsx +25 -0
- package/src/anyspend/react/components/icons/QrCodeIcon.tsx +25 -0
- package/src/anyspend/react/components/icons/credit-card.svg +5 -0
- package/src/anyspend/react/components/icons/qr-code.svg +5 -0
- package/src/anyspend/react/components/index.ts +2 -0
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +37 -12
- package/src/anyspend/react/hooks/useCreateDepositFirstOrder.ts +110 -0
- package/src/anyspend/utils/format.ts +33 -5
- package/src/global-account/react/stores/useModalStore.ts +4 -0
- package/src/styles/index.css +2 -0
|
@@ -20,6 +20,7 @@ export declare enum PanelView {
|
|
|
20
20
|
export declare function AnySpend(props: {
|
|
21
21
|
mode?: "page" | "modal";
|
|
22
22
|
defaultActiveTab?: "crypto" | "fiat";
|
|
23
|
+
sourceChainId?: number;
|
|
23
24
|
destinationTokenAddress?: string;
|
|
24
25
|
destinationTokenChainId?: number;
|
|
25
26
|
recipientAddress?: string;
|
|
@@ -34,4 +35,8 @@ export declare function AnySpend(props: {
|
|
|
34
35
|
}) => void;
|
|
35
36
|
onSuccess?: (txHash?: string) => void;
|
|
36
37
|
customUsdInputValues?: string[];
|
|
38
|
+
hideHeader?: boolean;
|
|
39
|
+
hideBottomNavigation?: boolean;
|
|
40
|
+
/** When true, disables URL parameter management for swap configuration */
|
|
41
|
+
disableUrlParamManagement?: boolean;
|
|
37
42
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -57,7 +57,7 @@ function AnySpend(props) {
|
|
|
57
57
|
const fingerprintConfig = (0, AnySpendFingerprintWrapper_1.getFingerprintConfig)();
|
|
58
58
|
return ((0, jsx_runtime_1.jsx)(AnySpendFingerprintWrapper_1.AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: (0, jsx_runtime_1.jsx)(AnySpendInner, { ...props }) }));
|
|
59
59
|
}
|
|
60
|
-
function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode = "modal", defaultActiveTab = "crypto", loadOrder, hideTransactionHistoryButton, recipientAddress: recipientAddressFromProps, onTokenSelect, onSuccess, customUsdInputValues, }) {
|
|
60
|
+
function AnySpendInner({ sourceChainId, destinationTokenAddress, destinationTokenChainId, mode = "modal", defaultActiveTab = "crypto", loadOrder, hideTransactionHistoryButton, recipientAddress: recipientAddressFromProps, onTokenSelect, onSuccess, customUsdInputValues, hideHeader, hideBottomNavigation = false, disableUrlParamManagement = false, }) {
|
|
61
61
|
const searchParams = (0, react_2.useSearchParamsSSR)();
|
|
62
62
|
const router = (0, react_2.useRouter)();
|
|
63
63
|
const { partnerId } = (0, react_2.useB3)();
|
|
@@ -97,7 +97,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
97
97
|
// const [newRecipientAddress, setNewRecipientAddress] = useState("");
|
|
98
98
|
// const recipientInputRef = useRef<HTMLInputElement>(null);
|
|
99
99
|
// Get initial chain IDs from URL or defaults
|
|
100
|
-
const initialSrcChainId = parseInt(searchParams.get("fromChainId") || "0") || chains_1.mainnet.id;
|
|
100
|
+
const initialSrcChainId = sourceChainId || parseInt(searchParams.get("fromChainId") || "0") || chains_1.mainnet.id;
|
|
101
101
|
const initialDstChainId = parseInt(searchParams.get("toChainId") || "0") || (isBuyMode ? destinationTokenChainId : chains_1.base.id);
|
|
102
102
|
// State for source chain/token selection
|
|
103
103
|
const [selectedSrcChainId, setSelectedSrcChainId] = (0, react_4.useState)(initialSrcChainId);
|
|
@@ -190,8 +190,8 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
190
190
|
}, [selectedDstToken.address, selectedDstToken.chainId]);
|
|
191
191
|
// Load swap configuration from URL on initial render
|
|
192
192
|
(0, react_4.useEffect)(() => {
|
|
193
|
-
// Skip if we've already processed the URL
|
|
194
|
-
if (initialUrlProcessed.current || loadOrder)
|
|
193
|
+
// Skip if we've already processed the URL, if we have an order to load, or if URL param management is disabled
|
|
194
|
+
if (initialUrlProcessed.current || loadOrder || disableUrlParamManagement)
|
|
195
195
|
return;
|
|
196
196
|
try {
|
|
197
197
|
const tabParam = searchParams.get("tab");
|
|
@@ -224,7 +224,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
224
224
|
}
|
|
225
225
|
// Mark that we've processed the initial URL
|
|
226
226
|
initialUrlProcessed.current = true;
|
|
227
|
-
}, [searchParams, loadOrder]);
|
|
227
|
+
}, [searchParams, loadOrder, disableUrlParamManagement]);
|
|
228
228
|
// Update URL when swap configuration changes - but not on initial load
|
|
229
229
|
const updateSwapParamsInURL = (0, react_4.useCallback)(() => {
|
|
230
230
|
// Skip if:
|
|
@@ -235,7 +235,8 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
235
235
|
activePanel !== PanelView.MAIN ||
|
|
236
236
|
!initialUrlProcessed.current ||
|
|
237
237
|
searchParams.has("orderId") ||
|
|
238
|
-
mode === "modal"
|
|
238
|
+
mode === "modal" ||
|
|
239
|
+
disableUrlParamManagement)
|
|
239
240
|
return;
|
|
240
241
|
// Create a representation of the current state
|
|
241
242
|
const currentState = {
|
|
@@ -295,6 +296,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
295
296
|
dstAmount,
|
|
296
297
|
router,
|
|
297
298
|
srcAmountOnRamp,
|
|
299
|
+
disableUrlParamManagement,
|
|
298
300
|
]);
|
|
299
301
|
// Update URL when relevant state changes - but only after initial render
|
|
300
302
|
(0, react_4.useEffect)(() => {
|
|
@@ -480,20 +482,20 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
480
482
|
setOrderId(orderId);
|
|
481
483
|
// setNewRecipientAddress("");
|
|
482
484
|
navigateToPanel(PanelView.ORDER_DETAILS, "forward");
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
485
|
+
if (!disableUrlParamManagement) {
|
|
486
|
+
// Debug: Check payment method before setting URL
|
|
487
|
+
console.log("Creating order - selectedCryptoPaymentMethod:", selectedCryptoPaymentMethod);
|
|
488
|
+
// Add orderId and payment method to URL for persistence
|
|
489
|
+
const params = new URLSearchParams(searchParams.toString()); // Preserve existing params
|
|
490
|
+
params.set("orderId", orderId);
|
|
491
|
+
if (effectiveCryptoPaymentMethod !== CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
492
|
+
params.set("cryptoPaymentMethod", effectiveCryptoPaymentMethod);
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
console.log("Payment method is NONE, not setting in URL");
|
|
496
|
+
}
|
|
497
|
+
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
494
498
|
}
|
|
495
|
-
console.log("Final URL params:", params.toString());
|
|
496
|
-
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
497
499
|
},
|
|
498
500
|
onError: error => {
|
|
499
501
|
console.error(error);
|
|
@@ -506,11 +508,13 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
506
508
|
const orderId = data.data.id;
|
|
507
509
|
setOrderId(orderId);
|
|
508
510
|
navigateToPanel(PanelView.ORDER_DETAILS, "forward");
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
511
|
+
if (!disableUrlParamManagement) {
|
|
512
|
+
// Add orderId and payment method to URL for persistence
|
|
513
|
+
const params = new URLSearchParams(searchParams.toString());
|
|
514
|
+
params.set("orderId", orderId);
|
|
515
|
+
params.set("paymentMethod", "fiat");
|
|
516
|
+
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
517
|
+
}
|
|
514
518
|
},
|
|
515
519
|
onError: error => {
|
|
516
520
|
console.error(error);
|
|
@@ -638,11 +642,13 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
638
642
|
type: "anySpendOrderHistory",
|
|
639
643
|
showBackButton: false,
|
|
640
644
|
});
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
645
|
+
if (!disableUrlParamManagement) {
|
|
646
|
+
// Remove orderId and paymentMethod from URL when going back to history
|
|
647
|
+
const params = new URLSearchParams(searchParams.toString());
|
|
648
|
+
params.delete("orderId");
|
|
649
|
+
params.delete("paymentMethod");
|
|
650
|
+
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
651
|
+
}
|
|
646
652
|
};
|
|
647
653
|
// Handle crypto swap creation
|
|
648
654
|
const handleCryptoSwap = async (method) => {
|
|
@@ -751,22 +757,24 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
751
757
|
// const setDynamicModalContentType = useModalStore(state => state.setB3ModalContentType);
|
|
752
758
|
// Update useEffect for URL parameter to not override loadOrder
|
|
753
759
|
(0, react_4.useEffect)(() => {
|
|
754
|
-
if (loadOrder)
|
|
755
|
-
return; // Skip if we have a loadOrder
|
|
760
|
+
if (loadOrder || disableUrlParamManagement)
|
|
761
|
+
return; // Skip if we have a loadOrder or URL param management is disabled
|
|
756
762
|
const orderIdParam = searchParams.get("orderId");
|
|
757
763
|
if (orderIdParam) {
|
|
758
764
|
setOrderId(orderIdParam);
|
|
759
765
|
setActivePanel(PanelView.ORDER_DETAILS);
|
|
760
766
|
}
|
|
761
|
-
}, [searchParams, loadOrder]);
|
|
767
|
+
}, [searchParams, loadOrder, disableUrlParamManagement]);
|
|
762
768
|
const onSelectOrder = (selectedOrderId) => {
|
|
763
769
|
setOrderId(selectedOrderId);
|
|
764
770
|
navigateToPanel(PanelView.ORDER_DETAILS, "forward");
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
771
|
+
if (!disableUrlParamManagement) {
|
|
772
|
+
// Update URL with the new orderId and preserve existing parameters
|
|
773
|
+
const params = new URLSearchParams(searchParams.toString());
|
|
774
|
+
params.set("orderId", selectedOrderId);
|
|
775
|
+
// Keep existing paymentMethod if present
|
|
776
|
+
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
777
|
+
}
|
|
770
778
|
};
|
|
771
779
|
// Save custom recipients to local storage when they change
|
|
772
780
|
(0, react_4.useEffect)(() => {
|
|
@@ -818,7 +826,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
818
826
|
// Reset payment methods when going back
|
|
819
827
|
resetPaymentMethods();
|
|
820
828
|
} })) }) }));
|
|
821
|
-
const mainView = ((0, jsx_runtime_1.jsxs)("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2 pt-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex w-full max-w-full flex-col items-center gap-2 px-5", 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: tab => {
|
|
829
|
+
const mainView = ((0, jsx_runtime_1.jsxs)("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2 pt-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex w-full max-w-full flex-col items-center gap-2 px-5", children: [isBuyMode && !hideHeader && ((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: tab => {
|
|
822
830
|
setActiveTab(tab);
|
|
823
831
|
// Reset payment methods when switching tabs
|
|
824
832
|
resetPaymentMethods();
|
|
@@ -873,21 +881,23 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
873
881
|
type: "anySpend",
|
|
874
882
|
});
|
|
875
883
|
}
|
|
876
|
-
}, children: mode !== "page" && (0, jsx_runtime_1.jsx)(BottomNavigation_1.default, {}) }) })] }));
|
|
884
|
+
}, children: mode !== "page" && !hideBottomNavigation && (0, jsx_runtime_1.jsx)(BottomNavigation_1.default, {}) }) })] }));
|
|
877
885
|
const onrampPaymentView = ((0, jsx_runtime_1.jsx)(PanelOnrampPayment_1.PanelOnrampPayment, { srcAmountOnRamp: srcAmountOnRamp, recipientName: recipientName || undefined, recipientAddress: effectiveRecipientAddress, isBuyMode: isBuyMode, destinationTokenChainId: destinationTokenChainId, destinationTokenAddress: destinationTokenAddress, selectedDstChainId: selectedDstChainId, selectedDstToken: selectedDstToken, orderType: "swap", anyspendQuote: anyspendQuote, globalAddress: globalAddress, onOrderCreated: orderId => {
|
|
878
886
|
setOrderId(orderId);
|
|
879
887
|
navigateToPanel(PanelView.ORDER_DETAILS, "forward");
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
888
|
+
if (!disableUrlParamManagement) {
|
|
889
|
+
// Add orderId and payment method to URL for persistence
|
|
890
|
+
const params = new URLSearchParams(searchParams.toString()); // Preserve existing params
|
|
891
|
+
params.set("orderId", orderId);
|
|
892
|
+
// For fiat payments, the payment method is always fiat (but we use the active tab context)
|
|
893
|
+
if (activeTab === "fiat") {
|
|
894
|
+
params.set("paymentMethod", "fiat");
|
|
895
|
+
}
|
|
896
|
+
else if (selectedCryptoPaymentMethod !== CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
897
|
+
params.set("paymentMethod", selectedCryptoPaymentMethod);
|
|
898
|
+
}
|
|
899
|
+
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
889
900
|
}
|
|
890
|
-
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
891
901
|
}, onBack: navigateBack, recipientEnsName: globalWallet?.ensName, recipientImageUrl: globalWalletImage }));
|
|
892
902
|
const recipientSelectionView = ((0, jsx_runtime_1.jsx)(RecipientSelection_1.RecipientSelection, { initialValue: effectiveRecipientAddress || "", onBack: navigateBack, onConfirm: address => {
|
|
893
903
|
// User manually selected a recipient
|
|
@@ -26,7 +26,7 @@ export interface AnySpendCustomExactInProps {
|
|
|
26
26
|
customUsdInputValues?: string[];
|
|
27
27
|
preferEoa?: boolean;
|
|
28
28
|
customExactInConfig?: CustomExactInConfig;
|
|
29
|
-
orderType?: "hype_duel" | "custom_exact_in";
|
|
29
|
+
orderType?: "hype_duel" | "custom_exact_in" | "swap";
|
|
30
30
|
minDestinationAmount?: number;
|
|
31
31
|
header?: ({ anyspendPrice, isLoadingAnyspendPrice, }: {
|
|
32
32
|
anyspendPrice: GetQuoteResponse | undefined;
|
|
@@ -41,7 +41,6 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
|
|
|
41
41
|
paymentType,
|
|
42
42
|
recipientAddress,
|
|
43
43
|
loadOrder,
|
|
44
|
-
isDepositMode: true,
|
|
45
44
|
onTransactionSuccess: onSuccess,
|
|
46
45
|
sourceTokenAddress,
|
|
47
46
|
sourceTokenChainId,
|
|
@@ -182,7 +181,7 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
|
|
|
182
181
|
}
|
|
183
182
|
};
|
|
184
183
|
const headerContent = header ? (header({ anyspendPrice: anyspendQuote, isLoadingAnyspendPrice: isLoadingAnyspendQuote })) : ((0, jsx_runtime_1.jsx)("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-as-primary text-xl font-bold", children: actionLabel }), (0, jsx_runtime_1.jsx)("p", { className: "text-as-secondary text-sm", children: "Pay from any token to execute a custom exact-in transaction." })] }) }));
|
|
185
|
-
const mainView = ((0, jsx_runtime_1.jsxs)("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [headerContent, (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)(CryptoPaySection_1.CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(useAnyspendFlow_1.PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : ((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: selectedRecipientOrDefault, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, dstTokenSymbol: DESTINATION_TOKEN_DETAILS.SYMBOL, hideDstToken: true, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: useAnyspendFlow_1.PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: useAnyspendFlow_1.PanelView.RECIPIENT_SELECTION, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.FEE_DETAIL), customUsdInputValues: customUsdInputValues }) })), (0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)("relative -my-1 flex h-0 items-center justify-center", paymentType === "fiat" && "hidden"), children: (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 z-10 h-10 w-10 cursor-default rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl"), 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, effectiveRecipientAddress: selectedRecipientOrDefault, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(useAnyspendFlow_1.PanelView.RECIPIENT_SELECTION), dstAmount: dstAmount, dstToken: selectedDstToken, dstTokenSymbol: DESTINATION_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: DESTINATION_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
|
|
184
|
+
const mainView = ((0, jsx_runtime_1.jsxs)("div", { className: "anyspend-custom-exact-in-container mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [headerContent, (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)(CryptoPaySection_1.CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(useAnyspendFlow_1.PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : ((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: selectedRecipientOrDefault, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, dstTokenSymbol: DESTINATION_TOKEN_DETAILS.SYMBOL, hideDstToken: true, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: useAnyspendFlow_1.PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: useAnyspendFlow_1.PanelView.RECIPIENT_SELECTION, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.FEE_DETAIL), customUsdInputValues: customUsdInputValues }) })), (0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)("relative -my-1 flex h-0 items-center justify-center", paymentType === "fiat" && "hidden"), children: (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 z-10 h-10 w-10 cursor-default rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl"), 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, effectiveRecipientAddress: selectedRecipientOrDefault, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(useAnyspendFlow_1.PanelView.RECIPIENT_SELECTION), dstAmount: dstAmount, dstToken: selectedDstToken, dstTokenSymbol: DESTINATION_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: DESTINATION_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
|
|
186
185
|
setIsSrcInputDirty(false);
|
|
187
186
|
setSrcAmount(value);
|
|
188
187
|
}, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.FEE_DETAIL) }))] }) }), (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"), 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: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-center gap-2", children: [btnInfo.loading && (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-4 w-4 animate-spin" }), btnInfo.text] }) }) }), mainFooter ? mainFooter : null] }));
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { components } from "../../../anyspend/types/api";
|
|
2
|
+
import { GetQuoteResponse } from "../../../anyspend/types/api_req_res";
|
|
3
|
+
export interface DepositContractConfig {
|
|
4
|
+
/** Custom function ABI JSON string */
|
|
5
|
+
functionAbi: string;
|
|
6
|
+
/** The function name to call */
|
|
7
|
+
functionName: string;
|
|
8
|
+
/** Custom function arguments. Use "{{amount_out}}" for the deposit amount placeholder */
|
|
9
|
+
functionArgs: string[];
|
|
10
|
+
/** The contract address to deposit to */
|
|
11
|
+
to: string;
|
|
12
|
+
/** Optional spender address if different from contract address */
|
|
13
|
+
spenderAddress?: string;
|
|
14
|
+
/** Custom action label */
|
|
15
|
+
action?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ChainConfig {
|
|
18
|
+
/** Chain ID */
|
|
19
|
+
id: number;
|
|
20
|
+
/** Display name */
|
|
21
|
+
name: string;
|
|
22
|
+
/** Optional icon URL */
|
|
23
|
+
iconUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface AnySpendDepositProps {
|
|
26
|
+
/** Order ID to load an existing order */
|
|
27
|
+
loadOrder?: string;
|
|
28
|
+
/** Display mode */
|
|
29
|
+
mode?: "modal" | "page";
|
|
30
|
+
/** The recipient address for the deposit */
|
|
31
|
+
recipientAddress: string;
|
|
32
|
+
/** Payment type - crypto or fiat. If not set, shows chain selection first */
|
|
33
|
+
paymentType?: "crypto" | "fiat";
|
|
34
|
+
/** Source token address to pre-select */
|
|
35
|
+
sourceTokenAddress?: string;
|
|
36
|
+
/** Source chain ID to pre-select. If not provided, shows chain selection */
|
|
37
|
+
sourceTokenChainId?: number;
|
|
38
|
+
/** The destination token to receive */
|
|
39
|
+
destinationToken: components["schemas"]["Token"];
|
|
40
|
+
/** The destination chain ID */
|
|
41
|
+
destinationChainId: number;
|
|
42
|
+
/** Callback when deposit succeeds */
|
|
43
|
+
onSuccess?: (amount: string) => void;
|
|
44
|
+
/** Callback for opening a custom modal (e.g., for special token handling) */
|
|
45
|
+
onOpenCustomModal?: () => void;
|
|
46
|
+
/** Custom footer content */
|
|
47
|
+
mainFooter?: React.ReactNode;
|
|
48
|
+
/** Called when a token is selected. Call event.preventDefault() to prevent default behavior */
|
|
49
|
+
onTokenSelect?: (token: components["schemas"]["Token"], event: {
|
|
50
|
+
preventDefault: () => void;
|
|
51
|
+
}) => void;
|
|
52
|
+
/** Custom USD input value presets for fiat payment */
|
|
53
|
+
customUsdInputValues?: string[];
|
|
54
|
+
/** Whether to prefer using connected EOA wallet */
|
|
55
|
+
preferEoa?: boolean;
|
|
56
|
+
/** Minimum destination amount required */
|
|
57
|
+
minDestinationAmount?: number;
|
|
58
|
+
/** Custom header component */
|
|
59
|
+
header?: ({ anyspendPrice, isLoadingAnyspendPrice, }: {
|
|
60
|
+
anyspendPrice: GetQuoteResponse | undefined;
|
|
61
|
+
isLoadingAnyspendPrice: boolean;
|
|
62
|
+
}) => React.JSX.Element;
|
|
63
|
+
/** Order type for the deposit */
|
|
64
|
+
orderType?: "hype_duel" | "custom_exact_in" | "swap";
|
|
65
|
+
/** Custom action label displayed on buttons */
|
|
66
|
+
actionLabel?: string;
|
|
67
|
+
/** Configuration for depositing to a custom contract.
|
|
68
|
+
* If provided, creates a custom_exact_in order that calls the contract.
|
|
69
|
+
* If not provided, creates a simple hype_duel order for direct deposits.
|
|
70
|
+
*/
|
|
71
|
+
depositContractConfig?: DepositContractConfig;
|
|
72
|
+
/** Whether to show chain selection step. Defaults to true if sourceTokenChainId is not provided */
|
|
73
|
+
showChainSelection?: boolean;
|
|
74
|
+
/** Custom list of supported chains. If not provided, uses default chains */
|
|
75
|
+
supportedChains?: ChainConfig[];
|
|
76
|
+
/** Minimum pool size for filtering tokens (default: 1,000,000) */
|
|
77
|
+
minPoolSize?: number;
|
|
78
|
+
/** Custom title for chain selection step */
|
|
79
|
+
chainSelectionTitle?: string;
|
|
80
|
+
/** Custom description for chain selection step */
|
|
81
|
+
chainSelectionDescription?: string;
|
|
82
|
+
/** Number of top chains to show (default: 3) */
|
|
83
|
+
topChainsCount?: number;
|
|
84
|
+
/** Callback when close button is clicked */
|
|
85
|
+
onClose?: () => void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A flexible deposit component that wraps AnySpendCustomExactIn with optional chain selection.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* // Simple deposit with chain selection
|
|
92
|
+
* <AnySpendDeposit
|
|
93
|
+
* recipientAddress={userAddress}
|
|
94
|
+
* destinationToken={myToken}
|
|
95
|
+
* destinationChainId={base.id}
|
|
96
|
+
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
97
|
+
* />
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* // Skip chain selection by providing sourceTokenChainId
|
|
101
|
+
* <AnySpendDeposit
|
|
102
|
+
* recipientAddress={userAddress}
|
|
103
|
+
* destinationToken={myToken}
|
|
104
|
+
* destinationChainId={base.id}
|
|
105
|
+
* sourceTokenChainId={base.id}
|
|
106
|
+
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
107
|
+
* />
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* // Deposit with custom contract
|
|
111
|
+
* <AnySpendDeposit
|
|
112
|
+
* recipientAddress={userAddress}
|
|
113
|
+
* destinationToken={myToken}
|
|
114
|
+
* destinationChainId={base.id}
|
|
115
|
+
* depositContractConfig={{
|
|
116
|
+
* contractAddress: "0x...",
|
|
117
|
+
* functionName: "depositFor",
|
|
118
|
+
* }}
|
|
119
|
+
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
120
|
+
* />
|
|
121
|
+
*/
|
|
122
|
+
export declare function AnySpendDeposit({ loadOrder, mode, recipientAddress, paymentType: initialPaymentType, sourceTokenAddress, sourceTokenChainId: initialSourceChainId, destinationToken, destinationChainId, onSuccess, onOpenCustomModal, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, minDestinationAmount, header, orderType, depositContractConfig, showChainSelection, supportedChains, minPoolSize, topChainsCount, onClose, }: AnySpendDepositProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnySpendDeposit = AnySpendDeposit;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const anyspend_1 = require("../../../anyspend");
|
|
6
|
+
const react_1 = require("../../../global-account/react");
|
|
7
|
+
const cn_1 = require("../../../shared/utils/cn");
|
|
8
|
+
const react_2 = require("@web3icons/react");
|
|
9
|
+
const lucide_react_1 = require("lucide-react");
|
|
10
|
+
const react_3 = require("react");
|
|
11
|
+
const AnySpend_1 = require("./AnySpend");
|
|
12
|
+
const AnySpendCustomExactIn_1 = require("./AnySpendCustomExactIn");
|
|
13
|
+
const WarningText_1 = require("./common/WarningText");
|
|
14
|
+
const CreditCardIcon_1 = require("./icons/CreditCardIcon");
|
|
15
|
+
const QrCodeIcon_1 = require("./icons/QrCodeIcon");
|
|
16
|
+
const QRDeposit_1 = require("./QRDeposit");
|
|
17
|
+
// Default supported chains
|
|
18
|
+
const DEFAULT_SUPPORTED_CHAINS = [
|
|
19
|
+
{ id: 8453, name: "Base" },
|
|
20
|
+
{ id: 1, name: "Ethereum" },
|
|
21
|
+
{ id: 42161, name: "Arbitrum" },
|
|
22
|
+
{ id: 10, name: "Optimism" },
|
|
23
|
+
{ id: 137, name: "Polygon" },
|
|
24
|
+
{ id: 56, name: "BNB Chain" },
|
|
25
|
+
];
|
|
26
|
+
// Minimum pool size to filter out low liquidity tokens
|
|
27
|
+
const DEFAULT_MIN_POOL_SIZE = 1000000;
|
|
28
|
+
function formatUsd(value) {
|
|
29
|
+
return new Intl.NumberFormat("en-US", {
|
|
30
|
+
style: "currency",
|
|
31
|
+
currency: "USD",
|
|
32
|
+
minimumFractionDigits: 0,
|
|
33
|
+
maximumFractionDigits: value >= 100 ? 0 : 2,
|
|
34
|
+
}).format(value);
|
|
35
|
+
}
|
|
36
|
+
function formatDecimal(value) {
|
|
37
|
+
return new Intl.NumberFormat("en-US", {
|
|
38
|
+
style: "decimal",
|
|
39
|
+
minimumFractionDigits: 0,
|
|
40
|
+
maximumFractionDigits: value >= 100 ? 0 : 2,
|
|
41
|
+
}).format(value);
|
|
42
|
+
}
|
|
43
|
+
// Chain icon component
|
|
44
|
+
function ChainIcon({ chainId, className }) {
|
|
45
|
+
const iconProps = {
|
|
46
|
+
variant: "branded",
|
|
47
|
+
className: (0, cn_1.cn)("anyspend-deposit-chain-icon", className),
|
|
48
|
+
};
|
|
49
|
+
switch (chainId) {
|
|
50
|
+
case 1:
|
|
51
|
+
return (0, jsx_runtime_1.jsx)(react_2.NetworkEthereum, { ...iconProps });
|
|
52
|
+
case 8453:
|
|
53
|
+
return (0, jsx_runtime_1.jsx)(react_2.NetworkBase, { ...iconProps });
|
|
54
|
+
case 137:
|
|
55
|
+
return (0, jsx_runtime_1.jsx)(react_2.NetworkPolygonPos, { ...iconProps });
|
|
56
|
+
case 42161:
|
|
57
|
+
return (0, jsx_runtime_1.jsx)(react_2.NetworkArbitrumOne, { ...iconProps });
|
|
58
|
+
case 10:
|
|
59
|
+
return (0, jsx_runtime_1.jsx)(react_2.NetworkOptimism, { ...iconProps });
|
|
60
|
+
case 56:
|
|
61
|
+
return (0, jsx_runtime_1.jsx)(react_2.NetworkBinanceSmartChain, { ...iconProps });
|
|
62
|
+
default:
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A flexible deposit component that wraps AnySpendCustomExactIn with optional chain selection.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Simple deposit with chain selection
|
|
71
|
+
* <AnySpendDeposit
|
|
72
|
+
* recipientAddress={userAddress}
|
|
73
|
+
* destinationToken={myToken}
|
|
74
|
+
* destinationChainId={base.id}
|
|
75
|
+
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
76
|
+
* />
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* // Skip chain selection by providing sourceTokenChainId
|
|
80
|
+
* <AnySpendDeposit
|
|
81
|
+
* recipientAddress={userAddress}
|
|
82
|
+
* destinationToken={myToken}
|
|
83
|
+
* destinationChainId={base.id}
|
|
84
|
+
* sourceTokenChainId={base.id}
|
|
85
|
+
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
86
|
+
* />
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* // Deposit with custom contract
|
|
90
|
+
* <AnySpendDeposit
|
|
91
|
+
* recipientAddress={userAddress}
|
|
92
|
+
* destinationToken={myToken}
|
|
93
|
+
* destinationChainId={base.id}
|
|
94
|
+
* depositContractConfig={{
|
|
95
|
+
* contractAddress: "0x...",
|
|
96
|
+
* functionName: "depositFor",
|
|
97
|
+
* }}
|
|
98
|
+
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
99
|
+
* />
|
|
100
|
+
*/
|
|
101
|
+
function AnySpendDeposit({ loadOrder, mode = "modal", recipientAddress, paymentType: initialPaymentType, sourceTokenAddress, sourceTokenChainId: initialSourceChainId, destinationToken, destinationChainId, onSuccess, onOpenCustomModal, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, minDestinationAmount, header, orderType, depositContractConfig, showChainSelection, supportedChains = DEFAULT_SUPPORTED_CHAINS, minPoolSize = DEFAULT_MIN_POOL_SIZE, topChainsCount = 3, onClose, }) {
|
|
102
|
+
const { connectedEOAWallet } = (0, react_1.useAccountWallet)();
|
|
103
|
+
const eoaAddress = connectedEOAWallet?.getAccount()?.address;
|
|
104
|
+
// Determine if we should show chain selection
|
|
105
|
+
const shouldShowChainSelection = showChainSelection ?? (!initialSourceChainId && !initialPaymentType);
|
|
106
|
+
const [step, setStep] = (0, react_3.useState)(shouldShowChainSelection ? "select-chain" : "deposit");
|
|
107
|
+
const [selectedChainId, setSelectedChainId] = (0, react_3.useState)(initialSourceChainId);
|
|
108
|
+
const [paymentType, setPaymentType] = (0, react_3.useState)(initialPaymentType ?? "crypto");
|
|
109
|
+
// Fetch balances for EOA wallet
|
|
110
|
+
const { data: balanceData, isLoading: isBalanceLoading } = (0, react_1.useSimBalance)(shouldShowChainSelection ? eoaAddress : undefined, supportedChains.map(c => c.id));
|
|
111
|
+
// Group balances by chain and calculate total USD value per chain
|
|
112
|
+
const chainBalances = (0, react_3.useMemo)(() => {
|
|
113
|
+
if (!balanceData?.balances)
|
|
114
|
+
return {};
|
|
115
|
+
const filteredBalances = balanceData.balances.filter(token => token.address === "native" || (token.pool_size && token.pool_size > minPoolSize));
|
|
116
|
+
return filteredBalances.reduce((acc, token) => {
|
|
117
|
+
const chainId = token.chain_id;
|
|
118
|
+
if (!acc[chainId]) {
|
|
119
|
+
acc[chainId] = {
|
|
120
|
+
chainId,
|
|
121
|
+
chainName: token.chain,
|
|
122
|
+
totalUsdValue: 0,
|
|
123
|
+
tokenCount: 0,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
acc[chainId].totalUsdValue += token.value_usd || 0;
|
|
127
|
+
acc[chainId].tokenCount += 1;
|
|
128
|
+
return acc;
|
|
129
|
+
}, {});
|
|
130
|
+
}, [balanceData, minPoolSize]);
|
|
131
|
+
// Sort chains by USD value (highest first)
|
|
132
|
+
const sortedChains = (0, react_3.useMemo)(() => {
|
|
133
|
+
return supportedChains
|
|
134
|
+
.map(chain => ({
|
|
135
|
+
...chain,
|
|
136
|
+
balance: chainBalances[chain.id]?.totalUsdValue || 0,
|
|
137
|
+
tokenCount: chainBalances[chain.id]?.tokenCount || 0,
|
|
138
|
+
}))
|
|
139
|
+
.sort((a, b) => b.balance - a.balance);
|
|
140
|
+
}, [supportedChains, chainBalances]);
|
|
141
|
+
// Get top chains with balance
|
|
142
|
+
const topChainsWithBalance = (0, react_3.useMemo)(() => {
|
|
143
|
+
return sortedChains.filter(chain => chain.balance > 0).slice(0, topChainsCount);
|
|
144
|
+
}, [sortedChains, topChainsCount]);
|
|
145
|
+
// Calculate total balance across all chains
|
|
146
|
+
const totalBalance = (0, react_3.useMemo)(() => {
|
|
147
|
+
return Object.values(chainBalances).reduce((sum, chain) => sum + chain.totalUsdValue, 0);
|
|
148
|
+
}, [chainBalances]);
|
|
149
|
+
if (!recipientAddress)
|
|
150
|
+
return null;
|
|
151
|
+
const tokenSymbol = destinationToken.symbol ?? "TOKEN";
|
|
152
|
+
// Determine order type based on config
|
|
153
|
+
const effectiveOrderType = orderType ?? (depositContractConfig ? "custom_exact_in" : "swap");
|
|
154
|
+
// Default header if not provided
|
|
155
|
+
const defaultHeader = () => ((0, jsx_runtime_1.jsx)("div", { className: "anyspend-deposit-header 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: "anyspend-deposit-title text-as-primary text-xl font-bold", children: paymentType === "crypto" ? `Deposit ${tokenSymbol}` : "Fund with Fiat" }) }) }));
|
|
156
|
+
const handleSelectChain = (chainId) => {
|
|
157
|
+
setSelectedChainId(chainId);
|
|
158
|
+
setPaymentType("crypto");
|
|
159
|
+
setStep("deposit");
|
|
160
|
+
};
|
|
161
|
+
const handleSelectCrypto = () => {
|
|
162
|
+
setPaymentType("crypto");
|
|
163
|
+
setSelectedChainId(undefined);
|
|
164
|
+
setStep("deposit");
|
|
165
|
+
};
|
|
166
|
+
const handleSelectFiat = () => {
|
|
167
|
+
setPaymentType("fiat");
|
|
168
|
+
setSelectedChainId(undefined);
|
|
169
|
+
setStep("deposit");
|
|
170
|
+
};
|
|
171
|
+
const handleBack = () => {
|
|
172
|
+
setStep("select-chain");
|
|
173
|
+
setSelectedChainId(undefined);
|
|
174
|
+
};
|
|
175
|
+
const handleSelectQrDeposit = () => {
|
|
176
|
+
setStep("qr-deposit");
|
|
177
|
+
};
|
|
178
|
+
// Chain selection view
|
|
179
|
+
if (step === "select-chain") {
|
|
180
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: (0, cn_1.cn)("anyspend-deposit anyspend-deposit-chain-selection font-inter bg-as-surface-primary relative mx-auto w-full max-w-[460px]", mode === "page" && "border-as-border-secondary overflow-hidden rounded-2xl border shadow-xl"), children: [onClose && ((0, jsx_runtime_1.jsx)("button", { onClick: onClose, className: "anyspend-deposit-close-button text-as-secondary hover:text-as-primary absolute right-4 top-4 z-10", children: (0, jsx_runtime_1.jsx)("svg", { className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: (0, jsx_runtime_1.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }) })), (0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-balance-header border-secondary border-b p-5", children: [!isBalanceLoading && totalBalance > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-balance", children: [(0, jsx_runtime_1.jsx)("p", { className: "anyspend-deposit-balance-label text-as-secondary text-sm", children: "Your Balance" }), (0, jsx_runtime_1.jsxs)("p", { className: "anyspend-deposit-balance-value text-as-primary text-3xl font-semibold", children: [formatDecimal(totalBalance), " ", (0, jsx_runtime_1.jsx)("span", { className: "text-sm", children: "USD" })] })] })), isBalanceLoading && ((0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-balance-skeleton", children: [(0, jsx_runtime_1.jsx)(react_1.Skeleton, { className: "mb-2 h-4 w-24" }), (0, jsx_runtime_1.jsx)(react_1.Skeleton, { className: "h-8 w-32" })] }))] }), (0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-options flex flex-col gap-2 p-6", children: [isBalanceLoading && ((0, jsx_runtime_1.jsx)("div", { className: "anyspend-deposit-chains-skeleton flex flex-col gap-2", children: [...Array(topChainsCount)].map((_, i) => ((0, jsx_runtime_1.jsxs)("div", { className: "border-border-primary flex items-center justify-between rounded-xl border p-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)(react_1.Skeleton, { className: "h-6 w-6 rounded-full" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-1", children: [(0, jsx_runtime_1.jsx)(react_1.Skeleton, { className: "h-4 w-32" }), (0, jsx_runtime_1.jsx)(react_1.Skeleton, { className: "h-3 w-20" })] })] }), (0, jsx_runtime_1.jsx)(react_1.Skeleton, { className: "h-5 w-5" })] }, i))) })), topChainsWithBalance.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "anyspend-deposit-chains flex flex-col gap-2", children: topChainsWithBalance.map(chain => ((0, jsx_runtime_1.jsxs)("button", { onClick: () => handleSelectChain(chain.id), className: "anyspend-deposit-chain-button border-border-primary hover:border-as-brand hover:bg-as-surface-secondary flex w-full items-center justify-between rounded-xl border p-4 text-left shadow-sm transition-all", children: [(0, jsx_runtime_1.jsx)("div", { className: "anyspend-deposit-chain-content", children: (0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-chain-info", children: [(0, jsx_runtime_1.jsxs)("span", { className: "anyspend-deposit-chain-name text-as-primary flex items-center gap-1.5 font-medium", children: ["Deposit from ", chain.name, (0, jsx_runtime_1.jsx)(ChainIcon, { chainId: chain.id, className: "h-5 w-5" })] }), (0, jsx_runtime_1.jsxs)("p", { className: "anyspend-deposit-chain-balance text-as-secondary text-xs", children: [formatUsd(chain.balance), " available"] })] }) }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "anyspend-deposit-chain-chevron text-as-secondary h-5 w-5" })] }, chain.id))) })), (0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-general-options flex flex-col gap-2", children: [(0, jsx_runtime_1.jsxs)("button", { onClick: handleSelectCrypto, className: "anyspend-deposit-option-button anyspend-deposit-crypto-button border-border-primary hover:border-as-brand hover:bg-as-surface-secondary flex w-full items-center justify-between rounded-xl border p-4 text-left shadow-sm transition-all", children: [(0, jsx_runtime_1.jsx)("div", { className: "anyspend-deposit-option-content", children: (0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-option-info", children: [(0, jsx_runtime_1.jsx)("span", { className: "anyspend-deposit-option-title text-as-primary font-medium", children: "Deposit Crypto" }), (0, jsx_runtime_1.jsx)("p", { className: "anyspend-deposit-option-description text-as-secondary text-xs", children: "Swap from any token on any chain" })] }) }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "anyspend-deposit-option-chevron text-as-secondary h-5 w-5" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-divider flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "bg-as-stroke h-px flex-1" }), (0, jsx_runtime_1.jsx)("span", { className: "anyspend-deposit-divider-text text-as-secondary text-sm", children: "More options" }), (0, jsx_runtime_1.jsx)("div", { className: "bg-as-stroke h-px flex-1" })] }), (0, jsx_runtime_1.jsxs)("button", { onClick: handleSelectQrDeposit, className: "anyspend-deposit-option-button anyspend-deposit-qr-button border-border-primary hover:border-as-brand hover:bg-as-surface-secondary flex w-full items-center justify-between rounded-xl border p-4 text-left shadow-sm transition-all", children: [(0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-option-content flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)(QrCodeIcon_1.QrCodeIcon, { className: "anyspend-deposit-option-icon h-10 w-10" }), (0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-option-info", children: [(0, jsx_runtime_1.jsx)("span", { className: "anyspend-deposit-option-title text-as-primary font-medium", children: "Deposit with QR Code" }), (0, jsx_runtime_1.jsx)("p", { className: "anyspend-deposit-option-description text-as-secondary text-xs", children: "Send tokens directly to deposit address" })] })] }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "anyspend-deposit-option-chevron text-as-secondary h-5 w-5" })] }), (0, jsx_runtime_1.jsxs)("button", { onClick: handleSelectFiat, className: "anyspend-deposit-option-button anyspend-deposit-fiat-button border-border-primary hover:border-as-brand hover:bg-as-surface-secondary flex w-full items-center justify-between rounded-xl border p-4 text-left transition-all", children: [(0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-option-content flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)(CreditCardIcon_1.CreditCardIcon, { className: "anyspend-deposit-option-icon h-10 w-10" }), (0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit-option-info", children: [(0, jsx_runtime_1.jsx)("span", { className: "anyspend-deposit-option-title text-as-primary font-medium", children: "Fund with Fiat" }), (0, jsx_runtime_1.jsx)("p", { className: "anyspend-deposit-option-description text-as-secondary text-xs", children: "Pay with card or bank transfer" })] })] }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "anyspend-deposit-option-chevron text-as-secondary h-5 w-5" })] })] }), (0, jsx_runtime_1.jsx)(WarningText_1.ChainWarningText, { chainId: destinationChainId, className: "mt-2" })] })] }));
|
|
181
|
+
}
|
|
182
|
+
// QR Deposit view
|
|
183
|
+
if (step === "qr-deposit") {
|
|
184
|
+
return ((0, jsx_runtime_1.jsx)(QRDeposit_1.QRDeposit, { mode: mode, recipientAddress: recipientAddress, destinationToken: destinationToken, destinationChainId: destinationChainId, depositContractConfig: depositContractConfig, onBack: handleBack, onClose: onClose ?? handleBack }));
|
|
185
|
+
}
|
|
186
|
+
// Check if destination is Hyperliquid
|
|
187
|
+
const isHyperliquidDeposit = destinationChainId === anyspend_1.HYPERLIQUID_CHAIN_ID;
|
|
188
|
+
// Deposit view
|
|
189
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "anyspend-deposit anyspend-deposit-form relative", children: [shouldShowChainSelection && ((0, jsx_runtime_1.jsxs)("button", { onClick: handleBack, className: "anyspend-deposit-back-button text-as-secondary hover:text-as-primary absolute left-4 top-4 z-10 flex items-center gap-1", children: [(0, jsx_runtime_1.jsx)("svg", { className: "anyspend-deposit-back-icon h-5 w-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: (0, jsx_runtime_1.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 19l-7-7 7-7" }) }), (0, jsx_runtime_1.jsx)("span", { className: "anyspend-deposit-back-text text-sm", children: "Back" })] })), onClose && ((0, jsx_runtime_1.jsx)("button", { onClick: onClose, className: "anyspend-deposit-close-button text-as-secondary hover:text-as-primary absolute right-4 top-4 z-10", children: (0, jsx_runtime_1.jsx)("svg", { className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: (0, jsx_runtime_1.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }) })), (0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)("anyspend-deposit-form-content", shouldShowChainSelection && "pt-8"), children: isHyperliquidDeposit ? ((0, jsx_runtime_1.jsx)(AnySpend_1.AnySpend, { loadOrder: loadOrder, mode: mode, defaultActiveTab: paymentType, recipientAddress: recipientAddress, sourceChainId: selectedChainId, destinationTokenAddress: destinationToken.address, destinationTokenChainId: destinationChainId, onSuccess: txHash => onSuccess?.(txHash ?? ""), onTokenSelect: onTokenSelect, customUsdInputValues: customUsdInputValues, hideHeader: true, hideBottomNavigation: true, disableUrlParamManagement: true })) : ((0, jsx_runtime_1.jsx)(AnySpendCustomExactIn_1.AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, paymentType: paymentType, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: selectedChainId, destinationToken: destinationToken, destinationChainId: destinationChainId, orderType: effectiveOrderType, minDestinationAmount: minDestinationAmount, header: header ?? defaultHeader, onSuccess: onSuccess, onOpenCustomModal: onOpenCustomModal, mainFooter: mainFooter, onTokenSelect: onTokenSelect, customUsdInputValues: customUsdInputValues, preferEoa: preferEoa, customExactInConfig: depositContractConfig })) }), (0, jsx_runtime_1.jsx)(WarningText_1.ChainWarningText, { chainId: destinationChainId, className: "px-4 pb-4" })] }));
|
|
190
|
+
}
|