@b3dotfun/sdk 0.0.42-alpha.2 → 0.0.42-alpha.3

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 (86) hide show
  1. package/dist/cjs/global-account/react/components/index.d.ts +8 -7
  2. package/dist/cjs/global-account/react/components/index.js +29 -23
  3. package/dist/cjs/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
  4. package/dist/cjs/global-account/react/components/ui/dropdown-menu.js +100 -0
  5. package/dist/cjs/shared/constants/currency.d.ts +1 -0
  6. package/dist/cjs/shared/constants/currency.js +5 -0
  7. package/dist/cjs/shared/constants/index.d.ts +1 -0
  8. package/dist/cjs/shared/constants/index.js +15 -0
  9. package/dist/cjs/shared/react/components/CurrencySelector.d.ts +7 -0
  10. package/dist/cjs/shared/react/components/CurrencySelector.js +14 -0
  11. package/dist/cjs/shared/react/components/FormattedCurrency.d.ts +12 -0
  12. package/dist/cjs/shared/react/components/FormattedCurrency.js +60 -0
  13. package/dist/cjs/shared/react/components/index.d.ts +2 -0
  14. package/dist/cjs/shared/react/components/index.js +18 -0
  15. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  16. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
  17. package/dist/cjs/shared/react/hooks/index.d.ts +1 -0
  18. package/dist/cjs/shared/react/hooks/index.js +1 -0
  19. package/dist/cjs/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
  20. package/dist/cjs/shared/react/hooks/useCurrencyConversion.js +200 -0
  21. package/dist/cjs/shared/react/index.d.ts +2 -0
  22. package/dist/cjs/shared/react/index.js +2 -0
  23. package/dist/cjs/shared/react/stores/currencyModalStore.d.ts +7 -0
  24. package/dist/cjs/shared/react/stores/currencyModalStore.js +9 -0
  25. package/dist/cjs/shared/react/stores/currencyStore.d.ts +51 -0
  26. package/dist/cjs/shared/react/stores/currencyStore.js +57 -0
  27. package/dist/cjs/shared/react/stores/index.d.ts +2 -0
  28. package/dist/cjs/shared/react/stores/index.js +18 -0
  29. package/dist/esm/global-account/react/components/index.d.ts +8 -7
  30. package/dist/esm/global-account/react/components/index.js +8 -7
  31. package/dist/esm/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
  32. package/dist/esm/global-account/react/components/ui/dropdown-menu.js +60 -0
  33. package/dist/esm/shared/constants/currency.d.ts +1 -0
  34. package/dist/esm/shared/constants/currency.js +2 -0
  35. package/dist/esm/shared/constants/index.d.ts +1 -0
  36. package/dist/esm/shared/constants/index.js +1 -0
  37. package/dist/esm/shared/react/components/CurrencySelector.d.ts +7 -0
  38. package/dist/esm/shared/react/components/CurrencySelector.js +11 -0
  39. package/dist/esm/shared/react/components/FormattedCurrency.d.ts +12 -0
  40. package/dist/esm/shared/react/components/FormattedCurrency.js +57 -0
  41. package/dist/esm/shared/react/components/index.d.ts +2 -0
  42. package/dist/esm/shared/react/components/index.js +2 -0
  43. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  44. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
  45. package/dist/esm/shared/react/hooks/index.d.ts +1 -0
  46. package/dist/esm/shared/react/hooks/index.js +1 -0
  47. package/dist/esm/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
  48. package/dist/esm/shared/react/hooks/useCurrencyConversion.js +197 -0
  49. package/dist/esm/shared/react/index.d.ts +2 -0
  50. package/dist/esm/shared/react/index.js +2 -0
  51. package/dist/esm/shared/react/stores/currencyModalStore.d.ts +7 -0
  52. package/dist/esm/shared/react/stores/currencyModalStore.js +6 -0
  53. package/dist/esm/shared/react/stores/currencyStore.d.ts +51 -0
  54. package/dist/esm/shared/react/stores/currencyStore.js +54 -0
  55. package/dist/esm/shared/react/stores/index.d.ts +2 -0
  56. package/dist/esm/shared/react/stores/index.js +2 -0
  57. package/dist/styles/index.css +1 -1
  58. package/dist/types/global-account/react/components/index.d.ts +8 -7
  59. package/dist/types/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
  60. package/dist/types/shared/constants/currency.d.ts +1 -0
  61. package/dist/types/shared/constants/index.d.ts +1 -0
  62. package/dist/types/shared/react/components/CurrencySelector.d.ts +7 -0
  63. package/dist/types/shared/react/components/FormattedCurrency.d.ts +12 -0
  64. package/dist/types/shared/react/components/index.d.ts +2 -0
  65. package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  66. package/dist/types/shared/react/hooks/index.d.ts +1 -0
  67. package/dist/types/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
  68. package/dist/types/shared/react/index.d.ts +2 -0
  69. package/dist/types/shared/react/stores/currencyModalStore.d.ts +7 -0
  70. package/dist/types/shared/react/stores/currencyStore.d.ts +51 -0
  71. package/dist/types/shared/react/stores/index.d.ts +2 -0
  72. package/package.json +29 -3
  73. package/src/global-account/react/components/index.ts +19 -12
  74. package/src/global-account/react/components/ui/dropdown-menu.tsx +132 -0
  75. package/src/shared/constants/currency.ts +2 -0
  76. package/src/shared/constants/index.ts +2 -0
  77. package/src/shared/react/components/CurrencySelector.tsx +71 -0
  78. package/src/shared/react/components/FormattedCurrency.tsx +106 -0
  79. package/src/shared/react/components/index.ts +2 -0
  80. package/src/shared/react/hooks/__tests__/useCurrencyConversion.test.ts +308 -0
  81. package/src/shared/react/hooks/index.ts +1 -0
  82. package/src/shared/react/hooks/useCurrencyConversion.ts +211 -0
  83. package/src/shared/react/index.ts +2 -0
  84. package/src/shared/react/stores/currencyModalStore.ts +13 -0
  85. package/src/shared/react/stores/currencyStore.ts +82 -0
  86. package/src/shared/react/stores/index.ts +2 -0
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const react_1 = require("@testing-library/react");
5
+ const useCurrencyConversion_1 = require("../useCurrencyConversion");
6
+ // Mock the external dependencies
7
+ // Store mock rates for different quote currencies
8
+ const mockRates = {};
9
+ // Mock store state
10
+ const mockStoreState = {
11
+ selectedCurrency: "B3",
12
+ baseCurrency: "B3",
13
+ setSelectedCurrency: vitest_1.vi.fn(),
14
+ setBaseCurrency: vitest_1.vi.fn(),
15
+ };
16
+ vitest_1.vi.mock("@b3dotfun/sdk/global-account/react", () => ({
17
+ useExchangeRate: vitest_1.vi.fn((params) => {
18
+ const rate = mockRates[params?.quoteCurrency];
19
+ return { rate };
20
+ }),
21
+ }));
22
+ vitest_1.vi.mock("@b3dotfun/sdk/shared/utils/number", () => ({
23
+ formatDisplayNumber: vitest_1.vi.fn((value) => {
24
+ const num = Number(value);
25
+ if (isNaN(num))
26
+ return "0";
27
+ return num.toLocaleString("en-US", { maximumFractionDigits: 6 });
28
+ }),
29
+ }));
30
+ vitest_1.vi.mock("../../stores/currencyStore", () => ({
31
+ useCurrencyStore: vitest_1.vi.fn((selector) => {
32
+ if (selector) {
33
+ return selector(mockStoreState);
34
+ }
35
+ return mockStoreState;
36
+ }),
37
+ CURRENCY_SYMBOLS: {
38
+ B3: "B3",
39
+ USD: "$",
40
+ EUR: "€",
41
+ GBP: "£",
42
+ JPY: "¥",
43
+ CAD: "C$",
44
+ AUD: "A$",
45
+ ETH: "ETH",
46
+ SOL: "SOL",
47
+ KRW: "₩",
48
+ },
49
+ }));
50
+ (0, vitest_1.describe)("useCurrencyConversion", () => {
51
+ (0, vitest_1.beforeEach)(() => {
52
+ vitest_1.vi.clearAllMocks();
53
+ // Reset mock rates to default
54
+ Object.keys(mockRates).forEach(key => delete mockRates[key]);
55
+ mockRates.USD = 1.0;
56
+ // Reset store state
57
+ mockStoreState.selectedCurrency = "B3";
58
+ mockStoreState.baseCurrency = "B3";
59
+ });
60
+ (0, vitest_1.describe)("formatCurrencyValue", () => {
61
+ (0, vitest_1.it)("should format base currency (B3) without conversion", () => {
62
+ mockStoreState.selectedCurrency = "B3";
63
+ mockStoreState.baseCurrency = "B3";
64
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
65
+ const formatted = result.current.formatCurrencyValue(100);
66
+ (0, vitest_1.expect)(formatted).toContain("B3");
67
+ (0, vitest_1.expect)(formatted).toContain("100");
68
+ });
69
+ (0, vitest_1.it)("should show base currency when exchange rate is unavailable", () => {
70
+ mockRates.USD = undefined;
71
+ mockStoreState.selectedCurrency = "USD";
72
+ mockStoreState.baseCurrency = "B3";
73
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
74
+ const formatted = result.current.formatCurrencyValue(100);
75
+ (0, vitest_1.expect)(formatted).toContain("B3");
76
+ (0, vitest_1.expect)(formatted).not.toContain("$");
77
+ });
78
+ (0, vitest_1.it)("should format USD with prefix symbol", () => {
79
+ mockRates.USD = 2.0;
80
+ mockStoreState.selectedCurrency = "USD";
81
+ mockStoreState.baseCurrency = "B3";
82
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
83
+ const formatted = result.current.formatCurrencyValue(100);
84
+ (0, vitest_1.expect)(formatted).toMatch(/^\$/);
85
+ (0, vitest_1.expect)(formatted).toContain("200");
86
+ });
87
+ (0, vitest_1.it)("should format EUR with prefix symbol", () => {
88
+ mockRates.EUR = 1.8;
89
+ mockRates.USD = 2.0;
90
+ mockStoreState.selectedCurrency = "EUR";
91
+ mockStoreState.baseCurrency = "B3";
92
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
93
+ const formatted = result.current.formatCurrencyValue(100);
94
+ (0, vitest_1.expect)(formatted).toMatch(/^€/);
95
+ });
96
+ (0, vitest_1.it)("should format JPY without decimals", () => {
97
+ mockRates.JPY = 150;
98
+ mockRates.USD = 2.0;
99
+ mockStoreState.selectedCurrency = "JPY";
100
+ mockStoreState.baseCurrency = "B3";
101
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
102
+ const formatted = result.current.formatCurrencyValue(100);
103
+ (0, vitest_1.expect)(formatted).toContain("¥");
104
+ (0, vitest_1.expect)(formatted).not.toContain(".");
105
+ });
106
+ (0, vitest_1.it)("should format KRW without decimals", () => {
107
+ mockRates.KRW = 1300;
108
+ mockRates.USD = 2.0;
109
+ mockStoreState.selectedCurrency = "KRW";
110
+ mockStoreState.baseCurrency = "B3";
111
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
112
+ const formatted = result.current.formatCurrencyValue(100);
113
+ (0, vitest_1.expect)(formatted).toContain("₩");
114
+ (0, vitest_1.expect)(formatted).not.toContain(".");
115
+ });
116
+ (0, vitest_1.it)("should format ETH with suffix symbol", () => {
117
+ mockRates.ETH = 0.0005;
118
+ mockRates.USD = 2.0;
119
+ mockStoreState.selectedCurrency = "ETH";
120
+ mockStoreState.baseCurrency = "B3";
121
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
122
+ const formatted = result.current.formatCurrencyValue(100);
123
+ (0, vitest_1.expect)(formatted).toContain("ETH");
124
+ (0, vitest_1.expect)(formatted).not.toMatch(/^ETH/);
125
+ });
126
+ (0, vitest_1.it)("should format SOL with suffix symbol", () => {
127
+ mockRates.SOL = 0.05;
128
+ mockRates.USD = 2.0;
129
+ mockStoreState.selectedCurrency = "SOL";
130
+ mockStoreState.baseCurrency = "B3";
131
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
132
+ const formatted = result.current.formatCurrencyValue(100);
133
+ (0, vitest_1.expect)(formatted).toContain("SOL");
134
+ (0, vitest_1.expect)(formatted).not.toMatch(/^SOL/);
135
+ });
136
+ (0, vitest_1.it)("should handle small USD amounts with proper conversion", () => {
137
+ mockRates.USD = 1.5;
138
+ mockStoreState.selectedCurrency = "USD";
139
+ mockStoreState.baseCurrency = "B3";
140
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
141
+ const formatted = result.current.formatCurrencyValue(10);
142
+ // 10 * 1.5 = 15
143
+ (0, vitest_1.expect)(formatted).toMatch(/^\$/);
144
+ (0, vitest_1.expect)(formatted).toContain("15");
145
+ });
146
+ (0, vitest_1.it)("should apply correct exchange rate conversion", () => {
147
+ const testRate = 3.5;
148
+ mockRates.USD = testRate;
149
+ mockStoreState.selectedCurrency = "USD";
150
+ mockStoreState.baseCurrency = "B3";
151
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
152
+ const inputValue = 100;
153
+ const formatted = result.current.formatCurrencyValue(inputValue);
154
+ (0, vitest_1.expect)(formatted).toContain("350");
155
+ });
156
+ });
157
+ (0, vitest_1.describe)("return values", () => {
158
+ (0, vitest_1.it)("should return selected currency", () => {
159
+ mockStoreState.selectedCurrency = "USD";
160
+ mockStoreState.baseCurrency = "B3";
161
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
162
+ (0, vitest_1.expect)(result.current.selectedCurrency).toBe("USD");
163
+ });
164
+ (0, vitest_1.it)("should return base currency", () => {
165
+ mockStoreState.selectedCurrency = "USD";
166
+ mockStoreState.baseCurrency = "B3";
167
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
168
+ (0, vitest_1.expect)(result.current.baseCurrency).toBe("B3");
169
+ });
170
+ (0, vitest_1.it)("should return exchange rate", () => {
171
+ const testRate = 2.5;
172
+ mockRates.USD = testRate;
173
+ mockStoreState.selectedCurrency = "USD";
174
+ mockStoreState.baseCurrency = "B3";
175
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
176
+ (0, vitest_1.expect)(result.current.exchangeRate).toBe(testRate);
177
+ });
178
+ (0, vitest_1.it)("should return correct currency symbols", () => {
179
+ mockStoreState.selectedCurrency = "EUR";
180
+ mockStoreState.baseCurrency = "B3";
181
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
182
+ (0, vitest_1.expect)(result.current.selectedCurrencySymbol).toBe("€");
183
+ (0, vitest_1.expect)(result.current.baseCurrencySymbol).toBe("B3");
184
+ });
185
+ });
186
+ (0, vitest_1.describe)("formatTooltipValue", () => {
187
+ (0, vitest_1.it)("should show USD equivalent when displaying base currency", () => {
188
+ mockRates.USD = 1.5;
189
+ mockStoreState.selectedCurrency = "B3";
190
+ mockStoreState.baseCurrency = "B3";
191
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
192
+ const tooltip = result.current.formatTooltipValue(100);
193
+ (0, vitest_1.expect)(tooltip).toContain("USD");
194
+ (0, vitest_1.expect)(tooltip).toContain("150");
195
+ });
196
+ (0, vitest_1.it)("should show base currency when displaying other currency", () => {
197
+ mockRates.EUR = 0.9;
198
+ mockRates.USD = 1.2;
199
+ mockStoreState.selectedCurrency = "EUR";
200
+ mockStoreState.baseCurrency = "B3";
201
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
202
+ const tooltip = result.current.formatTooltipValue(100);
203
+ (0, vitest_1.expect)(tooltip).toContain("B3");
204
+ (0, vitest_1.expect)(tooltip).toContain("100");
205
+ });
206
+ (0, vitest_1.it)("should handle custom currency for base currency", () => {
207
+ mockRates.USD = 2.0;
208
+ mockRates.EUR = 1.8;
209
+ mockStoreState.selectedCurrency = "EUR";
210
+ mockStoreState.baseCurrency = "B3";
211
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
212
+ const tooltip = result.current.formatTooltipValue(100, "B3");
213
+ (0, vitest_1.expect)(tooltip).toContain("USD");
214
+ (0, vitest_1.expect)(tooltip).toContain("200");
215
+ });
216
+ (0, vitest_1.it)("should handle custom currency for non-base currency", () => {
217
+ mockRates.USD = 2.0;
218
+ mockStoreState.selectedCurrency = "USD";
219
+ mockStoreState.baseCurrency = "B3";
220
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
221
+ const tooltip = result.current.formatTooltipValue(50, "ETH");
222
+ (0, vitest_1.expect)(tooltip).toContain("ETH");
223
+ (0, vitest_1.expect)(tooltip).toContain("50");
224
+ });
225
+ (0, vitest_1.it)("should handle absolute values for negative amounts", () => {
226
+ mockRates.USD = 1.5;
227
+ mockStoreState.selectedCurrency = "B3";
228
+ mockStoreState.baseCurrency = "B3";
229
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
230
+ const tooltip = result.current.formatTooltipValue(-100);
231
+ (0, vitest_1.expect)(tooltip).toContain("USD");
232
+ (0, vitest_1.expect)(tooltip).toContain("150");
233
+ (0, vitest_1.expect)(tooltip).not.toContain("-");
234
+ });
235
+ (0, vitest_1.it)("should handle exchange rate unavailable", () => {
236
+ mockRates.USD = undefined;
237
+ mockStoreState.selectedCurrency = "B3";
238
+ mockStoreState.baseCurrency = "B3";
239
+ const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
240
+ const tooltip = result.current.formatTooltipValue(100);
241
+ (0, vitest_1.expect)(tooltip).toContain("USD");
242
+ (0, vitest_1.expect)(tooltip).toContain("100");
243
+ });
244
+ });
245
+ });
@@ -1 +1,2 @@
1
+ export * from "./useCurrencyConversion";
1
2
  export * from "./useNavigation";
