@oanda/labs-spread-cost-calculator-widget 1.0.4 → 1.0.6
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/CHANGELOG.md +52 -0
- package/dist/main/SpreadCostCalculatorWidget/Main.js +6 -6
- package/dist/main/SpreadCostCalculatorWidget/Main.js.map +1 -1
- package/dist/main/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.js +25 -26
- package/dist/main/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.js.map +1 -1
- package/dist/main/SpreadCostCalculatorWidget/ValidationWrapper.js +3 -4
- package/dist/main/SpreadCostCalculatorWidget/ValidationWrapper.js.map +1 -1
- package/dist/main/SpreadCostCalculatorWidget/constant.js +2 -1
- package/dist/main/SpreadCostCalculatorWidget/constant.js.map +1 -1
- package/dist/main/SpreadCostCalculatorWidget/types.js.map +1 -1
- package/dist/main/SpreadCostCalculatorWidget/useCalculateSpread.js +9 -3
- package/dist/main/SpreadCostCalculatorWidget/useCalculateSpread.js.map +1 -1
- package/dist/main/SpreadCostCalculatorWidget/useInstrumentChange.js +5 -1
- package/dist/main/SpreadCostCalculatorWidget/useInstrumentChange.js.map +1 -1
- package/dist/main/SpreadCostCalculatorWidget/utils.js +2 -9
- package/dist/main/SpreadCostCalculatorWidget/utils.js.map +1 -1
- package/dist/module/SpreadCostCalculatorWidget/Main.js +8 -8
- package/dist/module/SpreadCostCalculatorWidget/Main.js.map +1 -1
- package/dist/module/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.js +26 -26
- package/dist/module/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.js.map +1 -1
- package/dist/module/SpreadCostCalculatorWidget/ValidationWrapper.js +3 -3
- package/dist/module/SpreadCostCalculatorWidget/ValidationWrapper.js.map +1 -1
- package/dist/module/SpreadCostCalculatorWidget/constant.js +1 -0
- package/dist/module/SpreadCostCalculatorWidget/constant.js.map +1 -1
- package/dist/module/SpreadCostCalculatorWidget/types.js.map +1 -1
- package/dist/module/SpreadCostCalculatorWidget/useCalculateSpread.js +9 -3
- package/dist/module/SpreadCostCalculatorWidget/useCalculateSpread.js.map +1 -1
- package/dist/module/SpreadCostCalculatorWidget/useInstrumentChange.js +5 -1
- package/dist/module/SpreadCostCalculatorWidget/useInstrumentChange.js.map +1 -1
- package/dist/module/SpreadCostCalculatorWidget/utils.js +2 -9
- package/dist/module/SpreadCostCalculatorWidget/utils.js.map +1 -1
- package/dist/types/SpreadCostCalculatorWidget/constant.d.ts +1 -0
- package/dist/types/SpreadCostCalculatorWidget/types.d.ts +2 -2
- package/dist/types/SpreadCostCalculatorWidget/useCalculateSpread.d.ts +2 -1
- package/dist/types/SpreadCostCalculatorWidget/useInstrumentChange.d.ts +1 -0
- package/dist/types/SpreadCostCalculatorWidget/utils.d.ts +1 -2
- package/package.json +3 -3
- package/src/SpreadCostCalculatorWidget/Main.tsx +6 -6
- package/src/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.tsx +28 -27
- package/src/SpreadCostCalculatorWidget/ValidationWrapper.tsx +3 -3
- package/src/SpreadCostCalculatorWidget/constant.ts +1 -0
- package/src/SpreadCostCalculatorWidget/types.ts +2 -5
- package/src/SpreadCostCalculatorWidget/useCalculateSpread.ts +14 -2
- package/src/SpreadCostCalculatorWidget/useInstrumentChange.ts +4 -0
- package/src/SpreadCostCalculatorWidget/utils.ts +2 -11
- package/test/SpreadCostCalculator.test.tsx +8 -3
- package/test/useCalculateSpread.test.tsx +15 -11
|
@@ -24,6 +24,7 @@ describe('spread cost calculator', () => {
|
|
|
24
24
|
unitsTraded: 10000,
|
|
25
25
|
spread: 1.4,
|
|
26
26
|
pipLocation: -4,
|
|
27
|
+
currency: 'USD',
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
it.each([
|
|
@@ -32,23 +33,26 @@ describe('spread cost calculator', () => {
|
|
|
32
33
|
{ ...input, pipLocation: undefined },
|
|
33
34
|
])(
|
|
34
35
|
'should return undefined, when one of params is undefined (%s)',
|
|
35
|
-
({
|
|
36
|
+
({
|
|
37
|
+
unitsTraded, spread, pipLocation, currency,
|
|
38
|
+
}) => {
|
|
36
39
|
// Given
|
|
37
40
|
// When
|
|
38
41
|
const { result } = renderHook(() => useCalculateSpread({
|
|
39
42
|
spread,
|
|
40
43
|
unitsTraded,
|
|
41
44
|
pipLocation,
|
|
45
|
+
currency,
|
|
42
46
|
}));
|
|
43
47
|
|
|
44
|
-
expect(result.current).
|
|
48
|
+
expect(result.current).toBe('\u2014');
|
|
45
49
|
|
|
46
50
|
act(() => {
|
|
47
51
|
jest.advanceTimersByTime(defaultDelay);
|
|
48
52
|
});
|
|
49
53
|
|
|
50
54
|
// Then
|
|
51
|
-
expect(result.current).
|
|
55
|
+
expect(result.current).toBe('\u2014');
|
|
52
56
|
},
|
|
53
57
|
);
|
|
54
58
|
|
|
@@ -61,14 +65,14 @@ describe('spread cost calculator', () => {
|
|
|
61
65
|
pipLocation: -4,
|
|
62
66
|
}));
|
|
63
67
|
|
|
64
|
-
expect(result.current).
|
|
68
|
+
expect(result.current).toBe('\u2014');
|
|
65
69
|
|
|
66
70
|
act(() => {
|
|
67
71
|
jest.advanceTimersByTime(defaultDelay);
|
|
68
72
|
});
|
|
69
73
|
|
|
70
74
|
// Then
|
|
71
|
-
expect(result.current).toEqual(1);
|
|
75
|
+
expect(result.current).toEqual('1 USD');
|
|
72
76
|
});
|
|
73
77
|
|
|
74
78
|
it('should return correct calculated values with 0 as pipLocation', () => {
|
|
@@ -80,14 +84,14 @@ describe('spread cost calculator', () => {
|
|
|
80
84
|
pipLocation: 0,
|
|
81
85
|
}));
|
|
82
86
|
|
|
83
|
-
expect(result.current).
|
|
87
|
+
expect(result.current).toBe('\u2014');
|
|
84
88
|
|
|
85
89
|
act(() => {
|
|
86
90
|
jest.advanceTimersByTime(defaultDelay);
|
|
87
91
|
});
|
|
88
92
|
|
|
89
93
|
// Then
|
|
90
|
-
expect(result.current).toEqual(
|
|
94
|
+
expect(result.current).toEqual('10,000 USD');
|
|
91
95
|
});
|
|
92
96
|
|
|
93
97
|
it('should round up result to 4 decimal places', () => {
|
|
@@ -99,14 +103,14 @@ describe('spread cost calculator', () => {
|
|
|
99
103
|
spread: 1.1,
|
|
100
104
|
}));
|
|
101
105
|
|
|
102
|
-
expect(result.current).
|
|
106
|
+
expect(result.current).toBe('\u2014');
|
|
103
107
|
|
|
104
108
|
act(() => {
|
|
105
109
|
jest.advanceTimersByTime(defaultDelay);
|
|
106
110
|
});
|
|
107
111
|
|
|
108
112
|
// Then
|
|
109
|
-
expect(result.current).toEqual(0.0003);
|
|
113
|
+
expect(result.current).toEqual('0.0003 USD');
|
|
110
114
|
});
|
|
111
115
|
|
|
112
116
|
it('should calculate big numbers', () => {
|
|
@@ -118,14 +122,14 @@ describe('spread cost calculator', () => {
|
|
|
118
122
|
spread: 123331,
|
|
119
123
|
}));
|
|
120
124
|
|
|
121
|
-
expect(result.current).
|
|
125
|
+
expect(result.current).toBe('\u2014');
|
|
122
126
|
|
|
123
127
|
act(() => {
|
|
124
128
|
jest.advanceTimersByTime(defaultDelay);
|
|
125
129
|
});
|
|
126
130
|
|
|
127
131
|
// Then
|
|
128
|
-
expect(result.current).toEqual(
|
|
132
|
+
expect(result.current).toEqual('6,920,978.0601 USD');
|
|
129
133
|
});
|
|
130
134
|
});
|
|
131
135
|
});
|