@b3dotfun/sdk 0.0.42 → 0.0.43-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/AnySpend.js +11 -4
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +43 -3
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +2 -2
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +5 -3
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +12 -0
- package/dist/cjs/anyspend/types/api.d.ts +2 -10
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
- package/dist/cjs/global-account/react/components/index.d.ts +8 -7
- package/dist/cjs/global-account/react/components/index.js +29 -23
- package/dist/cjs/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
- package/dist/cjs/global-account/react/components/ui/dropdown-menu.js +100 -0
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +5 -1
- package/dist/cjs/shared/constants/currency.d.ts +1 -0
- package/dist/cjs/shared/constants/currency.js +5 -0
- package/dist/cjs/shared/constants/index.d.ts +1 -0
- package/dist/cjs/shared/constants/index.js +15 -0
- package/dist/cjs/shared/react/components/CurrencySelector.d.ts +7 -0
- package/dist/cjs/shared/react/components/CurrencySelector.js +14 -0
- package/dist/cjs/shared/react/components/FormattedCurrency.d.ts +12 -0
- package/dist/cjs/shared/react/components/FormattedCurrency.js +60 -0
- package/dist/cjs/shared/react/components/index.d.ts +2 -0
- package/dist/cjs/shared/react/components/index.js +18 -0
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
- package/dist/cjs/shared/react/hooks/index.d.ts +1 -0
- package/dist/cjs/shared/react/hooks/index.js +1 -0
- package/dist/cjs/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
- package/dist/cjs/shared/react/hooks/useCurrencyConversion.js +200 -0
- package/dist/cjs/shared/react/index.d.ts +2 -0
- package/dist/cjs/shared/react/index.js +2 -0
- package/dist/cjs/shared/react/stores/currencyModalStore.d.ts +7 -0
- package/dist/cjs/shared/react/stores/currencyModalStore.js +9 -0
- package/dist/cjs/shared/react/stores/currencyStore.d.ts +51 -0
- package/dist/cjs/shared/react/stores/currencyStore.js +57 -0
- package/dist/cjs/shared/react/stores/index.d.ts +2 -0
- package/dist/cjs/shared/react/stores/index.js +18 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +1 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +11 -4
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +10 -3
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +1 -0
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +2 -2
- package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +5 -3
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +12 -0
- package/dist/esm/anyspend/types/api.d.ts +2 -10
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +1 -1
- package/dist/esm/global-account/react/components/index.d.ts +8 -7
- package/dist/esm/global-account/react/components/index.js +8 -7
- package/dist/esm/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
- package/dist/esm/global-account/react/components/ui/dropdown-menu.js +60 -0
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +5 -1
- package/dist/esm/shared/constants/currency.d.ts +1 -0
- package/dist/esm/shared/constants/currency.js +2 -0
- package/dist/esm/shared/constants/index.d.ts +1 -0
- package/dist/esm/shared/constants/index.js +1 -0
- package/dist/esm/shared/react/components/CurrencySelector.d.ts +7 -0
- package/dist/esm/shared/react/components/CurrencySelector.js +11 -0
- package/dist/esm/shared/react/components/FormattedCurrency.d.ts +12 -0
- package/dist/esm/shared/react/components/FormattedCurrency.js +57 -0
- package/dist/esm/shared/react/components/index.d.ts +2 -0
- package/dist/esm/shared/react/components/index.js +2 -0
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
- package/dist/esm/shared/react/hooks/index.d.ts +1 -0
- package/dist/esm/shared/react/hooks/index.js +1 -0
- package/dist/esm/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
- package/dist/esm/shared/react/hooks/useCurrencyConversion.js +197 -0
- package/dist/esm/shared/react/index.d.ts +2 -0
- package/dist/esm/shared/react/index.js +2 -0
- package/dist/esm/shared/react/stores/currencyModalStore.d.ts +7 -0
- package/dist/esm/shared/react/stores/currencyModalStore.js +6 -0
- package/dist/esm/shared/react/stores/currencyStore.d.ts +51 -0
- package/dist/esm/shared/react/stores/currencyStore.js +54 -0
- package/dist/esm/shared/react/stores/index.d.ts +2 -0
- package/dist/esm/shared/react/stores/index.js +2 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpend.d.ts +1 -0
- package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +1 -0
- package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
- package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +12 -0
- package/dist/types/anyspend/types/api.d.ts +2 -10
- package/dist/types/global-account/react/components/index.d.ts +8 -7
- package/dist/types/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +5 -1
- package/dist/types/shared/constants/currency.d.ts +1 -0
- package/dist/types/shared/constants/index.d.ts +1 -0
- package/dist/types/shared/react/components/CurrencySelector.d.ts +7 -0
- package/dist/types/shared/react/components/FormattedCurrency.d.ts +12 -0
- package/dist/types/shared/react/components/index.d.ts +2 -0
- package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/types/shared/react/hooks/index.d.ts +1 -0
- package/dist/types/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
- package/dist/types/shared/react/index.d.ts +2 -0
- package/dist/types/shared/react/stores/currencyModalStore.d.ts +7 -0
- package/dist/types/shared/react/stores/currencyStore.d.ts +51 -0
- package/dist/types/shared/react/stores/index.d.ts +2 -0
- package/package.json +29 -3
- package/src/anyspend/react/components/AnySpend.tsx +15 -2
- package/src/anyspend/react/components/AnySpendCustom.tsx +11 -2
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +3 -0
- package/src/anyspend/react/components/common/PanelOnramp.tsx +19 -15
- package/src/anyspend/types/api.ts +2 -10
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -7
- package/src/global-account/react/components/index.ts +19 -12
- package/src/global-account/react/components/ui/dropdown-menu.tsx +132 -0
- package/src/global-account/react/stores/useModalStore.ts +5 -1
- package/src/shared/constants/currency.ts +2 -0
- package/src/shared/constants/index.ts +2 -0
- package/src/shared/react/components/CurrencySelector.tsx +71 -0
- package/src/shared/react/components/FormattedCurrency.tsx +106 -0
- package/src/shared/react/components/index.ts +2 -0
- package/src/shared/react/hooks/__tests__/useCurrencyConversion.test.ts +308 -0
- package/src/shared/react/hooks/index.ts +1 -0
- package/src/shared/react/hooks/useCurrencyConversion.ts +211 -0
- package/src/shared/react/index.ts +2 -0
- package/src/shared/react/stores/currencyModalStore.ts +13 -0
- package/src/shared/react/stores/currencyStore.ts +82 -0
- package/src/shared/react/stores/index.ts +2 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCurrencyConversion = useCurrencyConversion;
|
|
4
|
+
const react_1 = require("../../../global-account/react");
|
|
5
|
+
const number_1 = require("../../../shared/utils/number");
|
|
6
|
+
const currencyStore_1 = require("../stores/currencyStore");
|
|
7
|
+
/**
|
|
8
|
+
* Hook for currency conversion and formatting with real-time exchange rates.
|
|
9
|
+
*
|
|
10
|
+
* This hook provides currency conversion functionality using live exchange rates
|
|
11
|
+
* and formats values according to currency-specific rules (decimals, symbols, etc.).
|
|
12
|
+
*
|
|
13
|
+
* @returns Currency conversion utilities and state
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* function PriceDisplay({ amount }: { amount: number }) {
|
|
18
|
+
* const { formatCurrencyValue, selectedCurrency } = useCurrencyConversion();
|
|
19
|
+
* return <div>{formatCurrencyValue(amount)}</div>;
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function useCurrencyConversion() {
|
|
24
|
+
const selectedCurrency = (0, currencyStore_1.useCurrencyStore)(state => state.selectedCurrency);
|
|
25
|
+
const baseCurrency = (0, currencyStore_1.useCurrencyStore)(state => state.baseCurrency);
|
|
26
|
+
// Get exchange rate for the selected currency
|
|
27
|
+
const { rate: exchangeRate } = (0, react_1.useExchangeRate)({
|
|
28
|
+
baseCurrency,
|
|
29
|
+
quoteCurrency: selectedCurrency === baseCurrency ? "USD" : selectedCurrency,
|
|
30
|
+
});
|
|
31
|
+
// Always fetch USD rate for tooltip purposes
|
|
32
|
+
const { rate: usdRate } = (0, react_1.useExchangeRate)({
|
|
33
|
+
baseCurrency,
|
|
34
|
+
quoteCurrency: "USD",
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Formats a numeric value as a currency string with proper conversion and formatting.
|
|
38
|
+
*
|
|
39
|
+
* Behavior:
|
|
40
|
+
* - When exchange rate is unavailable, displays value in base currency
|
|
41
|
+
* - Applies currency-specific formatting rules:
|
|
42
|
+
* - JPY/KRW: No decimal places
|
|
43
|
+
* - ETH/SOL: 6 significant digits with subscript notation for small values
|
|
44
|
+
* - Fiat (USD/EUR/GBP/CAD/AUD): 2 decimal places minimum for values < 1000
|
|
45
|
+
* - Handles symbol positioning (prefix for fiat, suffix for crypto)
|
|
46
|
+
*
|
|
47
|
+
* @param value - The numeric value to format (in base currency)
|
|
48
|
+
* @param options - Optional formatting overrides
|
|
49
|
+
* @param options.decimals - Override number of decimal places
|
|
50
|
+
* @param options.currency - Override currency (bypasses conversion)
|
|
51
|
+
* @returns Formatted currency string with appropriate symbol and decimal places
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* formatCurrencyValue(100) // Returns "$100.00" if USD is selected
|
|
56
|
+
* formatCurrencyValue(0.0001) // Returns "0.0₄1 ETH" if ETH is selected
|
|
57
|
+
* formatCurrencyValue(1500) // Returns "¥1,500" if JPY is selected
|
|
58
|
+
* formatCurrencyValue(100, { decimals: 4, currency: "ETH" }) // Returns "100.0000 ETH"
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
const formatCurrencyValue = (value, options) => {
|
|
62
|
+
const overrideCurrency = options?.currency;
|
|
63
|
+
const overrideDecimals = options?.decimals;
|
|
64
|
+
// Custom currency provided - bypass conversion and use simple formatting
|
|
65
|
+
if (overrideCurrency) {
|
|
66
|
+
const decimalsToUse = overrideDecimals !== undefined ? overrideDecimals : overrideCurrency === "B3" ? 0 : 2;
|
|
67
|
+
const formatted = (0, number_1.formatDisplayNumber)(value, {
|
|
68
|
+
fractionDigits: decimalsToUse,
|
|
69
|
+
showSubscripts: false,
|
|
70
|
+
});
|
|
71
|
+
return `${formatted} ${overrideCurrency}`;
|
|
72
|
+
}
|
|
73
|
+
// Custom decimals for base currency without conversion
|
|
74
|
+
if (overrideDecimals !== undefined && selectedCurrency === baseCurrency) {
|
|
75
|
+
const formatted = (0, number_1.formatDisplayNumber)(value, {
|
|
76
|
+
fractionDigits: overrideDecimals,
|
|
77
|
+
showSubscripts: false,
|
|
78
|
+
});
|
|
79
|
+
return `${formatted} ${baseCurrency}`;
|
|
80
|
+
}
|
|
81
|
+
// If no exchange rate available, show base currency to prevent showing
|
|
82
|
+
// incorrect values with wrong currency symbols during rate fetching
|
|
83
|
+
if (selectedCurrency === baseCurrency || !exchangeRate) {
|
|
84
|
+
const formatted = (0, number_1.formatDisplayNumber)(value, {
|
|
85
|
+
significantDigits: baseCurrency === "B3" ? 6 : 8,
|
|
86
|
+
showSubscripts: true,
|
|
87
|
+
});
|
|
88
|
+
return `${formatted} ${baseCurrency}`;
|
|
89
|
+
}
|
|
90
|
+
// Convert value using current exchange rate
|
|
91
|
+
const convertedValue = value * exchangeRate;
|
|
92
|
+
const symbol = currencyStore_1.CURRENCY_SYMBOLS[selectedCurrency];
|
|
93
|
+
// Currencies that display symbol before the number (e.g., $100.00)
|
|
94
|
+
const prefixCurrencies = ["USD", "EUR", "GBP", "CAD", "AUD"];
|
|
95
|
+
let formatted;
|
|
96
|
+
if (selectedCurrency === "JPY" || selectedCurrency === "KRW") {
|
|
97
|
+
// Japanese Yen and Korean Won don't use decimal places
|
|
98
|
+
formatted = (0, number_1.formatDisplayNumber)(convertedValue, {
|
|
99
|
+
fractionDigits: 0,
|
|
100
|
+
showSubscripts: false,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else if (selectedCurrency === "ETH" || selectedCurrency === "SOL") {
|
|
104
|
+
// Crypto currencies use more precision and subscript notation
|
|
105
|
+
// for very small amounts (e.g., 0.0₃45 ETH)
|
|
106
|
+
formatted = (0, number_1.formatDisplayNumber)(convertedValue, {
|
|
107
|
+
significantDigits: 6,
|
|
108
|
+
showSubscripts: true,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// Standard fiat currencies (USD, EUR, GBP, CAD, AUD)
|
|
113
|
+
// Use 2 decimal places minimum for amounts under 1000
|
|
114
|
+
formatted = (0, number_1.formatDisplayNumber)(convertedValue, {
|
|
115
|
+
significantDigits: 6,
|
|
116
|
+
fractionDigits: convertedValue < 1000 ? 2 : undefined,
|
|
117
|
+
showSubscripts: true,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Apply currency symbol with correct positioning
|
|
121
|
+
if (prefixCurrencies.includes(selectedCurrency)) {
|
|
122
|
+
return `${symbol}${formatted}`;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// Suffix currencies: JPY, KRW, ETH, SOL, B3
|
|
126
|
+
return `${formatted} ${symbol}`;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Formats a tooltip value showing the alternate currency representation.
|
|
131
|
+
*
|
|
132
|
+
* Behavior:
|
|
133
|
+
* - When displaying base currency: Shows USD equivalent
|
|
134
|
+
* - When displaying other currency: Shows base currency equivalent
|
|
135
|
+
* - For custom currencies: Shows appropriate conversion or original value
|
|
136
|
+
*
|
|
137
|
+
* @param value - The numeric value to format
|
|
138
|
+
* @param customCurrency - Optional custom currency override
|
|
139
|
+
* @returns Formatted tooltip string
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```tsx
|
|
143
|
+
* formatTooltipValue(100) // Returns "$150.00 USD" if displaying B3 with rate 1.5
|
|
144
|
+
* formatTooltipValue(100, "ETH") // Returns "100.0000 ETH" if custom currency
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
const formatTooltipValue = (value, customCurrency) => {
|
|
148
|
+
const displayCurrency = customCurrency || selectedCurrency;
|
|
149
|
+
const absoluteValue = Math.abs(value);
|
|
150
|
+
// Custom currency provided
|
|
151
|
+
if (customCurrency) {
|
|
152
|
+
if (customCurrency === baseCurrency) {
|
|
153
|
+
// Show USD equivalent for base currency using USD rate
|
|
154
|
+
const usdValue = usdRate ? absoluteValue * usdRate : absoluteValue;
|
|
155
|
+
const formatted = (0, number_1.formatDisplayNumber)(usdValue, {
|
|
156
|
+
significantDigits: 6,
|
|
157
|
+
fractionDigits: usdValue < 1000 ? 2 : undefined,
|
|
158
|
+
showSubscripts: true,
|
|
159
|
+
});
|
|
160
|
+
return `$${formatted} USD`;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Show as-is for other custom currencies
|
|
164
|
+
return `${(0, number_1.formatDisplayNumber)(absoluteValue, { significantDigits: 6 })} ${customCurrency}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Showing base currency - display USD equivalent
|
|
168
|
+
if (displayCurrency === baseCurrency) {
|
|
169
|
+
const usdValue = usdRate ? absoluteValue * usdRate : absoluteValue;
|
|
170
|
+
const formatted = (0, number_1.formatDisplayNumber)(usdValue, {
|
|
171
|
+
significantDigits: 6,
|
|
172
|
+
fractionDigits: usdValue < 1000 ? 2 : undefined,
|
|
173
|
+
showSubscripts: true,
|
|
174
|
+
});
|
|
175
|
+
return `$${formatted} USD`;
|
|
176
|
+
}
|
|
177
|
+
// Showing other currency - display base currency equivalent
|
|
178
|
+
const formatted = (0, number_1.formatDisplayNumber)(absoluteValue, {
|
|
179
|
+
significantDigits: baseCurrency === "B3" ? 6 : 8,
|
|
180
|
+
showSubscripts: true,
|
|
181
|
+
});
|
|
182
|
+
return `${formatted} ${baseCurrency}`;
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
/** Currently selected display currency */
|
|
186
|
+
selectedCurrency,
|
|
187
|
+
/** Base currency used for conversion (typically B3) */
|
|
188
|
+
baseCurrency,
|
|
189
|
+
/** Current exchange rate from base to selected currency (undefined while loading) */
|
|
190
|
+
exchangeRate,
|
|
191
|
+
/** Format a value with currency conversion and proper symbol/decimal handling */
|
|
192
|
+
formatCurrencyValue,
|
|
193
|
+
/** Format a tooltip value showing alternate currency representation */
|
|
194
|
+
formatTooltipValue,
|
|
195
|
+
/** Symbol for the currently selected currency (e.g., "$", "€", "ETH") */
|
|
196
|
+
selectedCurrencySymbol: currencyStore_1.CURRENCY_SYMBOLS[selectedCurrency],
|
|
197
|
+
/** Symbol for the base currency */
|
|
198
|
+
baseCurrencySymbol: currencyStore_1.CURRENCY_SYMBOLS[baseCurrency],
|
|
199
|
+
};
|
|
200
|
+
}
|
|
@@ -14,4 +14,6 @@ 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
|
+
__exportStar(require("./components"), exports);
|
|
17
18
|
__exportStar(require("./hooks"), exports);
|
|
19
|
+
__exportStar(require("./stores"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCurrencyModalStore = void 0;
|
|
4
|
+
const zustand_1 = require("zustand");
|
|
5
|
+
exports.useCurrencyModalStore = (0, zustand_1.create)(set => ({
|
|
6
|
+
isOpen: false,
|
|
7
|
+
openModal: () => set({ isOpen: true }),
|
|
8
|
+
closeModal: () => set({ isOpen: false }),
|
|
9
|
+
}));
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported currencies for display and conversion.
|
|
3
|
+
* Includes fiat currencies (USD, EUR, GBP, JPY, CAD, AUD, KRW) and crypto (ETH, SOL, B3).
|
|
4
|
+
*/
|
|
5
|
+
export type SupportedCurrency = "ETH" | "USD" | "EUR" | "GBP" | "JPY" | "CAD" | "AUD" | "B3" | "SOL" | "KRW";
|
|
6
|
+
/**
|
|
7
|
+
* Currency symbols used for display formatting.
|
|
8
|
+
* Prefix currencies (USD, EUR, GBP, CAD, AUD) show symbol before the amount.
|
|
9
|
+
* Suffix currencies (JPY, KRW, ETH, SOL, B3) show symbol after the amount.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CURRENCY_SYMBOLS: Record<SupportedCurrency, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Human-readable currency names for display in selectors and labels.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CURRENCY_NAMES: Record<SupportedCurrency, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Currency store state interface.
|
|
18
|
+
* @property selectedCurrency - The currency currently selected for display
|
|
19
|
+
* @property baseCurrency - The base currency for conversion (typically B3)
|
|
20
|
+
* @property setSelectedCurrency - Update the selected display currency
|
|
21
|
+
* @property setBaseCurrency - Update the base currency for conversions
|
|
22
|
+
*/
|
|
23
|
+
interface CurrencyState {
|
|
24
|
+
selectedCurrency: SupportedCurrency;
|
|
25
|
+
baseCurrency: SupportedCurrency;
|
|
26
|
+
setSelectedCurrency: (currency: SupportedCurrency) => void;
|
|
27
|
+
setBaseCurrency: (currency: SupportedCurrency) => void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Zustand store for managing currency selection and conversion.
|
|
31
|
+
* Persists user's selected currency preference in localStorage.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* const { selectedCurrency, setSelectedCurrency } = useCurrencyStore();
|
|
36
|
+
* // Change display currency to USD
|
|
37
|
+
* setSelectedCurrency('USD');
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const useCurrencyStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<CurrencyState>, "persist"> & {
|
|
41
|
+
persist: {
|
|
42
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<CurrencyState, CurrencyState>>) => void;
|
|
43
|
+
clearStorage: () => void;
|
|
44
|
+
rehydrate: () => Promise<void> | void;
|
|
45
|
+
hasHydrated: () => boolean;
|
|
46
|
+
onHydrate: (fn: (state: CurrencyState) => void) => () => void;
|
|
47
|
+
onFinishHydration: (fn: (state: CurrencyState) => void) => () => void;
|
|
48
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<CurrencyState, CurrencyState>>;
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCurrencyStore = exports.CURRENCY_NAMES = exports.CURRENCY_SYMBOLS = void 0;
|
|
4
|
+
const zustand_1 = require("zustand");
|
|
5
|
+
const middleware_1 = require("zustand/middleware");
|
|
6
|
+
/**
|
|
7
|
+
* Currency symbols used for display formatting.
|
|
8
|
+
* Prefix currencies (USD, EUR, GBP, CAD, AUD) show symbol before the amount.
|
|
9
|
+
* Suffix currencies (JPY, KRW, ETH, SOL, B3) show symbol after the amount.
|
|
10
|
+
*/
|
|
11
|
+
exports.CURRENCY_SYMBOLS = {
|
|
12
|
+
ETH: "ETH",
|
|
13
|
+
USD: "$",
|
|
14
|
+
EUR: "€",
|
|
15
|
+
GBP: "£",
|
|
16
|
+
JPY: "¥",
|
|
17
|
+
CAD: "C$",
|
|
18
|
+
AUD: "A$",
|
|
19
|
+
B3: "B3",
|
|
20
|
+
SOL: "SOL",
|
|
21
|
+
KRW: "₩",
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Human-readable currency names for display in selectors and labels.
|
|
25
|
+
*/
|
|
26
|
+
exports.CURRENCY_NAMES = {
|
|
27
|
+
ETH: "Ethereum",
|
|
28
|
+
USD: "US Dollar",
|
|
29
|
+
EUR: "Euro",
|
|
30
|
+
GBP: "British Pound",
|
|
31
|
+
JPY: "Japanese Yen",
|
|
32
|
+
CAD: "Canadian Dollar",
|
|
33
|
+
AUD: "Australian Dollar",
|
|
34
|
+
B3: "B3",
|
|
35
|
+
SOL: "Solana",
|
|
36
|
+
KRW: "Korean Won",
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Zustand store for managing currency selection and conversion.
|
|
40
|
+
* Persists user's selected currency preference in localStorage.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* const { selectedCurrency, setSelectedCurrency } = useCurrencyStore();
|
|
45
|
+
* // Change display currency to USD
|
|
46
|
+
* setSelectedCurrency('USD');
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
exports.useCurrencyStore = (0, zustand_1.create)()((0, middleware_1.persist)(set => ({
|
|
50
|
+
selectedCurrency: "B3",
|
|
51
|
+
baseCurrency: "B3",
|
|
52
|
+
setSelectedCurrency: currency => set({ selectedCurrency: currency }),
|
|
53
|
+
setBaseCurrency: currency => set({ baseCurrency: currency }),
|
|
54
|
+
}), {
|
|
55
|
+
name: "currency-storage",
|
|
56
|
+
version: 2,
|
|
57
|
+
}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./currencyModalStore"), exports);
|
|
18
|
+
__exportStar(require("./currencyStore"), exports);
|
|
@@ -42,7 +42,7 @@ export function AnySpend(props) {
|
|
|
42
42
|
const fingerprintConfig = getFingerprintConfig();
|
|
43
43
|
return (_jsx(AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: _jsx(AnySpendInner, { ...props }) }));
|
|
44
44
|
}
|
|
45
|
-
function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode = "modal", defaultActiveTab = "crypto", loadOrder, hideTransactionHistoryButton, recipientAddress: recipientAddressFromProps, onTokenSelect, onSuccess, }) {
|
|
45
|
+
function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode = "modal", defaultActiveTab = "crypto", loadOrder, hideTransactionHistoryButton, recipientAddress: recipientAddressFromProps, onTokenSelect, onSuccess, customUsdInputValues, }) {
|
|
46
46
|
const searchParams = useSearchParamsSSR();
|
|
47
47
|
const router = useRouter();
|
|
48
48
|
// Determine if we're in "buy mode" based on whether destination token props are provided
|
|
@@ -50,6 +50,8 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
50
50
|
// Add refs to track URL state
|
|
51
51
|
const initialUrlProcessed = useRef(false);
|
|
52
52
|
const lastUrlUpdate = useRef(null);
|
|
53
|
+
// Track if onSuccess has been called for the current order
|
|
54
|
+
const onSuccessCalled = useRef(false);
|
|
53
55
|
const [activeTab, setActiveTab] = useState(defaultActiveTab);
|
|
54
56
|
const [orderId, setOrderId] = useState(loadOrder);
|
|
55
57
|
const { orderAndTransactions: oat, getOrderAndTransactionsError } = useAnyspendOrderAndTransactions(orderId);
|
|
@@ -387,12 +389,17 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
387
389
|
}
|
|
388
390
|
}, [anyspendQuote, isSrcInputDirty]);
|
|
389
391
|
useEffect(() => {
|
|
390
|
-
if (oat?.data?.order.status === "executed") {
|
|
392
|
+
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
391
393
|
console.log("Calling onSuccess");
|
|
392
394
|
const txHash = oat?.data?.executeTx?.txHash;
|
|
393
395
|
onSuccess?.(txHash);
|
|
396
|
+
onSuccessCalled.current = true;
|
|
394
397
|
}
|
|
395
|
-
}, [oat?.data?.
|
|
398
|
+
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
399
|
+
// Reset flag when orderId changes
|
|
400
|
+
useEffect(() => {
|
|
401
|
+
onSuccessCalled.current = false;
|
|
402
|
+
}, [orderId]);
|
|
396
403
|
const { createOrder, isCreatingOrder } = useAnyspendCreateOrder({
|
|
397
404
|
onSuccess: data => {
|
|
398
405
|
const orderId = data.data.id;
|
|
@@ -667,7 +674,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
667
674
|
setActivePanel(PanelView.MAIN);
|
|
668
675
|
setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE); // Reset payment method when going back
|
|
669
676
|
} })) }) }));
|
|
670
|
-
const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [isBuyMode && (_jsxs("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: [selectedDstToken.metadata?.logoURI && (_jsx("div", { className: "relative", children: _jsx("img", { src: selectedDstToken.metadata.logoURI, alt: selectedDstToken.symbol, className: "border-as-stroke h-12 w-12 rounded-full border-2 shadow-md" }) })), _jsx("div", { children: _jsxs("h1", { className: "text-as-primary text-xl font-bold", children: ["Buy ", selectedDstToken.symbol] }) })] })), _jsx(TabSection, { activeTab: activeTab, setActiveTab: setActiveTab, setSelectedCryptoPaymentMethod: setSelectedCryptoPaymentMethod, setSelectedFiatPaymentMethod: setSelectedFiatPaymentMethod }), _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [activeTab === "crypto" ? (_jsx(CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : (_jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, children: _jsx(PanelOnramp, { srcAmountOnRamp: srcAmountOnRamp, setSrcAmountOnRamp: setSrcAmountOnRamp, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: recipientAddress, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, destinationAmount: dstAmount, onDestinationTokenChange: setSelectedDstToken, onDestinationChainChange: setSelectedDstChainId, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: PanelView.RECIPIENT_SELECTION, hideDstToken: isBuyMode, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL) }) })), _jsx(Button, { variant: "ghost", className: cn("border-as-stroke bg-as-surface-primary absolute left-1/2 top-1/2 z-10 h-10 w-10 -translate-x-1/2 -translate-y-1/2 rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl", isBuyMode && "top-[calc(50%+56px)] cursor-default", activeTab === "fiat" && "hidden"), onClick: () => {
|
|
677
|
+
const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [isBuyMode && (_jsxs("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: [selectedDstToken.metadata?.logoURI && (_jsx("div", { className: "relative", children: _jsx("img", { src: selectedDstToken.metadata.logoURI, alt: selectedDstToken.symbol, className: "border-as-stroke h-12 w-12 rounded-full border-2 shadow-md" }) })), _jsx("div", { children: _jsxs("h1", { className: "text-as-primary text-xl font-bold", children: ["Buy ", selectedDstToken.symbol] }) })] })), _jsx(TabSection, { activeTab: activeTab, setActiveTab: setActiveTab, setSelectedCryptoPaymentMethod: setSelectedCryptoPaymentMethod, setSelectedFiatPaymentMethod: setSelectedFiatPaymentMethod }), _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [activeTab === "crypto" ? (_jsx(CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : (_jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, children: _jsx(PanelOnramp, { srcAmountOnRamp: srcAmountOnRamp, setSrcAmountOnRamp: setSrcAmountOnRamp, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: recipientAddress, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, destinationAmount: dstAmount, onDestinationTokenChange: setSelectedDstToken, onDestinationChainChange: setSelectedDstChainId, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: PanelView.RECIPIENT_SELECTION, hideDstToken: isBuyMode, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), customUsdInputValues: customUsdInputValues }) })), _jsx(Button, { variant: "ghost", className: cn("border-as-stroke bg-as-surface-primary absolute left-1/2 top-1/2 z-10 h-10 w-10 -translate-x-1/2 -translate-y-1/2 rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl", isBuyMode && "top-[calc(50%+56px)] cursor-default", activeTab === "fiat" && "hidden"), onClick: () => {
|
|
671
678
|
if (activeTab === "fiat" || isBuyMode) {
|
|
672
679
|
return;
|
|
673
680
|
}
|
|
@@ -10,7 +10,7 @@ import { simpleHashChainToChainName } from "../../../shared/utils/simplehash.js"
|
|
|
10
10
|
import invariant from "invariant";
|
|
11
11
|
import { ChevronRight, ChevronRightCircle, Loader2 } from "lucide-react";
|
|
12
12
|
import { motion } from "motion/react";
|
|
13
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
13
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
14
14
|
import { toast } from "sonner";
|
|
15
15
|
import { base } from "viem/chains";
|
|
16
16
|
import { useFeatureFlags } from "../contexts/FeatureFlagsContext.js";
|
|
@@ -117,6 +117,8 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
117
117
|
// Update recipient logic to use custom recipient
|
|
118
118
|
const recipientAddress = customRecipientAddress || currentWallet.address;
|
|
119
119
|
const [orderId, setOrderId] = useState(loadOrder);
|
|
120
|
+
// Track if onSuccess has been called for the current order
|
|
121
|
+
const onSuccessCalled = React.useRef(false);
|
|
120
122
|
const [srcChainId, setSrcChainId] = useState(base.id);
|
|
121
123
|
// Get token list for token balance check
|
|
122
124
|
const chainName = useMemo(() => simpleHashChainToChainName(srcChainId), [srcChainId]);
|
|
@@ -230,12 +232,17 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
230
232
|
// Get geo data and onramp options (after quote is available)
|
|
231
233
|
const { geoData, isOnrampSupported, coinbaseAvailablePaymentMethods, stripeWeb2Support } = useGeoOnrampOptions(srcFiatAmount);
|
|
232
234
|
useEffect(() => {
|
|
233
|
-
if (oat?.data?.order.status === "executed") {
|
|
235
|
+
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
234
236
|
console.log("Calling onSuccess");
|
|
235
237
|
const txHash = oat?.data?.executeTx?.txHash;
|
|
236
238
|
onSuccess?.(txHash);
|
|
239
|
+
onSuccessCalled.current = true;
|
|
237
240
|
}
|
|
238
|
-
}, [oat?.data?.
|
|
241
|
+
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
242
|
+
// Reset flag when orderId changes
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
onSuccessCalled.current = false;
|
|
245
|
+
}, [orderId]);
|
|
239
246
|
const { createOrder: createRegularOrder, isCreatingOrder: isCreatingRegularOrder } = useAnyspendCreateOrder({
|
|
240
247
|
onSuccess: data => {
|
|
241
248
|
setOrderId(data.data.id);
|
|
@@ -19,5 +19,6 @@ export interface AnySpendDepositHypeProps {
|
|
|
19
19
|
onTokenSelect?: (token: components["schemas"]["Token"], event: {
|
|
20
20
|
preventDefault: () => void;
|
|
21
21
|
}) => void;
|
|
22
|
+
customUsdInputValues?: string[];
|
|
22
23
|
}
|
|
23
24
|
export declare function AnySpendDepositHype(props: AnySpendDepositHypeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -28,7 +28,7 @@ export function AnySpendDepositHype(props) {
|
|
|
28
28
|
const fingerprintConfig = getFingerprintConfig();
|
|
29
29
|
return (_jsx(AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: _jsx(AnySpendDepositHypeInner, { ...props }) }));
|
|
30
30
|
}
|
|
31
|
-
function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, onSuccess, mainFooter, onTokenSelect, }) {
|
|
31
|
+
function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, onSuccess, mainFooter, onTokenSelect, customUsdInputValues, }) {
|
|
32
32
|
// Use shared flow hook
|
|
33
33
|
const { activePanel, setActivePanel, orderId, setOrderId, 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({
|
|
34
34
|
paymentType,
|
|
@@ -112,7 +112,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
112
112
|
await handleFiatOrder();
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
|
-
const mainView = (_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(CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : (_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, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, hideDstToken: true, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: PanelView.RECIPIENT_SELECTION, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL) }) })), _jsx("div", { className: cn("relative -my-1 flex h-0 items-center justify-center", paymentType === "fiat" && "hidden"), children: _jsx(Button, { variant: "ghost", className: 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: _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, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: HYPE_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: base.id, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, onChangeDstAmount: value => {
|
|
115
|
+
const mainView = (_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(CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : (_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, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, hideDstToken: true, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: PanelView.RECIPIENT_SELECTION, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), customUsdInputValues: customUsdInputValues }) })), _jsx("div", { className: cn("relative -my-1 flex h-0 items-center justify-center", paymentType === "fiat" && "hidden"), children: _jsx(Button, { variant: "ghost", className: 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: _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, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: HYPE_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: base.id, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, onChangeDstAmount: value => {
|
|
116
116
|
setIsSrcInputDirty(false);
|
|
117
117
|
setSrcAmount(value);
|
|
118
118
|
}, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL) }))] }) }), _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 }) }), mainFooter ? mainFooter : null] }));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { components } from "../../../../anyspend/types/api";
|
|
2
2
|
import { GetQuoteResponse } from "../../../../anyspend/types/api_req_res";
|
|
3
3
|
import { FiatPaymentMethod } from "./FiatPaymentMethod";
|
|
4
|
-
export declare function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPaymentMethod, setActivePanel, _recipientAddress, destinationToken, destinationChainId, destinationAmount, onDestinationTokenChange, onDestinationChainChange, fiatPaymentMethodIndex, recipientSelectionPanelIndex, dstTokenSymbol, hideDstToken, anyspendQuote, onShowPointsDetail, }: {
|
|
4
|
+
export declare function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPaymentMethod, setActivePanel, _recipientAddress, destinationToken, destinationChainId, destinationAmount, onDestinationTokenChange, onDestinationChainChange, fiatPaymentMethodIndex, recipientSelectionPanelIndex, dstTokenSymbol, hideDstToken, anyspendQuote, onShowPointsDetail, customUsdInputValues, }: {
|
|
5
5
|
srcAmountOnRamp: string;
|
|
6
6
|
setSrcAmountOnRamp: (amount: string) => void;
|
|
7
7
|
selectedPaymentMethod?: FiatPaymentMethod;
|
|
@@ -18,4 +18,5 @@ export declare function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selec
|
|
|
18
18
|
hideDstToken?: boolean;
|
|
19
19
|
anyspendQuote?: GetQuoteResponse;
|
|
20
20
|
onShowPointsDetail?: () => void;
|
|
21
|
+
customUsdInputValues?: string[];
|
|
21
22
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -11,7 +11,7 @@ import { useFeatureFlags } from "../../contexts/FeatureFlagsContext.js";
|
|
|
11
11
|
import { FiatPaymentMethod } from "./FiatPaymentMethod.js";
|
|
12
12
|
import { OrderTokenAmountFiat } from "./OrderTokenAmountFiat.js";
|
|
13
13
|
import { PointsBadge } from "./PointsBadge.js";
|
|
14
|
-
export function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPaymentMethod, setActivePanel, _recipientAddress, destinationToken, destinationChainId, destinationAmount, onDestinationTokenChange, onDestinationChainChange, fiatPaymentMethodIndex, recipientSelectionPanelIndex, dstTokenSymbol, hideDstToken = false, anyspendQuote, onShowPointsDetail, }) {
|
|
14
|
+
export function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPaymentMethod, setActivePanel, _recipientAddress, destinationToken, destinationChainId, destinationAmount, onDestinationTokenChange, onDestinationChainChange, fiatPaymentMethodIndex, recipientSelectionPanelIndex, dstTokenSymbol, hideDstToken = false, anyspendQuote, onShowPointsDetail, customUsdInputValues = ["5", "10", "20", "25"], }) {
|
|
15
15
|
const featureFlags = useFeatureFlags();
|
|
16
16
|
// Get geo-based onramp options to access fee information
|
|
17
17
|
const { stripeWeb2Support } = useGeoOnrampOptions(srcAmountOnRamp);
|
|
@@ -69,9 +69,11 @@ export function PanelOnramp({ srcAmountOnRamp, setSrcAmountOnRamp, selectedPayme
|
|
|
69
69
|
const handleQuickAmount = (value) => {
|
|
70
70
|
setSrcAmountOnRamp(value);
|
|
71
71
|
};
|
|
72
|
-
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-
|
|
72
|
+
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-1 pt-1 text-4xl font-bold focus-visible:ring-0 focus-visible:ring-offset-0", style: {
|
|
73
73
|
width: `${Math.max(50, srcAmountOnRamp.length * 34)}px`,
|
|
74
|
-
} })] }) }), _jsx("div", { className: cn("mx-auto mb-6
|
|
74
|
+
} })] }) }), _jsx("div", { className: cn("mx-auto mb-6 flex justify-center gap-2", hideDstToken && "mb-0"), children: customUsdInputValues
|
|
75
|
+
.filter(v => !isNaN(Number(v)))
|
|
76
|
+
.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
|
|
75
77
|
? "border-as-border-secondary bg-as-surface-secondary"
|
|
76
78
|
: "bg-as-surface-secondary hover:bg-as-surface-secondary"}`, children: ["$", value] }, value))) }), destinationToken && destinationChainId && !hideDstToken && (_jsx(OrderTokenAmountFiat, { address: _recipientAddress, context: "to", inputValue: destinationAmount || "0", onChangeInput: () => { }, chainId: destinationChainId, setChainId: onDestinationChainChange || (() => { }), token: destinationToken, setToken: onDestinationTokenChange || (() => { }) }))] }), _jsxs("div", { className: "border-as-border-secondary bg-as-surface-secondary mt-4 flex w-full flex-col gap-3 rounded-xl border p-4", children: [_jsxs("div", { className: "flex w-full items-center justify-between gap-2", children: [_jsx("span", { className: "text-as-tertiarry flex items-center text-sm", children: "Recipient" }), _recipientAddress ? (_jsxs("button", { className: "text-as-tertiarry flex h-7 items-center gap-1 text-sm transition-colors hover:text-blue-700", onClick: () => setActivePanel(recipientSelectionPanelIndex), children: [_jsx("span", { className: "text-sm", children: recipientName ? formatUsername(recipientName) : formatAddress(_recipientAddress) }), _jsx(ChevronRight, { size: 16 })] })) : (_jsxs("button", { className: "text-as-tertiarry flex h-7 items-center gap-1 text-sm transition-colors hover:text-blue-700", onClick: () => setActivePanel(5), children: [_jsx(Wallet, { className: "text-as-brand", size: 16 }), "Select recipient", _jsx(ChevronRight, { size: 16 })] }))] }), _jsx("div", { className: "divider w-full" }), _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("span", { className: "text-as-tertiarry text-sm", children: "Expected to receive" }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsxs("span", { className: "text-as-primary font-semibold", children: [destinationAmount || "0", " ", dstTokenSymbol || destinationToken?.symbol || ""] }), _jsxs("span", { className: "text-as-tertiarry text-sm", children: ["on ", destinationChainId ? ALL_CHAINS[destinationChainId]?.name : ""] }), destinationToken && destinationChainId && destinationToken.metadata?.logoURI && (_jsx("img", { src: ALL_CHAINS[destinationChainId]?.logoUrl, alt: "Chain", className: "h-4 w-4 rounded-full" }))] })] }), _jsx("div", { className: "divider w-full" }), _jsx("div", { className: "", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-as-tertiarry text-sm", children: (() => {
|
|
77
79
|
const fee = getFeeFromApi(selectedPaymentMethod || FiatPaymentMethod.NONE);
|