@b3dotfun/sdk 0.0.44-alpha.1 → 0.0.45

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 (60) hide show
  1. package/README.md +215 -3
  2. package/dist/cjs/notifications/index.d.ts +4 -0
  3. package/dist/cjs/notifications/index.js +26 -0
  4. package/dist/cjs/notifications/react/hooks/index.d.ts +1 -0
  5. package/dist/cjs/notifications/react/hooks/index.js +17 -0
  6. package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +42 -0
  7. package/dist/cjs/notifications/react/hooks/useNotifications.js +148 -0
  8. package/dist/cjs/notifications/react/index.d.ts +1 -0
  9. package/dist/cjs/notifications/react/index.js +17 -0
  10. package/dist/cjs/notifications/services/api.d.ts +65 -0
  11. package/dist/cjs/notifications/services/api.js +178 -0
  12. package/dist/cjs/notifications/services/index.d.ts +1 -0
  13. package/dist/cjs/notifications/services/index.js +17 -0
  14. package/dist/cjs/notifications/types/index.d.ts +50 -0
  15. package/dist/cjs/notifications/types/index.js +2 -0
  16. package/dist/cjs/shared/utils/auth-token.d.ts +7 -0
  17. package/dist/cjs/shared/utils/auth-token.js +17 -0
  18. package/dist/cjs/shared/utils/index.d.ts +1 -0
  19. package/dist/cjs/shared/utils/index.js +1 -0
  20. package/dist/esm/notifications/index.d.ts +4 -0
  21. package/dist/esm/notifications/index.js +8 -0
  22. package/dist/esm/notifications/react/hooks/index.d.ts +1 -0
  23. package/dist/esm/notifications/react/hooks/index.js +1 -0
  24. package/dist/esm/notifications/react/hooks/useNotifications.d.ts +42 -0
  25. package/dist/esm/notifications/react/hooks/useNotifications.js +145 -0
  26. package/dist/esm/notifications/react/index.d.ts +1 -0
  27. package/dist/esm/notifications/react/index.js +1 -0
  28. package/dist/esm/notifications/services/api.d.ts +65 -0
  29. package/dist/esm/notifications/services/api.js +173 -0
  30. package/dist/esm/notifications/services/index.d.ts +1 -0
  31. package/dist/esm/notifications/services/index.js +1 -0
  32. package/dist/esm/notifications/types/index.d.ts +50 -0
  33. package/dist/esm/shared/utils/auth-token.d.ts +7 -0
  34. package/dist/esm/shared/utils/auth-token.js +11 -0
  35. package/dist/esm/shared/utils/index.d.ts +1 -0
  36. package/dist/esm/shared/utils/index.js +1 -0
  37. package/dist/types/notifications/index.d.ts +4 -0
  38. package/dist/types/notifications/react/hooks/index.d.ts +1 -0
  39. package/dist/types/notifications/react/hooks/useNotifications.d.ts +42 -0
  40. package/dist/types/notifications/react/index.d.ts +1 -0
  41. package/dist/types/notifications/services/api.d.ts +65 -0
  42. package/dist/types/notifications/services/index.d.ts +1 -0
  43. package/dist/types/notifications/types/index.d.ts +50 -0
  44. package/dist/types/shared/utils/auth-token.d.ts +7 -0
  45. package/dist/types/shared/utils/index.d.ts +1 -0
  46. package/package.json +21 -1
  47. package/src/notifications/index.ts +11 -0
  48. package/src/notifications/react/hooks/index.ts +1 -0
  49. package/src/notifications/react/hooks/useNotifications.ts +153 -0
  50. package/src/notifications/react/index.ts +1 -0
  51. package/src/notifications/services/api.ts +211 -0
  52. package/src/notifications/services/index.ts +1 -0
  53. package/src/notifications/types/index.ts +57 -0
  54. package/src/shared/utils/auth-token.ts +13 -0
  55. package/src/shared/utils/index.ts +1 -0
  56. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -245
  57. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
  58. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -243
  59. package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
  60. /package/dist/{cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts → esm/notifications/types/index.js} +0 -0
