@b3dotfun/sdk 0.0.46 → 0.0.47-test.4
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 +6 -225
- package/dist/cjs/anyspend/react/components/AnySpend.js +13 -14
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +14 -15
- package/dist/cjs/anyspend/react/components/common/OrderHistory.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +6 -3
- package/dist/cjs/anyspend/types/api.d.ts +176 -0
- package/dist/cjs/anyspend/utils/chain.js +1 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -64
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +26 -21
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/cjs/global-account/react/components/B3Provider/types.js +2 -0
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
- package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +6 -22
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +10 -45
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -1
- package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +134 -84
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -1
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/cjs/global-account/react/hooks/useUserQuery.js +86 -0
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +42 -0
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
- package/dist/cjs/shared/utils/index.d.ts +0 -1
- package/dist/cjs/shared/utils/index.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +14 -15
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +15 -16
- package/dist/esm/anyspend/react/components/common/OrderHistory.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +8 -5
- package/dist/esm/anyspend/types/api.d.ts +176 -0
- package/dist/esm/anyspend/utils/chain.js +1 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -68
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +24 -19
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/esm/global-account/react/components/B3Provider/types.js +2 -0
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +7 -23
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +4 -3
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +11 -46
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
- package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +3 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +137 -87
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +3 -2
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/esm/global-account/react/hooks/useUserQuery.js +83 -0
- package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/esm/global-account/react/hooks/useWagmiConfig.js +39 -0
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
- package/dist/esm/shared/utils/index.d.ts +0 -1
- package/dist/esm/shared/utils/index.js +0 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/types/api.d.ts +176 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/types/shared/utils/index.d.ts +0 -1
- package/package.json +4 -23
- package/src/anyspend/react/components/AnySpend.tsx +21 -19
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +21 -21
- package/src/anyspend/react/components/common/OrderHistory.tsx +11 -11
- package/src/anyspend/react/components/common/OrderHistoryItem.tsx +124 -129
- package/src/anyspend/types/api.ts +176 -0
- package/src/anyspend/utils/chain.ts +1 -4
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +51 -35
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +28 -72
- package/src/global-account/react/components/B3Provider/types.ts +4 -0
- package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +2 -3
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +4 -23
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +4 -3
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +8 -46
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
- package/src/global-account/react/components/custom/ManageAccountButton.tsx +3 -2
- package/src/global-account/react/hooks/useAuthentication.ts +159 -90
- package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +3 -2
- package/src/global-account/react/hooks/useUserQuery.ts +95 -0
- package/src/global-account/react/hooks/useWagmiConfig.tsx +44 -0
- package/src/global-account/react/stores/useModalStore.ts +0 -2
- package/src/shared/utils/index.ts +0 -1
- package/dist/cjs/anyspend/react/components/common/ErrorSection.d.ts +0 -6
- package/dist/cjs/anyspend/react/components/common/ErrorSection.js +0 -12
- package/dist/cjs/notifications/index.d.ts +0 -3
- package/dist/cjs/notifications/index.js +0 -25
- package/dist/cjs/notifications/react/hooks/index.d.ts +0 -1
- package/dist/cjs/notifications/react/hooks/index.js +0 -17
- package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +0 -42
- package/dist/cjs/notifications/react/hooks/useNotifications.js +0 -148
- package/dist/cjs/notifications/react/index.d.ts +0 -1
- package/dist/cjs/notifications/react/index.js +0 -17
- package/dist/cjs/notifications/services/api.d.ts +0 -67
- package/dist/cjs/notifications/services/api.js +0 -184
- package/dist/cjs/notifications/services/index.d.ts +0 -1
- package/dist/cjs/notifications/services/index.js +0 -17
- package/dist/cjs/notifications/types/index.d.ts +0 -51
- package/dist/cjs/notifications/types/index.js +0 -2
- package/dist/cjs/shared/utils/auth-token.d.ts +0 -7
- package/dist/cjs/shared/utils/auth-token.js +0 -17
- package/dist/esm/anyspend/react/components/common/ErrorSection.d.ts +0 -6
- package/dist/esm/anyspend/react/components/common/ErrorSection.js +0 -9
- package/dist/esm/notifications/index.d.ts +0 -3
- package/dist/esm/notifications/index.js +0 -7
- package/dist/esm/notifications/react/hooks/index.d.ts +0 -1
- package/dist/esm/notifications/react/hooks/index.js +0 -1
- package/dist/esm/notifications/react/hooks/useNotifications.d.ts +0 -42
- package/dist/esm/notifications/react/hooks/useNotifications.js +0 -145
- package/dist/esm/notifications/react/index.d.ts +0 -1
- package/dist/esm/notifications/react/index.js +0 -1
- package/dist/esm/notifications/services/api.d.ts +0 -67
- package/dist/esm/notifications/services/api.js +0 -179
- package/dist/esm/notifications/services/index.d.ts +0 -1
- package/dist/esm/notifications/services/index.js +0 -1
- package/dist/esm/notifications/types/index.d.ts +0 -51
- package/dist/esm/shared/utils/auth-token.d.ts +0 -7
- package/dist/esm/shared/utils/auth-token.js +0 -11
- package/dist/types/anyspend/react/components/common/ErrorSection.d.ts +0 -6
- package/dist/types/notifications/index.d.ts +0 -3
- package/dist/types/notifications/react/hooks/index.d.ts +0 -1
- package/dist/types/notifications/react/hooks/useNotifications.d.ts +0 -42
- package/dist/types/notifications/react/index.d.ts +0 -1
- package/dist/types/notifications/services/api.d.ts +0 -67
- package/dist/types/notifications/services/index.d.ts +0 -1
- package/dist/types/notifications/types/index.d.ts +0 -51
- package/dist/types/shared/utils/auth-token.d.ts +0 -7
- package/src/anyspend/react/components/common/ErrorSection.tsx +0 -21
- package/src/notifications/index.ts +0 -9
- package/src/notifications/react/hooks/index.ts +0 -1
- package/src/notifications/react/hooks/useNotifications.ts +0 -153
- package/src/notifications/react/index.ts +0 -1
- package/src/notifications/services/api.ts +0 -217
- package/src/notifications/services/index.ts +0 -1
- package/src/notifications/types/index.ts +0 -58
- package/src/shared/utils/auth-token.ts +0 -13
- /package/dist/{esm/notifications/types/index.js → cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts} +0 -0
|
@@ -0,0 +1,243 @@
|
|
|
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
|
+
});
|