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