@b3dotfun/sdk 0.0.58-alpha.3 → 0.0.58-test.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.
Files changed (47) hide show
  1. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +0 -4
  2. package/dist/cjs/anyspend/utils/index.d.ts +0 -1
  3. package/dist/cjs/anyspend/utils/index.js +0 -1
  4. package/dist/cjs/global-account/react/components/B3DynamicModal.js +0 -17
  5. package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +1 -441
  6. package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +0 -2
  7. package/dist/cjs/shared/react/components/CurrencySelector.js +3 -8
  8. package/dist/cjs/shared/react/components/FormattedCurrency.d.ts +3 -3
  9. package/dist/cjs/shared/react/components/FormattedCurrency.js +26 -31
  10. package/dist/cjs/shared/react/hooks/useCurrencyConversion.d.ts +5 -8
  11. package/dist/cjs/shared/react/hooks/useCurrencyConversion.js +94 -153
  12. package/dist/cjs/shared/react/stores/currencyStore.d.ts +8 -83
  13. package/dist/cjs/shared/react/stores/currencyStore.js +5 -147
  14. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +1 -5
  15. package/dist/esm/anyspend/utils/index.d.ts +0 -1
  16. package/dist/esm/anyspend/utils/index.js +0 -1
  17. package/dist/esm/global-account/react/components/B3DynamicModal.js +0 -17
  18. package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +1 -441
  19. package/dist/esm/global-account/react/hooks/useWagmiConfig.js +0 -2
  20. package/dist/esm/shared/react/components/CurrencySelector.js +5 -10
  21. package/dist/esm/shared/react/components/FormattedCurrency.d.ts +3 -3
  22. package/dist/esm/shared/react/components/FormattedCurrency.js +26 -31
  23. package/dist/esm/shared/react/hooks/useCurrencyConversion.d.ts +5 -8
  24. package/dist/esm/shared/react/hooks/useCurrencyConversion.js +95 -154
  25. package/dist/esm/shared/react/stores/currencyStore.d.ts +8 -83
  26. package/dist/esm/shared/react/stores/currencyStore.js +5 -143
  27. package/dist/types/anyspend/utils/index.d.ts +0 -1
  28. package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +1 -441
  29. package/dist/types/shared/react/components/FormattedCurrency.d.ts +3 -3
  30. package/dist/types/shared/react/hooks/useCurrencyConversion.d.ts +5 -8
  31. package/dist/types/shared/react/stores/currencyStore.d.ts +8 -83
  32. package/package.json +8 -4
  33. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +2 -6
  34. package/src/anyspend/utils/index.ts +0 -1
  35. package/src/global-account/react/components/B3DynamicModal.tsx +0 -20
  36. package/src/global-account/react/hooks/useWagmiConfig.tsx +0 -2
  37. package/src/shared/react/components/CurrencySelector.tsx +5 -36
  38. package/src/shared/react/components/FormattedCurrency.tsx +30 -36
  39. package/src/shared/react/hooks/__tests__/useCurrencyConversion.test.ts +14 -14
  40. package/src/shared/react/hooks/useCurrencyConversion.ts +96 -163
  41. package/src/shared/react/stores/currencyStore.ts +10 -216
  42. package/dist/cjs/anyspend/utils/accountStore.d.ts +0 -7
  43. package/dist/cjs/anyspend/utils/accountStore.js +0 -8
  44. package/dist/esm/anyspend/utils/accountStore.d.ts +0 -7
  45. package/dist/esm/anyspend/utils/accountStore.js +0 -5
  46. package/dist/types/anyspend/utils/accountStore.d.ts +0 -7
  47. package/src/anyspend/utils/accountStore.ts +0 -12
@@ -8,30 +8,21 @@ const utils_1 = require("../../../shared/utils");
8
8
  const tooltip_1 = require("../../../global-account/react/components/ui/tooltip");
9
9
  const useCurrencyConversion_1 = require("../hooks/useCurrencyConversion");
10
10
  const currencyModalStore_1 = require("../stores/currencyModalStore");
