@oanda/labs-instrument-live-rate-widget 1.0.9 → 1.0.11

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 (75) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/dist/main/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js +8 -12
  3. package/dist/main/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js.map +1 -1
  4. package/dist/main/InstrumentLiveRateWidget/Main.js +21 -56
  5. package/dist/main/InstrumentLiveRateWidget/Main.js.map +1 -1
  6. package/dist/main/InstrumentLiveRateWidget/ValidationWrapper.js +52 -0
  7. package/dist/main/InstrumentLiveRateWidget/ValidationWrapper.js.map +1 -0
  8. package/dist/main/InstrumentLiveRateWidget/types.js.map +1 -1
  9. package/dist/module/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js +7 -12
  10. package/dist/module/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js.map +1 -1
  11. package/dist/module/InstrumentLiveRateWidget/Main.js +24 -58
  12. package/dist/module/InstrumentLiveRateWidget/Main.js.map +1 -1
  13. package/dist/module/InstrumentLiveRateWidget/ValidationWrapper.js +45 -0
  14. package/dist/module/InstrumentLiveRateWidget/ValidationWrapper.js.map +1 -0
  15. package/dist/module/InstrumentLiveRateWidget/types.js.map +1 -1
  16. package/dist/types/InstrumentLiveRateWidget/Main.d.ts +1 -1
  17. package/dist/types/InstrumentLiveRateWidget/ValidationWrapper.d.ts +4 -0
  18. package/dist/types/InstrumentLiveRateWidget/types.d.ts +10 -4
  19. package/package.json +3 -4
  20. package/src/InstrumentLiveRateWidget/InstrumentLiveRateWidget.tsx +11 -20
  21. package/src/InstrumentLiveRateWidget/Main.tsx +27 -66
  22. package/src/InstrumentLiveRateWidget/ValidationWrapper.tsx +62 -0
  23. package/src/InstrumentLiveRateWidget/types.tsx +10 -4
  24. package/test/Main.test.tsx +7 -3
  25. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithChart/InstrumentRateWithChart.js +0 -46
  26. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithChart/InstrumentRateWithChart.js.map +0 -1
  27. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithChart/index.js +0 -28
  28. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithChart/index.js.map +0 -1
  29. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithChart/types.js +0 -6
  30. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithChart/types.js.map +0 -1
  31. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithChart/utils.js +0 -25
  32. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithChart/utils.js.map +0 -1
  33. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js +0 -42
  34. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js.map +0 -1
  35. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/index.js +0 -17
  36. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/index.js.map +0 -1
  37. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/types.js +0 -6
  38. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/types.js.map +0 -1
  39. package/dist/main/InstrumentLiveRateWidget/components/index.js +0 -28
  40. package/dist/main/InstrumentLiveRateWidget/components/index.js.map +0 -1
  41. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithChart/InstrumentRateWithChart.js +0 -38
  42. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithChart/InstrumentRateWithChart.js.map +0 -1
  43. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithChart/index.js +0 -3
  44. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithChart/index.js.map +0 -1
  45. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithChart/types.js +0 -2
  46. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithChart/types.js.map +0 -1
  47. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithChart/utils.js +0 -18
  48. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithChart/utils.js.map +0 -1
  49. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js +0 -35
  50. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js.map +0 -1
  51. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/index.js +0 -2
  52. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/index.js.map +0 -1
  53. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/types.js +0 -2
  54. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/types.js.map +0 -1
  55. package/dist/module/InstrumentLiveRateWidget/components/index.js +0 -3
  56. package/dist/module/InstrumentLiveRateWidget/components/index.js.map +0 -1
  57. package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithChart/InstrumentRateWithChart.d.ts +0 -4
  58. package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithChart/index.d.ts +0 -2
  59. package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithChart/types.d.ts +0 -9
  60. package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithChart/utils.d.ts +0 -3
  61. package/dist/types/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.d.ts +0 -4
  62. package/dist/types/InstrumentLiveRateWidget/components/LineChartWithData/index.d.ts +0 -1
  63. package/dist/types/InstrumentLiveRateWidget/components/LineChartWithData/types.d.ts +0 -8
  64. package/dist/types/InstrumentLiveRateWidget/components/index.d.ts +0 -2
  65. package/src/InstrumentLiveRateWidget/components/InstrumentRateWithChart/InstrumentRateWithChart.tsx +0 -43
  66. package/src/InstrumentLiveRateWidget/components/InstrumentRateWithChart/index.ts +0 -2
  67. package/src/InstrumentLiveRateWidget/components/InstrumentRateWithChart/types.ts +0 -10
  68. package/src/InstrumentLiveRateWidget/components/InstrumentRateWithChart/utils.ts +0 -25
  69. package/src/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.tsx +0 -43
  70. package/src/InstrumentLiveRateWidget/components/LineChartWithData/index.ts +0 -1
  71. package/src/InstrumentLiveRateWidget/components/LineChartWithData/types.tsx +0 -9
  72. package/src/InstrumentLiveRateWidget/components/index.ts +0 -2
  73. package/test/LineChartWithData.test.tsx +0 -164
  74. package/test/components/InstrumentRateWithChart.test.tsx +0 -62
  75. package/test/components/utils.test.ts +0 -13
