@b3dotfun/sdk 0.0.28 → 0.0.29-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/abis/escrow.d.ts +987 -0
- package/dist/cjs/anyspend/abis/escrow.js +1275 -0
- package/dist/cjs/anyspend/react/components/AnySpend.js +10 -168
- package/dist/cjs/anyspend/react/components/AnySpendBondKit.d.ts +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +23 -24
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +2 -2
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +10 -0
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +263 -0
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +17 -0
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +53 -0
- package/dist/cjs/anyspend/react/components/common/ErrorSection.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/common/ErrorSection.js +12 -0
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +2 -2
- package/dist/cjs/anyspend/react/components/common/PaySection.d.ts +20 -0
- package/dist/cjs/anyspend/react/components/common/PaySection.js +58 -0
- package/dist/cjs/anyspend/react/components/common/TabSection.d.ts +10 -0
- package/dist/cjs/anyspend/react/components/common/TabSection.js +18 -0
- package/dist/cjs/anyspend/react/components/index.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/index.js +5 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +165 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +184 -0
- package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +2 -2
- package/dist/cjs/bondkit/abis/BondkitTokenABI.d.ts +2 -5
- package/dist/cjs/bondkit/abis/BondkitTokenABI.js +2 -3
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +3 -0
- package/dist/cjs/global-account/react/components/custom/Button.d.ts +1 -1
- package/dist/cjs/global-account/react/components/ui/button.d.ts +1 -1
- package/dist/cjs/global-account/react/components/ui/command.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useSiwe.native.d.ts +4 -0
- package/dist/cjs/global-account/react/hooks/useSiwe.native.js +40 -0
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +19 -3
- package/dist/cjs/shared/constants/chains/b3Chain.d.ts +1 -1
- package/dist/cjs/shared/constants/chains/supported.d.ts +3 -3
- package/dist/esm/anyspend/abis/escrow.d.ts +987 -0
- package/dist/esm/anyspend/abis/escrow.js +1272 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +12 -170
- package/dist/esm/anyspend/react/components/AnySpendBondKit.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnySpendBondKit.js +23 -24
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -3
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +10 -0
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +257 -0
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +17 -0
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +50 -0
- package/dist/esm/anyspend/react/components/common/ErrorSection.d.ts +6 -0
- package/dist/esm/anyspend/react/components/common/ErrorSection.js +9 -0
- package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +2 -2
- package/dist/esm/anyspend/react/components/common/PaySection.d.ts +20 -0
- package/dist/esm/anyspend/react/components/common/PaySection.js +55 -0
- package/dist/esm/anyspend/react/components/common/TabSection.d.ts +10 -0
- package/dist/esm/anyspend/react/components/common/TabSection.js +15 -0
- package/dist/esm/anyspend/react/components/index.d.ts +2 -0
- package/dist/esm/anyspend/react/components/index.js +2 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +165 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +180 -0
- package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +2 -2
- package/dist/esm/bondkit/abis/BondkitTokenABI.d.ts +2 -5
- package/dist/esm/bondkit/abis/BondkitTokenABI.js +2 -3
- package/dist/esm/global-account/react/components/B3DynamicModal.js +3 -0
- package/dist/esm/global-account/react/components/custom/Button.d.ts +1 -1
- package/dist/esm/global-account/react/components/ui/button.d.ts +1 -1
- package/dist/esm/global-account/react/components/ui/command.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useSiwe.native.d.ts +4 -0
- package/dist/esm/global-account/react/hooks/useSiwe.native.js +34 -0
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +19 -3
- package/dist/esm/shared/constants/chains/b3Chain.d.ts +1 -1
- package/dist/esm/shared/constants/chains/supported.d.ts +3 -3
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/abis/escrow.d.ts +987 -0
- package/dist/types/anyspend/react/components/AnySpendBondKit.d.ts +1 -1
- package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +10 -0
- package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +17 -0
- package/dist/types/anyspend/react/components/common/ErrorSection.d.ts +6 -0
- package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
- package/dist/types/anyspend/react/components/common/PaySection.d.ts +20 -0
- package/dist/types/anyspend/react/components/common/TabSection.d.ts +10 -0
- package/dist/types/anyspend/react/components/index.d.ts +2 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +165 -0
- package/dist/types/anyspend/react/hooks/useSigMint.d.ts +2 -2
- package/dist/types/bondkit/abis/BondkitTokenABI.d.ts +2 -5
- package/dist/types/global-account/react/components/custom/Button.d.ts +1 -1
- package/dist/types/global-account/react/components/ui/button.d.ts +1 -1
- package/dist/types/global-account/react/components/ui/command.d.ts +2 -2
- package/dist/types/global-account/react/hooks/useSiwe.native.d.ts +4 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +19 -3
- package/dist/types/shared/constants/chains/b3Chain.d.ts +1 -1
- package/dist/types/shared/constants/chains/supported.d.ts +3 -3
- package/package.json +13 -1
- package/src/anyspend/abis/escrow.ts +1272 -0
- package/src/anyspend/react/components/AnySpend.tsx +48 -389
- package/src/anyspend/react/components/AnySpendBondKit.tsx +28 -28
- package/src/anyspend/react/components/AnySpendCustom.tsx +2 -10
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +525 -0
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +152 -0
- package/src/anyspend/react/components/common/ErrorSection.tsx +21 -0
- package/src/anyspend/react/components/common/PanelOnramp.tsx +4 -2
- package/src/anyspend/react/components/common/PaySection.tsx +222 -0
- package/src/anyspend/react/components/common/TabSection.tsx +58 -0
- package/src/anyspend/react/components/index.ts +2 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +226 -0
- package/src/bondkit/abis/BondkitTokenABI.ts +2 -3
- package/src/global-account/react/components/B3DynamicModal.tsx +3 -0
- package/src/global-account/react/hooks/useSiwe.native.tsx +40 -0
- package/src/global-account/react/stores/useModalStore.ts +21 -3
- package/dist/cjs/anyspend/abis/bondKit.d.ts +0 -35
- package/dist/cjs/anyspend/abis/bondKit.js +0 -29
- package/dist/esm/anyspend/abis/bondKit.d.ts +0 -35
- package/dist/esm/anyspend/abis/bondKit.js +0 -26
- package/dist/types/anyspend/abis/bondKit.d.ts +0 -35
- package/src/anyspend/abis/bondKit.ts +0 -26
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { B3_TOKEN } from "../../../anyspend/index.js";
|
|
3
|
+
import { Button, ShinyButton, StyleRoot, TransitionPanel } from "../../../global-account/react/index.js";
|
|
4
|
+
import { cn } from "../../../shared/utils/cn.js";
|
|
5
|
+
import invariant from "invariant";
|
|
6
|
+
import { motion } from "motion/react";
|
|
7
|
+
import { useMemo } from "react";
|
|
8
|
+
import { toast } from "sonner";
|
|
9
|
+
import { encodeFunctionData } from "viem";
|
|
10
|
+
import { base } from "viem/chains";
|
|
11
|
+
import { PanelView, useAnyspendFlow } from "../hooks/useAnyspendFlow.js";
|
|
12
|
+
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
|
|
13
|
+
import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod.js";
|
|
14
|
+
import { CryptoReceiveSection } from "./common/CryptoReceiveSection.js";
|
|
15
|
+
import { ErrorSection } from "./common/ErrorSection.js";
|
|
16
|
+
import { FiatPaymentMethod, FiatPaymentMethodComponent } from "./common/FiatPaymentMethod.js";
|
|
17
|
+
import { OrderDetails } from "./common/OrderDetails.js";
|
|
18
|
+
import { OrderStatus } from "./common/OrderStatus.js";
|
|
19
|
+
import { PaySection } from "./common/PaySection.js";
|
|
20
|
+
import { RecipientSelection } from "./common/RecipientSelection.js";
|
|
21
|
+
import { ESCROW_ABI } from "../../../anyspend/abis/escrow.js";
|
|
22
|
+
import { ArrowDown } from "lucide-react";
|
|
23
|
+
import { PanelOnramp } from "./common/PanelOnramp.js";
|
|
24
|
+
function generateEncodedDataForDepositHype(amount, beneficiary) {
|
|
25
|
+
invariant(BigInt(amount) > 0, "Amount must be greater than zero");
|
|
26
|
+
const encodedData = encodeFunctionData({
|
|
27
|
+
abi: ESCROW_ABI,
|
|
28
|
+
functionName: "depositFor",
|
|
29
|
+
args: [beneficiary, B3_TOKEN.address, BigInt(amount)],
|
|
30
|
+
});
|
|
31
|
+
return encodedData;
|
|
32
|
+
}
|
|
33
|
+
export function AnySpendDepositHype(props) {
|
|
34
|
+
const fingerprintConfig = getFingerprintConfig();
|
|
35
|
+
return (_jsx(AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: _jsx(AnySpendDepositHypeInner, { ...props }) }));
|
|
36
|
+
}
|
|
37
|
+
function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, onSuccess, depositContractAddress, }) {
|
|
38
|
+
// Use shared flow hook
|
|
39
|
+
const { activePanel, setActivePanel, orderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, dstAmount, setIsSrcInputDirty, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, anyspendQuote, isLoadingAnyspendQuote, getAnyspendQuoteError, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = useAnyspendFlow({
|
|
40
|
+
paymentType,
|
|
41
|
+
recipientAddress,
|
|
42
|
+
loadOrder,
|
|
43
|
+
isDepositMode: true,
|
|
44
|
+
onTransactionSuccess: onSuccess,
|
|
45
|
+
sourceTokenAddress,
|
|
46
|
+
sourceTokenChainId,
|
|
47
|
+
});
|
|
48
|
+
// Button state logic
|
|
49
|
+
const btnInfo = useMemo(() => {
|
|
50
|
+
if (activeInputAmountInWei === "0")
|
|
51
|
+
return { text: "Enter an amount", disable: true, error: false };
|
|
52
|
+
if (isLoadingAnyspendQuote)
|
|
53
|
+
return { text: "Loading quote...", disable: true, error: false };
|
|
54
|
+
if (isCreatingOrder || isCreatingOnrampOrder)
|
|
55
|
+
return { text: "Creating order...", disable: true, error: false };
|
|
56
|
+
if (!selectedRecipientAddress)
|
|
57
|
+
return { text: "Select recipient", disable: false, error: false };
|
|
58
|
+
if (!anyspendQuote || !anyspendQuote.success)
|
|
59
|
+
return { text: "Get quote error", disable: true, error: true };
|
|
60
|
+
if (!dstAmount)
|
|
61
|
+
return { text: "No quote available", disable: true, error: true };
|
|
62
|
+
// Check minimum deposit amount (10 HYPE)
|
|
63
|
+
// Use the raw amount from the quote instead of the formatted display string
|
|
64
|
+
if (anyspendQuote.data?.currencyOut?.amount && anyspendQuote.data.currencyOut.currency?.decimals) {
|
|
65
|
+
const rawAmountInWei = anyspendQuote.data.currencyOut.amount;
|
|
66
|
+
const decimals = anyspendQuote.data.currencyOut.currency.decimals;
|
|
67
|
+
const actualAmount = parseFloat(rawAmountInWei) / Math.pow(10, decimals);
|
|
68
|
+
if (actualAmount < 10) {
|
|
69
|
+
return { text: "Minimum 10 HYPE deposit", disable: true, error: true };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (paymentType === "crypto") {
|
|
73
|
+
if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
74
|
+
return { text: "Choose payment method", disable: false, error: false };
|
|
75
|
+
}
|
|
76
|
+
return { text: "Continue to deposit", disable: false, error: false };
|
|
77
|
+
}
|
|
78
|
+
if (paymentType === "fiat") {
|
|
79
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod.NONE) {
|
|
80
|
+
return { text: "Select payment method", disable: false, error: false };
|
|
81
|
+
}
|
|
82
|
+
return { text: "Buy", disable: false, error: false };
|
|
83
|
+
}
|
|
84
|
+
return { text: "Continue to deposit", disable: false, error: false };
|
|
85
|
+
}, [
|
|
86
|
+
activeInputAmountInWei,
|
|
87
|
+
isLoadingAnyspendQuote,
|
|
88
|
+
isCreatingOrder,
|
|
89
|
+
isCreatingOnrampOrder,
|
|
90
|
+
selectedRecipientAddress,
|
|
91
|
+
anyspendQuote,
|
|
92
|
+
dstAmount,
|
|
93
|
+
paymentType,
|
|
94
|
+
selectedCryptoPaymentMethod,
|
|
95
|
+
selectedFiatPaymentMethod,
|
|
96
|
+
]);
|
|
97
|
+
const onMainButtonClick = async () => {
|
|
98
|
+
if (btnInfo.disable)
|
|
99
|
+
return;
|
|
100
|
+
if (!selectedRecipientAddress) {
|
|
101
|
+
setActivePanel(PanelView.RECIPIENT_SELECTION);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (paymentType === "crypto") {
|
|
105
|
+
if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
106
|
+
setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
await handleCryptoOrder();
|
|
110
|
+
}
|
|
111
|
+
else if (paymentType === "fiat") {
|
|
112
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod.NONE) {
|
|
113
|
+
setActivePanel(PanelView.FIAT_PAYMENT_METHOD);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
await handleFiatOrder();
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
// Handle crypto order creation
|
|
120
|
+
const handleCryptoOrder = async () => {
|
|
121
|
+
try {
|
|
122
|
+
invariant(anyspendQuote, "Relay price is not found");
|
|
123
|
+
invariant(selectedRecipientAddress, "Recipient address is not found");
|
|
124
|
+
invariant(depositContractAddress, "Deposit contract address is not found");
|
|
125
|
+
const srcAmountBigInt = BigInt(activeInputAmountInWei);
|
|
126
|
+
const depositAmountWei = anyspendQuote.data?.currencyOut?.amount || "0";
|
|
127
|
+
const encodedData = generateEncodedDataForDepositHype(depositAmountWei, selectedRecipientAddress);
|
|
128
|
+
createOrder({
|
|
129
|
+
recipientAddress: selectedRecipientAddress,
|
|
130
|
+
orderType: "custom",
|
|
131
|
+
srcChain: selectedSrcChainId,
|
|
132
|
+
dstChain: base.id,
|
|
133
|
+
srcToken: selectedSrcToken,
|
|
134
|
+
dstToken: B3_TOKEN,
|
|
135
|
+
srcAmount: srcAmountBigInt.toString(),
|
|
136
|
+
creatorAddress: globalAddress,
|
|
137
|
+
payload: {
|
|
138
|
+
amount: depositAmountWei,
|
|
139
|
+
data: encodedData,
|
|
140
|
+
to: depositContractAddress,
|
|
141
|
+
action: "deposit HYPE",
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
console.error(err);
|
|
147
|
+
toast.error("Failed to create order: " + err.message);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
// Handle fiat order creation
|
|
151
|
+
const handleFiatOrder = async () => {
|
|
152
|
+
try {
|
|
153
|
+
invariant(anyspendQuote, "Relay price is not found");
|
|
154
|
+
invariant(selectedRecipientAddress, "Recipient address is not found");
|
|
155
|
+
invariant(depositContractAddress, "Deposit contract address is not found");
|
|
156
|
+
if (!srcAmount || parseFloat(srcAmount) <= 0) {
|
|
157
|
+
toast.error("Please enter a valid amount");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
// Determine vendor and payment method string
|
|
161
|
+
let vendor;
|
|
162
|
+
let paymentMethodString = "";
|
|
163
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod.COINBASE_PAY) {
|
|
164
|
+
if (coinbaseAvailablePaymentMethods.length === 0) {
|
|
165
|
+
toast.error("Coinbase Pay not available");
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
vendor = "coinbase";
|
|
169
|
+
paymentMethodString = coinbaseAvailablePaymentMethods[0]?.id || "";
|
|
170
|
+
}
|
|
171
|
+
else if (selectedFiatPaymentMethod === FiatPaymentMethod.STRIPE) {
|
|
172
|
+
if (!stripeWeb2Support || !stripeWeb2Support.isSupport) {
|
|
173
|
+
toast.error("Stripe not available");
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
vendor = "stripe-web2";
|
|
177
|
+
paymentMethodString = "";
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
toast.error("Please select a payment method");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const depositAmountWei = anyspendQuote.data?.currencyOut?.amount || "0";
|
|
184
|
+
const encodedData = generateEncodedDataForDepositHype(depositAmountWei, selectedRecipientAddress);
|
|
185
|
+
createOnrampOrder({
|
|
186
|
+
recipientAddress: selectedRecipientAddress,
|
|
187
|
+
orderType: "custom",
|
|
188
|
+
dstChain: base.id,
|
|
189
|
+
dstToken: B3_TOKEN,
|
|
190
|
+
srcFiatAmount: srcAmount,
|
|
191
|
+
onramp: {
|
|
192
|
+
vendor: vendor,
|
|
193
|
+
paymentMethod: paymentMethodString,
|
|
194
|
+
country: geoData?.country || "US",
|
|
195
|
+
redirectUrl: window.location.origin,
|
|
196
|
+
},
|
|
197
|
+
expectedDstAmount: anyspendQuote?.data?.currencyOut?.amount?.toString() || "0",
|
|
198
|
+
creatorAddress: globalAddress,
|
|
199
|
+
payload: {
|
|
200
|
+
amount: depositAmountWei,
|
|
201
|
+
data: encodedData,
|
|
202
|
+
to: depositContractAddress,
|
|
203
|
+
action: "deposit HYPE",
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
console.error(err);
|
|
209
|
+
toast.error("Failed to create order: " + err.message);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
// Order details view
|
|
213
|
+
const orderDetailsView = (_jsx("div", { className: "mx-auto w-[460px] max-w-full", children: _jsx("div", { className: "relative flex flex-col gap-4", children: oat && (_jsxs(_Fragment, { children: [_jsx(OrderStatus, { order: oat.data.order }), _jsx(OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTx: oat.data.relayTx, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, cryptoPaymentMethod: paymentType === "fiat" ? CryptoPaymentMethodType.NONE : selectedCryptoPaymentMethod, onBack: () => {
|
|
214
|
+
setActivePanel(PanelView.MAIN);
|
|
215
|
+
onSuccess?.();
|
|
216
|
+
} })] })) }) }));
|
|
217
|
+
// Loading view
|
|
218
|
+
const loadingView = (_jsx("div", { className: "mx-auto flex w-full flex-col items-center gap-4 p-5", children: _jsx("div", { className: "text-as-primary", children: "Loading order details..." }) }));
|
|
219
|
+
// Panel views
|
|
220
|
+
const recipientSelectionView = (_jsx(RecipientSelection, { initialValue: selectedRecipientAddress || "", onBack: () => setActivePanel(PanelView.MAIN), onConfirm: address => {
|
|
221
|
+
setSelectedRecipientAddress(address);
|
|
222
|
+
setActivePanel(PanelView.MAIN);
|
|
223
|
+
} }));
|
|
224
|
+
const cryptoPaymentMethodView = (_jsx(CryptoPaymentMethod, { globalAddress: globalAddress, globalWallet: undefined, selectedPaymentMethod: selectedCryptoPaymentMethod, setSelectedPaymentMethod: setSelectedCryptoPaymentMethod, isCreatingOrder: isCreatingOrder, onBack: () => setActivePanel(PanelView.MAIN), onSelectPaymentMethod: (method) => {
|
|
225
|
+
setSelectedCryptoPaymentMethod(method);
|
|
226
|
+
setActivePanel(PanelView.MAIN);
|
|
227
|
+
} }));
|
|
228
|
+
const fiatPaymentMethodView = (_jsx(FiatPaymentMethodComponent, { selectedPaymentMethod: selectedFiatPaymentMethod, setSelectedPaymentMethod: setSelectedFiatPaymentMethod, onBack: () => setActivePanel(PanelView.MAIN), onSelectPaymentMethod: (method) => {
|
|
229
|
+
setSelectedFiatPaymentMethod(method);
|
|
230
|
+
setActivePanel(PanelView.MAIN);
|
|
231
|
+
}, srcAmountOnRamp: srcAmount }));
|
|
232
|
+
// If showing token selection, render with panel transitions
|
|
233
|
+
return (_jsx(StyleRoot, { children: _jsx("div", { className: cn("anyspend-container font-inter mx-auto w-full max-w-[460px]", mode === "page" &&
|
|
234
|
+
"bg-as-surface-primary border-as-border-secondary overflow-hidden rounded-2xl border shadow-xl"), children: _jsx(TransitionPanel, { activeIndex: orderId
|
|
235
|
+
? oat
|
|
236
|
+
? PanelView.ORDER_DETAILS
|
|
237
|
+
: PanelView.LOADING
|
|
238
|
+
: activePanel === PanelView.ORDER_DETAILS
|
|
239
|
+
? PanelView.MAIN
|
|
240
|
+
: activePanel, className: cn("rounded-2xl", {
|
|
241
|
+
"mt-0": mode === "modal",
|
|
242
|
+
}), variants: {
|
|
243
|
+
enter: { x: 300, opacity: 0 },
|
|
244
|
+
center: { x: 0, opacity: 1 },
|
|
245
|
+
exit: { x: -300, opacity: 0 },
|
|
246
|
+
}, transition: { type: "spring", stiffness: 300, damping: 30 }, children: [
|
|
247
|
+
_jsx("div", { className: cn(mode === "page" && "p-6"), children: _jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [_jsx("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: _jsx("div", { children: _jsx("h1", { className: "text-as-primary text-xl font-bold", children: paymentType === "crypto" ? "Deposit Crypto" : "Fund with Fiat" }) }) }), _jsx("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [paymentType === "crypto" ? (_jsx(PaySection, { paymentType: "crypto", selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, selectedFiatPaymentMethod: selectedFiatPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), onSelectFiatPaymentMethod: () => setActivePanel(PanelView.FIAT_PAYMENT_METHOD), anyspendQuote: anyspendQuote })) : (_jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, children: _jsx(PanelOnramp, { srcAmountOnRamp: srcAmount, setSrcAmountOnRamp: setSrcAmount, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: recipientAddress, destinationToken: B3_TOKEN, destinationChainId: base.id, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD }) })), _jsx(Button, { variant: "ghost", className: cn("swap-direction-button border-as-stroke bg-as-surface-primary absolute left-1/2 top-[calc(50%+56px)] z-10 h-10 w-10 -translate-x-1/2 -translate-y-1/2 cursor-default rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl", paymentType === "fiat" && "hidden"), children: _jsx("div", { className: "relative flex items-center justify-center transition-opacity", children: _jsx(ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }), paymentType === "crypto" && (_jsx(CryptoReceiveSection, { isDepositMode: false, isBuyMode: true, selectedRecipientAddress: recipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(PanelView.RECIPIENT_SELECTION), dstAmount: dstAmount, dstToken: B3_TOKEN, selectedDstChainId: base.id, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, onChangeDstAmount: value => {
|
|
248
|
+
setIsSrcInputDirty(false);
|
|
249
|
+
setSrcAmount(value);
|
|
250
|
+
}, anyspendQuote: anyspendQuote }))] }) }), _jsx(ErrorSection, { error: getAnyspendQuoteError }), _jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: cn("mt-4 flex w-full max-w-[460px] flex-col gap-2", getAnyspendQuoteError && "mt-0"), children: _jsx(ShinyButton, { accentColor: "hsl(var(--as-brand))", disabled: btnInfo.disable, onClick: onMainButtonClick, className: cn("as-main-button relative w-full", btnInfo.error ? "!bg-as-red" : btnInfo.disable ? "!bg-as-on-surface-2" : "!bg-as-brand"), textClassName: cn(btnInfo.error ? "text-white" : btnInfo.disable ? "text-as-secondary" : "text-white"), children: btnInfo.text }) })] }) }, "main-view"),
|
|
251
|
+
_jsx("div", { className: cn(mode === "page" && "p-6"), children: cryptoPaymentMethodView }, "crypto-payment-method-view"),
|
|
252
|
+
_jsx("div", { className: cn(mode === "page" && "p-6"), children: fiatPaymentMethodView }, "fiat-payment-method-view"),
|
|
253
|
+
_jsx("div", { className: cn(mode === "page" && "p-6"), children: recipientSelectionView }, "recipient-selection-view"),
|
|
254
|
+
_jsx("div", { className: cn(mode === "page" && "p-6"), children: orderDetailsView }, "order-details-view"),
|
|
255
|
+
_jsx("div", { className: cn(mode === "page" && "p-6"), children: loadingView }, "loading-view"),
|
|
256
|
+
] }) }) }));
|
|
257
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { components } from "../../../types/api";
|
|
2
|
+
interface CryptoReceiveSectionProps {
|
|
3
|
+
isDepositMode?: boolean;
|
|
4
|
+
isBuyMode?: boolean;
|
|
5
|
+
selectedRecipientAddress?: string;
|
|
6
|
+
recipientName?: string;
|
|
7
|
+
onSelectRecipient: () => void;
|
|
8
|
+
dstAmount: string;
|
|
9
|
+
dstToken: components["schemas"]["Token"];
|
|
10
|
+
selectedDstChainId?: number;
|
|
11
|
+
setSelectedDstChainId?: (chainId: number) => void;
|
|
12
|
+
setSelectedDstToken?: (token: components["schemas"]["Token"]) => void;
|
|
13
|
+
onChangeDstAmount?: (value: string) => void;
|
|
14
|
+
anyspendQuote?: any;
|
|
15
|
+
}
|
|
16
|
+
export declare function CryptoReceiveSection({ isDepositMode, isBuyMode, selectedRecipientAddress, recipientName, onSelectRecipient, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, onChangeDstAmount, anyspendQuote, }: CryptoReceiveSectionProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { formatUsername } from "../../../../shared/utils/index.js";
|
|
3
|
+
import { cn } from "../../../../shared/utils/cn.js";
|
|
4
|
+
import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
|
|
5
|
+
import { formatDisplayNumber } from "../../../../shared/utils/number.js";
|
|
6
|
+
import { ChevronRight } from "lucide-react";
|
|
7
|
+
import { motion } from "motion/react";
|
|
8
|
+
import { OrderTokenAmount } from "./OrderTokenAmount.js";
|
|
9
|
+
export function CryptoReceiveSection({ isDepositMode = false, isBuyMode = false, selectedRecipientAddress, recipientName, onSelectRecipient, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, onChangeDstAmount, anyspendQuote, }) {
|
|
10
|
+
return (_jsxs(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, className: "receive-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [_jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: isDepositMode ? "Deposit" : "Receive" }), selectedRecipientAddress ? (_jsx("button", { className: cn("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: onSelectRecipient, children: _jsxs(_Fragment, { children: [_jsx("span", { className: "text-as-tertiarry flex items-center gap-1 text-sm", children: recipientName ? formatUsername(recipientName) : shortenAddress(selectedRecipientAddress || "") }), _jsx(ChevronRight, { className: "h-4 w-4" })] }) })) : (_jsx("button", { className: "text-as-primary/70 flex items-center gap-1 rounded-lg", onClick: onSelectRecipient, children: _jsx("div", { className: "text-sm font-medium", children: "Select recipient" }) }))] }), isBuyMode || isDepositMode ? (
|
|
11
|
+
// Fixed destination token display for buy mode and deposit mode
|
|
12
|
+
_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-as-primary text-2xl font-bold", children: dstAmount || "0" }), _jsxs("div", { className: "bg-as-brand/10 border-as-brand/30 flex items-center gap-3 rounded-xl border px-4 py-3", children: [dstToken.metadata?.logoURI && (_jsx("img", { src: dstToken.metadata.logoURI, alt: dstToken.symbol, className: "h-8 w-8 rounded-full" })), _jsx("span", { className: "text-as-brand text-lg font-bold", children: dstToken.symbol })] })] })) : (
|
|
13
|
+
// Token selection for regular swap mode
|
|
14
|
+
_jsx(OrderTokenAmount, { address: selectedRecipientAddress, context: "to", inputValue: dstAmount, onChangeInput: onChangeDstAmount || (() => { }), chainId: selectedDstChainId || dstToken.chainId, setChainId: setSelectedDstChainId || (() => { }), token: dstToken, setToken: setSelectedDstToken || (() => { }) })), _jsxs("div", { className: "text-as-primary/50 flex h-5 items-center text-sm", children: [formatDisplayNumber(anyspendQuote?.data?.currencyOut?.amountUsd, {
|
|
15
|
+
style: "currency",
|
|
16
|
+
fallback: "",
|
|
17
|
+
}), anyspendQuote?.data?.currencyIn?.amountUsd &&
|
|
18
|
+
anyspendQuote?.data?.currencyOut?.amountUsd &&
|
|
19
|
+
(() => {
|
|
20
|
+
const calculatePriceImpact = (inputUsd, outputUsd) => {
|
|
21
|
+
if (!inputUsd || !outputUsd) {
|
|
22
|
+
return { percentage: "0.00", isNegative: false };
|
|
23
|
+
}
|
|
24
|
+
const input = Number(inputUsd);
|
|
25
|
+
const output = Number(outputUsd);
|
|
26
|
+
// Handle edge cases
|
|
27
|
+
if (input === 0 || isNaN(input) || isNaN(output) || input <= output) {
|
|
28
|
+
return { percentage: "0.00", isNegative: false };
|
|
29
|
+
}
|
|
30
|
+
const percentageValue = ((output - input) / input) * 100;
|
|
31
|
+
// Handle the -0.00% case
|
|
32
|
+
if (percentageValue > -0.005 && percentageValue < 0) {
|
|
33
|
+
return { percentage: "0.00", isNegative: false };
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
percentage: Math.abs(percentageValue).toFixed(2),
|
|
37
|
+
isNegative: percentageValue < 0,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const { percentage, isNegative } = calculatePriceImpact(anyspendQuote.data.currencyIn.amountUsd, anyspendQuote.data.currencyOut.amountUsd);
|
|
41
|
+
// Parse the percentage as a number for comparison
|
|
42
|
+
const percentageNum = parseFloat(percentage);
|
|
43
|
+
// Don't show if less than 1%
|
|
44
|
+
if (percentageNum < 1) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
// Using inline style to ensure color displays
|
|
48
|
+
return (_jsxs("span", { className: "ml-2", style: { color: percentageNum >= 10 ? "red" : "#FFD700" }, children: ["(", isNegative ? "-" : "", percentage, "%)"] }));
|
|
49
|
+
})()] })] }));
|
|
50
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CircleAlert } from "lucide-react";
|
|
3
|
+
export function ErrorSection({ error, message }) {
|
|
4
|
+
if (!error && !message) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
const errorMessage = message || error?.message || "An error occurred";
|
|
8
|
+
return (_jsxs("div", { className: "error-section bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl px-4 py-2", children: [_jsx(CircleAlert, { className: "bg-as-red h-4 min-h-4 w-4 min-w-4 rounded-full p-0 text-sm font-medium text-white" }), _jsx("div", { className: "text-as-red text-sm", children: errorMessage })] }));
|
|
9
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { components } from "../../../../anyspend/types/api";
|
|
2
2
|
import { FiatPaymentMethod } from "./FiatPaymentMethod";
|
|
3
|
-
export declare function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPaymentMethod, setActivePanel, _recipientAddress, destinationToken, destinationChainId, destinationAmount, onDestinationTokenChange, onDestinationChainChange, }: {
|
|
3
|
+
export declare function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPaymentMethod, setActivePanel, _recipientAddress, destinationToken, destinationChainId, destinationAmount, onDestinationTokenChange, onDestinationChainChange, fiatPaymentMethodIndex, }: {
|
|
4
4
|
srcAmountOnRamp: string;
|
|
5
5
|
setSrcAmountOnRamp: (amount: string) => void;
|
|
6
6
|
selectedPaymentMethod?: FiatPaymentMethod;
|
|
@@ -11,4 +11,5 @@ export declare function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selec
|
|
|
11
11
|
destinationAmount?: string;
|
|
12
12
|
onDestinationTokenChange?: (token: components["schemas"]["Token"]) => void;
|
|
13
13
|
onDestinationChainChange?: (chainId: number) => void;
|
|
14
|
+
fiatPaymentMethodIndex: number;
|
|
14
15
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -9,7 +9,7 @@ import { useRef } from "react";
|
|
|
9
9
|
import { toast } from "sonner";
|
|
10
10
|
import { FiatPaymentMethod } from "./FiatPaymentMethod.js";
|
|
11
11
|
import { OrderTokenAmountFiat } from "./OrderTokenAmountFiat.js";
|
|
12
|
-
export function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPaymentMethod, setActivePanel, _recipientAddress, destinationToken, destinationChainId, destinationAmount, onDestinationTokenChange, onDestinationChainChange, }) {
|
|
12
|
+
export function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPaymentMethod, setActivePanel, _recipientAddress, destinationToken, destinationChainId, destinationAmount, onDestinationTokenChange, onDestinationChainChange, fiatPaymentMethodIndex, }) {
|
|
13
13
|
// Get geo-based onramp options to access fee information
|
|
14
14
|
const { stripeWeb2Support } = useGeoOnrampOptions(srcAmountOnRamp);
|
|
15
15
|
// Helper function to get fees from API data
|
|
@@ -66,7 +66,7 @@ export function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPayme
|
|
|
66
66
|
const handleQuickAmount = (value) => {
|
|
67
67
|
setSrcAmountOnRamp(value);
|
|
68
68
|
};
|
|
69
|
-
return (_jsxs("div", { className: "bg-as-surface-primary flex w-full flex-col", children: [_jsxs("div", { className: "border-as-border-secondary bg-as-surface-secondary relative flex w-full flex-col rounded-2xl border p-4", children: [_jsxs("div", { className: "flex h-7 w-full items-center justify-between", children: [_jsx("span", { className: "text-as-tertiarry flex items-center text-sm font-bold", children: "Pay" }), _jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-1 text-sm", onClick: () => setActivePanel(
|
|
69
|
+
return (_jsxs("div", { className: "panel-onramp bg-as-surface-primary flex w-full flex-col", children: [_jsxs("div", { className: "border-as-border-secondary bg-as-surface-secondary relative flex w-full flex-col rounded-2xl border p-4", children: [_jsxs("div", { className: "flex h-7 w-full items-center justify-between", children: [_jsx("span", { className: "text-as-tertiarry flex items-center text-sm font-bold", children: "Pay" }), _jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-1 text-sm", onClick: () => setActivePanel(fiatPaymentMethodIndex), children: selectedPaymentMethod === FiatPaymentMethod.COINBASE_PAY ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-blue-600", children: _jsx("span", { className: "text-xs font-bold text-white", children: "C" }) }), "Coinbase Pay"] }), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : selectedPaymentMethod === FiatPaymentMethod.STRIPE ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-blue-600", children: _jsx("span", { className: "text-xs font-bold text-white", children: "S" }) }), "Stripe"] }), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : (_jsxs(_Fragment, { children: ["Select payment method", _jsx(ChevronRight, { className: "h-4 w-4" })] })) })] }), _jsx("div", { className: "flex items-center justify-center pb-2 pt-8", children: _jsxs("div", { className: "flex gap-1", children: [_jsx("span", { className: "text-as-tertiarry text-2xl font-bold", children: "$" }), _jsx(Input, { ref: amountInputRef, type: "text", value: srcAmountOnRamp, onChange: handleAmountChange, placeholder: "5", className: "text-as-primary placeholder:text-as-primary/50 h-auto min-w-[70px] border-0 bg-transparent p-0 px-3 pt-1 text-4xl font-bold focus-visible:ring-0 focus-visible:ring-offset-0", style: {
|
|
70
70
|
width: `${Math.max(50, srcAmountOnRamp.length * 34)}px`,
|
|
71
71
|
} })] }) }), _jsx("div", { className: "mx-auto mb-6 inline-grid grid-cols-4 gap-2", children: ["5", "10", "20", "25"].map(value => (_jsxs("button", { onClick: () => handleQuickAmount(value), className: `bg-as-surface-secondary border-as-border-secondary hover:border-as-border-secondary h-7 w-14 rounded-lg border text-sm font-medium transition-all duration-200 ${srcAmountOnRamp === value
|
|
72
72
|
? "border-as-border-secondary bg-as-surface-secondary"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { components } from "../../../types/api";
|
|
2
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
3
|
+
import { FiatPaymentMethod } from "./FiatPaymentMethod";
|
|
4
|
+
interface PaySectionProps {
|
|
5
|
+
paymentType: "crypto" | "fiat";
|
|
6
|
+
selectedSrcChainId: number;
|
|
7
|
+
setSelectedSrcChainId: (chainId: number) => void;
|
|
8
|
+
selectedSrcToken: components["schemas"]["Token"];
|
|
9
|
+
setSelectedSrcToken: (token: components["schemas"]["Token"]) => void;
|
|
10
|
+
srcAmount: string;
|
|
11
|
+
setSrcAmount: (amount: string) => void;
|
|
12
|
+
setIsSrcInputDirty: (dirty: boolean) => void;
|
|
13
|
+
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
14
|
+
selectedFiatPaymentMethod: FiatPaymentMethod;
|
|
15
|
+
onSelectCryptoPaymentMethod: () => void;
|
|
16
|
+
onSelectFiatPaymentMethod: () => void;
|
|
17
|
+
anyspendQuote?: any;
|
|
18
|
+
}
|
|
19
|
+
export declare function PaySection({ paymentType, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, setIsSrcInputDirty, selectedCryptoPaymentMethod, selectedFiatPaymentMethod, onSelectCryptoPaymentMethod, onSelectFiatPaymentMethod, anyspendQuote, }: PaySectionProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Input, useAccountWallet, useTokenData } from "../../../../global-account/react/index.js";
|
|
3
|
+
import { formatUsername } from "../../../../shared/utils/index.js";
|
|
4
|
+
import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
|
|
5
|
+
import { formatDisplayNumber } from "../../../../shared/utils/number.js";
|
|
6
|
+
import { ChevronRight } from "lucide-react";
|
|
7
|
+
import { motion } from "motion/react";
|
|
8
|
+
import { useEffect, useRef } from "react";
|
|
9
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod.js";
|
|
10
|
+
import { FiatPaymentMethod } from "./FiatPaymentMethod.js";
|
|
11
|
+
import { OrderTokenAmount } from "./OrderTokenAmount.js";
|
|
12
|
+
import { TokenBalance } from "./TokenBalance.js";
|
|
13
|
+
export function PaySection({ paymentType, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, setIsSrcInputDirty, selectedCryptoPaymentMethod, selectedFiatPaymentMethod, onSelectCryptoPaymentMethod, onSelectFiatPaymentMethod, anyspendQuote, }) {
|
|
14
|
+
const { address: globalAddress, wallet: globalWallet, ensName: connectedName } = useAccountWallet();
|
|
15
|
+
const connectedAddress = globalWallet?.address;
|
|
16
|
+
const { data: srcTokenMetadata } = useTokenData(selectedSrcToken?.chainId, selectedSrcToken?.address);
|
|
17
|
+
// Add ref to track if we've applied metadata
|
|
18
|
+
const appliedSrcMetadataRef = useRef(false);
|
|
19
|
+
// Update source token with metadata
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (selectedSrcToken && srcTokenMetadata && !appliedSrcMetadataRef.current) {
|
|
22
|
+
// Mark as applied
|
|
23
|
+
appliedSrcMetadataRef.current = true;
|
|
24
|
+
const enhancedToken = {
|
|
25
|
+
...selectedSrcToken,
|
|
26
|
+
decimals: srcTokenMetadata.decimals || selectedSrcToken.decimals,
|
|
27
|
+
symbol: srcTokenMetadata.symbol || selectedSrcToken.symbol,
|
|
28
|
+
name: srcTokenMetadata.name || selectedSrcToken.name,
|
|
29
|
+
metadata: {
|
|
30
|
+
...selectedSrcToken.metadata,
|
|
31
|
+
logoURI: srcTokenMetadata?.logoURI || selectedSrcToken.metadata.logoURI,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
setSelectedSrcToken(enhancedToken);
|
|
35
|
+
}
|
|
36
|
+
}, [srcTokenMetadata, selectedSrcToken, setSelectedSrcToken]);
|
|
37
|
+
// Reset source token ref when address/chain changes
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
appliedSrcMetadataRef.current = false;
|
|
40
|
+
}, [selectedSrcToken.address, selectedSrcToken.chainId]);
|
|
41
|
+
return (_jsxs(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Pay" }), paymentType === "crypto" ? (_jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors", onClick: onSelectCryptoPaymentMethod, children: selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (_jsxs(_Fragment, { children: [globalAddress ? (_jsx("div", { className: "flex items-center gap-1", children: connectedName ? formatUsername(connectedName) : shortenAddress(connectedAddress || "") })) : ("Connect wallet"), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (_jsxs(_Fragment, { children: ["Transfer crypto", _jsx(ChevronRight, { className: "h-4 w-4" })] })) : (_jsxs(_Fragment, { children: ["Select payment method", _jsx(ChevronRight, { className: "h-4 w-4" })] })) })) : (_jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors", onClick: onSelectFiatPaymentMethod, children: selectedFiatPaymentMethod === FiatPaymentMethod.COINBASE_PAY ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-blue-600", children: _jsx("span", { className: "text-xs font-bold text-white", children: "C" }) }), "Coinbase Pay"] }), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : selectedFiatPaymentMethod === FiatPaymentMethod.STRIPE ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-blue-600", children: _jsx("span", { className: "text-xs font-bold text-white", children: "S" }) }), "Credit/Debit Card"] }), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : (_jsxs(_Fragment, { children: ["Select payment method", _jsx(ChevronRight, { className: "h-4 w-4" })] })) }))] }), paymentType === "crypto" ? (_jsxs(_Fragment, { children: [_jsx(OrderTokenAmount, { address: globalAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
|
|
42
|
+
setIsSrcInputDirty(true);
|
|
43
|
+
setSrcAmount(value);
|
|
44
|
+
}, chainId: selectedSrcChainId, setChainId: setSelectedSrcChainId, token: selectedSrcToken, setToken: setSelectedSrcToken }), _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-as-primary/50 flex h-5 items-center text-sm", children: formatDisplayNumber(anyspendQuote?.data?.currencyIn?.amountUsd, {
|
|
45
|
+
style: "currency",
|
|
46
|
+
fallback: "",
|
|
47
|
+
}) }), _jsx(TokenBalance, { token: selectedSrcToken, walletAddress: globalAddress, onChangeInput: value => {
|
|
48
|
+
setIsSrcInputDirty(true);
|
|
49
|
+
setSrcAmount(value);
|
|
50
|
+
} })] })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex items-center justify-center pb-2 pt-8", children: _jsxs("div", { className: "flex gap-1", children: [_jsx("span", { className: "text-as-tertiarry text-2xl font-bold", children: "$" }), _jsx(Input, { type: "text", value: srcAmount, onChange: e => setSrcAmount(e.target.value.replace(/[^0-9.]/g, "")), placeholder: "5", className: "text-as-primary placeholder:text-as-primary/50 h-auto min-w-[70px] border-0 bg-transparent p-0 px-3 pt-1 text-4xl font-bold focus-visible:ring-0 focus-visible:ring-offset-0", style: {
|
|
51
|
+
width: `${Math.max(50, srcAmount.length * 34)}px`,
|
|
52
|
+
} })] }) }), _jsx("div", { className: "mx-auto mb-6 inline-grid grid-cols-4 gap-2", children: ["5", "10", "20", "25"].map(value => (_jsxs("button", { onClick: () => setSrcAmount(value), className: `bg-as-surface-secondary border-as-border-secondary hover:border-as-border-secondary h-7 w-14 rounded-lg border text-sm font-medium transition-all duration-200 ${srcAmount === value
|
|
53
|
+
? "border-as-border-secondary bg-as-surface-secondary"
|
|
54
|
+
: "bg-as-surface-secondary hover:bg-as-surface-secondary"}`, children: ["$", value] }, value))) })] }))] }));
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
2
|
+
import { FiatPaymentMethod } from "./FiatPaymentMethod";
|
|
3
|
+
interface TabSectionProps {
|
|
4
|
+
activeTab: "crypto" | "fiat";
|
|
5
|
+
setActiveTab: (tab: "crypto" | "fiat") => void;
|
|
6
|
+
setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
7
|
+
setSelectedFiatPaymentMethod: (method: FiatPaymentMethod) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function TabSection({ activeTab, setActiveTab, setSelectedCryptoPaymentMethod, setSelectedFiatPaymentMethod, }: TabSectionProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "../../../../shared/utils/cn.js";
|
|
3
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod.js";
|
|
4
|
+
import { FiatPaymentMethod } from "./FiatPaymentMethod.js";
|
|
5
|
+
export function TabSection({ activeTab, setActiveTab, setSelectedCryptoPaymentMethod, setSelectedFiatPaymentMethod, }) {
|
|
6
|
+
return (_jsx("div", { className: "tab-section w-full", children: _jsxs("div", { className: "bg-as-surface-secondary relative mb-4 grid h-10 grid-cols-2 rounded-xl", children: [_jsx("div", { className: cn("bg-as-brand absolute bottom-0 left-0 top-0 z-0 rounded-xl transition-transform duration-100", "h-full w-1/2", activeTab === "fiat" ? "translate-x-full" : "translate-x-0"), style: { willChange: "transform" } }), _jsx("button", { className: cn("relative z-10 h-full w-full rounded-xl px-3 text-sm font-medium transition-colors duration-100", activeTab === "crypto" ? "text-white" : "text-as-primary/70 hover:bg-as-on-surface-2 bg-transparent"), onClick: () => {
|
|
7
|
+
setActiveTab("crypto");
|
|
8
|
+
setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE); // Reset payment method when switching to crypto
|
|
9
|
+
setSelectedFiatPaymentMethod(FiatPaymentMethod.NONE); // Reset fiat payment method when switching to crypto
|
|
10
|
+
}, children: "Pay with crypto" }), _jsx("button", { className: cn("relative z-10 h-full w-full rounded-xl px-3 text-sm font-medium transition-colors duration-100", activeTab === "fiat" ? "text-white" : "text-as-primary/70 hover:bg-as-on-surface-2 bg-transparent"), onClick: () => {
|
|
11
|
+
setActiveTab("fiat");
|
|
12
|
+
setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE); // Reset crypto payment method when switching to fiat
|
|
13
|
+
setSelectedFiatPaymentMethod(FiatPaymentMethod.NONE); // Reset fiat payment method when switching to fiat
|
|
14
|
+
}, children: "Pay with Fiat" })] }) }));
|
|
15
|
+
}
|
|
@@ -9,6 +9,7 @@ export { AnySpendStakeB3 } from "./AnySpendStakeB3";
|
|
|
9
9
|
export { AnySpendTournament } from "./AnySpendTournament";
|
|
10
10
|
export { AnySpendNFTButton } from "./common/AnySpendNFTButton";
|
|
11
11
|
export { ChainTokenIcon } from "./common/ChainTokenIcon";
|
|
12
|
+
export { CryptoReceiveSection } from "./common/CryptoReceiveSection";
|
|
12
13
|
export { OrderDetails } from "./common/OrderDetails";
|
|
13
14
|
export { OrderDetailsCollapsible } from "./common/OrderDetailsCollapsible";
|
|
14
15
|
export { OrderHistory } from "./common/OrderHistory";
|
|
@@ -16,6 +17,7 @@ export { OrderHistoryItem } from "./common/OrderHistoryItem";
|
|
|
16
17
|
export { OrderStatus } from "./common/OrderStatus";
|
|
17
18
|
export { OrderToken } from "./common/OrderToken";
|
|
18
19
|
export { OrderTokenAmount } from "./common/OrderTokenAmount";
|
|
20
|
+
export { PaySection } from "./common/PaySection";
|
|
19
21
|
export { RecipientSelection } from "./common/RecipientSelection";
|
|
20
22
|
export { StepProgress } from "./common/StepProgress";
|
|
21
23
|
export { TokenBalance } from "./common/TokenBalance";
|
|
@@ -11,6 +11,7 @@ export { AnySpendTournament } from "./AnySpendTournament.js";
|
|
|
11
11
|
export { AnySpendNFTButton } from "./common/AnySpendNFTButton.js";
|
|
12
12
|
// Common Components
|
|
13
13
|
export { ChainTokenIcon } from "./common/ChainTokenIcon.js";
|
|
14
|
+
export { CryptoReceiveSection } from "./common/CryptoReceiveSection.js";
|
|
14
15
|
export { OrderDetails } from "./common/OrderDetails.js";
|
|
15
16
|
export { OrderDetailsCollapsible } from "./common/OrderDetailsCollapsible.js";
|
|
16
17
|
export { OrderHistory } from "./common/OrderHistory.js";
|
|
@@ -18,6 +19,7 @@ export { OrderHistoryItem } from "./common/OrderHistoryItem.js";
|
|
|
18
19
|
export { OrderStatus } from "./common/OrderStatus.js";
|
|
19
20
|
export { OrderToken } from "./common/OrderToken.js";
|
|
20
21
|
export { OrderTokenAmount } from "./common/OrderTokenAmount.js";
|
|
22
|
+
export { PaySection } from "./common/PaySection.js";
|
|
21
23
|
export { RecipientSelection } from "./common/RecipientSelection.js";
|
|
22
24
|
export { StepProgress } from "./common/StepProgress.js";
|
|
23
25
|
export { TokenBalance } from "./common/TokenBalance.js";
|