11
- const currencyStore_1 = require("../stores/currencyStore");
12
- function FormattedCurrency({ amount, sourceCurrency, showChange = false, showColor = false, className, subB3Icon = true, clickable = true, decimals, }) {
11
+ function FormattedCurrency({ amount, showChange = false, showColor = false, className, subB3Icon = true, clickable = true, decimals, currency, }) {
13
12
  const { formatCurrencyValue, formatTooltipValue, selectedCurrency, baseCurrency } = (0, useCurrencyConversion_1.useCurrencyConversion)();
14
13
  const { openModal } = (0, currencyModalStore_1.useCurrencyModalStore)();
15
- // Convert from smallest unit to human-readable using currency's decimal places
16
- const decimalPlaces = (0, currencyStore_1.getCurrencyDecimalPlaces)(sourceCurrency);
17
- const divisor = Math.pow(10, decimalPlaces);
18
- // Parse amount - handle both string and numeric inputs, including negatives
19
- let parsedAmount;
20
- if (typeof amount === "string") {
21
- // Handle BigInt strings and negative values
22
- const numericAmount = amount.startsWith("-") ? -Math.abs(parseFloat(amount.replace("-", ""))) : parseFloat(amount);
23
- parsedAmount = numericAmount / divisor;
24
- }
25
- else {
26
- parsedAmount = amount / divisor;
27
- }
28
- const isPositive = parsedAmount >= 0;
29
- // Always format with absolute value, we'll add the sign separately
30
- const absoluteAmount = Math.abs(parsedAmount);
31
- // Format value with automatic conversion from source to display currency
32
- const formattedValue = formatCurrencyValue(absoluteAmount, sourceCurrency, { decimals });
14
+ // Use passed currency or fall back to selected currency
15
+ const activeCurrency = currency || selectedCurrency;
16
+ const isPositive = amount >= 0;
17
+ // Get the formatted value (using absolute value for negative numbers when showing change)
18
+ const baseAmount = showChange ? Math.abs(amount) : amount;
19
+ // Use centralized formatting from hook with optional overrides
20
+ const formattedValue = formatCurrencyValue(baseAmount, {
21
+ decimals,
22
+ currency,
23
+ });
33
24
  // Generate tooltip using the centralized hook function
34
- const baseTooltipValue = formatTooltipValue(parsedAmount, sourceCurrency);
25
+ const baseTooltipValue = formatTooltipValue(amount, currency);
35
26
  // Add change indicator if needed
36
27
  const tooltipValue = showChange ? `${isPositive ? "+" : "-"}${baseTooltipValue}` : baseTooltipValue;
37
28
  // Determine color class
@@ -44,22 +35,26 @@ function FormattedCurrency({ amount, sourceCurrency, showChange = false, showCol
44
35
  colorClass = "text-red-400";
45
36
  }
46
37
  }
47
- // Build display value with appropriate sign
38
+ // Add change indicator
48
39
  let displayValue = formattedValue;
49
40
  if (showChange) {
50
- // Add +/- prefix for change indicators
51
- displayValue = `${isPositive ? "+" : "-"}${formattedValue}`;
52
- }
53
- else if (!isPositive) {
54
- // Add minus sign for negative values
55
- displayValue = `-${formattedValue}`;
41
+ if (isPositive) {
42
+ displayValue = `+${formattedValue}`;
43
+ }
44
+ else {
45
+ displayValue = `-${formattedValue}`;
46
+ }
56
47
  }
57
48
  const handleClick = () => {
58
49
  if (clickable) {
59
50
  openModal();
60
51
  }
61
52
  };
62
- // Check if we should show B3 icon (when displaying in B3 and baseCurrency is B3)
63
- const shouldShowB3Icon = subB3Icon && selectedCurrency === "B3" && baseCurrency === "B3";
64
- return ((0, jsx_runtime_1.jsxs)(tooltip_1.Tooltip, { children: [(0, jsx_runtime_1.jsx)(tooltip_1.TooltipTrigger, { asChild: true, children: (0, jsx_runtime_1.jsxs)("span", { onClick: handleClick, className: (0, utils_1.cn)("inline-flex items-center gap-1 whitespace-nowrap", colorClass, className, clickable && "cursor-pointer transition-opacity hover:opacity-80"), children: [shouldShowB3Icon ? displayValue.split(" ")[0] : displayValue, shouldShowB3Icon && ((0, jsx_runtime_1.jsx)("img", { src: currency_1.B3_COIN_IMAGE_URL, className: "inline-block h-4 w-4 align-middle", alt: "B3 coin" }))] }) }), (0, jsx_runtime_1.jsx)(tooltip_1.TooltipContent, { children: tooltipValue })] }));
53
+ return ((0, jsx_runtime_1.jsxs)(tooltip_1.Tooltip, { children: [(0, jsx_runtime_1.jsx)(tooltip_1.TooltipTrigger, { asChild: true, children: (0, jsx_runtime_1.jsxs)("span", { onClick: handleClick, className: (0, utils_1.cn)("inline-flex items-center gap-1 whitespace-nowrap", colorClass, className, clickable && "cursor-pointer transition-opacity hover:opacity-80"), children: [subB3Icon &&
54
+ (currency === baseCurrency || (!currency && activeCurrency === baseCurrency)) &&
55
+ baseCurrency === "B3"
56
+ ? displayValue.split(" ")[0]
57
+ : displayValue, subB3Icon &&
58
+ (currency === baseCurrency || (!currency && activeCurrency === baseCurrency)) &&
59
+ baseCurrency === "B3" && ((0, jsx_runtime_1.jsx)("img", { src: currency_1.B3_COIN_IMAGE_URL, className: "inline-block h-4 w-4 align-middle", alt: "B3 coin" }))] }) }), (0, jsx_runtime_1.jsx)(tooltip_1.TooltipContent, { children: tooltipValue })] }));
65
60
  }
@@ -16,23 +16,20 @@
16
16
  */
17
17
  export declare function useCurrencyConversion(): {
18
18
  /** Currently selected display currency */
19
- selectedCurrency: string;
19
+ selectedCurrency: import("../stores/currencyStore").SupportedCurrency;
20
20
  /** Base currency used for conversion (typically B3) */
21
- baseCurrency: string;
21
+ baseCurrency: import("../stores/currencyStore").SupportedCurrency;
22
22
  /** Current exchange rate from base to selected currency (undefined while loading) */
23
23
  exchangeRate: number | undefined;
24
24
  /** Format a value with currency conversion and proper symbol/decimal handling */
25
- formatCurrencyValue: (value: number, sourceCurrency: string, options?: {
25
+ formatCurrencyValue: (value: number, options?: {
26
26
  decimals?: number;
27
+ currency?: string;
27
28
  }) => string;
28
29
  /** Format a tooltip value showing alternate currency representation */
29
- formatTooltipValue: (value: number, sourceCurrency: string) => string;
30
+ formatTooltipValue: (value: number, customCurrency?: string) => string;
30
31
  /** Symbol for the currently selected currency (e.g., "$", "€", "ETH") */
31
32
  selectedCurrencySymbol: string;
32
33
  /** Symbol for the base currency */
33
34
  baseCurrencySymbol: string;
34
- /** Get exchange rate between any two currencies */
35
- getExchangeRate: (from: string, to: string) => number | undefined;
36
- /** All registered custom currencies */
37
- customCurrencies: Record<string, import("../stores/currencyStore").CurrencyMetadata>;
38
35
  };
@@ -40,10 +40,8 @@ async function fetchAllExchangeRates(baseCurrency) {
40
40
  function useCurrencyConversion() {
41
41
  const selectedCurrency = (0, currencyStore_1.useCurrencyStore)(state => state.selectedCurrency);
42
42
  const baseCurrency = (0, currencyStore_1.useCurrencyStore)(state => state.baseCurrency);
43
- const getCustomExchangeRate = (0, currencyStore_1.useCurrencyStore)(state => state.getExchangeRate);
44
- const customCurrencies = (0, currencyStore_1.useCurrencyStore)(state => state.customCurrencies);
45
- // Fetch all exchange rates for the base currency from Coinbase API
46
- const { data: apiExchangeRates } = (0, react_query_1.useQuery)({
43
+ // Fetch all exchange rates for the base currency
44
+ const { data: exchangeRates } = (0, react_query_1.useQuery)({
47
45
  queryKey: ["exchangeRates", baseCurrency],
48
46
  queryFn: () => fetchAllExchangeRates(baseCurrency),
49
47
  refetchInterval: REFETCH_INTERVAL_MS,
@@ -51,208 +49,155 @@ function useCurrencyConversion() {
51
49
  retry: 3,
52
50
  retryDelay: attemptIndex => Math.min(1000 * 2 ** attemptIndex, REFETCH_INTERVAL_MS),
53
51
  });
52
+ // Extract specific rates from the full rates object
53
+ const exchangeRate = exchangeRates?.[selectedCurrency];
54
+ const usdRate = exchangeRates?.["USD"];
54
55
  /**
55
- * Get exchange rate between two currencies, checking custom rates first, then API rates.
56
- * Supports chaining through base currency for custom currencies.
56
+ * Formats a numeric value as a currency string with proper conversion and formatting.
57
57
  *
58
- * Examples:
59
- * - WIN USD: Checks WIN→USD custom rate, then chains WIN→B3→USD
60
- * - BTC EUR: Checks BTC→EUR custom rate, then chains BTC→B3→EUR
61
- */
62
- const getExchangeRate = (from, to) => {
63
- // If same currency, rate is 1
64
- if (from === to)
65
- return 1;
66
- // 1. Check direct custom exchange rate first
67
- const directCustomRate = getCustomExchangeRate(from, to);
68
- if (directCustomRate !== undefined) {
69
- return directCustomRate;
70
- }
71
- // 2. Check direct API rate (from base currency)
72
- if (from === baseCurrency && apiExchangeRates) {
73
- return apiExchangeRates[to];
74
- }
75
- // 3. Try to chain through base currency using custom rates
76
- // e.g., WIN → B3 → USD (where WIN→B3 is custom, B3→USD is API)
77
- const customFromToBase = getCustomExchangeRate(from, baseCurrency);
78
- if (customFromToBase !== undefined) {
79
- // We have a custom rate from 'from' to base
80
- // Now get rate from base to 'to'
81
- const baseToTo = apiExchangeRates?.[to] ?? getCustomExchangeRate(baseCurrency, to);
82
- if (baseToTo !== undefined) {
83
- return customFromToBase * baseToTo;
84
- }
85
- }
86
- // 4. Try reverse: chain from base currency through custom rate
87
- // e.g., USD → B3 → WIN (where B3→WIN is custom)
88
- const customBaseToTo = getCustomExchangeRate(baseCurrency, to);
89
- if (customBaseToTo !== undefined && apiExchangeRates) {
90
- // We have a custom rate from base to 'to'
91
- // Now get rate from 'from' to base
92
- const fromToBase = apiExchangeRates[from];
93
- if (fromToBase !== undefined && fromToBase !== 0) {
94
- return fromToBase * customBaseToTo;
95
- }
96
- }
97
- // 5. Fall back to pure API conversion through base
98
- // e.g., EUR to GBP = (EUR to B3) * (B3 to GBP)
99
- if (apiExchangeRates) {
100
- const fromToBase = apiExchangeRates[from];
101
- const baseToTo = apiExchangeRates[to];
102
- if (fromToBase && baseToTo && fromToBase !== 0) {
103
- return baseToTo / fromToBase;
104
- }
105
- }
106
- return undefined;
107
- };
108
- // Extract specific rates
109
- const exchangeRate = getExchangeRate(baseCurrency, selectedCurrency);
110
- /**
111
- * Formats a numeric value as a currency string with automatic conversion.
112
- *
113
- * New behavior:
114
- * - Takes the SOURCE currency (what the value is in) as a required parameter
115
- * - Automatically converts from source → display currency (selected in picker)
116
- * - Supports multi-hop conversions (e.g., WIN → B3 → USD)
117
- * - Applies currency-specific formatting rules to the TARGET currency
58
+ * Behavior:
59
+ * - When exchange rate is unavailable, displays value in base currency
60
+ * - Applies currency-specific formatting rules:
61
+ * - JPY/KRW: No decimal places
62
+ * - ETH/SOL: 6 significant digits with subscript notation for small values
63
+ * - Fiat (USD/EUR/GBP/CAD/AUD): 2 decimal places minimum for values < 1000
64
+ * - Handles symbol positioning (prefix for fiat, suffix for crypto)
118
65
  *
119
- * @param value - The numeric value to format
120
- * @param sourceCurrency - The currency the value is currently in (e.g., "WIN", "B3", "USD")
66
+ * @param value - The numeric value to format (in base currency)
121
67
  * @param options - Optional formatting overrides
122
- * @param options.decimals - Override number of decimal places for display
68
+ * @param options.decimals - Override number of decimal places
69
+ * @param options.currency - Override currency (bypasses conversion)
123
70
  * @returns Formatted currency string with appropriate symbol and decimal places
124
71
  *
125
72
  * @example
126
73
  * ```tsx
127
- * // Value is 3031 WIN, user has USD selected
128
- * formatCurrencyValue(3031, "WIN") // Returns "$30.31" (converts WIN→B3→USD)
129
- *
130
- * // Value is 100 B3, user has B3 selected (no conversion)
131
- * formatCurrencyValue(100, "B3") // Returns "100 B3"
132
- *
133
- * // Value is 50 USD, user has EUR selected
134
- * formatCurrencyValue(50, "USD") // Returns "€45.50" (converts USD→EUR)
74
+ * formatCurrencyValue(100) // Returns "$100.00" if USD is selected
75
+ * formatCurrencyValue(0.0001) // Returns "0.0₄1 ETH" if ETH is selected
76
+ * formatCurrencyValue(1500) // Returns "¥1,500" if JPY is selected
77
+ * formatCurrencyValue(100, { decimals: 4, currency: "ETH" }) // Returns "100.0000 ETH"
135
78
  * ```
136
79
  */
137
- const formatCurrencyValue = (value, sourceCurrency, options) => {
80
+ const formatCurrencyValue = (value, options) => {
81
+ const overrideCurrency = options?.currency;
138
82
  const overrideDecimals = options?.decimals;
139
- // If source and display currency are the same, no conversion needed
140
- if (sourceCurrency === selectedCurrency) {
141
- const customMetadata = (0, currencyStore_1.getCurrencyMetadata)(sourceCurrency);
142
- const decimalsToUse = overrideDecimals !== undefined ? overrideDecimals : customMetadata?.decimals;
83
+ // Custom currency provided - bypass conversion and use simple formatting
84
+ if (overrideCurrency) {
85
+ const decimalsToUse = overrideDecimals !== undefined ? overrideDecimals : overrideCurrency === "B3" ? 0 : 2;
143
86
  const formatted = (0, number_1.formatDisplayNumber)(value, {
144
87
  fractionDigits: decimalsToUse,
145
- significantDigits: decimalsToUse === undefined ? 6 : undefined,
146
- showSubscripts: customMetadata?.showSubscripts ?? false,
88
+ showSubscripts: false,
147
89
  });
148
- const symbol = (0, currencyStore_1.getCurrencySymbol)(sourceCurrency);
149
- const usePrefix = customMetadata?.prefixSymbol ?? ["USD", "EUR", "GBP", "CAD", "AUD"].includes(sourceCurrency);
150
- return usePrefix ? `${symbol}${formatted}` : `${formatted} ${symbol}`;
90
+ return `${formatted} ${overrideCurrency}`;
151
91
  }
152
- // Get exchange rate from source to display currency
153
- const conversionRate = getExchangeRate(sourceCurrency, selectedCurrency);
154
- // If no conversion rate available, display in source currency
155
- if (conversionRate === undefined) {
156
- const customMetadata = (0, currencyStore_1.getCurrencyMetadata)(sourceCurrency);
92
+ // Custom decimals for base currency without conversion
93
+ if (overrideDecimals !== undefined && selectedCurrency === baseCurrency) {
157
94
  const formatted = (0, number_1.formatDisplayNumber)(value, {
158
- significantDigits: 6,
159
- showSubscripts: customMetadata?.showSubscripts ?? false,
160
- });
161
- const symbol = (0, currencyStore_1.getCurrencySymbol)(sourceCurrency);
162
- return `${formatted} ${symbol}`;
163
- }
164
- // Convert value
165
- const convertedValue = value * conversionRate;
166
- // Get symbol and metadata for display currency
167
- const symbol = (0, currencyStore_1.getCurrencySymbol)(selectedCurrency);
168
- const customMetadata = (0, currencyStore_1.getCurrencyMetadata)(selectedCurrency);
169
- const usePrefix = customMetadata?.prefixSymbol ?? ["USD", "EUR", "GBP", "CAD", "AUD"].includes(selectedCurrency);
170
- let formatted;
171
- // Apply formatting based on display currency
172
- if (overrideDecimals !== undefined) {
173
- formatted = (0, number_1.formatDisplayNumber)(convertedValue, {
174
95
  fractionDigits: overrideDecimals,
175
96
  showSubscripts: false,
176
97
  });
98
+ return `${formatted} ${baseCurrency}`;
177
99
  }
178
- else if (customMetadata) {
179
- formatted = (0, number_1.formatDisplayNumber)(convertedValue, {
180
- fractionDigits: customMetadata.decimals,
181
- significantDigits: customMetadata.decimals === undefined ? 6 : undefined,
182
- showSubscripts: customMetadata.showSubscripts ?? false,
100
+ // If showing base currency, no conversion needed
101
+ if (selectedCurrency === baseCurrency || !exchangeRate) {
102
+ const formatted = (0, number_1.formatDisplayNumber)(value, {
103
+ significantDigits: baseCurrency === "B3" ? 6 : 8,
104
+ showSubscripts: true,
183
105
  });
106
+ return `${formatted} ${baseCurrency}`;
184
107
  }
185
- else if (selectedCurrency === "JPY" || selectedCurrency === "KRW") {
108
+ // Convert value using current exchange rate
109
+ const convertedValue = value * exchangeRate;
110
+ const symbol = currencyStore_1.CURRENCY_SYMBOLS[selectedCurrency];
111
+ // Currencies that display symbol before the number (e.g., $100.00)
112
+ const prefixCurrencies = ["USD", "EUR", "GBP", "CAD", "AUD"];
113
+ let formatted;
114
+ if (selectedCurrency === "JPY" || selectedCurrency === "KRW") {
115
+ // Japanese Yen and Korean Won don't use decimal places
186
116
  formatted = (0, number_1.formatDisplayNumber)(convertedValue, {
187
117
  fractionDigits: 0,
188
118
  showSubscripts: false,
189
119
  });
190
120
  }
191
121
  else if (selectedCurrency === "ETH" || selectedCurrency === "SOL") {
122
+ // Crypto currencies use more precision and subscript notation
123
+ // for very small amounts (e.g., 0.0₃45 ETH)
192
124
  formatted = (0, number_1.formatDisplayNumber)(convertedValue, {
193
125
  significantDigits: 6,
194
126
  showSubscripts: true,
195
127
  });
196
128
  }
197
129
  else {
130
+ // Standard fiat currencies (USD, EUR, GBP, CAD, AUD)
131
+ // Use 2 decimal places minimum for amounts under 1000
198
132
  formatted = (0, number_1.formatDisplayNumber)(convertedValue, {
199
133
  significantDigits: 6,
200
134
  fractionDigits: convertedValue < 1000 ? 2 : undefined,
201
135
  showSubscripts: true,
202
136
  });
203
137
  }
204
- return usePrefix ? `${symbol}${formatted}` : `${formatted} ${symbol}`;
138
+ // Apply currency symbol with correct positioning
139
+ if (prefixCurrencies.includes(selectedCurrency)) {
140
+ return `${symbol}${formatted}`;
141
+ }
142
+ else {
143
+ // Suffix currencies: JPY, KRW, ETH, SOL, B3
144
+ return `${formatted} ${symbol}`;
145
+ }
205
146
  };
206
147
  /**
207
148
  * Formats a tooltip value showing the alternate currency representation.
208
149
  *
209
- * New behavior:
210
- * - Takes the SOURCE currency (what the value is in)
211
- * - When displaying in non-USD: Shows USD equivalent in tooltip
212
- * - When displaying in USD: Shows source currency in tooltip
150
+ * Behavior:
151
+ * - When displaying base currency: Shows USD equivalent
152
+ * - When displaying other currency: Shows base currency equivalent
153
+ * - For custom currencies: Shows appropriate conversion or original value
213
154
  *
214
155
  * @param value - The numeric value to format
215
- * @param sourceCurrency - The currency the value is currently in
156
+ * @param customCurrency - Optional custom currency override
216
157
  * @returns Formatted tooltip string
217
158
  *
218
159
  * @example
219
160
  * ```tsx
220
- * // Value is 3031 WIN, displaying as EUR
221
- * formatTooltipValue(3031, "WIN") // Returns "$30.31 USD"
222
- *
223
- * // Value is 100 B3, displaying as USD
224
- * formatTooltipValue(100, "B3") // Returns "100 B3"
161
+ * formatTooltipValue(100) // Returns "$150.00 USD" if displaying B3 with rate 1.5
162
+ * formatTooltipValue(100, "ETH") // Returns "100.0000 ETH" if custom currency
225
163
  * ```
226
164
  */
227
- const formatTooltipValue = (value, sourceCurrency) => {
165
+ const formatTooltipValue = (value, customCurrency) => {
166
+ const displayCurrency = customCurrency || selectedCurrency;
228
167
  const absoluteValue = Math.abs(value);
229
- // If displaying in USD, show source currency in tooltip
230
- if (selectedCurrency === "USD") {
231
- const formatted = (0, number_1.formatDisplayNumber)(absoluteValue, {
232
- significantDigits: 6,
233
- showSubscripts: (0, currencyStore_1.getCurrencyMetadata)(sourceCurrency)?.showSubscripts ?? false,
234
- });
235
- const symbol = (0, currencyStore_1.getCurrencySymbol)(sourceCurrency);
236
- return `${formatted} ${symbol}`;
168
+ // Custom currency provided
169
+ if (customCurrency) {
170
+ if (customCurrency === baseCurrency) {
171
+ // Show USD equivalent for base currency using USD rate
172
+ const usdValue = usdRate ? absoluteValue * usdRate : absoluteValue;
173
+ const formatted = (0, number_1.formatDisplayNumber)(usdValue, {
174
+ significantDigits: 6,
175
+ fractionDigits: usdValue < 1000 ? 2 : undefined,
176
+ showSubscripts: true,
177
+ });
178
+ return `$${formatted} USD`;
179
+ }
180
+ else {
181
+ // Show as-is for other custom currencies
182
+ return `${(0, number_1.formatDisplayNumber)(absoluteValue, { significantDigits: 6 })} ${customCurrency}`;
183
+ }
237
184
  }
238
- // Otherwise, show USD equivalent in tooltip
239
- const usdRate = getExchangeRate(sourceCurrency, "USD");
240
- if (usdRate === undefined) {
241
- // Fallback to source currency if no USD rate
242
- const formatted = (0, number_1.formatDisplayNumber)(absoluteValue, {
185
+ // Showing base currency - display USD equivalent
186
+ if (displayCurrency === baseCurrency) {
187
+ const usdValue = usdRate ? absoluteValue * usdRate : absoluteValue;
188
+ const formatted = (0, number_1.formatDisplayNumber)(usdValue, {
243
189
  significantDigits: 6,
244
- showSubscripts: (0, currencyStore_1.getCurrencyMetadata)(sourceCurrency)?.showSubscripts ?? false,
190
+ fractionDigits: usdValue < 1000 ? 2 : undefined,
191
+ showSubscripts: true,
245
192
  });
246
- const symbol = (0, currencyStore_1.getCurrencySymbol)(sourceCurrency);
247
- return `${formatted} ${symbol}`;
193
+ return `$${formatted} USD`;
248
194
  }
249
- const usdValue = absoluteValue * usdRate;
250
- const formatted = (0, number_1.formatDisplayNumber)(usdValue, {
251
- significantDigits: 6,
252
- fractionDigits: usdValue < 1000 ? 2 : undefined,
195
+ // Showing other currency - display base currency equivalent
196
+ const formatted = (0, number_1.formatDisplayNumber)(absoluteValue, {
197
+ significantDigits: baseCurrency === "B3" ? 6 : 8,
253
198
  showSubscripts: true,
254
199
  });
255
- return `$${formatted} USD`;
200
+ return `${formatted} ${baseCurrency}`;
256
201
  };
257
202
  return {
258
203
  /** Currently selected display currency */
@@ -266,12 +211,8 @@ function useCurrencyConversion() {
266
211
  /** Format a tooltip value showing alternate currency representation */
267
212
  formatTooltipValue,
268
213
  /** Symbol for the currently selected currency (e.g., "$", "€", "ETH") */
269
- selectedCurrencySymbol: (0, currencyStore_1.getCurrencySymbol)(selectedCurrency),
214
+ selectedCurrencySymbol: currencyStore_1.CURRENCY_SYMBOLS[selectedCurrency],
270
215
  /** Symbol for the base currency */
271
- baseCurrencySymbol: (0, currencyStore_1.getCurrencySymbol)(baseCurrency),
272
- /** Get exchange rate between any two currencies */
273
- getExchangeRate,
274
- /** All registered custom currencies */
275
- customCurrencies,
216
+ baseCurrencySymbol: currencyStore_1.CURRENCY_SYMBOLS[baseCurrency],
276
217
  };
277
218
  }
@@ -1,36 +1,8 @@
1
1
  /**
2
- * Built-in supported currencies for display and conversion.
2
+ * Supported currencies for display and conversion.
3
3
  * Includes fiat currencies (USD, EUR, GBP, JPY, CAD, AUD, KRW) and crypto (ETH, SOL, B3).
4
4
  */
5
5
  export type SupportedCurrency = "ETH" | "USD" | "EUR" | "GBP" | "JPY" | "CAD" | "AUD" | "B3" | "SOL" | "KRW";
6
- /**
7
- * Metadata for a custom currency including display formatting rules.
8
- */
9
- export interface CurrencyMetadata {
10
- /** The currency code/symbol (e.g., "BTC", "DOGE") */
11
- code: string;
12
- /** Display symbol for the currency (e.g., "₿", "Ð") */
13
- symbol: string;
14
- /** Human-readable name (e.g., "Bitcoin", "Dogecoin") */
15
- name: string;
16
- /** Whether to show symbol before the value (true for $100, false for 100 ETH) */
17
- prefixSymbol?: boolean;
18
- /** Number of decimal places to show (undefined uses smart formatting) */
19
- decimals?: number;
20
- /** Whether to use subscript notation for small values */
21
- showSubscripts?: boolean;
22
- }
23
- /**
24
- * Exchange rate between two currencies.
25
- */
26
- export interface ExchangeRate {
27
- /** Currency code being converted from */
28
- from: string;
29
- /** Currency code being converted to */
30
- to: string;
31
- /** Exchange rate multiplier (amount_in_to = amount_in_from * rate) */
32
- rate: number;
33
- }
34
6
  /**
35
7
  * Currency symbols used for display formatting.
36
8
  * Prefix currencies (USD, EUR, GBP, CAD, AUD) show symbol before the amount.
@@ -45,51 +17,24 @@ export declare const CURRENCY_NAMES: Record<SupportedCurrency, string>;
45
17
  * Currency store state interface.
46
18
  * @property selectedCurrency - The currency currently selected for display
47
19
  * @property baseCurrency - The base currency for conversion (typically B3)
48
- * @property customCurrencies - Map of custom currency codes to their metadata
49
- * @property customExchangeRates - Map of "FROM-TO" pairs to exchange rates
50
20
  * @property setSelectedCurrency - Update the selected display currency
51
21
  * @property setBaseCurrency - Update the base currency for conversions
52
- * @property addCurrency - Register a new custom currency with metadata
53
- * @property removeCurrency - Remove a custom currency
54
- * @property setExchangeRate - Set a custom exchange rate between two currencies
55
- * @property getExchangeRate - Get exchange rate between two currencies
56
- * @property getAllCurrencies - Get all available currencies (built-in + custom)
57
22
  */
58
23
  interface CurrencyState {
59
- selectedCurrency: string;
60
- baseCurrency: string;
61
- customCurrencies: Record<string, CurrencyMetadata>;
62
- customExchangeRates: Record<string, number>;
63
- setSelectedCurrency: (currency: string) => void;
64
- setBaseCurrency: (currency: string) => void;
65
- addCurrency: (metadata: CurrencyMetadata) => void;
66
- removeCurrency: (code: string) => void;
67
- setExchangeRate: (from: string, to: string, rate: number) => void;
68
- getExchangeRate: (from: string, to: string) => number | undefined;
69
- getAllCurrencies: () => string[];
24
+ selectedCurrency: SupportedCurrency;
25
+ baseCurrency: SupportedCurrency;
26
+ setSelectedCurrency: (currency: SupportedCurrency) => void;
27
+ setBaseCurrency: (currency: SupportedCurrency) => void;
70
28
  }
71
29
  /**
72
30
  * Zustand store for managing currency selection and conversion.
73
31
  * Persists user's selected currency preference in localStorage.
74
- * Supports dynamic currency registration and custom exchange rates.
75
32
  *
76
33
  * @example
77
34
  * ```tsx
78
- * const { selectedCurrency, setSelectedCurrency, addCurrency, setExchangeRate } = useCurrencyStore();
79
- *
80
- * // Add a new currency
81
- * addCurrency({
82
- * code: "BTC",
83
- * symbol: "₿",
84
- * name: "Bitcoin",
85
- * showSubscripts: true,
86
- * });
87
- *
88
- * // Set exchange rate: 1 BTC = 50000 USD
89
- * setExchangeRate("BTC", "USD", 50000);
90
- *
91
- * // Change display currency
92
- * setSelectedCurrency('BTC');
35
+ * const { selectedCurrency, setSelectedCurrency } = useCurrencyStore();
36
+ * // Change display currency to USD
37
+ * setSelectedCurrency('USD');
93
38
  * ```
94
39
  */
95
40
  export declare const useCurrencyStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<CurrencyState>, "persist"> & {
@@ -103,24 +48,4 @@ export declare const useCurrencyStore: import("zustand").UseBoundStore<Omit<impo
103
48
  getOptions: () => Partial<import("zustand/middleware").PersistOptions<CurrencyState, CurrencyState>>;
104
49
  };
105
50
  }>;
106
- /**
107
- * Get the symbol for any currency (built-in or custom).
108
- */
109
- export declare function getCurrencySymbol(currency: string): string;
110
- /**
111
- * Get the name for any currency (built-in or custom).
112
- */
113
- export declare function getCurrencyName(currency: string): string;
114
- /**
115
- * Get metadata for a custom currency.
116
- */
117
- export declare function getCurrencyMetadata(currency: string): CurrencyMetadata | undefined;
118
- /**
119
- * Get the number of decimal places for a currency (for converting from smallest unit).
120
- * Used when parsing amounts from wei/smallest unit format.
121
- *
122
- * @param currency - Currency code
123
- * @returns Number of decimal places (e.g., 18 for ETH/wei, 2 for USD cents, 0 for JPY)
124
- */
125
- export declare function getCurrencyDecimalPlaces(currency: string): number;
126
51
  export {};