@b3dotfun/sdk 0.0.42 → 0.0.43-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.
Files changed (114) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +1 -0
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +11 -4
  3. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +43 -3
  4. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +1 -0
  5. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +2 -2
  6. package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
  7. package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +5 -3
  8. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
  9. package/dist/cjs/global-account/react/components/index.d.ts +8 -7
  10. package/dist/cjs/global-account/react/components/index.js +29 -23
  11. package/dist/cjs/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
  12. package/dist/cjs/global-account/react/components/ui/dropdown-menu.js +100 -0
  13. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +5 -1
  14. package/dist/cjs/shared/constants/currency.d.ts +1 -0
  15. package/dist/cjs/shared/constants/currency.js +5 -0
  16. package/dist/cjs/shared/constants/index.d.ts +1 -0
  17. package/dist/cjs/shared/constants/index.js +15 -0
  18. package/dist/cjs/shared/react/components/CurrencySelector.d.ts +7 -0
  19. package/dist/cjs/shared/react/components/CurrencySelector.js +14 -0
  20. package/dist/cjs/shared/react/components/FormattedCurrency.d.ts +12 -0
  21. package/dist/cjs/shared/react/components/FormattedCurrency.js +60 -0
  22. package/dist/cjs/shared/react/components/index.d.ts +2 -0
  23. package/dist/cjs/shared/react/components/index.js +18 -0
  24. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  25. package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
  26. package/dist/cjs/shared/react/hooks/index.d.ts +1 -0
  27. package/dist/cjs/shared/react/hooks/index.js +1 -0
  28. package/dist/cjs/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
  29. package/dist/cjs/shared/react/hooks/useCurrencyConversion.js +200 -0
  30. package/dist/cjs/shared/react/index.d.ts +2 -0
  31. package/dist/cjs/shared/react/index.js +2 -0
  32. package/dist/cjs/shared/react/stores/currencyModalStore.d.ts +7 -0
  33. package/dist/cjs/shared/react/stores/currencyModalStore.js +9 -0
  34. package/dist/cjs/shared/react/stores/currencyStore.d.ts +51 -0
  35. package/dist/cjs/shared/react/stores/currencyStore.js +57 -0
  36. package/dist/cjs/shared/react/stores/index.d.ts +2 -0
  37. package/dist/cjs/shared/react/stores/index.js +18 -0
  38. package/dist/esm/anyspend/react/components/AnySpend.d.ts +1 -0
  39. package/dist/esm/anyspend/react/components/AnySpend.js +11 -4
  40. package/dist/esm/anyspend/react/components/AnySpendCustom.js +10 -3
  41. package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +1 -0
  42. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +2 -2
  43. package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
  44. package/dist/esm/anyspend/react/components/common/PanelOnramp.js +5 -3
  45. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +1 -1
  46. package/dist/esm/global-account/react/components/index.d.ts +8 -7
  47. package/dist/esm/global-account/react/components/index.js +8 -7
  48. package/dist/esm/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
  49. package/dist/esm/global-account/react/components/ui/dropdown-menu.js +60 -0
  50. package/dist/esm/global-account/react/stores/useModalStore.d.ts +5 -1
  51. package/dist/esm/shared/constants/currency.d.ts +1 -0
  52. package/dist/esm/shared/constants/currency.js +2 -0
  53. package/dist/esm/shared/constants/index.d.ts +1 -0
  54. package/dist/esm/shared/constants/index.js +1 -0
  55. package/dist/esm/shared/react/components/CurrencySelector.d.ts +7 -0
  56. package/dist/esm/shared/react/components/CurrencySelector.js +11 -0
  57. package/dist/esm/shared/react/components/FormattedCurrency.d.ts +12 -0
  58. package/dist/esm/shared/react/components/FormattedCurrency.js +57 -0
  59. package/dist/esm/shared/react/components/index.d.ts +2 -0
  60. package/dist/esm/shared/react/components/index.js +2 -0
  61. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  62. package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
  63. package/dist/esm/shared/react/hooks/index.d.ts +1 -0
  64. package/dist/esm/shared/react/hooks/index.js +1 -0
  65. package/dist/esm/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
  66. package/dist/esm/shared/react/hooks/useCurrencyConversion.js +197 -0
  67. package/dist/esm/shared/react/index.d.ts +2 -0
  68. package/dist/esm/shared/react/index.js +2 -0
  69. package/dist/esm/shared/react/stores/currencyModalStore.d.ts +7 -0
  70. package/dist/esm/shared/react/stores/currencyModalStore.js +6 -0
  71. package/dist/esm/shared/react/stores/currencyStore.d.ts +51 -0
  72. package/dist/esm/shared/react/stores/currencyStore.js +54 -0
  73. package/dist/esm/shared/react/stores/index.d.ts +2 -0
  74. package/dist/esm/shared/react/stores/index.js +2 -0
  75. package/dist/styles/index.css +1 -1
  76. package/dist/types/anyspend/react/components/AnySpend.d.ts +1 -0
  77. package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +1 -0
  78. package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +2 -1
  79. package/dist/types/global-account/react/components/index.d.ts +8 -7
  80. package/dist/types/global-account/react/components/ui/dropdown-menu.d.ts +27 -0
  81. package/dist/types/global-account/react/stores/useModalStore.d.ts +5 -1
  82. package/dist/types/shared/constants/currency.d.ts +1 -0
  83. package/dist/types/shared/constants/index.d.ts +1 -0
  84. package/dist/types/shared/react/components/CurrencySelector.d.ts +7 -0
  85. package/dist/types/shared/react/components/FormattedCurrency.d.ts +12 -0
  86. package/dist/types/shared/react/components/index.d.ts +2 -0
  87. package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
  88. package/dist/types/shared/react/hooks/index.d.ts +1 -0
  89. package/dist/types/shared/react/hooks/useCurrencyConversion.d.ts +35 -0
  90. package/dist/types/shared/react/index.d.ts +2 -0
  91. package/dist/types/shared/react/stores/currencyModalStore.d.ts +7 -0
  92. package/dist/types/shared/react/stores/currencyStore.d.ts +51 -0
  93. package/dist/types/shared/react/stores/index.d.ts +2 -0
  94. package/package.json +29 -3
  95. package/src/anyspend/react/components/AnySpend.tsx +15 -2
  96. package/src/anyspend/react/components/AnySpendCustom.tsx +11 -2
  97. package/src/anyspend/react/components/AnyspendDepositHype.tsx +3 -0
  98. package/src/anyspend/react/components/common/PanelOnramp.tsx +19 -15
  99. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -7
  100. package/src/global-account/react/components/index.ts +19 -12
  101. package/src/global-account/react/components/ui/dropdown-menu.tsx +132 -0
  102. package/src/global-account/react/stores/useModalStore.ts +5 -1
  103. package/src/shared/constants/currency.ts +2 -0
  104. package/src/shared/constants/index.ts +2 -0
  105. package/src/shared/react/components/CurrencySelector.tsx +71 -0
  106. package/src/shared/react/components/FormattedCurrency.tsx +106 -0
  107. package/src/shared/react/components/index.ts +2 -0
  108. package/src/shared/react/hooks/__tests__/useCurrencyConversion.test.ts +308 -0
  109. package/src/shared/react/hooks/index.ts +1 -0
  110. package/src/shared/react/hooks/useCurrencyConversion.ts +211 -0
  111. package/src/shared/react/index.ts +2 -0
  112. package/src/shared/react/stores/currencyModalStore.ts +13 -0
  113. package/src/shared/react/stores/currencyStore.ts +82 -0
  114. package/src/shared/react/stores/index.ts +2 -0