@@ -1,38 +0,0 @@
1
- import React, { useContext } from 'react';
2
- import { InstrumentRate, ThemeContext } from '@oanda/labs-widget-common';
3
- import { getChartColor, getColorIndicator } from './utils';
4
- import { INSTRUMENT_TOOLTIP_ID } from '../../constant';
5
- import { LineChartWithData } from '../LineChartWithData';
6
- import { useRecords } from '../../utils';
7
- const InstrumentRateWithChart = _ref => {
8
- let {
9
- loading,
10
- record,
11
- target,
12
- division,
13
- size
14
- } = _ref;
15
- const {
16
- isDark
17
- } = useContext(ThemeContext);
18
- const {
19
- updatedRecord,
20
- error
21
- } = useRecords(record, record?.instrument ? target : null);
22
- const indicator = getColorIndicator(updatedRecord.dailyPercentChange);
23
- return React.createElement(React.Fragment, null, React.createElement(InstrumentRate, {
24
- isLoading: loading,
25
- isError: !!error,
26
- record: updatedRecord,
27
- size: size,
28
- tooltipId: INSTRUMENT_TOOLTIP_ID,
29
- colorIndicator: indicator
30
- }), size === 'fullWithChart' && React.createElement(LineChartWithData, {
31
- record: record,
32
- isLoading: loading,
33
- division: division,
34
- color: getChartColor(indicator, isDark)
35
- }));
36
- };
37
- export { InstrumentRateWithChart };
38
- //# sourceMappingURL=InstrumentRateWithChart.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InstrumentRateWithChart.js","names":["React","useContext","InstrumentRate","ThemeContext","getChartColor","getColorIndicator","INSTRUMENT_TOOLTIP_ID","LineChartWithData","useRecords","InstrumentRateWithChart","_ref","loading","record","target","division","size","isDark","updatedRecord","error","instrument","indicator","dailyPercentChange","createElement","Fragment","isLoading","isError","tooltipId","colorIndicator","color"],"sources":["../../../../../src/InstrumentLiveRateWidget/components/InstrumentRateWithChart/InstrumentRateWithChart.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { InstrumentRate, ThemeContext } from '@oanda/labs-widget-common';\nimport { InstrumentRateWithChartProps } from './types';\nimport { getChartColor, getColorIndicator } from './utils';\nimport { INSTRUMENT_TOOLTIP_ID } from '../../constant';\nimport { LineChartWithData } from '../LineChartWithData';\nimport { useRecords } from '../../utils';\n\nconst InstrumentRateWithChart = ({\n loading,\n record,\n target,\n division,\n size,\n}: InstrumentRateWithChartProps) => {\n const { isDark } = useContext(ThemeContext);\n const { updatedRecord, error } = useRecords(record, record?.instrument ? target : null);\n\n const indicator = getColorIndicator(updatedRecord.dailyPercentChange);\n\n return (\n <>\n <InstrumentRate\n isLoading={loading}\n isError={!!error}\n record={updatedRecord}\n size={size}\n tooltipId={INSTRUMENT_TOOLTIP_ID}\n colorIndicator={indicator}\n />\n {size === 'fullWithChart' && (\n <LineChartWithData\n record={record}\n isLoading={loading}\n division={division}\n color={getChartColor(indicator, isDark)}\n />\n )}\n </>\n );\n};\n\nexport { InstrumentRateWithChart };\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,SAASC,cAAc,EAAEC,YAAY,QAAQ,2BAA2B;AAExE,SAASC,aAAa,EAAEC,iBAAiB,QAAQ,SAAS;AAC1D,SAASC,qBAAqB,QAAQ,gBAAgB;AACtD,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,UAAU,QAAQ,aAAa;AAExC,MAAMC,uBAAuB,GAAGC,IAAA,IAMI;EAAA,IANH;IAC/BC,OAAO;IACPC,MAAM;IACNC,MAAM;IACNC,QAAQ;IACRC;EAC4B,CAAC,GAAAL,IAAA;EAC7B,MAAM;IAAEM;EAAO,CAAC,GAAGf,UAAU,CAACE,YAAY,CAAC;EAC3C,MAAM;IAAEc,aAAa;IAAEC;EAAM,CAAC,GAAGV,UAAU,CAACI,MAAM,EAAEA,MAAM,EAAEO,UAAU,GAAGN,MAAM,GAAG,IAAI,CAAC;EAEvF,MAAMO,SAAS,GAAGf,iBAAiB,CAACY,aAAa,CAACI,kBAAkB,CAAC;EAErE,OACErB,KAAA,CAAAsB,aAAA,CAAAtB,KAAA,CAAAuB,QAAA,QACEvB,KAAA,CAAAsB,aAAA,CAACpB,cAAc;IACbsB,SAAS,EAAEb,OAAQ;IACnBc,OAAO,EAAE,CAAC,CAACP,KAAM;IACjBN,MAAM,EAAEK,aAAc;IACtBF,IAAI,EAAEA,IAAK;IACXW,SAAS,EAAEpB,qBAAsB;IACjCqB,cAAc,EAAEP;EAAU,CAC3B,CAAC,EACDL,IAAI,KAAK,eAAe,IACvBf,KAAA,CAAAsB,aAAA,CAACf,iBAAiB;IAChBK,MAAM,EAAEA,MAAO;IACfY,SAAS,EAAEb,OAAQ;IACnBG,QAAQ,EAAEA,QAAS;IACnBc,KAAK,EAAExB,aAAa,CAACgB,SAAS,EAAEJ,MAAM;EAAE,CACzC,CAEH,CAAC;AAEP,CAAC;AAED,SAASP,uBAAuB","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- export * from './InstrumentRateWithChart';
2
- export * from './utils';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/InstrumentLiveRateWidget/components/InstrumentRateWithChart/index.ts"],"sourcesContent":["export * from './InstrumentRateWithChart';\nexport * from './utils';\n"],"mappings":"AAAA,cAAc,2BAA2B;AACzC,cAAc,SAAS","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/InstrumentLiveRateWidget/components/InstrumentRateWithChart/types.ts"],"sourcesContent":["import { DataRecord } from '@oanda/labs-widget-common';\nimport { Division } from '../../types';\n\nexport interface InstrumentRateWithChartProps {\n loading: boolean;\n record: DataRecord;\n target: EventTarget | null;\n division: Division;\n size?: 'compact' | 'full' | 'fullWithChart'\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,18 +0,0 @@
1
- import { lightTheme, darkTheme } from '@oanda/labs-widget-common';
2
- const getColorIndicator = dailyChange => {
3
- const numberValue = Number(dailyChange?.substring(0, dailyChange.length - 1));
4
- return Math.sign(numberValue);
5
- };
6
- const getChartColor = (indicator, isDarkMode) => {
7
- const theme = isDarkMode ? darkTheme : lightTheme;
8
- switch (indicator) {
9
- case 1:
10
- return theme.textOk;
11
- case -1:
12
- return theme.textDanger;
13
- default:
14
- return theme.textDisabled;
15
- }
16
- };
17
- export { getColorIndicator, getChartColor };
18
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","names":["lightTheme","darkTheme","getColorIndicator","dailyChange","numberValue","Number","substring","length","Math","sign","getChartColor","indicator","isDarkMode","theme","textOk","textDanger","textDisabled"],"sources":["../../../../../src/InstrumentLiveRateWidget/components/InstrumentRateWithChart/utils.ts"],"sourcesContent":["import { lightTheme, darkTheme } from '@oanda/labs-widget-common';\n\nconst getColorIndicator = (dailyChange?: string) => {\n const numberValue = Number(dailyChange?.substring(0, dailyChange.length - 1));\n\n return Math.sign(numberValue);\n};\n\nconst getChartColor = (indicator?: number, isDarkMode?: boolean) => {\n const theme = isDarkMode ? darkTheme : lightTheme;\n\n switch (indicator) {\n case 1:\n return theme.textOk;\n case -1:\n return theme.textDanger;\n default:\n return theme.textDisabled;\n }\n};\n\nexport {\n getColorIndicator,\n getChartColor,\n};\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,SAAS,QAAQ,2BAA2B;AAEjE,MAAMC,iBAAiB,GAAIC,WAAoB,IAAK;EAClD,MAAMC,WAAW,GAAGC,MAAM,CAACF,WAAW,EAAEG,SAAS,CAAC,CAAC,EAAEH,WAAW,CAACI,MAAM,GAAG,CAAC,CAAC,CAAC;EAE7E,OAAOC,IAAI,CAACC,IAAI,CAACL,WAAW,CAAC;AAC/B,CAAC;AAED,MAAMM,aAAa,GAAGA,CAACC,SAAkB,EAAEC,UAAoB,KAAK;EAClE,MAAMC,KAAK,GAAGD,UAAU,GAAGX,SAAS,GAAGD,UAAU;EAEjD,QAAQW,SAAS;IACf,KAAK,CAAC;MACJ,OAAOE,KAAK,CAACC,MAAM;IACrB,KAAK,CAAC,CAAC;MACL,OAAOD,KAAK,CAACE,UAAU;IACzB;MACE,OAAOF,KAAK,CAACG,YAAY;EAC7B;AACF,CAAC;AAED,SACEd,iBAAiB,EACjBQ,aAAa","ignoreList":[]}
@@ -1,35 +0,0 @@
1
- import React from 'react';
2
- import { useQuery } from '@apollo/client';
3
- import { LineChart } from '@oanda/labs-widget-common';
4
- import { getInstrumentsChart } from '../../../gql/getInstrumentsChart';
5
- const LineChartWithData = _ref => {
6
- let {
7
- record,
8
- isLoading,
9
- division,
10
- color
11
- } = _ref;
12
- const {
13
- loading,
14
- data
15
- } = useQuery(getInstrumentsChart, {
16
- variables: {
17
- instruments: [record.instrument],
18
- division
19
- },
20
- fetchPolicy: 'network-only',
21
- skip: !record.instrument
22
- });
23
- const showChart = isLoading || loading;
24
- const chart = data?.topicalInstrumentsCharts?.[0].chart || [];
25
- return React.createElement("div", {
26
- className: "lw-relative"
27
- }, !showChart ? React.createElement("div", {
28
- className: "lw-absolute lw-bottom-0 lw-right-0 lw--z-50 lw-flex lw-h-10 lw-w-[100px] lw-items-center lw-justify-center"
29
- }, React.createElement(LineChart, {
30
- color: color,
31
- data: chart
32
- })) : null);
33
- };
34
- export { LineChartWithData };
35
- //# sourceMappingURL=LineChartWithData.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LineChartWithData.js","names":["React","useQuery","LineChart","getInstrumentsChart","LineChartWithData","_ref","record","isLoading","division","color","loading","data","variables","instruments","instrument","fetchPolicy","skip","showChart","chart","topicalInstrumentsCharts","createElement","className"],"sources":["../../../../../src/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.tsx"],"sourcesContent":["import React from 'react';\nimport { useQuery } from '@apollo/client';\nimport { LineChart } from '@oanda/labs-widget-common';\nimport { LineChartWithDataProps } from './types';\nimport { getInstrumentsChart } from '../../../gql/getInstrumentsChart';\nimport { GetInstrumentsChartQuery, GetInstrumentsChartQueryVariables } from '../../../gql/types/graphql';\n\nconst LineChartWithData = ({\n record,\n isLoading,\n division,\n color,\n}: LineChartWithDataProps) => {\n const { loading, data } = useQuery<\n GetInstrumentsChartQuery,\n GetInstrumentsChartQueryVariables\n >(getInstrumentsChart, {\n variables: {\n instruments: [record.instrument],\n division,\n },\n fetchPolicy: 'network-only',\n skip: !record.instrument,\n });\n\n const showChart = isLoading || loading;\n const chart = data?.topicalInstrumentsCharts?.[0].chart || [];\n\n return (\n <div className=\"lw-relative\">\n {!showChart ? (\n <div className=\"lw-absolute lw-bottom-0 lw-right-0 lw--z-50 lw-flex lw-h-10 lw-w-[100px] lw-items-center lw-justify-center\">\n <LineChart\n color={color}\n data={chart}\n />\n </div>\n ) : null}\n </div>\n );\n};\n\nexport { LineChartWithData };\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,SAAS,QAAQ,2BAA2B;AAErD,SAASC,mBAAmB,QAAQ,kCAAkC;AAGtE,MAAMC,iBAAiB,GAAGC,IAAA,IAKI;EAAA,IALH;IACzBC,MAAM;IACNC,SAAS;IACTC,QAAQ;IACRC;EACsB,CAAC,GAAAJ,IAAA;EACvB,MAAM;IAAEK,OAAO;IAAEC;EAAK,CAAC,GAAGV,QAAQ,CAGhCE,mBAAmB,EAAE;IACrBS,SAAS,EAAE;MACTC,WAAW,EAAE,CAACP,MAAM,CAACQ,UAAU,CAAC;MAChCN;IACF,CAAC;IACDO,WAAW,EAAE,cAAc;IAC3BC,IAAI,EAAE,CAACV,MAAM,CAACQ;EAChB,CAAC,CAAC;EAEF,MAAMG,SAAS,GAAGV,SAAS,IAAIG,OAAO;EACtC,MAAMQ,KAAK,GAAGP,IAAI,EAAEQ,wBAAwB,GAAG,CAAC,CAAC,CAACD,KAAK,IAAI,EAAE;EAE7D,OACElB,KAAA,CAAAoB,aAAA;IAAKC,SAAS,EAAC;EAAa,GACzB,CAACJ,SAAS,GACTjB,KAAA,CAAAoB,aAAA;IAAKC,SAAS,EAAC;EAA4G,GACzHrB,KAAA,CAAAoB,aAAA,CAAClB,SAAS;IACRO,KAAK,EAAEA,KAAM;IACbE,IAAI,EAAEO;EAAM,CACb,CACE,CAAC,GACJ,IACD,CAAC;AAEV,CAAC;AAED,SAASd,iBAAiB","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export * from './LineChartWithData';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/InstrumentLiveRateWidget/components/LineChartWithData/index.ts"],"sourcesContent":["export * from './LineChartWithData';\n"],"mappings":"AAAA,cAAc,qBAAqB","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/InstrumentLiveRateWidget/components/LineChartWithData/types.tsx"],"sourcesContent":["import { DataRecord } from '@oanda/labs-widget-common';\nimport { Division } from '../../../gql/types/graphql';\n\nexport interface LineChartWithDataProps {\n record: DataRecord;\n isLoading: boolean;\n division: Division;\n color: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- export * from './InstrumentRateWithChart';
2
- export * from './LineChartWithData';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/InstrumentLiveRateWidget/components/index.ts"],"sourcesContent":["export * from './InstrumentRateWithChart';\nexport * from './LineChartWithData';\n"],"mappings":"AAAA,cAAc,2BAA2B;AACzC,cAAc,qBAAqB","ignoreList":[]}
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import { InstrumentRateWithChartProps } from './types';
3
- declare const InstrumentRateWithChart: ({ loading, record, target, division, size, }: InstrumentRateWithChartProps) => React.JSX.Element;
4
- export { InstrumentRateWithChart };
@@ -1,2 +0,0 @@
1
- export * from './InstrumentRateWithChart';
2
- export * from './utils';
@@ -1,9 +0,0 @@
1
- import { DataRecord } from '@oanda/labs-widget-common';
2
- import { Division } from '../../types';
3
- export interface InstrumentRateWithChartProps {
4
- loading: boolean;
5
- record: DataRecord;
6
- target: EventTarget | null;
7
- division: Division;
8
- size?: 'compact' | 'full' | 'fullWithChart';
9
- }
@@ -1,3 +0,0 @@
1
- declare const getColorIndicator: (dailyChange?: string) => number;
2
- declare const getChartColor: (indicator?: number, isDarkMode?: boolean) => string;
3
- export { getColorIndicator, getChartColor, };
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import { LineChartWithDataProps } from './types';
3
- declare const LineChartWithData: ({ record, isLoading, division, color, }: LineChartWithDataProps) => React.JSX.Element;
4
- export { LineChartWithData };
@@ -1 +0,0 @@
1
- export * from './LineChartWithData';
@@ -1,8 +0,0 @@
1
- import { DataRecord } from '@oanda/labs-widget-common';
2
- import { Division } from '../../../gql/types/graphql';
3
- export interface LineChartWithDataProps {
4
- record: DataRecord;
5
- isLoading: boolean;
6
- division: Division;
7
- color: string;
8
- }
@@ -1,2 +0,0 @@
1
- export * from './InstrumentRateWithChart';
2
- export * from './LineChartWithData';
@@ -1,43 +0,0 @@
1
- import React, { useContext } from 'react';
2
- import { InstrumentRate, ThemeContext } from '@oanda/labs-widget-common';
3
- import { InstrumentRateWithChartProps } from './types';
4
- import { getChartColor, getColorIndicator } from './utils';
5
- import { INSTRUMENT_TOOLTIP_ID } from '../../constant';
6
- import { LineChartWithData } from '../LineChartWithData';
7
- import { useRecords } from '../../utils';
8
-
9
- const InstrumentRateWithChart = ({
10
- loading,
11
- record,
12
- target,
13
- division,
14
- size,
15
- }: InstrumentRateWithChartProps) => {
16
- const { isDark } = useContext(ThemeContext);
17
- const { updatedRecord, error } = useRecords(record, record?.instrument ? target : null);
18
-
19
- const indicator = getColorIndicator(updatedRecord.dailyPercentChange);
20
-
21
- return (
22
- <>
23
- <InstrumentRate
24
- isLoading={loading}
25
- isError={!!error}
26
- record={updatedRecord}
27
- size={size}
28
- tooltipId={INSTRUMENT_TOOLTIP_ID}
29
- colorIndicator={indicator}
30
- />
31
- {size === 'fullWithChart' && (
32
- <LineChartWithData
33
- record={record}
34
- isLoading={loading}
35
- division={division}
36
- color={getChartColor(indicator, isDark)}
37
- />
38
- )}
39
- </>
40
- );
41
- };
42
-
43
- export { InstrumentRateWithChart };
@@ -1,2 +0,0 @@
1
- export * from './InstrumentRateWithChart';
2
- export * from './utils';
@@ -1,10 +0,0 @@
1
- import { DataRecord } from '@oanda/labs-widget-common';
2
- import { Division } from '../../types';
3
-
4
- export interface InstrumentRateWithChartProps {
5
- loading: boolean;
6
- record: DataRecord;
7
- target: EventTarget | null;
8
- division: Division;
9
- size?: 'compact' | 'full' | 'fullWithChart'
10
- }
@@ -1,25 +0,0 @@
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
- };
@@ -1,43 +0,0 @@
1
- import React from 'react';
2
- import { useQuery } from '@apollo/client';
3
- import { LineChart } from '@oanda/labs-widget-common';
4
- import { LineChartWithDataProps } from './types';
5
- import { getInstrumentsChart } from '../../../gql/getInstrumentsChart';
6
- import { GetInstrumentsChartQuery, GetInstrumentsChartQueryVariables } from '../../../gql/types/graphql';
7
-
8
- const LineChartWithData = ({
9
- record,
10
- isLoading,
11
- division,
12
- color,
13
- }: LineChartWithDataProps) => {
14
- const { loading, data } = useQuery<
15
- GetInstrumentsChartQuery,
16
- GetInstrumentsChartQueryVariables
17
- >(getInstrumentsChart, {
18
- variables: {
19
- instruments: [record.instrument],
20
- division,
21
- },
22
- fetchPolicy: 'network-only',
23
- skip: !record.instrument,
24
- });
25
-
26
- const showChart = isLoading || loading;
27
- const chart = data?.topicalInstrumentsCharts?.[0].chart || [];
28
-
29
- return (
30
- <div className="lw-relative">
31
- {!showChart ? (
32
- <div className="lw-absolute lw-bottom-0 lw-right-0 lw--z-50 lw-flex lw-h-10 lw-w-[100px] lw-items-center lw-justify-center">
33
- <LineChart
34
- color={color}
35
- data={chart}
36
- />
37
- </div>
38
- ) : null}
39
- </div>
40
- );
41
- };
42
-
43
- export { LineChartWithData };
@@ -1 +0,0 @@
1
- export * from './LineChartWithData';
@@ -1,9 +0,0 @@
1
- import { DataRecord } from '@oanda/labs-widget-common';
2
- import { Division } from '../../../gql/types/graphql';
3
-
4
- export interface LineChartWithDataProps {
5
- record: DataRecord;
6
- isLoading: boolean;
7
- division: Division;
8
- color: string;
9
- }
@@ -1,2 +0,0 @@
1
- export * from './InstrumentRateWithChart';
2
- export * from './LineChartWithData';
@@ -1,164 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- import React from 'react';
5
- import { render } from '@testing-library/react';
6
- import { MockedProvider } from '@apollo/client/testing';
7
- import { lightTheme } from '@oanda/labs-widget-common';
8
- import { LineChartWithData } from '../src/InstrumentLiveRateWidget/components/LineChartWithData';
9
- import { getInstrumentsChart } from '../src/gql/getInstrumentsChart';
10
- import { Division } from '../src/gql/types/graphql';
11
-
12
- const chartPointsMocks = [
13
- {
14
- request: {
15
- query: getInstrumentsChart,
16
- variables: {
17
- instruments: ['EUR_USD'],
18
- division: 'OC',
19
- },
20
- },
21
- result: {
22
- data: {
23
- topicalInstrumentsCharts: [
24
- {
25
- name: 'EUR_USD',
26
- displayName: 'EUR_USD',
27
- chart: [
28
- 1.0544, 1.05704, 1.05716, 1.05596, 1.05556, 1.05556, 1.05238,
29
- 1.05292, 1.05443, 1.0544, 1.05704, 1.05716, 1.05596, 1.05556,
30
- 1.05556,
31
- ],
32
- },
33
- ],
34
- },
35
- },
36
- },
37
- ];
38
-
39
- const chartsPointsBelowTenMocks = [
40
- {
41
- request: {
42
- query: getInstrumentsChart,
43
- variables: {
44
- instruments: ['CAD_JPY'],
45
- division: 'OC',
46
- },
47
- },
48
- result: {
49
- data: {
50
- topicalInstrumentsCharts: [
51
- {
52
- name: 'CAD_JPY',
53
- displayName: 'CAD_JPY',
54
- chart: [0.8601, 0.85996, 0.85962, 0.86022, 0.8592],
55
- },
56
- ],
57
- },
58
- },
59
- },
60
- ];
61
-
62
- describe('LineChartWithData component', () => {
63
- const record = {
64
- instrument: 'EUR_USD',
65
- displayName: 'EUR_USD',
66
- buy: 1.04508,
67
- sell: 1.04523,
68
- spread: 1.2,
69
- dailyPercentChange: '+3,23%',
70
- };
71
-
72
- it('should render line chart', async () => {
73
- const { findByTestId } = render(
74
- <MockedProvider mocks={chartPointsMocks}>
75
- <LineChartWithData
76
- isLoading={false}
77
- division={Division.Oc}
78
- record={record}
79
- color={lightTheme.textOk}
80
- />
81
- </MockedProvider>,
82
- );
83
-
84
- expect(await findByTestId('line-chart')).toBeInTheDocument();
85
- });
86
- it('should render line chart in green', async () => {
87
- const { findByTestId, container } = render(
88
- <MockedProvider mocks={chartPointsMocks}>
89
- <LineChartWithData
90
- isLoading={false}
91
- division={Division.Oc}
92
- record={record}
93
- color={lightTheme.textOk}
94
- />
95
- </MockedProvider>,
96
- );
97
-
98
- expect(await findByTestId('line-chart')).toBeInTheDocument();
99
-
100
- expect(container.querySelector('path')).toHaveAttribute(
101
- 'stroke',
102
- '#00884E',
103
- );
104
- });
105
- it('should render line chart in red', async () => {
106
- record.dailyPercentChange = '-1.56%';
107
-
108
- const { findByTestId, container } = render(
109
- <MockedProvider mocks={chartPointsMocks}>
110
- <LineChartWithData
111
- isLoading={false}
112
- division={Division.Oc}
113
- record={record}
114
- color={lightTheme.textDanger}
115
- />
116
- </MockedProvider>,
117
- );
118
-
119
- expect(await findByTestId('line-chart')).toBeInTheDocument();
120
-
121
- expect(container.querySelector('path')).toHaveAttribute(
122
- 'stroke',
123
- '#E41F37',
124
- );
125
- });
126
- it('should render line chart in grey', async () => {
127
- record.dailyPercentChange = '0%';
128
-
129
- const { findByTestId, container } = render(
130
- <MockedProvider mocks={chartPointsMocks}>
131
- <LineChartWithData
132
- isLoading={false}
133
- division={Division.Oc}
134
- record={record}
135
- color={lightTheme.textDisabled}
136
- />
137
- </MockedProvider>,
138
- );
139
-
140
- expect(await findByTestId('line-chart')).toBeInTheDocument();
141
-
142
- expect(container.querySelector('path')).toHaveAttribute(
143
- 'stroke',
144
- '#7B8085',
145
- );
146
- });
147
- it('should render empty value when number of points is below 10', async () => {
148
- record.instrument = 'CAD_JPY';
149
-
150
- const { queryByTestId, findByTestId } = render(
151
- <MockedProvider mocks={chartsPointsBelowTenMocks}>
152
- <LineChartWithData
153
- isLoading={false}
154
- division={Division.Oc}
155
- record={record}
156
- color={lightTheme.textOk}
157
- />
158
- </MockedProvider>,
159
- );
160
-
161
- expect(await queryByTestId('line-chart')).not.toBeInTheDocument();
162
- expect(await findByTestId('line-chart-empty-value')).toBeInTheDocument();
163
- });
164
- });
@@ -1,62 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- import React from 'react';
5
- import { render } from '@testing-library/react';
6
- import { MockedProvider } from '@apollo/client/testing';
7
- import { InstrumentRateWithChart } from '../../src/InstrumentLiveRateWidget/components';
8
- import { getInstrumentsChart } from '../../src/gql/getInstrumentsChart';
9
- import { Division } from '../../src/gql/types/graphql';
10
-
11
- const chartPointsMocks = [
12
- {
13
- request: {
14
- query: getInstrumentsChart,
15
- variables: {
16
- instruments: ['EUR_USD'],
17
- division: 'OC',
18
- },
19
- },
20
- result: {
21
- data: {
22
- topicalInstrumentsCharts: [
23
- {
24
- name: 'EUR_USD',
25
- displayName: 'EUR_USD',
26
- chart: [
27
- 1.0544, 1.05704, 1.05716, 1.05596, 1.05556, 1.05556, 1.05238,
28
- 1.05292, 1.05443, 1.0544, 1.05704, 1.05716, 1.05596, 1.05556,
29
- 1.05556,
30
- ],
31
- },
32
- ],
33
- },
34
- },
35
- },
36
- ];
37
-
38
- describe('InstrumentRateWithChart component', () => {
39
- const record = {
40
- instrument: 'EUR_USD',
41
- displayName: 'EUR_USD',
42
- buy: 1.04508,
43
- dailyPercentChange: '+3,23%',
44
- dailyPipsChange: 123,
45
- };
46
-
47
- it('should render compact instrument rate', async () => {
48
- const { getAllByTestId } = render(
49
- <MockedProvider mocks={chartPointsMocks}>
50
- <InstrumentRateWithChart
51
- loading={false}
52
- division={Division.Oc}
53
- record={record}
54
- target={null}
55
- size="compact"
56
- />
57
- </MockedProvider>,
58
- );
59
-
60
- expect(getAllByTestId('label-wrapper').length).toEqual(2);
61
- });
62
- });
@@ -1,13 +0,0 @@
1
- import { getColorIndicator } from '../../src/InstrumentLiveRateWidget/components/InstrumentRateWithChart';
2
-
3
- describe('getColorIndicator', () => {
4
- it('should return value greater than 0', () => {
5
- expect(getColorIndicator('+0.06%')).toEqual(1);
6
- });
7
- it('should return value equal to 0', () => {
8
- expect(getColorIndicator('0%')).toEqual(0);
9
- });
10
- it('should return value lower than 0', () => {
11
- expect(getColorIndicator('-0.20%')).toEqual(-1);
12
- });
13
- });