@@ -0,0 +1,211 @@
1
+ import { getAuthToken } from "@b3dotfun/sdk/shared/utils/auth-token";
2
+ import type {
3
+ NotificationHistory,
4
+ NotificationPreferences,
5
+ SendNotificationRequest,
6
+ TelegramLinkResponse,
7
+ TelegramStatusResponse,
8
+ UserData,
9
+ } from "../types";
10
+
11
+ const DEFAULT_API_URL = "https://notifications.b3.fun";
12
+
13
+ let apiUrl: string = DEFAULT_API_URL;
14
+
15
+ export function setApiUrl(url: string) {
16
+ apiUrl = url;
17
+ }
18
+
19
+ export function getApiUrl(): string {
20
+ return apiUrl;
21
+ }
22
+
23
+ function getHeaders(includeAuth = false): HeadersInit {
24
+ const headers: HeadersInit = {
25
+ "Content-Type": "application/json",
26
+ };
27
+
28
+ if (includeAuth) {
29
+ const token = getAuthToken();
30
+ if (token) {
31
+ headers["Authorization"] = `Bearer ${token}`;
32
+ }
33
+ }
34
+
35
+ return headers;
36
+ }
37
+
38
+ export const notificationsAPI = {
39
+ // ===== USER MANAGEMENT =====
40
+
41
+ /**
42
+ * Register the current user (userId extracted from JWT)
43
+ */
44
+ async registerUser() {
45
+ const res = await fetch(`${apiUrl}/users`, {
46
+ method: "POST",
47
+ headers: getHeaders(true),
48
+ });
49
+ return res.json();
50
+ },
51
+
52
+ /**
53
+ * Get current user's profile and preferences
54
+ */
55
+ async getUser(): Promise<UserData> {
56
+ const res = await fetch(`${apiUrl}/users/me`, {
57
+ headers: getHeaders(true),
58
+ });
59
+ return res.json();
60
+ },
61
+
62
+ /**
63
+ * Get current user's notification history
64
+ */
65
+ async getHistory(appId?: string, limit = 100): Promise<NotificationHistory[]> {
66
+ const params = new URLSearchParams();
67
+ if (appId) params.append("appId", appId);
68
+ params.append("limit", limit.toString());
69
+
70
+ const res = await fetch(`${apiUrl}/users/me/history?${params}`, {
71
+ headers: getHeaders(true),
72
+ });
73
+ return res.json();
74
+ },
75
+
76
+ // ===== CHANNELS =====
77
+
78
+ /**
79
+ * Add a notification channel for current user
80
+ */
81
+ async addChannel(channelType: string, channelIdentifier: string, metadata?: Record<string, any>) {
82
+ const res = await fetch(`${apiUrl}/users/me/channels`, {
83
+ method: "POST",
84
+ headers: getHeaders(true),
85
+ body: JSON.stringify({
86
+ channelType,
87
+ channelIdentifier,
88
+ enabled: true,
89
+ metadata,
90
+ }),
91
+ });
92
+ return res.json();
93
+ },
94
+
95
+ /**
96
+ * Connect email for current user
97
+ */
98
+ async connectEmail(email: string) {
99
+ return this.addChannel("email", email);
100
+ },
101
+
102
+ /**
103
+ * Update a notification channel
104
+ */
105
+ async updateChannel(
106
+ channelId: string,
107
+ updates: { enabled?: boolean; channelIdentifier?: string; metadata?: Record<string, any> },
108
+ ) {
109
+ const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
110
+ method: "PUT",
111
+ headers: getHeaders(true),
112
+ body: JSON.stringify(updates),
113
+ });
114
+ return res.json();
115
+ },
116
+
117
+ /**
118
+ * Delete a notification channel
119
+ */
120
+ async deleteChannel(channelId: string) {
121
+ const res = await fetch(`${apiUrl}/users/me/channels/${channelId}`, {
122
+ method: "DELETE",
123
+ headers: getHeaders(true),
124
+ });
125
+ return res.json();
126
+ },
127
+
128
+ // ===== TELEGRAM =====
129
+
130
+ /**
131
+ * Get Telegram deep link for current user
132
+ */
133
+ async getTelegramLink(): Promise<TelegramLinkResponse> {
134
+ const res = await fetch(`${apiUrl}/telegram/request-link`, {
135
+ method: "POST",
136
+ headers: getHeaders(true),
137
+ });
138
+ return res.json();
139
+ },
140
+
141
+ /**
142
+ * Check current user's Telegram connection status
143
+ */
144
+ async checkTelegramStatus(): Promise<TelegramStatusResponse> {
145
+ const res = await fetch(`${apiUrl}/telegram/status/me`, {
146
+ headers: getHeaders(true),
147
+ });
148
+ return res.json();
149
+ },
150
+
151
+ // ===== APP PREFERENCES =====
152
+
153
+ /**
154
+ * Save notification preferences for an app
155
+ */
156
+ async savePreferences(appId: string, settings: NotificationPreferences) {
157
+ const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
158
+ method: "POST",
159
+ headers: getHeaders(true),
160
+ body: JSON.stringify({ ...settings, enabled: true }),
161
+ });
162
+ return res.json();
163
+ },
164
+
165
+ /**
166
+ * Get notification settings for an app
167
+ */
168
+ async getAppSettings(appId: string) {
169
+ const res = await fetch(`${apiUrl}/users/me/apps/${appId}/settings`, {
170
+ headers: getHeaders(true),
171
+ });
172
+ return res.json();
173
+ },
174
+
175
+ // ===== IN-APP NOTIFICATIONS =====
176
+
177
+ /**
178
+ * Get current user's in-app notifications
179
+ */
180
+ async getInAppNotifications() {
181
+ const res = await fetch(`${apiUrl}/users/me/notifications`, {
182
+ headers: getHeaders(true),
183
+ });
184
+ return res.json();
185
+ },
186
+
187
+ /**
188
+ * Mark a notification as read
189
+ */
190
+ async markNotificationAsRead(notificationId: string) {
191
+ const res = await fetch(`${apiUrl}/users/me/notifications/${notificationId}/read`, {
192
+ method: "PUT",
193
+ headers: getHeaders(true),
194
+ });
195
+ return res.json();
196
+ },
197
+
198
+ // ===== SENDING NOTIFICATIONS =====
199
+
200
+ /**
201
+ * Send a notification (requires auth)
202
+ */
203
+ async sendNotification(data: SendNotificationRequest) {
204
+ const res = await fetch(`${apiUrl}/send`, {
205
+ method: "POST",
206
+ headers: getHeaders(true),
207
+ body: JSON.stringify(data),
208
+ });
209
+ return res.json();
210
+ },
211
+ };
@@ -0,0 +1 @@
1
+ export * from "./api";
@@ -0,0 +1,57 @@
1
+ export type ChannelType = "email" | "telegram" | "discord" | "sms" | "whatsapp" | "in_app";
2
+
3
+ export interface NotificationChannel {
4
+ id: number;
5
+ channel_type: ChannelType;
6
+ enabled: number;
7
+ channel_identifier: string;
8
+ }
9
+
10
+ export interface UserData {
11
+ user: {
12
+ id: number;
13
+ user_id: string;
14
+ };
15
+ channels: NotificationChannel[];
16
+ appSettings: Array<{
17
+ app_id: string;
18
+ notification_type: string;
19
+ enabled: number;
20
+ channels: string;
21
+ }>;
22
+ }
23
+
24
+ export interface NotificationHistory {
25
+ id: string;
26
+ app_id: string;
27
+ notification_type: string;
28
+ title: string;
29
+ message: string;
30
+ created_at: string;
31
+ read: boolean;
32
+ }
33
+
34
+ export interface TelegramLinkResponse {
35
+ deepLink: string;
36
+ verificationCode: string;
37
+ botUsername: string;
38
+ }
39
+
40
+ export interface TelegramStatusResponse {
41
+ connected: boolean;
42
+ chatId?: string;
43
+ }
44
+
45
+ export interface NotificationPreferences {
46
+ notificationType: string;
47
+ channels: string[];
48
+ }
49
+
50
+ export interface SendNotificationRequest {
51
+ userId: string;
52
+ appId: string;
53
+ notificationType: string;
54
+ message: string;
55
+ title?: string;
56
+ data?: Record<string, any>;
57
+ }
@@ -0,0 +1,13 @@
1
+ import Cookies from "js-cookie";
2
+
3
+ const B3_AUTH_COOKIE_NAME = "b3-auth";
4
+
5
+ /**
6
+ * Get the authentication token from the B3 auth cookie
7
+ * This token is managed by the B3 Global Account authentication system
8
+ *
9
+ * @returns The JWT token string or null if not found
10
+ */
11
+ export function getAuthToken(): string | null {
12
+ return Cookies.get(B3_AUTH_COOKIE_NAME) || null;
13
+ }
@@ -1,4 +1,5 @@
1
1
  // Export utility functions
2
+ export * from "./auth-token";
2
3
  export * from "./cn";
3
4
  export * from "./formatNumber";
4
5
  export * from "./formatUsername";
@@ -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
- });