@b3dotfun/sdk 0.0.65 → 0.0.66
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.js +38 -24
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +22 -9
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +44 -13
- package/dist/cjs/anyspend/react/components/AnySpendDepositUpside.d.ts +11 -0
- package/dist/cjs/anyspend/react/components/AnySpendDepositUpside.js +41 -0
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +1 -1
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +14 -251
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +2 -10
- package/dist/cjs/anyspend/react/components/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/index.js +4 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +16 -10
- package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
- package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +13 -9
- package/dist/cjs/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
- package/dist/cjs/anyspend/react/hooks/useCryptoPaymentMethodState.js +51 -0
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +3 -0
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +21 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +38 -24
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +22 -9
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +3 -1
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +44 -13
- package/dist/esm/anyspend/react/components/AnySpendDepositUpside.d.ts +11 -0
- package/dist/esm/anyspend/react/components/AnySpendDepositUpside.js +38 -0
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +15 -249
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -10
- package/dist/esm/anyspend/react/components/index.d.ts +1 -0
- package/dist/esm/anyspend/react/components/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +16 -10
- package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
- package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +13 -9
- package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
- package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.js +48 -0
- package/dist/esm/global-account/react/components/B3DynamicModal.js +3 -0
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +21 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +3 -1
- package/dist/types/anyspend/react/components/AnySpendDepositUpside.d.ts +11 -0
- package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +1 -1
- package/dist/types/anyspend/react/components/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
- package/dist/types/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
- package/dist/types/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +21 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +50 -29
- package/src/anyspend/react/components/AnySpendCustom.tsx +28 -15
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +54 -13
- package/src/anyspend/react/components/AnySpendDepositUpside.tsx +81 -0
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +36 -526
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +2 -13
- package/src/anyspend/react/components/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +24 -12
- package/src/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.ts +20 -12
- package/src/anyspend/react/hooks/useCryptoPaymentMethodState.ts +71 -0
- package/src/global-account/react/components/B3DynamicModal.tsx +3 -0
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +6 -12
- package/src/global-account/react/stores/useModalStore.ts +22 -0
- package/src/styles/index.css +8 -0
|
@@ -1,264 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.HYPE_TOKEN_DETAILS = void 0;
|
|
7
4
|
exports.AnySpendDepositHype = AnySpendDepositHype;
|
|
8
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
6
|
const anyspend_1 = require("../../../anyspend");
|
|
10
|
-
const react_1 = require("../../../global-account/react");
|
|
11
|
-
const cn_1 = require("../../../shared/utils/cn");
|
|
12
|
-
const invariant_1 = __importDefault(require("invariant"));
|
|
13
|
-
const react_2 = require("motion/react");
|
|
14
|
-
const react_3 = require("react");
|
|
15
|
-
const sonner_1 = require("sonner");
|
|
16
|
-
const react_4 = require("thirdweb/react");
|
|
17
7
|
const chains_1 = require("viem/chains");
|
|
18
|
-
const
|
|
19
|
-
const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
|
|
20
|
-
const CryptoPaySection_1 = require("./common/CryptoPaySection");
|
|
21
|
-
const CryptoPaymentMethod_1 = require("./common/CryptoPaymentMethod");
|
|
22
|
-
const CryptoReceiveSection_1 = require("./common/CryptoReceiveSection");
|
|
23
|
-
const FeeDetailPanel_1 = require("./common/FeeDetailPanel");
|
|
24
|
-
const FiatPaymentMethod_1 = require("./common/FiatPaymentMethod");
|
|
25
|
-
const OrderDetails_1 = require("./common/OrderDetails");
|
|
26
|
-
const PointsDetailPanel_1 = require("./common/PointsDetailPanel");
|
|
27
|
-
const RecipientSelection_1 = require("./common/RecipientSelection");
|
|
28
|
-
const lucide_react_1 = require("lucide-react");
|
|
29
|
-
const PanelOnramp_1 = require("./common/PanelOnramp");
|
|
30
|
-
const SLIPPAGE_PERCENT = 3;
|
|
8
|
+
const AnySpendCustomExactIn_1 = require("./AnySpendCustomExactIn");
|
|
31
9
|
exports.HYPE_TOKEN_DETAILS = {
|
|
32
10
|
SYMBOL: "HYPE",
|
|
33
11
|
LOGO_URI: "https://cdn.hypeduel.com/hypes-coin.svg",
|
|
34
12
|
};
|
|
35
|
-
function AnySpendDepositHype(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
sourceTokenAddress,
|
|
48
|
-
sourceTokenChainId,
|
|
49
|
-
slippage: SLIPPAGE_PERCENT,
|
|
50
|
-
disableUrlParamManagement: true,
|
|
51
|
-
});
|
|
52
|
-
const { connectedEOAWallet: connectedEOAWallet } = (0, react_1.useAccountWallet)();
|
|
53
|
-
const setActiveWallet = (0, react_4.useSetActiveWallet)();
|
|
54
|
-
const appliedPreferEoa = (0, react_3.useRef)(false);
|
|
55
|
-
(0, react_3.useEffect)(() => {
|
|
56
|
-
if (preferEoa && !appliedPreferEoa.current) {
|
|
57
|
-
if (connectedEOAWallet) {
|
|
58
|
-
appliedPreferEoa.current = true;
|
|
59
|
-
setActiveWallet(connectedEOAWallet);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}, [preferEoa, connectedEOAWallet, setActiveWallet]);
|
|
63
|
-
// Button state logic
|
|
64
|
-
const btnInfo = (0, react_3.useMemo)(() => {
|
|
65
|
-
if (activeInputAmountInWei === "0")
|
|
66
|
-
return { text: "Enter an amount", disable: true, error: false, loading: false };
|
|
67
|
-
if (isLoadingAnyspendQuote)
|
|
68
|
-
return { text: "Loading quote...", disable: true, error: false, loading: true };
|
|
69
|
-
if (isCreatingOrder || isCreatingOnrampOrder)
|
|
70
|
-
return { text: "Creating order...", disable: true, error: false, loading: true };
|
|
71
|
-
if (!selectedRecipientAddress)
|
|
72
|
-
return { text: "Select recipient", disable: false, error: false, loading: false };
|
|
73
|
-
if (!anyspendQuote || !anyspendQuote.success)
|
|
74
|
-
return { text: "Get quote error", disable: true, error: true, loading: false };
|
|
75
|
-
if (!dstAmount)
|
|
76
|
-
return { text: "No quote available", disable: true, error: true, loading: false };
|
|
77
|
-
// Check minimum deposit amount (10 HYPE)
|
|
78
|
-
// Use the raw amount from the quote instead of the formatted display string
|
|
79
|
-
if (anyspendQuote.data?.currencyOut?.amount && anyspendQuote.data.currencyOut.currency?.decimals) {
|
|
80
|
-
const rawAmountInWei = anyspendQuote.data.currencyOut.amount;
|
|
81
|
-
const decimals = anyspendQuote.data.currencyOut.currency.decimals;
|
|
82
|
-
const actualAmount = parseFloat(rawAmountInWei) / Math.pow(10, decimals);
|
|
83
|
-
if (actualAmount < 10) {
|
|
84
|
-
return { text: "Minimum 10 HYPE deposit", disable: true, error: true, loading: false };
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (paymentType === "crypto") {
|
|
88
|
-
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
89
|
-
return { text: "Choose payment method", disable: false, error: false, loading: false };
|
|
90
|
-
}
|
|
91
|
-
return { text: "Continue to deposit", disable: false, error: false, loading: false };
|
|
92
|
-
}
|
|
93
|
-
if (paymentType === "fiat") {
|
|
94
|
-
if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.NONE) {
|
|
95
|
-
return { text: "Select payment method", disable: false, error: false, loading: false };
|
|
96
|
-
}
|
|
97
|
-
return { text: "Buy", disable: false, error: false, loading: false };
|
|
98
|
-
}
|
|
99
|
-
return { text: "Continue to deposit", disable: false, error: false, loading: false };
|
|
100
|
-
}, [
|
|
101
|
-
activeInputAmountInWei,
|
|
102
|
-
isLoadingAnyspendQuote,
|
|
103
|
-
isCreatingOrder,
|
|
104
|
-
isCreatingOnrampOrder,
|
|
105
|
-
selectedRecipientAddress,
|
|
106
|
-
anyspendQuote,
|
|
107
|
-
dstAmount,
|
|
108
|
-
paymentType,
|
|
109
|
-
selectedCryptoPaymentMethod,
|
|
110
|
-
selectedFiatPaymentMethod,
|
|
111
|
-
]);
|
|
112
|
-
const onMainButtonClick = async () => {
|
|
113
|
-
if (btnInfo.disable)
|
|
114
|
-
return;
|
|
115
|
-
if (!selectedRecipientAddress) {
|
|
116
|
-
setActivePanel(useAnyspendFlow_1.PanelView.RECIPIENT_SELECTION);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (paymentType === "crypto") {
|
|
120
|
-
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
121
|
-
setActivePanel(useAnyspendFlow_1.PanelView.CRYPTO_PAYMENT_METHOD);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
await handleCryptoOrder();
|
|
125
|
-
}
|
|
126
|
-
else if (paymentType === "fiat") {
|
|
127
|
-
if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.NONE) {
|
|
128
|
-
setActivePanel(useAnyspendFlow_1.PanelView.FIAT_PAYMENT_METHOD);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
await handleFiatOrder();
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const mainView = ((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)(CryptoPaySection_1.CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, 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: recipientAddress, destinationToken: anyspend_1.B3_TOKEN, destinationChainId: chains_1.base.id, dstTokenSymbol: exports.HYPE_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, selectedRecipientAddress: selectedRecipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(useAnyspendFlow_1.PanelView.RECIPIENT_SELECTION), setRecipientAddress: setSelectedRecipientAddress, recipientAddressFromProps: recipientAddress, globalAddress: globalAddress, dstAmount: dstAmount, dstToken: anyspend_1.B3_TOKEN, dstTokenSymbol: exports.HYPE_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: exports.HYPE_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: chains_1.base.id, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
|
|
135
|
-
setIsSrcInputDirty(false);
|
|
136
|
-
setSrcAmount(value);
|
|
137
|
-
}, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.FEE_DETAIL), selectedCryptoPaymentMethod: selectedCryptoPaymentMethod }))] }) }), (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] }));
|
|
138
|
-
// Handle crypto order creation
|
|
139
|
-
const handleCryptoOrder = async () => {
|
|
140
|
-
try {
|
|
141
|
-
(0, invariant_1.default)(anyspendQuote, "Relay price is not found");
|
|
142
|
-
(0, invariant_1.default)(selectedRecipientAddress, "Recipient address is not found");
|
|
143
|
-
const srcAmountBigInt = BigInt(activeInputAmountInWei);
|
|
144
|
-
createOrder({
|
|
145
|
-
recipientAddress: selectedRecipientAddress,
|
|
146
|
-
orderType: "hype_duel",
|
|
147
|
-
srcChain: selectedSrcChainId,
|
|
148
|
-
dstChain: chains_1.base.id,
|
|
149
|
-
srcToken: selectedSrcToken,
|
|
150
|
-
dstToken: anyspend_1.B3_TOKEN,
|
|
151
|
-
srcAmount: srcAmountBigInt.toString(),
|
|
152
|
-
expectedDstAmount: anyspendQuote?.data?.currencyOut?.amount?.toString() || "0",
|
|
153
|
-
creatorAddress: globalAddress,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
catch (err) {
|
|
157
|
-
console.error(err);
|
|
158
|
-
sonner_1.toast.error("Failed to create order: " + err.message);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
// Handle fiat order creation
|
|
162
|
-
const handleFiatOrder = async () => {
|
|
163
|
-
try {
|
|
164
|
-
(0, invariant_1.default)(anyspendQuote, "Relay price is not found");
|
|
165
|
-
(0, invariant_1.default)(selectedRecipientAddress, "Recipient address is not found");
|
|
166
|
-
if (!srcAmount || parseFloat(srcAmount) <= 0) {
|
|
167
|
-
sonner_1.toast.error("Please enter a valid amount");
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
// Determine vendor and payment method string
|
|
171
|
-
let vendor;
|
|
172
|
-
let paymentMethodString = "";
|
|
173
|
-
if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.COINBASE_PAY) {
|
|
174
|
-
if (coinbaseAvailablePaymentMethods.length === 0) {
|
|
175
|
-
sonner_1.toast.error("Coinbase Pay not available");
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
vendor = "coinbase";
|
|
179
|
-
paymentMethodString = coinbaseAvailablePaymentMethods[0]?.id || "";
|
|
180
|
-
}
|
|
181
|
-
else if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.STRIPE) {
|
|
182
|
-
if (!stripeWeb2Support || !stripeWeb2Support.isSupport) {
|
|
183
|
-
sonner_1.toast.error("Stripe not available");
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
vendor = "stripe-web2";
|
|
187
|
-
paymentMethodString = "";
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
sonner_1.toast.error("Please select a payment method");
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
createOnrampOrder({
|
|
194
|
-
recipientAddress: selectedRecipientAddress,
|
|
195
|
-
orderType: "hype_duel",
|
|
196
|
-
dstChain: chains_1.base.id,
|
|
197
|
-
dstToken: anyspend_1.B3_TOKEN,
|
|
198
|
-
srcFiatAmount: srcAmount,
|
|
199
|
-
onramp: {
|
|
200
|
-
vendor: vendor,
|
|
201
|
-
paymentMethod: paymentMethodString,
|
|
202
|
-
country: geoData?.country || "US",
|
|
203
|
-
redirectUrl: window.location.origin,
|
|
204
|
-
},
|
|
205
|
-
expectedDstAmount: anyspendQuote?.data?.currencyOut?.amount?.toString() || "0",
|
|
206
|
-
creatorAddress: globalAddress,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
catch (err) {
|
|
210
|
-
console.error(err);
|
|
211
|
-
sonner_1.toast.error("Failed to create order: " + err.message);
|
|
212
|
-
}
|
|
13
|
+
function AnySpendDepositHype({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, onSuccess, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, }) {
|
|
14
|
+
if (!recipientAddress)
|
|
15
|
+
return null;
|
|
16
|
+
const header = () => ((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" }) }) }));
|
|
17
|
+
// Create a modified B3_TOKEN with HYPE branding
|
|
18
|
+
const hypeToken = {
|
|
19
|
+
...anyspend_1.B3_TOKEN,
|
|
20
|
+
symbol: exports.HYPE_TOKEN_DETAILS.SYMBOL,
|
|
21
|
+
metadata: {
|
|
22
|
+
...anyspend_1.B3_TOKEN.metadata,
|
|
23
|
+
logoURI: exports.HYPE_TOKEN_DETAILS.LOGO_URI,
|
|
24
|
+
},
|
|
213
25
|
};
|
|
214
|
-
|
|
215
|
-
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.jsx)(OrderDetails_1.OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTxs: oat.data.relayTxs, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, cryptoPaymentMethod: paymentType === "fiat" ? CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE : selectedCryptoPaymentMethod, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onPaymentMethodChange: setSelectedCryptoPaymentMethod, onBack: () => {
|
|
216
|
-
setOrderId(undefined);
|
|
217
|
-
setActivePanel(useAnyspendFlow_1.PanelView.MAIN);
|
|
218
|
-
}, disableUrlParamManagement: true, points: oat.data.points || undefined })) }) }));
|
|
219
|
-
// Loading view
|
|
220
|
-
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..." }) }));
|
|
221
|
-
// Panel views
|
|
222
|
-
const recipientSelectionView = ((0, jsx_runtime_1.jsx)(RecipientSelection_1.RecipientSelection, { initialValue: selectedRecipientAddress || "", onBack: () => setActivePanel(useAnyspendFlow_1.PanelView.MAIN), onConfirm: address => {
|
|
223
|
-
setSelectedRecipientAddress(address);
|
|
224
|
-
setActivePanel(useAnyspendFlow_1.PanelView.MAIN);
|
|
225
|
-
} }));
|
|
226
|
-
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) => {
|
|
227
|
-
setSelectedCryptoPaymentMethod(method);
|
|
228
|
-
setActivePanel(useAnyspendFlow_1.PanelView.MAIN);
|
|
229
|
-
} }));
|
|
230
|
-
const fiatPaymentMethodView = ((0, jsx_runtime_1.jsx)(FiatPaymentMethod_1.FiatPaymentMethodComponent, { selectedPaymentMethod: selectedFiatPaymentMethod, setSelectedPaymentMethod: setSelectedFiatPaymentMethod, onBack: () => setActivePanel(useAnyspendFlow_1.PanelView.MAIN), onSelectPaymentMethod: (method) => {
|
|
231
|
-
setSelectedFiatPaymentMethod(method);
|
|
232
|
-
setActivePanel(useAnyspendFlow_1.PanelView.MAIN);
|
|
233
|
-
}, srcAmountOnRamp: srcAmount }));
|
|
234
|
-
const pointsDetailView = ((0, jsx_runtime_1.jsx)(PointsDetailPanel_1.PointsDetailPanel, { pointsAmount: anyspendQuote?.data?.pointsAmount || 0, onBack: () => setActivePanel(useAnyspendFlow_1.PanelView.MAIN) }));
|
|
235
|
-
const feeDetailView = anyspendQuote?.data?.fee ? ((0, jsx_runtime_1.jsx)(FeeDetailPanel_1.FeeDetailPanel, { fee: anyspendQuote.data.fee, transactionAmountUsd: paymentType === "fiat"
|
|
236
|
-
? parseFloat(srcAmount)
|
|
237
|
-
: anyspendQuote.data.currencyIn?.amountUsd
|
|
238
|
-
? Number(anyspendQuote.data.currencyIn.amountUsd)
|
|
239
|
-
: undefined, onBack: () => setActivePanel(useAnyspendFlow_1.PanelView.MAIN) })) : null;
|
|
240
|
-
// If showing token selection, render with panel transitions
|
|
241
|
-
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" &&
|
|
242
|
-
"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
|
|
243
|
-
? oat
|
|
244
|
-
? useAnyspendFlow_1.PanelView.ORDER_DETAILS
|
|
245
|
-
: useAnyspendFlow_1.PanelView.LOADING
|
|
246
|
-
: activePanel === useAnyspendFlow_1.PanelView.ORDER_DETAILS
|
|
247
|
-
? useAnyspendFlow_1.PanelView.MAIN
|
|
248
|
-
: activePanel, className: (0, cn_1.cn)("rounded-2xl", {
|
|
249
|
-
"mt-0": mode === "modal",
|
|
250
|
-
}), variants: {
|
|
251
|
-
enter: { x: 300, opacity: 0 },
|
|
252
|
-
center: { x: 0, opacity: 1 },
|
|
253
|
-
exit: { x: -300, opacity: 0 },
|
|
254
|
-
}, transition: { type: "spring", stiffness: 300, damping: 30 }, children: [
|
|
255
|
-
(0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)(mode === "page" && "p-6"), children: mainView }, "main-view"),
|
|
256
|
-
(0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)(mode === "page" && "p-6"), children: cryptoPaymentMethodView }, "crypto-payment-method-view"),
|
|
257
|
-
(0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)(mode === "page" && "p-6"), children: fiatPaymentMethodView }, "fiat-payment-method-view"),
|
|
258
|
-
(0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)(mode === "page" && "p-6"), children: recipientSelectionView }, "recipient-selection-view"),
|
|
259
|
-
(0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)(mode === "page" && "p-6"), children: orderDetailsView }, "order-details-view"),
|
|
260
|
-
(0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)(mode === "page" && "p-6"), children: loadingView }, "loading-view"),
|
|
261
|
-
(0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)(mode === "page" && "p-6"), children: pointsDetailView }, "points-detail-view"),
|
|
262
|
-
(0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)(mode === "page" && "p-6"), children: feeDetailView }, "fee-detail-view"),
|
|
263
|
-
] }) }) }));
|
|
26
|
+
return ((0, jsx_runtime_1.jsx)(AnySpendCustomExactIn_1.AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, paymentType: paymentType, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: sourceTokenChainId, destinationToken: hypeToken, destinationChainId: chains_1.base.id, orderType: "hype_duel", minDestinationAmount: 10, header: header, onSuccess: onSuccess, mainFooter: mainFooter, onTokenSelect: onTokenSelect, customUsdInputValues: customUsdInputValues, preferEoa: preferEoa }));
|
|
264
27
|
}
|
|
@@ -17,26 +17,19 @@ const ChainTokenIcon_1 = require("./ChainTokenIcon");
|
|
|
17
17
|
function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, address, chainId, setChainId, token, setToken, hideTokenSelect = false, canEditAmount = true, className, innerClassName, amountClassName, tokenSelectClassName, onTokenSelect, walletAddress, }) {
|
|
18
18
|
// Track previous token to detect changes
|
|
19
19
|
const prevTokenRef = (0, react_1.useRef)(token.address);
|
|
20
|
-
// Track if initial balance has been set
|
|
21
|
-
const initialBalanceSetRef = (0, react_1.useRef)(false);
|
|
22
20
|
// Only get token balance when context is "from" (for setting max amount)
|
|
23
21
|
const { rawBalance } = (0, react_2.useTokenBalance)({
|
|
24
22
|
token,
|
|
25
23
|
address: context === "from" && walletAddress ? walletAddress : undefined,
|
|
26
24
|
});
|
|
27
|
-
// Reset balance ref when token address or chain changes
|
|
28
|
-
(0, react_1.useEffect)(() => {
|
|
29
|
-
initialBalanceSetRef.current = false;
|
|
30
|
-
}, [token.address, token.chainId]);
|
|
31
25
|
(0, react_1.useEffect)(() => {
|
|
32
26
|
// Only handle "from" context
|
|
33
27
|
if (context !== "from")
|
|
34
28
|
return;
|
|
35
29
|
// Check if token changed or if this is the initial load with balance
|
|
36
30
|
const isTokenChanged = prevTokenRef.current !== token.address;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}, Initial: ${isInitialLoad}`);
|
|
31
|
+
if (isTokenChanged && rawBalance) {
|
|
32
|
+
console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}`);
|
|
40
33
|
// Calculate max amount with gas reserve for native tokens
|
|
41
34
|
let maxAmount;
|
|
42
35
|
if ((0, token_1.isNativeToken)(token.address)) {
|
|
@@ -52,7 +45,6 @@ function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, addres
|
|
|
52
45
|
onChangeInput((0, viem_1.formatUnits)(maxAmount, token.decimals));
|
|
53
46
|
// Update refs
|
|
54
47
|
prevTokenRef.current = token.address;
|
|
55
|
-
initialBalanceSetRef.current = true;
|
|
56
48
|
}
|
|
57
49
|
}, [token.address, token.chainId, token.decimals, chainId, context, onChangeInput, rawBalance]);
|
|
58
50
|
const handleTokenSelect = (newToken) => {
|
|
@@ -3,6 +3,7 @@ export { AnySpendBondKit } from "./AnySpendBondKit";
|
|
|
3
3
|
export { AnySpendBuySpin } from "./AnySpendBuySpin";
|
|
4
4
|
export { AnySpendCustom } from "./AnySpendCustom";
|
|
5
5
|
export { AnySpendCustomExactIn } from "./AnySpendCustomExactIn";
|
|
6
|
+
export { AnySpendDepositHype, HYPE_TOKEN_DETAILS } from "./AnyspendDepositHype";
|
|
6
7
|
export * from "./AnySpendFingerprintWrapper";
|
|
7
8
|
export { AnySpendNFT } from "./AnySpendNFT";
|
|
8
9
|
export { AnyspendSignatureMint } from "./AnyspendSignatureMint";
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WebviewOnrampPayment = exports.WebviewOnrampOrderStatus = exports.TransferCryptoDetails = exports.TokenBalance = exports.StepProgress = exports.RecipientSelection = exports.OrderTokenAmount = exports.OrderToken = exports.OrderStatus = exports.OrderHistoryItem = exports.OrderHistory = exports.OrderDetailsCollapsible = exports.OrderDetails = exports.CryptoReceiveSection = exports.CryptoPaySection = exports.ChainTokenIcon = exports.AnySpendNFTButton = exports.AnySpendTournament = exports.AnySpendStakeUpsideExactIn = exports.AnySpendStakeUpside = exports.AnySpendStakeB3ExactIn = exports.AnySpendStakeB3 = exports.AnyspendSignatureMint = exports.AnySpendNFT = exports.AnySpendCustomExactIn = exports.AnySpendCustom = exports.AnySpendBuySpin = exports.AnySpendBondKit = exports.AnySpend = void 0;
|
|
17
|
+
exports.WebviewOnrampPayment = exports.WebviewOnrampOrderStatus = exports.TransferCryptoDetails = exports.TokenBalance = exports.StepProgress = exports.RecipientSelection = exports.OrderTokenAmount = exports.OrderToken = exports.OrderStatus = exports.OrderHistoryItem = exports.OrderHistory = exports.OrderDetailsCollapsible = exports.OrderDetails = exports.CryptoReceiveSection = exports.CryptoPaySection = exports.ChainTokenIcon = exports.AnySpendNFTButton = exports.AnySpendTournament = exports.AnySpendStakeUpsideExactIn = exports.AnySpendStakeUpside = exports.AnySpendStakeB3ExactIn = exports.AnySpendStakeB3 = exports.AnyspendSignatureMint = exports.AnySpendNFT = exports.HYPE_TOKEN_DETAILS = exports.AnySpendDepositHype = exports.AnySpendCustomExactIn = exports.AnySpendCustom = exports.AnySpendBuySpin = exports.AnySpendBondKit = exports.AnySpend = void 0;
|
|
18
18
|
// Components
|
|
19
19
|
var AnySpend_1 = require("./AnySpend");
|
|
20
20
|
Object.defineProperty(exports, "AnySpend", { enumerable: true, get: function () { return AnySpend_1.AnySpend; } });
|
|
@@ -26,6 +26,9 @@ var AnySpendCustom_1 = require("./AnySpendCustom");
|
|
|
26
26
|
Object.defineProperty(exports, "AnySpendCustom", { enumerable: true, get: function () { return AnySpendCustom_1.AnySpendCustom; } });
|
|
27
27
|
var AnySpendCustomExactIn_1 = require("./AnySpendCustomExactIn");
|
|
28
28
|
Object.defineProperty(exports, "AnySpendCustomExactIn", { enumerable: true, get: function () { return AnySpendCustomExactIn_1.AnySpendCustomExactIn; } });
|
|
29
|
+
var AnyspendDepositHype_1 = require("./AnyspendDepositHype");
|
|
30
|
+
Object.defineProperty(exports, "AnySpendDepositHype", { enumerable: true, get: function () { return AnyspendDepositHype_1.AnySpendDepositHype; } });
|
|
31
|
+
Object.defineProperty(exports, "HYPE_TOKEN_DETAILS", { enumerable: true, get: function () { return AnyspendDepositHype_1.HYPE_TOKEN_DETAILS; } });
|
|
29
32
|
__exportStar(require("./AnySpendFingerprintWrapper"), exports);
|
|
30
33
|
var AnySpendNFT_1 = require("./AnySpendNFT");
|
|
31
34
|
Object.defineProperty(exports, "AnySpendNFT", { enumerable: true, get: function () { return AnySpendNFT_1.AnySpendNFT; } });
|
|
@@ -93,8 +93,12 @@ export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrd
|
|
|
93
93
|
setDstAmount: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
94
94
|
isSrcInputDirty: boolean;
|
|
95
95
|
setIsSrcInputDirty: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
96
|
+
cryptoPaymentMethod: CryptoPaymentMethodType;
|
|
97
|
+
setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
96
98
|
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
97
|
-
setSelectedCryptoPaymentMethod:
|
|
99
|
+
setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
100
|
+
effectiveCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
101
|
+
resetPaymentMethods: () => void;
|
|
98
102
|
selectedFiatPaymentMethod: FiatPaymentMethod;
|
|
99
103
|
setSelectedFiatPaymentMethod: import("react").Dispatch<import("react").SetStateAction<FiatPaymentMethod>>;
|
|
100
104
|
selectedRecipientAddress: string | undefined;
|
|
@@ -11,11 +11,12 @@ const react_3 = require("react");
|
|
|
11
11
|
const sonner_1 = require("sonner");
|
|
12
12
|
const viem_1 = require("viem");
|
|
13
13
|
const chains_1 = require("viem/chains");
|
|
14
|
-
const wagmi_1 = require("wagmi");
|
|
15
14
|
const CryptoPaymentMethod_1 = require("../components/common/CryptoPaymentMethod");
|
|
16
15
|
const FiatPaymentMethod_1 = require("../components/common/FiatPaymentMethod");
|
|
17
16
|
const useAutoSelectCryptoPaymentMethod_1 = require("./useAutoSelectCryptoPaymentMethod");
|
|
18
17
|
const useAutoSetActiveWalletFromWagmi_1 = require("./useAutoSetActiveWalletFromWagmi");
|
|
18
|
+
const useConnectedWalletDisplay_1 = require("./useConnectedWalletDisplay");
|
|
19
|
+
const useCryptoPaymentMethodState_1 = require("./useCryptoPaymentMethodState");
|
|
19
20
|
var PanelView;
|
|
20
21
|
(function (PanelView) {
|
|
21
22
|
PanelView[PanelView["MAIN"] = 0] = "MAIN";
|
|
@@ -41,17 +42,17 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
41
42
|
const defaultDstToken = anyspend_1.B3_TOKEN; // Default destination token
|
|
42
43
|
const [selectedSrcToken, setSelectedSrcToken] = (0, react_3.useState)(defaultSrcToken);
|
|
43
44
|
const [selectedDstToken, setSelectedDstToken] = (0, react_3.useState)(defaultDstToken);
|
|
44
|
-
const [srcAmount, setSrcAmount] = (0, react_3.useState)(paymentType === "fiat" ? "5" : "0
|
|
45
|
+
const [srcAmount, setSrcAmount] = (0, react_3.useState)(paymentType === "fiat" ? "5" : "0");
|
|
45
46
|
const [dstAmount, setDstAmount] = (0, react_3.useState)("");
|
|
46
47
|
const [isSrcInputDirty, setIsSrcInputDirty] = (0, react_3.useState)(true);
|
|
47
48
|
// Derive destination chain ID from token or prop (cannot change)
|
|
48
49
|
const selectedDstChainId = destinationTokenChainId || selectedDstToken.chainId;
|
|
49
|
-
// Payment method state
|
|
50
|
-
const
|
|
50
|
+
// Payment method state with dual-state system (auto + explicit user selection)
|
|
51
|
+
const { cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, effectiveCryptoPaymentMethod, resetPaymentMethods, } = (0, useCryptoPaymentMethodState_1.useCryptoPaymentMethodState)();
|
|
51
52
|
const [selectedFiatPaymentMethod, setSelectedFiatPaymentMethod] = (0, react_3.useState)(FiatPaymentMethod_1.FiatPaymentMethod.NONE);
|
|
52
53
|
// Recipient state
|
|
53
54
|
const { address: globalAddress } = (0, react_2.useAccountWallet)();
|
|
54
|
-
const {
|
|
55
|
+
const { walletAddress } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(effectiveCryptoPaymentMethod);
|
|
55
56
|
const [selectedRecipientAddress, setSelectedRecipientAddress] = (0, react_3.useState)(recipientAddress);
|
|
56
57
|
const recipientProfile = (0, react_2.useProfile)({ address: selectedRecipientAddress, fresh: true });
|
|
57
58
|
const recipientName = recipientProfile.data?.name;
|
|
@@ -66,7 +67,7 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
66
67
|
// Check token balance for crypto payments
|
|
67
68
|
const { rawBalance, isLoading: isBalanceLoading } = (0, react_2.useTokenBalance)({
|
|
68
69
|
token: selectedSrcToken,
|
|
69
|
-
address:
|
|
70
|
+
address: walletAddress,
|
|
70
71
|
});
|
|
71
72
|
// Check if user has enough balance
|
|
72
73
|
const hasEnoughBalance = (0, react_3.useMemo)(() => {
|
|
@@ -83,8 +84,9 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
83
84
|
// Auto-select crypto payment method based on available wallets and balance
|
|
84
85
|
(0, useAutoSelectCryptoPaymentMethod_1.useAutoSelectCryptoPaymentMethod)({
|
|
85
86
|
paymentType,
|
|
87
|
+
cryptoPaymentMethod,
|
|
88
|
+
setCryptoPaymentMethod,
|
|
86
89
|
selectedCryptoPaymentMethod,
|
|
87
|
-
setSelectedCryptoPaymentMethod,
|
|
88
90
|
hasEnoughBalance,
|
|
89
91
|
isBalanceLoading,
|
|
90
92
|
});
|
|
@@ -184,9 +186,9 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
184
186
|
if (!disableUrlParamManagement) {
|
|
185
187
|
const params = new URLSearchParams(searchParams.toString()); // Preserve existing params
|
|
186
188
|
params.set("orderId", newOrderId);
|
|
187
|
-
if (
|
|
188
|
-
console.log("Setting cryptoPaymentMethod in URL:",
|
|
189
|
-
params.set("cryptoPaymentMethod",
|
|
189
|
+
if (effectiveCryptoPaymentMethod !== CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
190
|
+
console.log("Setting cryptoPaymentMethod in URL:", effectiveCryptoPaymentMethod);
|
|
191
|
+
params.set("cryptoPaymentMethod", effectiveCryptoPaymentMethod);
|
|
190
192
|
}
|
|
191
193
|
else {
|
|
192
194
|
console.log("Payment method is NONE, not setting in URL");
|
|
@@ -250,8 +252,12 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
250
252
|
isSrcInputDirty,
|
|
251
253
|
setIsSrcInputDirty,
|
|
252
254
|
// Payment methods
|
|
255
|
+
cryptoPaymentMethod,
|
|
256
|
+
setCryptoPaymentMethod,
|
|
253
257
|
selectedCryptoPaymentMethod,
|
|
254
258
|
setSelectedCryptoPaymentMethod,
|
|
259
|
+
effectiveCryptoPaymentMethod,
|
|
260
|
+
resetPaymentMethods,
|
|
255
261
|
selectedFiatPaymentMethod,
|
|
256
262
|
setSelectedFiatPaymentMethod,
|
|
257
263
|
// Recipient
|
|
@@ -2,10 +2,12 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
|
|
|
2
2
|
interface UseAutoSelectCryptoPaymentMethodParams {
|
|
3
3
|
/** Current payment type (crypto or fiat) */
|
|
4
4
|
paymentType?: "crypto" | "fiat";
|
|
5
|
-
/**
|
|
5
|
+
/** Auto-selected payment method based on balance (not used in hook logic, but part of state management) */
|
|
6
|
+
cryptoPaymentMethod: CryptoPaymentMethodType;
|
|
7
|
+
/** Function to update the auto-selected payment method */
|
|
8
|
+
setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
9
|
+
/** User explicitly selected payment method (NONE means no explicit selection) */
|
|
6
10
|
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
7
|
-
/** Function to update the selected payment method */
|
|
8
|
-
setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
9
11
|
/** Whether user has enough balance to pay */
|
|
10
12
|
hasEnoughBalance: boolean;
|
|
11
13
|
/** Whether balance is still loading */
|
|
@@ -16,11 +18,11 @@ interface UseAutoSelectCryptoPaymentMethodParams {
|
|
|
16
18
|
* based on available wallets and balance.
|
|
17
19
|
*
|
|
18
20
|
* Auto-selection logic:
|
|
19
|
-
* - Only auto-selects when
|
|
21
|
+
* - Only auto-selects when selectedCryptoPaymentMethod is NONE (user hasn't explicitly chosen)
|
|
20
22
|
* - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
|
|
21
23
|
* - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
|
|
22
24
|
* - If only Global wallet available → GLOBAL_WALLET
|
|
23
25
|
* - If no wallets → remains NONE
|
|
24
26
|
*/
|
|
25
|
-
export declare function useAutoSelectCryptoPaymentMethod({ paymentType,
|
|
27
|
+
export declare function useAutoSelectCryptoPaymentMethod({ paymentType, cryptoPaymentMethod: _cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }: UseAutoSelectCryptoPaymentMethodParams): void;
|
|
26
28
|
export {};
|
|
@@ -9,18 +9,22 @@ const useConnectedWalletDisplay_1 = require("./useConnectedWalletDisplay");
|
|
|
9
9
|
* based on available wallets and balance.
|
|
10
10
|
*
|
|
11
11
|
* Auto-selection logic:
|
|
12
|
-
* - Only auto-selects when
|
|
12
|
+
* - Only auto-selects when selectedCryptoPaymentMethod is NONE (user hasn't explicitly chosen)
|
|
13
13
|
* - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
|
|
14
14
|
* - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
|
|
15
15
|
* - If only Global wallet available → GLOBAL_WALLET
|
|
16
16
|
* - If no wallets → remains NONE
|
|
17
17
|
*/
|
|
18
|
-
function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto",
|
|
18
|
+
function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto", cryptoPaymentMethod: _cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }) {
|
|
19
19
|
// Get suggested payment method based on available wallets
|
|
20
20
|
const { suggestedPaymentMethod } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(selectedCryptoPaymentMethod);
|
|
21
21
|
(0, react_1.useEffect)(() => {
|
|
22
|
-
// Only auto-select when on crypto payment type
|
|
23
|
-
if (paymentType !== "crypto"
|
|
22
|
+
// Only auto-select when on crypto payment type
|
|
23
|
+
if (paymentType !== "crypto") {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// Only auto-switch if user hasn't explicitly selected a payment method
|
|
27
|
+
if (selectedCryptoPaymentMethod !== CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
24
28
|
return;
|
|
25
29
|
}
|
|
26
30
|
// If we have a suggested payment method (wallet is connected), use it
|
|
@@ -29,28 +33,28 @@ function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto", selectedCryp
|
|
|
29
33
|
// Otherwise, default to TRANSFER_CRYPTO if balance is insufficient
|
|
30
34
|
if (!isBalanceLoading) {
|
|
31
35
|
if (hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
32
|
-
|
|
36
|
+
setCryptoPaymentMethod(CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET);
|
|
33
37
|
}
|
|
34
38
|
else if (!hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
35
39
|
// Wallet connected but insufficient balance - suggest transfer
|
|
36
|
-
|
|
40
|
+
setCryptoPaymentMethod(CryptoPaymentMethod_1.CryptoPaymentMethodType.TRANSFER_CRYPTO);
|
|
37
41
|
}
|
|
38
42
|
else {
|
|
39
43
|
// Use suggested method (e.g., GLOBAL_WALLET)
|
|
40
|
-
|
|
44
|
+
setCryptoPaymentMethod(suggestedPaymentMethod);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
else {
|
|
44
48
|
// Balance still loading, use suggested method
|
|
45
|
-
|
|
49
|
+
setCryptoPaymentMethod(suggestedPaymentMethod);
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
52
|
}, [
|
|
49
53
|
paymentType,
|
|
54
|
+
setCryptoPaymentMethod,
|
|
50
55
|
selectedCryptoPaymentMethod,
|
|
51
56
|
suggestedPaymentMethod,
|
|
52
57
|
hasEnoughBalance,
|
|
53
58
|
isBalanceLoading,
|
|
54
|
-
setSelectedCryptoPaymentMethod,
|
|
55
59
|
]);
|
|
56
60
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
2
|
+
interface UseCryptoPaymentMethodStateResult {
|
|
3
|
+
/** Auto-selected payment method based on balance */
|
|
4
|
+
cryptoPaymentMethod: CryptoPaymentMethodType;
|
|
5
|
+
/** Function to update the auto-selected payment method */
|
|
6
|
+
setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
7
|
+
/** User explicitly selected payment method (NONE means no explicit selection) */
|
|
8
|
+
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
9
|
+
/** Function to update the user-selected payment method */
|
|
10
|
+
setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
11
|
+
/** Effective payment method (user selection takes priority over auto-selection) */
|
|
12
|
+
effectiveCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
13
|
+
/** Reset both payment method states to NONE */
|
|
14
|
+
resetPaymentMethods: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Custom hook to manage crypto payment method state with dual-state system:
|
|
18
|
+
*
|
|
19
|
+
* - `cryptoPaymentMethod`: Auto-selected based on wallet availability and balance
|
|
20
|
+
* - `selectedCryptoPaymentMethod`: Explicitly selected by user
|
|
21
|
+
* - `effectiveCryptoPaymentMethod`: User selection takes priority over auto-selection
|
|
22
|
+
*
|
|
23
|
+
* This allows automatic payment method suggestions while respecting explicit user choices.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* const {
|
|
28
|
+
* cryptoPaymentMethod,
|
|
29
|
+
* setCryptoPaymentMethod,
|
|
30
|
+
* selectedCryptoPaymentMethod,
|
|
31
|
+
* setSelectedCryptoPaymentMethod,
|
|
32
|
+
* effectiveCryptoPaymentMethod,
|
|
33
|
+
* resetPaymentMethods
|
|
34
|
+
* } = useCryptoPaymentMethodState();
|
|
35
|
+
*
|
|
36
|
+
* // Use effectiveCryptoPaymentMethod for display
|
|
37
|
+
* // Use setSelectedCryptoPaymentMethod when user explicitly selects
|
|
38
|
+
* // Call resetPaymentMethods when switching tabs or going back
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function useCryptoPaymentMethodState(): UseCryptoPaymentMethodStateResult;
|
|
42
|
+
export {};
|