@@ -14,4 +14,5 @@ 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("./useCurrencyConversion"), exports);
17
18
  __exportStar(require("./useNavigation"), exports);
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Hook for currency conversion and formatting with real-time exchange rates.
3
+ *
4
+ * This hook provides currency conversion functionality using live exchange rates
5
+ * and formats values according to currency-specific rules (decimals, symbols, etc.).
6
+ *
7
+ * @returns Currency conversion utilities and state
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * function PriceDisplay({ amount }: { amount: number }) {
12
+ * const { formatCurrencyValue, selectedCurrency } = useCurrencyConversion();
13
+ * return <div>{formatCurrencyValue(amount)}</div>;
14
+ * }
15
+ * ```
16
+ */
17
+ export declare function useCurrencyConversion(): {
18
+ /** Currently selected display currency */
19
+ selectedCurrency: import("../stores/currencyStore").SupportedCurrency;
20
+ /** Base currency used for conversion (typically B3) */
21
+ baseCurrency: import("../stores/currencyStore").SupportedCurrency;
22
+ /** Current exchange rate from base to selected currency (undefined while loading) */
23
+ exchangeRate: number;
24
+ /** Format a value with currency conversion and proper symbol/decimal handling */
25
+ formatCurrencyValue: (value: number, options?: {
26
+ decimals?: number;
27
+ currency?: string;
28
+ }) => string;
29
+ /** Format a tooltip value showing alternate currency representation */
30
+ formatTooltipValue: (value: number, customCurrency?: string) => string;
31
+ /** Symbol for the currently selected currency (e.g., "$", "€", "ETH") */
32
+ selectedCurrencySymbol: string;
33
+ /** Symbol for the base currency */
34
+ baseCurrencySymbol: string;
35
+ };
@@ -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
+ }
@@ -1 +1,3 @@
1
+ export * from "./components";
1
2
  export * from "./hooks";
3
+ export * from "./stores";
@@ -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,7 @@
1
+ interface CurrencyModalState {
2
+ isOpen: boolean;
3
+ openModal: () => void;
4
+ closeModal: () => void;
5
+ }
6
+ export declare const useCurrencyModalStore: import("zustand").UseBoundStore<import("zustand").StoreApi<CurrencyModalState>>;
7
+ export {};
@@ -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,2 @@
1
+ export * from "./currencyModalStore";
2
+ export * from "./currencyStore";
@@ -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);