@oanda/labs-currency-power-balance-widget 1.0.111 → 1.0.113
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 +908 -0
- package/dist/main/CurrencyPowerBalanceWidget/ChartWithData.js +9 -10
- package/dist/main/CurrencyPowerBalanceWidget/ChartWithData.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js +14 -19
- package/dist/main/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/Main.js +11 -11
- package/dist/main/CurrencyPowerBalanceWidget/Main.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/Chart.js +12 -12
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/Chart.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/constants.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/types.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/utils.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/types.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js +4 -4
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js +11 -12
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/config.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/constants.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/render.js +8 -8
- package/dist/main/CurrencyPowerBalanceWidget/render.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/types.js.map +1 -1
- package/dist/main/gql/types/fragment-masking.js.map +1 -1
- package/dist/main/gql/types/gql.js +1 -1
- package/dist/main/gql/types/gql.js.map +1 -1
- package/dist/main/gql/types/graphql.js +64 -64
- package/dist/main/gql/types/graphql.js.map +1 -1
- package/dist/main/gql/types/index.js.map +1 -1
- package/dist/main/translations/index.js +1 -1
- package/dist/main/translations/index.js.map +1 -1
- package/dist/main/translations/translations.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/ChartWithData.js +8 -8
- package/dist/module/CurrencyPowerBalanceWidget/ChartWithData.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js +15 -20
- package/dist/module/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/Main.js +12 -12
- package/dist/module/CurrencyPowerBalanceWidget/Main.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/Chart.js +11 -11
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/Chart.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/constants.js +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/constants.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js +2 -2
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js +2 -2
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/types.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/utils.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/types.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js +4 -4
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js +11 -11
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/config.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/constants.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/render.js +8 -8
- package/dist/module/CurrencyPowerBalanceWidget/render.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/types.js.map +1 -1
- package/dist/module/gql/types/fragment-masking.js.map +1 -1
- package/dist/module/gql/types/gql.js +1 -1
- package/dist/module/gql/types/gql.js.map +1 -1
- package/dist/module/gql/types/graphql.js +64 -64
- package/dist/module/gql/types/graphql.js.map +1 -1
- package/dist/module/gql/types/index.js +2 -2
- package/dist/module/gql/types/index.js.map +1 -1
- package/dist/module/translations/index.js +1 -1
- package/dist/module/translations/index.js.map +1 -1
- package/dist/module/translations/translations.js.map +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/ChartWithData.d.ts +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/CurrencyPowerBalance.d.ts +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/Main.d.ts +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/Chart.d.ts +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/constants.d.ts +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/formatters.d.ts +4 -3
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/getOption.d.ts +2 -1
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/utils.d.ts +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/types.d.ts +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.d.ts +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.d.ts +1 -1
- package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.d.ts +3 -3
- package/dist/types/CurrencyPowerBalanceWidget/types.d.ts +2 -2
- package/dist/types/gql/types/gql.d.ts +2 -2
- package/dist/types/gql/types/index.d.ts +2 -2
- package/dist/types/translations/index.d.ts +2 -2
- package/package.json +3 -3
- package/src/CurrencyPowerBalanceWidget/ChartWithData.tsx +32 -18
- package/src/CurrencyPowerBalanceWidget/CurrencyPowerBalance.tsx +26 -23
- package/src/CurrencyPowerBalanceWidget/Main.tsx +20 -11
- package/src/CurrencyPowerBalanceWidget/components/Chart/Chart.tsx +26 -21
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/constants.ts +11 -10
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/formatters.ts +42 -22
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/getOption.ts +59 -44
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.ts +7 -4
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/types.ts +1 -1
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/utils.ts +10 -9
- package/src/CurrencyPowerBalanceWidget/components/Chart/types.ts +4 -1
- package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.tsx +21 -15
- package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.tsx +48 -38
- package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.ts +3 -3
- package/src/CurrencyPowerBalanceWidget/config.ts +8 -2
- package/src/CurrencyPowerBalanceWidget/constants.ts +2 -1
- package/src/CurrencyPowerBalanceWidget/render.tsx +24 -20
- package/src/CurrencyPowerBalanceWidget/types.ts +5 -3
- package/src/gql/types/fragment-masking.ts +41 -21
- package/src/gql/types/gql.ts +7 -3
- package/src/gql/types/graphql.ts +117 -44
- package/src/gql/types/index.ts +2 -2
- package/src/translations/index.ts +4 -4
- package/src/translations/translations.ts +2 -1
- package/test/Main.test.tsx +39 -25
- package/test/chartFormatters.test.ts +84 -24
- package/test/responsesMocks.ts +254 -255
- package/test/utils.test.ts +0 -1
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
import { darkTheme, lightTheme } from '@oanda/labs-widget-common';
|
|
2
|
+
|
|
3
|
+
import type { CurrencyPowerBalance } from '../../../../gql/types/graphql';
|
|
4
|
+
import { CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
|
|
2
5
|
import { COLOR_CONFIG, TOOLTIP_LINE_COLOR_CONFIG } from './constants';
|
|
3
6
|
import {
|
|
4
|
-
|
|
7
|
+
formatLegendData,
|
|
8
|
+
intervalFormatter,
|
|
9
|
+
tooltipFormatter,
|
|
10
|
+
xAxisLabelFormatter,
|
|
5
11
|
} from './formatters';
|
|
6
|
-
import { CurrencyPowerBalance, CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
|
|
7
12
|
import { findLastIndexesBeforeWeekend } from './utils';
|
|
8
13
|
|
|
9
14
|
const getOption = (
|
|
10
15
|
chartData: CurrencyPowerBalance[],
|
|
11
16
|
timeUnit: CurrencyPowerBalanceTimeUnit,
|
|
12
17
|
isDark: boolean,
|
|
13
|
-
lang: (key: string) => string
|
|
18
|
+
lang: (key: string) => string
|
|
14
19
|
) => {
|
|
15
20
|
const currentTheme = isDark ? darkTheme : lightTheme;
|
|
16
|
-
const dataTimestamps = chartData[0].power.map((x) =>
|
|
21
|
+
const dataTimestamps = chartData[0].power.map((x) =>
|
|
22
|
+
new Date(x.point).getTime()
|
|
23
|
+
);
|
|
17
24
|
const weekendsIndexes = findLastIndexesBeforeWeekend(dataTimestamps);
|
|
18
|
-
const disableWeekendsIndicator =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
const disableWeekendsIndicator =
|
|
26
|
+
[
|
|
27
|
+
CurrencyPowerBalanceTimeUnit.CurrentDay,
|
|
28
|
+
CurrencyPowerBalanceTimeUnit.PreviousDay,
|
|
29
|
+
CurrencyPowerBalanceTimeUnit.M3,
|
|
30
|
+
].includes(timeUnit) || weekendsIndexes.length === 0;
|
|
23
31
|
|
|
24
32
|
const weekendsMarks = weekendsIndexes.map((item) => ({
|
|
25
33
|
xAxis: item,
|
|
@@ -37,40 +45,45 @@ const getOption = (
|
|
|
37
45
|
color: COLOR_CONFIG[currency],
|
|
38
46
|
},
|
|
39
47
|
data: power.map(({ point, price }) => [point, price]),
|
|
40
|
-
markLine:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
markLine:
|
|
49
|
+
index === chartData.length - 1 && !disableWeekendsIndicator
|
|
50
|
+
? {
|
|
51
|
+
label: {
|
|
52
|
+
show: false,
|
|
53
|
+
position: 'end',
|
|
54
|
+
align: 'center',
|
|
55
|
+
distance: -32,
|
|
56
|
+
padding: [8, 8],
|
|
57
|
+
fontSize: 12,
|
|
58
|
+
shadowBlur: 24,
|
|
59
|
+
shadowOffsetX: 0,
|
|
60
|
+
shadowOffsetY: 6,
|
|
61
|
+
borderWidth: 0,
|
|
62
|
+
color: currentTheme.textPrimary,
|
|
63
|
+
shadowColor: 'rgba(0,0,0,0.1)',
|
|
64
|
+
borderRadius: 4,
|
|
65
|
+
backgroundColor: isDark
|
|
66
|
+
? currentTheme.borderPrimary
|
|
67
|
+
: currentTheme.backgroundSecondary,
|
|
68
|
+
},
|
|
69
|
+
show: false,
|
|
70
|
+
emphasis: {
|
|
71
|
+
label: {
|
|
72
|
+
show: true,
|
|
73
|
+
},
|
|
74
|
+
lineStyle: {
|
|
75
|
+
width: 1,
|
|
76
|
+
opacity: 0,
|
|
77
|
+
color: currentTheme.borderPrimary,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
symbol: ['none', 'none'],
|
|
81
|
+
itemStyle: {
|
|
82
|
+
color: currentTheme.borderPrimary,
|
|
83
|
+
},
|
|
84
|
+
data: weekendsMarks,
|
|
85
|
+
}
|
|
86
|
+
: undefined,
|
|
74
87
|
}));
|
|
75
88
|
|
|
76
89
|
const legendData = formatLegendData(chartData);
|
|
@@ -88,7 +101,9 @@ const getOption = (
|
|
|
88
101
|
axis: 'x',
|
|
89
102
|
z: 0,
|
|
90
103
|
lineStyle: {
|
|
91
|
-
color: isDark
|
|
104
|
+
color: isDark
|
|
105
|
+
? TOOLTIP_LINE_COLOR_CONFIG.DARK
|
|
106
|
+
: TOOLTIP_LINE_COLOR_CONFIG.LIGHT,
|
|
92
107
|
},
|
|
93
108
|
},
|
|
94
109
|
formatter: tooltipFormatter,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getGridLines } from '@oanda/labs-widget-common';
|
|
2
|
+
|
|
2
3
|
import {
|
|
3
4
|
CHART_HEIGHT,
|
|
4
5
|
CHART_WIDTH,
|
|
@@ -10,7 +11,11 @@ import {
|
|
|
10
11
|
Y_LABEL_SIZE_MOBILE,
|
|
11
12
|
} from './constants';
|
|
12
13
|
|
|
13
|
-
const getResponsiveOption = (
|
|
14
|
+
const getResponsiveOption = (
|
|
15
|
+
isDesktop: boolean,
|
|
16
|
+
isMobile: boolean,
|
|
17
|
+
isDark: boolean
|
|
18
|
+
) => {
|
|
14
19
|
const baseGridLines = getGridLines({
|
|
15
20
|
isDark,
|
|
16
21
|
chartWidth: CHART_WIDTH,
|
|
@@ -36,9 +41,7 @@ const getResponsiveOption = (isDesktop: boolean, isMobile: boolean, isDark: bool
|
|
|
36
41
|
bottom: `${isMobile ? X_LABEL_SIZE_MOBILE : X_LABEL_SIZE}px`,
|
|
37
42
|
},
|
|
38
43
|
],
|
|
39
|
-
graphic: [
|
|
40
|
-
...baseGridLines,
|
|
41
|
-
],
|
|
44
|
+
graphic: [...baseGridLines],
|
|
42
45
|
};
|
|
43
46
|
};
|
|
44
47
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { WEEKEND_DURATION } from './constants';
|
|
2
2
|
|
|
3
|
-
const findLastIndexesBeforeWeekend = (timestamps: number[]) =>
|
|
4
|
-
.reduce(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const findLastIndexesBeforeWeekend = (timestamps: number[]) =>
|
|
4
|
+
timestamps.reduce(
|
|
5
|
+
(acc, timestamp, index) =>
|
|
6
|
+
timestamps.length - 1 !== index &&
|
|
7
|
+
timestamps[index + 1] - timestamp >= WEEKEND_DURATION
|
|
8
|
+
? [...acc, index]
|
|
9
|
+
: acc,
|
|
10
|
+
[] as number[]
|
|
11
|
+
);
|
|
9
12
|
|
|
10
|
-
export {
|
|
11
|
-
findLastIndexesBeforeWeekend,
|
|
12
|
-
};
|
|
13
|
+
export { findLastIndexesBeforeWeekend };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
CurrencyPowerBalance,
|
|
3
|
+
CurrencyPowerBalanceTimeUnit,
|
|
4
|
+
} from '../../../gql/types/graphql';
|
|
2
5
|
|
|
3
6
|
export interface ChartProps {
|
|
4
7
|
values: CurrencyPowerBalance[];
|
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { Select } from '@oanda/labs-widget-common';
|
|
3
2
|
import { useLocale } from '@oanda/mono-i18n';
|
|
4
|
-
import
|
|
5
|
-
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
import type { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
|
|
6
|
+
import type { TimeUnitSwitchProps } from './types';
|
|
6
7
|
|
|
7
8
|
const TimeUnitSelect = ({
|
|
8
|
-
selected,
|
|
9
|
+
selected,
|
|
10
|
+
options,
|
|
11
|
+
callback,
|
|
9
12
|
}: TimeUnitSwitchProps) => {
|
|
10
13
|
const { lang } = useLocale();
|
|
11
|
-
const selectOptions = options
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const selectOptions = options.map(({ value: id, label, tooltipLabel }) => ({
|
|
15
|
+
id,
|
|
16
|
+
label: tooltipLabel
|
|
17
|
+
? lang(tooltipLabel.translationKey, { count: tooltipLabel.count })
|
|
18
|
+
: lang(label),
|
|
19
|
+
}));
|
|
20
|
+
const [{ label: selectedLabel }] = selectOptions.filter(
|
|
21
|
+
({ id }) => id === selected
|
|
22
|
+
);
|
|
19
23
|
|
|
20
24
|
return (
|
|
21
|
-
<div
|
|
25
|
+
<div className="lw-mb-6 lw-w-full" data-testid="time-unit-select">
|
|
22
26
|
<Select
|
|
23
|
-
searchPlaceholder={lang('search')}
|
|
24
27
|
options={selectOptions}
|
|
28
|
+
searchPlaceholder={lang('search')}
|
|
25
29
|
selectedOption={{ id: selected, label: selectedLabel }}
|
|
26
|
-
setSelectedOption={({ id }) =>
|
|
30
|
+
setSelectedOption={({ id }) =>
|
|
31
|
+
callback(id as CurrencyPowerBalanceTimeUnit)
|
|
32
|
+
}
|
|
27
33
|
/>
|
|
28
34
|
</div>
|
|
29
35
|
);
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
1
|
import {
|
|
3
|
-
Button,
|
|
2
|
+
Button,
|
|
3
|
+
ButtonSize,
|
|
4
|
+
ButtonVariant,
|
|
5
|
+
Size,
|
|
6
|
+
useLayoutProvider,
|
|
4
7
|
} from '@oanda/labs-widget-common';
|
|
5
8
|
import { useLocale } from '@oanda/mono-i18n';
|
|
6
|
-
import
|
|
7
|
-
|
|
9
|
+
import React from 'react';
|
|
10
|
+
|
|
11
|
+
import type { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
|
|
8
12
|
import { CURRENCY_POWER_BALANCE_TOOLTIP_ID } from '../../constants';
|
|
9
13
|
import { TimeUnitSelect } from './TimeUnitSelect';
|
|
14
|
+
import type { TimeUnitSwitchProps } from './types';
|
|
10
15
|
|
|
11
16
|
const TimeUnitSwitch = ({
|
|
12
|
-
selected,
|
|
17
|
+
selected,
|
|
18
|
+
options,
|
|
19
|
+
callback,
|
|
13
20
|
}: TimeUnitSwitchProps) => {
|
|
14
21
|
const { lang } = useLocale();
|
|
15
|
-
const { size } =
|
|
22
|
+
const { size } = useLayoutProvider();
|
|
16
23
|
const isDesktop = size === Size.DESKTOP;
|
|
17
24
|
|
|
18
25
|
const handleButtonClick = (e: React.SyntheticEvent<HTMLButtonElement>) => {
|
|
@@ -21,40 +28,43 @@ const TimeUnitSwitch = ({
|
|
|
21
28
|
|
|
22
29
|
return (
|
|
23
30
|
<>
|
|
24
|
-
{isDesktop
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
{isDesktop ? (
|
|
32
|
+
<div
|
|
33
|
+
className="lw-mb-6 lw-flex lw-gap-1 lw-self-end"
|
|
34
|
+
data-testid="time-unit-switch"
|
|
35
|
+
>
|
|
36
|
+
{options.map(({ value, label, tooltipLabel }) => {
|
|
37
|
+
const tooltip = tooltipLabel
|
|
38
|
+
? lang(tooltipLabel.translationKey, { count: tooltipLabel.count })
|
|
39
|
+
: tooltipLabel;
|
|
40
|
+
const buttonLabel = lang(label);
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
return (
|
|
43
|
+
<Button
|
|
44
|
+
key={value}
|
|
45
|
+
data-tooltip-content={tooltip}
|
|
46
|
+
data-tooltip-id={CURRENCY_POWER_BALANCE_TOOLTIP_ID}
|
|
47
|
+
size={ButtonSize.full}
|
|
48
|
+
value={value}
|
|
49
|
+
variant={
|
|
50
|
+
selected === value
|
|
38
51
|
? ButtonVariant.primary
|
|
39
|
-
: ButtonVariant.secondary
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
options={options}
|
|
56
|
-
/>
|
|
57
|
-
)}
|
|
52
|
+
: ButtonVariant.secondary
|
|
53
|
+
}
|
|
54
|
+
onClick={handleButtonClick}
|
|
55
|
+
>
|
|
56
|
+
{buttonLabel}
|
|
57
|
+
</Button>
|
|
58
|
+
);
|
|
59
|
+
})}
|
|
60
|
+
</div>
|
|
61
|
+
) : (
|
|
62
|
+
<TimeUnitSelect
|
|
63
|
+
callback={callback}
|
|
64
|
+
options={options}
|
|
65
|
+
selected={selected}
|
|
66
|
+
/>
|
|
67
|
+
)}
|
|
58
68
|
</>
|
|
59
69
|
);
|
|
60
70
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
|
|
1
|
+
import type { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
|
|
2
2
|
|
|
3
3
|
export interface TimeUnitOption {
|
|
4
4
|
value: CurrencyPowerBalanceTimeUnit;
|
|
@@ -12,7 +12,7 @@ export interface TimeUnitSwitchProps {
|
|
|
12
12
|
callback: (value: CurrencyPowerBalanceTimeUnit) => void;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
interface TooltipLabel {
|
|
16
16
|
translationKey: string;
|
|
17
17
|
count: number;
|
|
18
|
-
}
|
|
18
|
+
}
|
|
@@ -49,8 +49,14 @@ const timeUnitConfig = [
|
|
|
49
49
|
count: 4,
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
|
-
{
|
|
53
|
-
|
|
52
|
+
{
|
|
53
|
+
value: CurrencyPowerBalanceTimeUnit.PreviousDay,
|
|
54
|
+
label: 'previous_business_day',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
value: CurrencyPowerBalanceTimeUnit.CurrentDay,
|
|
58
|
+
label: 'current_business_day',
|
|
59
|
+
},
|
|
54
60
|
];
|
|
55
61
|
|
|
56
62
|
export { timeUnitConfig };
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export const CURRENCY_POWER_BALANCE_TOOLTIP_ID =
|
|
1
|
+
export const CURRENCY_POWER_BALANCE_TOOLTIP_ID =
|
|
2
|
+
'currency-power-balance-widget-tooltip';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { Theme } from '@oanda/labs-widget-common';
|
|
2
|
+
import { validateLocale, validateToolParams } from '@oanda/labs-widget-common';
|
|
1
3
|
import React from 'react';
|
|
2
4
|
import { createRoot } from 'react-dom/client';
|
|
3
|
-
|
|
5
|
+
|
|
4
6
|
import { CurrencyPowerBalance } from './CurrencyPowerBalance';
|
|
5
7
|
|
|
6
8
|
const {
|
|
@@ -9,48 +11,50 @@ const {
|
|
|
9
11
|
locale: configLocale,
|
|
10
12
|
} = window.currencyPowerBalanceWidgetConfig || {};
|
|
11
13
|
|
|
12
|
-
const {
|
|
13
|
-
graphqlUrl,
|
|
14
|
-
} = window.widgetsConfig || {};
|
|
14
|
+
const { graphqlUrl } = window.widgetsConfig || {};
|
|
15
15
|
|
|
16
|
-
const currencyPowerBalanceParamsElements = document.querySelectorAll(
|
|
16
|
+
const currencyPowerBalanceParamsElements = document.querySelectorAll(
|
|
17
|
+
'div[data-currency-power-balance-params]'
|
|
18
|
+
);
|
|
17
19
|
|
|
18
20
|
if (currencyPowerBalanceParamsElements.length > 0) {
|
|
19
21
|
currencyPowerBalanceParamsElements.forEach((element) => {
|
|
20
22
|
const root = createRoot(element);
|
|
21
23
|
const params = element.getAttribute('data-currency-power-balance-params');
|
|
22
24
|
const mode = element.getAttribute('data-mode');
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
const { timeUnit, currencies, locale, logoLink } = JSON.parse(
|
|
26
|
+
params as string
|
|
27
|
+
);
|
|
26
28
|
|
|
27
29
|
const isParamError = validateToolParams({ locale, graphqlUrl }, [
|
|
28
30
|
{
|
|
29
31
|
name: 'locale',
|
|
30
|
-
valueCheck: (value) => validateLocale(value),
|
|
31
|
-
},
|
|
32
|
+
valueCheck: (value: string | undefined) => validateLocale(value),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
32
35
|
name: 'graphqlUrl',
|
|
33
|
-
}
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
34
38
|
root.render(
|
|
35
39
|
<CurrencyPowerBalance
|
|
40
|
+
currencies={currencies}
|
|
36
41
|
graphqlUrl={graphqlUrl}
|
|
42
|
+
isParamError={isParamError}
|
|
37
43
|
locale={locale}
|
|
44
|
+
logoLink={logoLink}
|
|
38
45
|
theme={mode as Theme}
|
|
39
|
-
isParamError={isParamError}
|
|
40
46
|
timeUnit={timeUnit}
|
|
41
|
-
|
|
42
|
-
logoLink={logoLink}
|
|
43
|
-
/>,
|
|
47
|
+
/>
|
|
44
48
|
);
|
|
45
49
|
});
|
|
46
50
|
} else {
|
|
47
|
-
const container = document.
|
|
51
|
+
const container: HTMLElement | null = document.querySelector(
|
|
52
|
+
configRenderElementId
|
|
53
|
+
);
|
|
54
|
+
|
|
48
55
|
const root = createRoot(container!);
|
|
49
56
|
|
|
50
57
|
root.render(
|
|
51
|
-
<CurrencyPowerBalance
|
|
52
|
-
locale={configLocale}
|
|
53
|
-
graphqlUrl={configGraphQl}
|
|
54
|
-
/>,
|
|
58
|
+
<CurrencyPowerBalance graphqlUrl={configGraphQl} locale={configLocale} />
|
|
55
59
|
);
|
|
56
60
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { WidgetConfig } from '@oanda/labs-widget-common';
|
|
2
|
-
|
|
1
|
+
import type { WidgetConfig } from '@oanda/labs-widget-common';
|
|
2
|
+
|
|
3
|
+
import type { CurrencyPowerBalanceTimeUnit } from '../gql/types/graphql';
|
|
3
4
|
|
|
4
5
|
export interface CurrencyPowerBalanceConfig extends WidgetConfig {
|
|
5
6
|
timeUnit?: CurrencyPowerBalanceTimeUnit;
|
|
6
7
|
currencies?: string[];
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export interface CurrencyPowerBalanceWrapperConfig
|
|
10
|
+
export interface CurrencyPowerBalanceWrapperConfig
|
|
11
|
+
extends CurrencyPowerBalanceConfig {
|
|
10
12
|
renderElementId: string;
|
|
11
13
|
}
|
|
12
14
|
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ResultOf,
|
|
3
|
+
DocumentTypeDecoration,
|
|
4
|
+
TypedDocumentNode,
|
|
5
|
+
} from '@graphql-typed-document-node/core';
|
|
2
6
|
import { FragmentDefinitionNode } from 'graphql';
|
|
3
7
|
import { Incremental } from './graphql';
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
any
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export type FragmentType<
|
|
10
|
+
TDocumentType extends DocumentTypeDecoration<any, any>,
|
|
11
|
+
> =
|
|
12
|
+
TDocumentType extends DocumentTypeDecoration<infer TType, any>
|
|
13
|
+
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
|
|
14
|
+
? TKey extends string
|
|
15
|
+
? { ' $fragmentRefs'?: { [key in TKey]: TType } }
|
|
16
|
+
: never
|
|
13
17
|
: never
|
|
14
|
-
: never
|
|
15
|
-
: never;
|
|
18
|
+
: never;
|
|
16
19
|
|
|
17
20
|
// return non-nullable if `fragmentType` is non-nullable
|
|
18
21
|
export function useFragment<TType>(
|
|
@@ -22,7 +25,10 @@ export function useFragment<TType>(
|
|
|
22
25
|
// return nullable if `fragmentType` is nullable
|
|
23
26
|
export function useFragment<TType>(
|
|
24
27
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
25
|
-
fragmentType:
|
|
28
|
+
fragmentType:
|
|
29
|
+
| FragmentType<DocumentTypeDecoration<TType, any>>
|
|
30
|
+
| null
|
|
31
|
+
| undefined
|
|
26
32
|
): TType | null | undefined;
|
|
27
33
|
// return array of non-nullable if `fragmentType` is array of non-nullable
|
|
28
34
|
export function useFragment<TType>(
|
|
@@ -32,35 +38,49 @@ export function useFragment<TType>(
|
|
|
32
38
|
// return array of nullable if `fragmentType` is array of nullable
|
|
33
39
|
export function useFragment<TType>(
|
|
34
40
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
35
|
-
fragmentType:
|
|
41
|
+
fragmentType:
|
|
42
|
+
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
43
|
+
| null
|
|
44
|
+
| undefined
|
|
36
45
|
): ReadonlyArray<TType> | null | undefined;
|
|
37
46
|
export function useFragment<TType>(
|
|
38
47
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
39
|
-
fragmentType:
|
|
48
|
+
fragmentType:
|
|
49
|
+
| FragmentType<DocumentTypeDecoration<TType, any>>
|
|
50
|
+
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
51
|
+
| null
|
|
52
|
+
| undefined
|
|
40
53
|
): TType | ReadonlyArray<TType> | null | undefined {
|
|
41
54
|
return fragmentType as any;
|
|
42
55
|
}
|
|
43
56
|
|
|
44
|
-
|
|
45
57
|
export function makeFragmentData<
|
|
46
58
|
F extends DocumentTypeDecoration<any, any>,
|
|
47
|
-
FT extends ResultOf<F
|
|
59
|
+
FT extends ResultOf<F>,
|
|
48
60
|
>(data: FT, _fragment: F): FragmentType<F> {
|
|
49
61
|
return data as FragmentType<F>;
|
|
50
62
|
}
|
|
51
63
|
export function isFragmentReady<TQuery, TFrag>(
|
|
52
64
|
queryNode: DocumentTypeDecoration<TQuery, any>,
|
|
53
65
|
fragmentNode: TypedDocumentNode<TFrag>,
|
|
54
|
-
data:
|
|
66
|
+
data:
|
|
67
|
+
| FragmentType<TypedDocumentNode<Incremental<TFrag>, any>>
|
|
68
|
+
| null
|
|
69
|
+
| undefined
|
|
55
70
|
): data is FragmentType<typeof fragmentNode> {
|
|
56
|
-
const deferredFields = (
|
|
57
|
-
|
|
71
|
+
const deferredFields = (
|
|
72
|
+
queryNode as {
|
|
73
|
+
__meta__?: { deferredFields: Record<string, (keyof TFrag)[]> };
|
|
74
|
+
}
|
|
75
|
+
).__meta__?.deferredFields;
|
|
58
76
|
|
|
59
77
|
if (!deferredFields) return true;
|
|
60
78
|
|
|
61
|
-
const fragDef = fragmentNode.definitions[0] as
|
|
79
|
+
const fragDef = fragmentNode.definitions[0] as
|
|
80
|
+
| FragmentDefinitionNode
|
|
81
|
+
| undefined;
|
|
62
82
|
const fragName = fragDef?.name?.value;
|
|
63
83
|
|
|
64
84
|
const fields = (fragName && deferredFields[fragName]) || [];
|
|
65
|
-
return fields.length > 0 && fields.every(field => data && field in data);
|
|
85
|
+
return fields.length > 0 && fields.every((field) => data && field in data);
|
|
66
86
|
}
|
package/src/gql/types/gql.ts
CHANGED
|
@@ -13,7 +13,8 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
|
|
|
13
13
|
* Therefore it is highly recommended to use the babel or swc plugin for production.
|
|
14
14
|
*/
|
|
15
15
|
const documents = {
|
|
16
|
-
|
|
16
|
+
'\n query GetCurrencyPowerBalance($timeUnit: CurrencyPowerBalanceTimeUnit!) {\n currencyPowerBalance(timeUnit: $timeUnit) {\n currency\n power {\n point\n price\n }\n updatedAt\n }\n }\n':
|
|
17
|
+
types.GetCurrencyPowerBalanceDocument,
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -33,10 +34,13 @@ export function graphql(source: string): unknown;
|
|
|
33
34
|
/**
|
|
34
35
|
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
35
36
|
*/
|
|
36
|
-
export function graphql(
|
|
37
|
+
export function graphql(
|
|
38
|
+
source: '\n query GetCurrencyPowerBalance($timeUnit: CurrencyPowerBalanceTimeUnit!) {\n currencyPowerBalance(timeUnit: $timeUnit) {\n currency\n power {\n point\n price\n }\n updatedAt\n }\n }\n'
|
|
39
|
+
): (typeof documents)['\n query GetCurrencyPowerBalance($timeUnit: CurrencyPowerBalanceTimeUnit!) {\n currencyPowerBalance(timeUnit: $timeUnit) {\n currency\n power {\n point\n price\n }\n updatedAt\n }\n }\n'];
|
|
37
40
|
|
|
38
41
|
export function graphql(source: string) {
|
|
39
42
|
return (documents as any)[source] ?? {};
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> =
|
|
45
|
+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> =
|
|
46
|
+
TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;
|