@oanda/labs-instrument-live-rate-widget 1.0.1
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 +8 -0
- package/codegen.ts +15 -0
- package/dist/main/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js +56 -0
- package/dist/main/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/Main.js +77 -0
- package/dist/main/InstrumentLiveRateWidget/Main.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.js +83 -0
- package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.js +28 -0
- package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.js +25 -0
- package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js +44 -0
- package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/index.js +17 -0
- package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/index.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/types.js +6 -0
- package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/types.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/components/index.js +17 -0
- package/dist/main/InstrumentLiveRateWidget/components/index.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/constant.js +8 -0
- package/dist/main/InstrumentLiveRateWidget/constant.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/render.js +51 -0
- package/dist/main/InstrumentLiveRateWidget/render.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/types.js +20 -0
- package/dist/main/InstrumentLiveRateWidget/types.js.map +1 -0
- package/dist/main/InstrumentLiveRateWidget/utils.js +43 -0
- package/dist/main/InstrumentLiveRateWidget/utils.js.map +1 -0
- package/dist/main/gql/getInstrumentsChart.js +16 -0
- package/dist/main/gql/getInstrumentsChart.js.map +1 -0
- package/dist/main/gql/types/fragment-masking.js +23 -0
- package/dist/main/gql/types/fragment-masking.js.map +1 -0
- package/dist/main/gql/types/gql.js +17 -0
- package/dist/main/gql/types/gql.js.map +1 -0
- package/dist/main/gql/types/graphql.js +326 -0
- package/dist/main/gql/types/graphql.js.map +1 -0
- package/dist/main/gql/types/index.js +28 -0
- package/dist/main/gql/types/index.js.map +1 -0
- package/dist/main/gql/validateInstruments.js +16 -0
- package/dist/main/gql/validateInstruments.js.map +1 -0
- package/dist/main/index.js +28 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/translations/index.js +27 -0
- package/dist/main/translations/index.js.map +1 -0
- package/dist/main/translations/sources/en.json +4 -0
- package/dist/main/translations/sources/es.json +4 -0
- package/dist/main/translations/sources/th.json +4 -0
- package/dist/main/translations/sources/zh_TW.json +4 -0
- package/dist/main/translations/translations.js +11 -0
- package/dist/main/translations/translations.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js +49 -0
- package/dist/module/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/Main.js +69 -0
- package/dist/module/InstrumentLiveRateWidget/Main.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.js +74 -0
- package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.js +3 -0
- package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.js +18 -0
- package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js +37 -0
- package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/index.js +2 -0
- package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/index.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/types.js +2 -0
- package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/types.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/components/index.js +2 -0
- package/dist/module/InstrumentLiveRateWidget/components/index.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/constant.js +3 -0
- package/dist/module/InstrumentLiveRateWidget/constant.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/render.js +48 -0
- package/dist/module/InstrumentLiveRateWidget/render.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/types.js +3 -0
- package/dist/module/InstrumentLiveRateWidget/types.js.map +1 -0
- package/dist/module/InstrumentLiveRateWidget/utils.js +36 -0
- package/dist/module/InstrumentLiveRateWidget/utils.js.map +1 -0
- package/dist/module/gql/getInstrumentsChart.js +10 -0
- package/dist/module/gql/getInstrumentsChart.js.map +1 -0
- package/dist/module/gql/types/fragment-masking.js +15 -0
- package/dist/module/gql/types/fragment-masking.js.map +1 -0
- package/dist/module/gql/types/gql.js +9 -0
- package/dist/module/gql/types/gql.js.map +1 -0
- package/dist/module/gql/types/graphql.js +320 -0
- package/dist/module/gql/types/graphql.js.map +1 -0
- package/dist/module/gql/types/index.js +3 -0
- package/dist/module/gql/types/index.js.map +1 -0
- package/dist/module/gql/validateInstruments.js +10 -0
- package/dist/module/gql/validateInstruments.js.map +1 -0
- package/dist/module/index.js +3 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/translations/index.js +20 -0
- package/dist/module/translations/index.js.map +1 -0
- package/dist/module/translations/sources/en.json +4 -0
- package/dist/module/translations/sources/es.json +4 -0
- package/dist/module/translations/sources/th.json +4 -0
- package/dist/module/translations/sources/zh_TW.json +4 -0
- package/dist/module/translations/translations.js +5 -0
- package/dist/module/translations/translations.js.map +1 -0
- package/dist/types/InstrumentLiveRateWidget/InstrumentLiveRateWidget.d.ts +4 -0
- package/dist/types/InstrumentLiveRateWidget/Main.d.ts +4 -0
- package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.d.ts +4 -0
- package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.d.ts +2 -0
- package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.d.ts +3 -0
- package/dist/types/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.d.ts +4 -0
- package/dist/types/InstrumentLiveRateWidget/components/LineChartWithData/index.d.ts +1 -0
- package/dist/types/InstrumentLiveRateWidget/components/LineChartWithData/types.d.ts +11 -0
- package/dist/types/InstrumentLiveRateWidget/components/index.d.ts +1 -0
- package/dist/types/InstrumentLiveRateWidget/constant.d.ts +2 -0
- package/dist/types/InstrumentLiveRateWidget/render.d.ts +1 -0
- package/dist/types/InstrumentLiveRateWidget/types.d.ts +43 -0
- package/dist/types/InstrumentLiveRateWidget/utils.d.ts +12 -0
- package/dist/types/gql/getInstrumentsChart.d.ts +1 -0
- package/dist/types/gql/types/fragment-masking.d.ts +15 -0
- package/dist/types/gql/types/gql.d.ts +45 -0
- package/dist/types/gql/types/graphql.d.ts +397 -0
- package/dist/types/gql/types/index.d.ts +2 -0
- package/dist/types/gql/validateInstruments.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/translations/index.d.ts +4 -0
- package/dist/types/translations/translations.d.ts +4 -0
- package/index.ts +1 -0
- package/lokalise.config.json +18 -0
- package/package.json +25 -0
- package/src/InstrumentLiveRateWidget/InstrumentLiveRateWidget.tsx +57 -0
- package/src/InstrumentLiveRateWidget/Main.tsx +82 -0
- package/src/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.tsx +92 -0
- package/src/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.ts +2 -0
- package/src/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.ts +25 -0
- package/src/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.tsx +48 -0
- package/src/InstrumentLiveRateWidget/components/LineChartWithData/index.ts +1 -0
- package/src/InstrumentLiveRateWidget/components/LineChartWithData/types.tsx +12 -0
- package/src/InstrumentLiveRateWidget/components/index.ts +1 -0
- package/src/InstrumentLiveRateWidget/constant.ts +5 -0
- package/src/InstrumentLiveRateWidget/render.tsx +48 -0
- package/src/InstrumentLiveRateWidget/types.tsx +50 -0
- package/src/InstrumentLiveRateWidget/utils.ts +49 -0
- package/src/gql/getInstrumentsChart.ts +10 -0
- package/src/gql/types/fragment-masking.ts +66 -0
- package/src/gql/types/gql.ts +47 -0
- package/src/gql/types/graphql.ts +432 -0
- package/src/gql/types/index.ts +2 -0
- package/src/gql/validateInstruments.ts +10 -0
- package/src/index.ts +2 -0
- package/src/translations/index.ts +17 -0
- package/src/translations/sources/en.json +4 -0
- package/src/translations/sources/es.json +4 -0
- package/src/translations/sources/th.json +4 -0
- package/src/translations/sources/zh_TW.json +4 -0
- package/src/translations/translations.ts +4 -0
- package/test/LineChartWithData.test.tsx +164 -0
- package/test/Main.test.tsx +27 -0
- package/test/components/InstrumentRateWithData.test.tsx +62 -0
- package/test/components/utils.test.ts +13 -0
- package/test/mocks.ts +52 -0
- package/tsconfig.types.json +12 -0
package/src/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.tsx
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
LabelWrapper, Price, ThemeContext, Truncate,
|
|
4
|
+
} from '@oanda/labs-widget-common';
|
|
5
|
+
import classNames from 'classnames';
|
|
6
|
+
import { InstrumentRateWithDataProps } from '../../types';
|
|
7
|
+
import { LineChartWithData } from '../LineChartWithData';
|
|
8
|
+
import { useRecords } from '../../utils';
|
|
9
|
+
import { INSTRUMENT_TOOLTIP_ID } from '../../constant';
|
|
10
|
+
import { getChartColor, getColorIndicator } from './utils';
|
|
11
|
+
|
|
12
|
+
const InstrumentRateWithData = ({
|
|
13
|
+
loading,
|
|
14
|
+
record,
|
|
15
|
+
target,
|
|
16
|
+
division,
|
|
17
|
+
size = 'fullWithChart',
|
|
18
|
+
}: InstrumentRateWithDataProps) => {
|
|
19
|
+
const { isDark } = useContext(ThemeContext);
|
|
20
|
+
const { updatedRecord, error } = useRecords(record, record.instrument ? target : null);
|
|
21
|
+
|
|
22
|
+
const checkLoading = (id: string) => loading || (!error && updatedRecord?.[id] === undefined);
|
|
23
|
+
|
|
24
|
+
const indicator = getColorIndicator(updatedRecord.dailyPercentChange);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className="lw-flex lw-flex-col lw-px-4 lw-pb-1 lw-pt-2">
|
|
28
|
+
<div className="lw-flex lw-items-center lw-gap-x-2">
|
|
29
|
+
<LabelWrapper
|
|
30
|
+
isLoading={checkLoading('instrument')}
|
|
31
|
+
isError={!!error}
|
|
32
|
+
>
|
|
33
|
+
<span className="lw-text-xl lw-font-bold">
|
|
34
|
+
<Truncate maxWidth={130} text={record.displayName} tooltipId={INSTRUMENT_TOOLTIP_ID} />
|
|
35
|
+
</span>
|
|
36
|
+
</LabelWrapper>
|
|
37
|
+
<LabelWrapper
|
|
38
|
+
isLoading={checkLoading('buy')}
|
|
39
|
+
isError={!!error}
|
|
40
|
+
>
|
|
41
|
+
<div className="lw-text-xl lw-font-bold">
|
|
42
|
+
<Price priceMovement={updatedRecord.buyPriceMovement} withoutArrow>
|
|
43
|
+
<span>{updatedRecord.buy?.toFixed(updatedRecord.displayPrecision)}</span>
|
|
44
|
+
</Price>
|
|
45
|
+
</div>
|
|
46
|
+
</LabelWrapper>
|
|
47
|
+
</div>
|
|
48
|
+
{size !== 'compact'
|
|
49
|
+
&& (
|
|
50
|
+
<div className="lw-mt-1 lw-flex lw-items-center lw-gap-x-2">
|
|
51
|
+
<LabelWrapper
|
|
52
|
+
isLoading={checkLoading('dailyPercentChange')}
|
|
53
|
+
isError={!!error}
|
|
54
|
+
>
|
|
55
|
+
<span className={classNames('lw-font-bold', {
|
|
56
|
+
'lw-text-text-ok': indicator > 0,
|
|
57
|
+
'lw-text-text-danger': indicator < 0,
|
|
58
|
+
'lw-text-text-disabled': indicator === 0,
|
|
59
|
+
})}
|
|
60
|
+
>
|
|
61
|
+
{updatedRecord.dailyPercentChange}
|
|
62
|
+
</span>
|
|
63
|
+
|
|
64
|
+
</LabelWrapper>
|
|
65
|
+
<LabelWrapper
|
|
66
|
+
isLoading={checkLoading('dailyPipsChange')}
|
|
67
|
+
isError={!!error}
|
|
68
|
+
>
|
|
69
|
+
<span className={classNames('lw-font-bold', {
|
|
70
|
+
'lw-text-text-ok': indicator > 0,
|
|
71
|
+
'lw-text-text-danger': indicator < 0,
|
|
72
|
+
'lw-text-text-disabled': indicator === 0,
|
|
73
|
+
})}
|
|
74
|
+
>
|
|
75
|
+
{`(${updatedRecord.dailyPipsChange})`}
|
|
76
|
+
</span>
|
|
77
|
+
</LabelWrapper>
|
|
78
|
+
{size === 'fullWithChart' && (
|
|
79
|
+
<LineChartWithData
|
|
80
|
+
record={updatedRecord}
|
|
81
|
+
isLoading={checkLoading('instrument')}
|
|
82
|
+
division={division}
|
|
83
|
+
color={getChartColor(indicator, isDark)}
|
|
84
|
+
/>
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
87
|
+
)}
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export { InstrumentRateWithData };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { lightTheme, darkTheme } from '@oanda/labs-widget-common';
|
|
2
|
+
|
|
3
|
+
const getColorIndicator = (dailyChange?: string) => {
|
|
4
|
+
const numberValue = Number(dailyChange?.substring(0, dailyChange.length - 1));
|
|
5
|
+
|
|
6
|
+
return Math.sign(numberValue);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const getChartColor = (indicator?: number, isDarkMode?: boolean) => {
|
|
10
|
+
const theme = isDarkMode ? darkTheme : lightTheme;
|
|
11
|
+
|
|
12
|
+
switch (indicator) {
|
|
13
|
+
case 1:
|
|
14
|
+
return theme.textOk;
|
|
15
|
+
case -1:
|
|
16
|
+
return theme.textDanger;
|
|
17
|
+
default:
|
|
18
|
+
return theme.textDisabled;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
getColorIndicator,
|
|
24
|
+
getChartColor,
|
|
25
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useQuery } from '@apollo/client';
|
|
3
|
+
import {
|
|
4
|
+
LineChart, Loader, LoaderSize,
|
|
5
|
+
} from '@oanda/labs-widget-common';
|
|
6
|
+
import { LineChartWithDataProps } from './types';
|
|
7
|
+
import { getInstrumentsChart } from '../../../gql/getInstrumentsChart';
|
|
8
|
+
import { GetInstrumentsChartQuery, GetInstrumentsChartQueryVariables } from '../../../gql/types/graphql';
|
|
9
|
+
|
|
10
|
+
const LineChartWithData = ({
|
|
11
|
+
padding,
|
|
12
|
+
record,
|
|
13
|
+
size,
|
|
14
|
+
isLoading,
|
|
15
|
+
division,
|
|
16
|
+
color,
|
|
17
|
+
}: LineChartWithDataProps) => {
|
|
18
|
+
const { loading, data } = useQuery<
|
|
19
|
+
GetInstrumentsChartQuery,
|
|
20
|
+
GetInstrumentsChartQueryVariables
|
|
21
|
+
>(getInstrumentsChart, {
|
|
22
|
+
variables: {
|
|
23
|
+
instruments: [record.instrument],
|
|
24
|
+
division,
|
|
25
|
+
},
|
|
26
|
+
fetchPolicy: 'network-only',
|
|
27
|
+
skip: !record.instrument,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const showLoader = isLoading || loading;
|
|
31
|
+
const chart = data?.topicalInstrumentsCharts?.[0].chart || [];
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<>
|
|
35
|
+
{showLoader && <Loader size={LoaderSize.md} />}
|
|
36
|
+
{!showLoader && (
|
|
37
|
+
<LineChart
|
|
38
|
+
padding={padding}
|
|
39
|
+
size={size}
|
|
40
|
+
color={color}
|
|
41
|
+
data={chart}
|
|
42
|
+
/>
|
|
43
|
+
)}
|
|
44
|
+
</>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { LineChartWithData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './LineChartWithData';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LineChartSize } from '@oanda/labs-widget-common';
|
|
2
|
+
import { DataRecord } from '../../types';
|
|
3
|
+
import { Division } from '../../../gql/types/graphql';
|
|
4
|
+
|
|
5
|
+
export interface LineChartWithDataProps {
|
|
6
|
+
padding?: number;
|
|
7
|
+
record: DataRecord;
|
|
8
|
+
size?: LineChartSize;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
division: Division;
|
|
11
|
+
color: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './LineChartWithData';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
import { Theme, validateLocale, validateToolParams } from '@oanda/labs-widget-common';
|
|
4
|
+
import { InstrumentLiveRateWidget } from './InstrumentLiveRateWidget';
|
|
5
|
+
import { Division } from '../gql/types/graphql';
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
graphqlUrl,
|
|
9
|
+
liveRatesUrl,
|
|
10
|
+
} = window.widgetsConfig || {};
|
|
11
|
+
|
|
12
|
+
const instrumentLiveRateElements = document.querySelectorAll('div[data-instrument-live-rate-params]');
|
|
13
|
+
|
|
14
|
+
instrumentLiveRateElements.forEach((element) => {
|
|
15
|
+
const root = createRoot(element);
|
|
16
|
+
const params = element.getAttribute('data-instrument-live-rate-params');
|
|
17
|
+
const mode = element.getAttribute('data-mode');
|
|
18
|
+
const {
|
|
19
|
+
instrument, division, locale, size,
|
|
20
|
+
} = JSON.parse(params as string);
|
|
21
|
+
|
|
22
|
+
const isParamError = validateToolParams({
|
|
23
|
+
division, locale, graphqlUrl, liveRatesUrl,
|
|
24
|
+
}, [{
|
|
25
|
+
name: 'locale',
|
|
26
|
+
valueCheck: (value) => validateLocale(value),
|
|
27
|
+
}, {
|
|
28
|
+
name: 'division',
|
|
29
|
+
valueCheck: (value) => Object.values(Division).includes(value),
|
|
30
|
+
}, {
|
|
31
|
+
name: 'graphqlUrl',
|
|
32
|
+
}, {
|
|
33
|
+
name: 'liveRatesUrl',
|
|
34
|
+
}]);
|
|
35
|
+
|
|
36
|
+
root.render(
|
|
37
|
+
<InstrumentLiveRateWidget
|
|
38
|
+
graphqlUrl={graphqlUrl}
|
|
39
|
+
liveRatesUrl={liveRatesUrl}
|
|
40
|
+
division={division}
|
|
41
|
+
instrument={instrument}
|
|
42
|
+
locale={locale}
|
|
43
|
+
theme={mode as Theme}
|
|
44
|
+
isParamError={isParamError}
|
|
45
|
+
size={size}
|
|
46
|
+
/>,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Locale } from '@oanda/mono-i18n';
|
|
2
|
+
import { Theme } from '@oanda/labs-widget-common';
|
|
3
|
+
import { Division } from '../gql/types/graphql';
|
|
4
|
+
|
|
5
|
+
export { Locale } from '@oanda/mono-i18n';
|
|
6
|
+
export { Division } from '../gql/types/graphql';
|
|
7
|
+
|
|
8
|
+
export interface InstrumentLiveRateConfig {
|
|
9
|
+
graphqlUrl: string;
|
|
10
|
+
division: Division;
|
|
11
|
+
liveRatesUrl: string;
|
|
12
|
+
instrument: string;
|
|
13
|
+
locale: Locale;
|
|
14
|
+
theme?: Theme;
|
|
15
|
+
isParamError?: boolean;
|
|
16
|
+
removePadding?: boolean;
|
|
17
|
+
size?: 'compact' | 'full' | 'fullWithChart';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MainProps {
|
|
21
|
+
instrument: string;
|
|
22
|
+
division: Division;
|
|
23
|
+
size?: 'compact' | 'full' | 'fullWithChart'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface Sentiment {
|
|
27
|
+
shortPercent: number;
|
|
28
|
+
longPercent: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type EmptyRecord = Record<any, never>;
|
|
32
|
+
|
|
33
|
+
export interface DataRecord {
|
|
34
|
+
[key: string]: string | number | undefined;
|
|
35
|
+
instrument: string;
|
|
36
|
+
displayName: string;
|
|
37
|
+
buy?: number;
|
|
38
|
+
buyPriceMovement?: number;
|
|
39
|
+
dailyPercentChange?: string;
|
|
40
|
+
dailyPipsChange?: number;
|
|
41
|
+
displayPrecision?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface InstrumentRateWithDataProps {
|
|
45
|
+
loading: boolean;
|
|
46
|
+
record: DataRecord;
|
|
47
|
+
target: EventTarget | null;
|
|
48
|
+
division: Division;
|
|
49
|
+
size?: 'compact' | 'full' | 'fullWithChart'
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { LiveRatesErrorMessage, useLiveRatesMessage } from '@oanda/labs-widget-common';
|
|
3
|
+
import { DataRecord, EmptyRecord } from './types';
|
|
4
|
+
import { ValidateInstrumentsQuery } from '../gql/types/graphql';
|
|
5
|
+
|
|
6
|
+
const getRecords = (data: ValidateInstrumentsQuery) => data?.mapInstrumentNames?.map((item) => ({
|
|
7
|
+
instrument: item?.name || '',
|
|
8
|
+
displayName: item?.displayName || '',
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
const useRecords = (
|
|
12
|
+
record: DataRecord | EmptyRecord,
|
|
13
|
+
target: EventTarget | null,
|
|
14
|
+
) => {
|
|
15
|
+
const [updatedRecord, setUpdatedRecord] = useState<DataRecord>({
|
|
16
|
+
displayName: record.displayName,
|
|
17
|
+
instrument: record.instrument,
|
|
18
|
+
sentiment: record.sentiment,
|
|
19
|
+
});
|
|
20
|
+
const [error, setError] = useState<LiveRatesErrorMessage | null>(null);
|
|
21
|
+
|
|
22
|
+
const { update, error: liveRatesError } = useLiveRatesMessage(
|
|
23
|
+
record.instrument,
|
|
24
|
+
target,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
setUpdatedRecord({
|
|
29
|
+
displayName: record.displayName,
|
|
30
|
+
instrument: record.instrument,
|
|
31
|
+
buy: update?.bid,
|
|
32
|
+
buyPriceMovement: update?.bidPriceMovement,
|
|
33
|
+
dailyPercentChange: update?.dailyPercentChangeFromOpen,
|
|
34
|
+
dailyPipsChange: update?.dailyPipsChangeFromOpen,
|
|
35
|
+
displayPrecision: update?.displayPrecision,
|
|
36
|
+
});
|
|
37
|
+
setError(liveRatesError);
|
|
38
|
+
}, [update, record, liveRatesError]);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
updatedRecord,
|
|
42
|
+
error,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
getRecords,
|
|
48
|
+
useRecords,
|
|
49
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const getInstrumentsChart = gql`
|
|
4
|
+
query GetInstrumentsChart($instruments: [String!], $division: Division) {
|
|
5
|
+
topicalInstrumentsCharts(instruments: $instruments, division: $division) {
|
|
6
|
+
name
|
|
7
|
+
chart
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { FragmentDefinitionNode } from 'graphql';
|
|
3
|
+
import { Incremental } from './graphql';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<
|
|
7
|
+
infer TType,
|
|
8
|
+
any
|
|
9
|
+
>
|
|
10
|
+
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
|
|
11
|
+
? TKey extends string
|
|
12
|
+
? { ' $fragmentRefs'?: { [key in TKey]: TType } }
|
|
13
|
+
: never
|
|
14
|
+
: never
|
|
15
|
+
: never;
|
|
16
|
+
|
|
17
|
+
// return non-nullable if `fragmentType` is non-nullable
|
|
18
|
+
export function useFragment<TType>(
|
|
19
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
20
|
+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
|
|
21
|
+
): TType;
|
|
22
|
+
// return nullable if `fragmentType` is nullable
|
|
23
|
+
export function useFragment<TType>(
|
|
24
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
25
|
+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
|
|
26
|
+
): TType | null | undefined;
|
|
27
|
+
// return array of non-nullable if `fragmentType` is array of non-nullable
|
|
28
|
+
export function useFragment<TType>(
|
|
29
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
30
|
+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
31
|
+
): ReadonlyArray<TType>;
|
|
32
|
+
// return array of nullable if `fragmentType` is array of nullable
|
|
33
|
+
export function useFragment<TType>(
|
|
34
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
35
|
+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
|
|
36
|
+
): ReadonlyArray<TType> | null | undefined;
|
|
37
|
+
export function useFragment<TType>(
|
|
38
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
39
|
+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
|
|
40
|
+
): TType | ReadonlyArray<TType> | null | undefined {
|
|
41
|
+
return fragmentType as any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export function makeFragmentData<
|
|
46
|
+
F extends DocumentTypeDecoration<any, any>,
|
|
47
|
+
FT extends ResultOf<F>
|
|
48
|
+
>(data: FT, _fragment: F): FragmentType<F> {
|
|
49
|
+
return data as FragmentType<F>;
|
|
50
|
+
}
|
|
51
|
+
export function isFragmentReady<TQuery, TFrag>(
|
|
52
|
+
queryNode: DocumentTypeDecoration<TQuery, any>,
|
|
53
|
+
fragmentNode: TypedDocumentNode<TFrag>,
|
|
54
|
+
data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined
|
|
55
|
+
): data is FragmentType<typeof fragmentNode> {
|
|
56
|
+
const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__
|
|
57
|
+
?.deferredFields;
|
|
58
|
+
|
|
59
|
+
if (!deferredFields) return true;
|
|
60
|
+
|
|
61
|
+
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
|
|
62
|
+
const fragName = fragDef?.name?.value;
|
|
63
|
+
|
|
64
|
+
const fields = (fragName && deferredFields[fragName]) || [];
|
|
65
|
+
return fields.length > 0 && fields.every(field => data && field in data);
|
|
66
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as types from './graphql';
|
|
3
|
+
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Map of all GraphQL operations in the project.
|
|
7
|
+
*
|
|
8
|
+
* This map has several performance disadvantages:
|
|
9
|
+
* 1. It is not tree-shakeable, so it will include all operations in the project.
|
|
10
|
+
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
|
|
11
|
+
* 3. It does not support dead code elimination, so it will add unused operations.
|
|
12
|
+
*
|
|
13
|
+
* Therefore it is highly recommended to use the babel or swc plugin for production.
|
|
14
|
+
*/
|
|
15
|
+
const documents = {
|
|
16
|
+
"\n query GetInstrumentsChart($instruments: [String!], $division: Division) {\n topicalInstrumentsCharts(instruments: $instruments, division: $division) {\n name\n chart\n }\n }\n": types.GetInstrumentsChartDocument,
|
|
17
|
+
"\n query validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n": types.ValidateInstrumentsDocument,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* The query argument is unknown!
|
|
30
|
+
* Please regenerate the types.
|
|
31
|
+
*/
|
|
32
|
+
export function graphql(source: string): unknown;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
36
|
+
*/
|
|
37
|
+
export function graphql(source: "\n query GetInstrumentsChart($instruments: [String!], $division: Division) {\n topicalInstrumentsCharts(instruments: $instruments, division: $division) {\n name\n chart\n }\n }\n"): (typeof documents)["\n query GetInstrumentsChart($instruments: [String!], $division: Division) {\n topicalInstrumentsCharts(instruments: $instruments, division: $division) {\n name\n chart\n }\n }\n"];
|
|
38
|
+
/**
|
|
39
|
+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
40
|
+
*/
|
|
41
|
+
export function graphql(source: "\n query validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n"): (typeof documents)["\n query validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n"];
|
|
42
|
+
|
|
43
|
+
export function graphql(source: string) {
|
|
44
|
+
return (documents as any)[source] ?? {};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;
|