@@ -0,0 +1,71 @@
1
+ "use client";
2
+
3
+ import { cn } from "@b3dotfun/sdk/shared/utils";
4
+ import { Button } from "../../../global-account/react/components/ui/button";
5
+ import {
6
+ DropdownMenu,
7
+ DropdownMenuContent,
8
+ DropdownMenuItem,
9
+ DropdownMenuSeparator,
10
+ DropdownMenuTrigger,
11
+ } from "../../../global-account/react/components/ui/dropdown-menu";
12
+ import { CURRENCY_NAMES, CURRENCY_SYMBOLS, SupportedCurrency, useCurrencyStore } from "../stores/currencyStore";
13
+
14
+ const currencies: SupportedCurrency[] = ["B3", "ETH", "SOL", "USD", "EUR", "GBP", "KRW", "JPY", "CAD", "AUD"];
15
+
16
+ interface CurrencySelectorProps {
17
+ labelClassName?: string;
18
+ buttonVariant?: "dark" | "primary" | "ghost" | "gold";
19
+ label?: string;
20
+ }
21
+
22
+ export function CurrencySelector({ labelClassName, buttonVariant = "dark", label }: CurrencySelectorProps) {
23
+ const { selectedCurrency, setSelectedCurrency } = useCurrencyStore();
24
+
25
+ return (
26
+ <div className="flex items-center gap-2">
27
+ <DropdownMenu>
28
+ <DropdownMenuTrigger asChild>
29
+ <div className="flex items-center gap-3">
30
+ {label && (
31
+ <span
32
+ className={cn(
33
+ "text-foreground text-sm font-medium leading-none tracking-tight sm:text-base",
34
+ labelClassName,
35
+ )}
36
+ >
37
+ {label}
38
+ </span>
39
+ )}
40
+ <Button variant={buttonVariant as any} className="flex items-center gap-2">
41
+ <span className="text-sm font-medium">{CURRENCY_NAMES[selectedCurrency]}</span>
42
+ <svg className="h-4 w-4" fill="currentColor" viewBox="0 0 20 20">
43
+ <path
44
+ fillRule="evenodd"
45
+ d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
46
+ clipRule="evenodd"
47
+ />
48
+ </svg>
49
+ </Button>
50
+ </div>
51
+ </DropdownMenuTrigger>
52
+ <DropdownMenuContent align="end" className="z-[100] min-w-[200px]">
53
+ {currencies.map(currency => (
54
+ <div key={currency}>
55
+ <DropdownMenuItem
56
+ onClick={() => setSelectedCurrency(currency)}
57
+ className={`flex cursor-pointer items-center justify-between gap-3 px-3 py-2.5 transition-colors ${
58
+ selectedCurrency === currency ? "bg-accent" : "hover:bg-accent/50"
59
+ }`}
60
+ >
61
+ <span className="text-foreground text-sm font-medium">{CURRENCY_NAMES[currency]}</span>
62
+ <span className="text-muted-foreground text-xs font-medium">{CURRENCY_SYMBOLS[currency]}</span>
63
+ </DropdownMenuItem>
64
+ {currency === "SOL" && <DropdownMenuSeparator key="separator" className="bg-border my-1" />}
65
+ </div>
66
+ ))}
67
+ </DropdownMenuContent>
68
+ </DropdownMenu>
69
+ </div>
70
+ );
71
+ }
@@ -0,0 +1,106 @@
1
+ "use client";
2
+
3
+ import { B3_COIN_IMAGE_URL } from "@b3dotfun/sdk/shared/constants/currency";
4
+ import { cn } from "@b3dotfun/sdk/shared/utils";
5
+ import { Tooltip, TooltipContent, TooltipTrigger } from "../../../global-account/react/components/ui/tooltip";
6
+ import { useCurrencyConversion } from "../hooks/useCurrencyConversion";
7
+ import { useCurrencyModalStore } from "../stores/currencyModalStore";
8
+
9
+ interface FormattedCurrencyProps {
10
+ amount: number;
11
+ showChange?: boolean;
12
+ showColor?: boolean;
13
+ className?: string;
14
+ subB3Icon?: boolean;
15
+ clickable?: boolean;
16
+ decimals?: number;
17
+ currency?: string; // Override currency (e.g., "ETH", "USDC", "B3")
18
+ }
19
+
20
+ export function FormattedCurrency({
21
+ amount,
22
+ showChange = false,
23
+ showColor = false,
24
+ className,
25
+ subB3Icon = true,
26
+ clickable = true,
27
+ decimals,
28
+ currency,
29
+ }: FormattedCurrencyProps) {
30
+ const { formatCurrencyValue, formatTooltipValue, selectedCurrency, baseCurrency } = useCurrencyConversion();
31
+ const { openModal } = useCurrencyModalStore();
32
+
33
+ // Use passed currency or fall back to selected currency
34
+ const activeCurrency = currency || selectedCurrency;
35
+
36
+ const isPositive = amount >= 0;
37
+
38
+ // Get the formatted value (using absolute value for negative numbers when showing change)
39
+ const baseAmount = showChange ? Math.abs(amount) : amount;
40
+
41
+ // Use centralized formatting from hook with optional overrides
42
+ const formattedValue = formatCurrencyValue(baseAmount, {
43
+ decimals,
44
+ currency,
45
+ });
46
+
47
+ // Generate tooltip using the centralized hook function
48
+ const baseTooltipValue = formatTooltipValue(amount, currency);
49
+
50
+ // Add change indicator if needed
51
+ const tooltipValue = showChange ? `${isPositive ? "+" : "-"}${baseTooltipValue}` : baseTooltipValue;
52
+
53
+ // Determine color class
54
+ let colorClass = "";
55
+ if (showColor) {
56
+ if (isPositive) {
57
+ colorClass = "text-green-400";
58
+ } else {
59
+ colorClass = "text-red-400";
60
+ }
61
+ }
62
+
63
+ // Add change indicator
64
+ let displayValue = formattedValue;
65
+ if (showChange) {
66
+ if (isPositive) {
67
+ displayValue = `+${formattedValue}`;
68
+ } else {
69
+ displayValue = `-${formattedValue}`;
70
+ }
71
+ }
72
+
73
+ const handleClick = () => {
74
+ if (clickable) {
75
+ openModal();
76
+ }
77
+ };
78
+
79
+ return (
80
+ <Tooltip>
81
+ <TooltipTrigger asChild>
82
+ <span
83
+ onClick={handleClick}
84
+ className={cn(
85
+ "inline-flex items-center gap-1 whitespace-nowrap",
86
+ colorClass,
87
+ className,
88
+ clickable && "cursor-pointer transition-opacity hover:opacity-80",
89
+ )}
90
+ >
91
+ {subB3Icon &&
92
+ (currency === baseCurrency || (!currency && activeCurrency === baseCurrency)) &&
93
+ baseCurrency === "B3"
94
+ ? displayValue.split(" ")[0]
95
+ : displayValue}
96
+ {subB3Icon &&
97
+ (currency === baseCurrency || (!currency && activeCurrency === baseCurrency)) &&
98
+ baseCurrency === "B3" && (
99
+ <img src={B3_COIN_IMAGE_URL} className="inline-block h-4 w-4 align-middle" alt="B3 coin" />
100
+ )}
101
+ </span>
102
+ </TooltipTrigger>
103
+ <TooltipContent>{tooltipValue}</TooltipContent>
104
+ </Tooltip>
105
+ );
106
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./CurrencySelector";
2
+ export * from "./FormattedCurrency";
@@ -0,0 +1,308 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { renderHook } from "@testing-library/react";
3
+ import { useCurrencyConversion } from "../useCurrencyConversion";
4
+
5
+ // Mock the external dependencies
6
+ // Store mock rates for different quote currencies
7
+ const mockRates: Record<string, number | undefined> = {};
8
+
9
+ // Mock store state
10
+ const mockStoreState: any = {
11
+ selectedCurrency: "B3",
12
+ baseCurrency: "B3",
13
+ setSelectedCurrency: vi.fn(),
14
+ setBaseCurrency: vi.fn(),
15
+ };
16
+
17
+ vi.mock("@b3dotfun/sdk/global-account/react", () => ({
18
+ useExchangeRate: vi.fn((params: any) => {
19
+ const rate = mockRates[params?.quoteCurrency];
20
+ return { rate };
21
+ }),
22
+ }));
23
+
24
+ vi.mock("@b3dotfun/sdk/shared/utils/number", () => ({
25
+ formatDisplayNumber: vi.fn((value: any) => {
26
+ const num = Number(value);
27
+ if (isNaN(num)) return "0";
28
+ return num.toLocaleString("en-US", { maximumFractionDigits: 6 });
29
+ }),
30
+ }));
31
+
32
+ vi.mock("../../stores/currencyStore", () => ({
33
+ useCurrencyStore: vi.fn((selector: any) => {
34
+ if (selector) {
35
+ return selector(mockStoreState);
36
+ }
37
+ return mockStoreState;
38
+ }),
39
+ CURRENCY_SYMBOLS: {
40
+ B3: "B3",
41
+ USD: "$",
42
+ EUR: "€",
43
+ GBP: "£",
44
+ JPY: "¥",
45
+ CAD: "C$",
46
+ AUD: "A$",
47
+ ETH: "ETH",
48
+ SOL: "SOL",
49
+ KRW: "₩",
50
+ },
51
+ }));
52
+
53
+ describe("useCurrencyConversion", () => {
54
+ beforeEach(() => {
55
+ vi.clearAllMocks();
56
+ // Reset mock rates to default
57
+ Object.keys(mockRates).forEach(key => delete mockRates[key]);
58
+ mockRates.USD = 1.0;
59
+ // Reset store state
60
+ mockStoreState.selectedCurrency = "B3";
61
+ mockStoreState.baseCurrency = "B3";
62
+ });
63
+
64
+ describe("formatCurrencyValue", () => {
65
+ it("should format base currency (B3) without conversion", () => {
66
+ mockStoreState.selectedCurrency = "B3";
67
+ mockStoreState.baseCurrency = "B3";
68
+
69
+ const { result } = renderHook(() => useCurrencyConversion());
70
+ const formatted = result.current.formatCurrencyValue(100);
71
+
72
+ expect(formatted).toContain("B3");
73
+ expect(formatted).toContain("100");
74
+ });
75
+
76
+ it("should show base currency when exchange rate is unavailable", () => {
77
+ mockRates.USD = undefined;
78
+ mockStoreState.selectedCurrency = "USD";
79
+ mockStoreState.baseCurrency = "B3";
80
+
81
+ const { result } = renderHook(() => useCurrencyConversion());
82
+ const formatted = result.current.formatCurrencyValue(100);
83
+
84
+ expect(formatted).toContain("B3");
85
+ expect(formatted).not.toContain("$");
86
+ });
87
+
88
+ it("should format USD with prefix symbol", () => {
89
+ mockRates.USD = 2.0;
90
+ mockStoreState.selectedCurrency = "USD";
91
+ mockStoreState.baseCurrency = "B3";
92
+
93
+ const { result } = renderHook(() => useCurrencyConversion());
94
+ const formatted = result.current.formatCurrencyValue(100);
95
+
96
+ expect(formatted).toMatch(/^\$/);
97
+ expect(formatted).toContain("200");
98
+ });
99
+
100
+ it("should format EUR with prefix symbol", () => {
101
+ mockRates.EUR = 1.8;
102
+ mockRates.USD = 2.0;
103
+ mockStoreState.selectedCurrency = "EUR";
104
+ mockStoreState.baseCurrency = "B3";
105
+
106
+ const { result } = renderHook(() => useCurrencyConversion());
107
+ const formatted = result.current.formatCurrencyValue(100);
108
+
109
+ expect(formatted).toMatch(/^€/);
110
+ });
111
+
112
+ it("should format JPY without decimals", () => {
113
+ mockRates.JPY = 150;
114
+ mockRates.USD = 2.0;
115
+ mockStoreState.selectedCurrency = "JPY";
116
+ mockStoreState.baseCurrency = "B3";
117
+
118
+ const { result } = renderHook(() => useCurrencyConversion());
119
+ const formatted = result.current.formatCurrencyValue(100);
120
+
121
+ expect(formatted).toContain("¥");
122
+ expect(formatted).not.toContain(".");
123
+ });
124
+
125
+ it("should format KRW without decimals", () => {
126
+ mockRates.KRW = 1300;
127
+ mockRates.USD = 2.0;
128
+ mockStoreState.selectedCurrency = "KRW";
129
+ mockStoreState.baseCurrency = "B3";
130
+
131
+ const { result } = renderHook(() => useCurrencyConversion());
132
+ const formatted = result.current.formatCurrencyValue(100);
133
+
134
+ expect(formatted).toContain("₩");
135
+ expect(formatted).not.toContain(".");
136
+ });
137
+
138
+ it("should format ETH with suffix symbol", () => {
139
+ mockRates.ETH = 0.0005;
140
+ mockRates.USD = 2.0;
141
+ mockStoreState.selectedCurrency = "ETH";
142
+ mockStoreState.baseCurrency = "B3";
143
+
144
+ const { result } = renderHook(() => useCurrencyConversion());
145
+ const formatted = result.current.formatCurrencyValue(100);
146
+
147
+ expect(formatted).toContain("ETH");
148
+ expect(formatted).not.toMatch(/^ETH/);
149
+ });
150
+
151
+ it("should format SOL with suffix symbol", () => {
152
+ mockRates.SOL = 0.05;
153
+ mockRates.USD = 2.0;
154
+ mockStoreState.selectedCurrency = "SOL";
155
+ mockStoreState.baseCurrency = "B3";
156
+
157
+ const { result } = renderHook(() => useCurrencyConversion());
158
+ const formatted = result.current.formatCurrencyValue(100);
159
+
160
+ expect(formatted).toContain("SOL");
161
+ expect(formatted).not.toMatch(/^SOL/);
162
+ });
163
+
164
+ it("should handle small USD amounts with proper conversion", () => {
165
+ mockRates.USD = 1.5;
166
+ mockStoreState.selectedCurrency = "USD";
167
+ mockStoreState.baseCurrency = "B3";
168
+
169
+ const { result } = renderHook(() => useCurrencyConversion());
170
+ const formatted = result.current.formatCurrencyValue(10);
171
+
172
+ // 10 * 1.5 = 15
173
+ expect(formatted).toMatch(/^\$/);
174
+ expect(formatted).toContain("15");
175
+ });
176
+
177
+ it("should apply correct exchange rate conversion", () => {
178
+ const testRate = 3.5;
179
+ mockRates.USD = testRate;
180
+ mockStoreState.selectedCurrency = "USD";
181
+ mockStoreState.baseCurrency = "B3";
182
+
183
+ const { result } = renderHook(() => useCurrencyConversion());
184
+ const inputValue = 100;
185
+ const formatted = result.current.formatCurrencyValue(inputValue);
186
+
187
+ expect(formatted).toContain("350");
188
+ });
189
+ });
190
+
191
+ describe("return values", () => {
192
+ it("should return selected currency", () => {
193
+ mockStoreState.selectedCurrency = "USD";
194
+ mockStoreState.baseCurrency = "B3";
195
+
196
+ const { result } = renderHook(() => useCurrencyConversion());
197
+
198
+ expect(result.current.selectedCurrency).toBe("USD");
199
+ });
200
+
201
+ it("should return base currency", () => {
202
+ mockStoreState.selectedCurrency = "USD";
203
+ mockStoreState.baseCurrency = "B3";
204
+
205
+ const { result } = renderHook(() => useCurrencyConversion());
206
+
207
+ expect(result.current.baseCurrency).toBe("B3");
208
+ });
209
+
210
+ it("should return exchange rate", () => {
211
+ const testRate = 2.5;
212
+ mockRates.USD = testRate;
213
+ mockStoreState.selectedCurrency = "USD";
214
+ mockStoreState.baseCurrency = "B3";
215
+
216
+ const { result } = renderHook(() => useCurrencyConversion());
217
+
218
+ expect(result.current.exchangeRate).toBe(testRate);
219
+ });
220
+
221
+ it("should return correct currency symbols", () => {
222
+ mockStoreState.selectedCurrency = "EUR";
223
+ mockStoreState.baseCurrency = "B3";
224
+
225
+ const { result } = renderHook(() => useCurrencyConversion());
226
+
227
+ expect(result.current.selectedCurrencySymbol).toBe("€");
228
+ expect(result.current.baseCurrencySymbol).toBe("B3");
229
+ });
230
+ });
231
+
232
+ describe("formatTooltipValue", () => {
233
+ it("should show USD equivalent when displaying base currency", () => {
234
+ mockRates.USD = 1.5;
235
+ mockStoreState.selectedCurrency = "B3";
236
+ mockStoreState.baseCurrency = "B3";
237
+
238
+ const { result } = renderHook(() => useCurrencyConversion());
239
+ const tooltip = result.current.formatTooltipValue(100);
240
+
241
+ expect(tooltip).toContain("USD");
242
+ expect(tooltip).toContain("150");
243
+ });
244
+
245
+ it("should show base currency when displaying other currency", () => {
246
+ mockRates.EUR = 0.9;
247
+ mockRates.USD = 1.2;
248
+ mockStoreState.selectedCurrency = "EUR";
249
+ mockStoreState.baseCurrency = "B3";
250
+
251
+ const { result } = renderHook(() => useCurrencyConversion());
252
+ const tooltip = result.current.formatTooltipValue(100);
253
+
254
+ expect(tooltip).toContain("B3");
255
+ expect(tooltip).toContain("100");
256
+ });
257
+
258
+ it("should handle custom currency for base currency", () => {
259
+ mockRates.USD = 2.0;
260
+ mockRates.EUR = 1.8;
261
+ mockStoreState.selectedCurrency = "EUR";
262
+ mockStoreState.baseCurrency = "B3";
263
+
264
+ const { result } = renderHook(() => useCurrencyConversion());
265
+ const tooltip = result.current.formatTooltipValue(100, "B3");
266
+
267
+ expect(tooltip).toContain("USD");
268
+ expect(tooltip).toContain("200");
269
+ });
270
+
271
+ it("should handle custom currency for non-base currency", () => {
272
+ mockRates.USD = 2.0;
273
+ mockStoreState.selectedCurrency = "USD";
274
+ mockStoreState.baseCurrency = "B3";
275
+
276
+ const { result } = renderHook(() => useCurrencyConversion());
277
+ const tooltip = result.current.formatTooltipValue(50, "ETH");
278
+
279
+ expect(tooltip).toContain("ETH");
280
+ expect(tooltip).toContain("50");
281
+ });
282
+
283
+ it("should handle absolute values for negative amounts", () => {
284
+ mockRates.USD = 1.5;
285
+ mockStoreState.selectedCurrency = "B3";
286
+ mockStoreState.baseCurrency = "B3";
287
+
288
+ const { result } = renderHook(() => useCurrencyConversion());
289
+ const tooltip = result.current.formatTooltipValue(-100);
290
+
291
+ expect(tooltip).toContain("USD");
292
+ expect(tooltip).toContain("150");
293
+ expect(tooltip).not.toContain("-");
294
+ });
295
+
296
+ it("should handle exchange rate unavailable", () => {
297
+ mockRates.USD = undefined;
298
+ mockStoreState.selectedCurrency = "B3";
299
+ mockStoreState.baseCurrency = "B3";
300
+
301
+ const { result } = renderHook(() => useCurrencyConversion());
302
+ const tooltip = result.current.formatTooltipValue(100);
303
+
304
+ expect(tooltip).toContain("USD");
305
+ expect(tooltip).toContain("100");
306
+ });
307
+ });
308
+ });
@@ -1 +1,2 @@
1
+ export * from "./useCurrencyConversion";
1
2
  export * from "./useNavigation";