@oanda/labs-currency-strength-widget 1.0.90 → 1.0.92

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 (85) hide show
  1. package/CHANGELOG.md +740 -0
  2. package/dist/main/CurrencyStrengthWidget/ChartsWithData.js +7 -9
  3. package/dist/main/CurrencyStrengthWidget/ChartsWithData.js.map +1 -1
  4. package/dist/main/CurrencyStrengthWidget/CurrencyStrengthWidget.js +13 -18
  5. package/dist/main/CurrencyStrengthWidget/CurrencyStrengthWidget.js.map +1 -1
  6. package/dist/main/CurrencyStrengthWidget/Main.js +4 -5
  7. package/dist/main/CurrencyStrengthWidget/Main.js.map +1 -1
  8. package/dist/main/CurrencyStrengthWidget/components/Chart/Chart.js +14 -14
  9. package/dist/main/CurrencyStrengthWidget/components/Chart/Chart.js.map +1 -1
  10. package/dist/main/CurrencyStrengthWidget/components/Chart/constants.js.map +1 -1
  11. package/dist/main/CurrencyStrengthWidget/components/Chart/formatters.js.map +1 -1
  12. package/dist/main/CurrencyStrengthWidget/components/Chart/getOption.js.map +1 -1
  13. package/dist/main/CurrencyStrengthWidget/components/Chart/types.js.map +1 -1
  14. package/dist/main/CurrencyStrengthWidget/render.js +5 -5
  15. package/dist/main/CurrencyStrengthWidget/render.js.map +1 -1
  16. package/dist/main/CurrencyStrengthWidget/types.js.map +1 -1
  17. package/dist/main/gql/types/fragment-masking.js.map +1 -1
  18. package/dist/main/gql/types/gql.js +1 -1
  19. package/dist/main/gql/types/gql.js.map +1 -1
  20. package/dist/main/gql/types/graphql.js +40 -40
  21. package/dist/main/gql/types/graphql.js.map +1 -1
  22. package/dist/main/gql/types/index.js.map +1 -1
  23. package/dist/main/translations/index.js +1 -1
  24. package/dist/main/translations/index.js.map +1 -1
  25. package/dist/main/translations/translations.js.map +1 -1
  26. package/dist/module/CurrencyStrengthWidget/ChartsWithData.js +7 -7
  27. package/dist/module/CurrencyStrengthWidget/ChartsWithData.js.map +1 -1
  28. package/dist/module/CurrencyStrengthWidget/CurrencyStrengthWidget.js +14 -19
  29. package/dist/module/CurrencyStrengthWidget/CurrencyStrengthWidget.js.map +1 -1
  30. package/dist/module/CurrencyStrengthWidget/Main.js +3 -3
  31. package/dist/module/CurrencyStrengthWidget/Main.js.map +1 -1
  32. package/dist/module/CurrencyStrengthWidget/components/Chart/Chart.js +13 -13
  33. package/dist/module/CurrencyStrengthWidget/components/Chart/Chart.js.map +1 -1
  34. package/dist/module/CurrencyStrengthWidget/components/Chart/constants.js.map +1 -1
  35. package/dist/module/CurrencyStrengthWidget/components/Chart/formatters.js +1 -1
  36. package/dist/module/CurrencyStrengthWidget/components/Chart/formatters.js.map +1 -1
  37. package/dist/module/CurrencyStrengthWidget/components/Chart/getOption.js +1 -1
  38. package/dist/module/CurrencyStrengthWidget/components/Chart/getOption.js.map +1 -1
  39. package/dist/module/CurrencyStrengthWidget/components/Chart/types.js.map +1 -1
  40. package/dist/module/CurrencyStrengthWidget/render.js +5 -5
  41. package/dist/module/CurrencyStrengthWidget/render.js.map +1 -1
  42. package/dist/module/CurrencyStrengthWidget/types.js.map +1 -1
  43. package/dist/module/gql/types/fragment-masking.js.map +1 -1
  44. package/dist/module/gql/types/gql.js +1 -1
  45. package/dist/module/gql/types/gql.js.map +1 -1
  46. package/dist/module/gql/types/graphql.js +40 -40
  47. package/dist/module/gql/types/graphql.js.map +1 -1
  48. package/dist/module/gql/types/index.js +2 -2
  49. package/dist/module/gql/types/index.js.map +1 -1
  50. package/dist/module/translations/index.js +1 -1
  51. package/dist/module/translations/index.js.map +1 -1
  52. package/dist/module/translations/translations.js.map +1 -1
  53. package/dist/types/CurrencyStrengthWidget/ChartsWithData.d.ts +1 -1
  54. package/dist/types/CurrencyStrengthWidget/CurrencyStrengthWidget.d.ts +1 -1
  55. package/dist/types/CurrencyStrengthWidget/Main.d.ts +1 -1
  56. package/dist/types/CurrencyStrengthWidget/components/Chart/Chart.d.ts +1 -1
  57. package/dist/types/CurrencyStrengthWidget/components/Chart/formatters.d.ts +2 -2
  58. package/dist/types/CurrencyStrengthWidget/components/Chart/getOption.d.ts +1 -1
  59. package/dist/types/CurrencyStrengthWidget/components/Chart/types.d.ts +5 -5
  60. package/dist/types/CurrencyStrengthWidget/types.d.ts +1 -1
  61. package/dist/types/gql/types/gql.d.ts +2 -2
  62. package/dist/types/gql/types/index.d.ts +2 -2
  63. package/dist/types/translations/index.d.ts +2 -2
  64. package/package.json +3 -3
  65. package/src/CurrencyStrengthWidget/ChartsWithData.tsx +49 -30
  66. package/src/CurrencyStrengthWidget/CurrencyStrengthWidget.tsx +24 -22
  67. package/src/CurrencyStrengthWidget/Main.tsx +10 -9
  68. package/src/CurrencyStrengthWidget/components/Chart/Chart.tsx +25 -16
  69. package/src/CurrencyStrengthWidget/components/Chart/constants.tsx +1 -0
  70. package/src/CurrencyStrengthWidget/components/Chart/formatters.ts +4 -7
  71. package/src/CurrencyStrengthWidget/components/Chart/getOption.ts +22 -18
  72. package/src/CurrencyStrengthWidget/components/Chart/types.ts +8 -8
  73. package/src/CurrencyStrengthWidget/render.tsx +17 -15
  74. package/src/CurrencyStrengthWidget/types.ts +1 -1
  75. package/src/gql/types/fragment-masking.ts +41 -21
  76. package/src/gql/types/gql.ts +7 -3
  77. package/src/gql/types/graphql.ts +98 -45
  78. package/src/gql/types/index.ts +2 -2
  79. package/src/translations/index.ts +4 -4
  80. package/src/translations/translations.ts +1 -3
  81. package/test/Main.test.tsx +28 -16
  82. package/test/chartOptions.test.ts +9 -7
  83. package/test/mocks/currencyStrengthMock.ts +1 -3
  84. package/test/mocks/responsesMocks.ts +2 -4
  85. package/test/sortData.test.ts +10 -12
@@ -1,18 +1,24 @@
1
- import React, { useContext } from 'react';
2
- import ReactEChartsCore from 'echarts-for-react/lib/core';
3
- import * as echarts from 'echarts/core';
4
- import { BarChart } from 'echarts/charts';
5
- import { CanvasRenderer } from 'echarts/renderers';
6
1
  import {
7
- GridSimpleComponent, GraphicComponent, TooltipComponent, TitleComponent,
8
- } from 'echarts/components';
2
+ getChartTheme,
3
+ Theme,
4
+ useLayoutProvider,
5
+ } from '@oanda/labs-widget-common';
9
6
  import { useLocale } from '@oanda/mono-i18n';
10
- import { Theme, ThemeContext, getChartTheme } from '@oanda/labs-widget-common';
7
+ import { BarChart } from 'echarts/charts';
11
8
  import {
12
- CHART_HEIGHT,
13
- } from './constants';
9
+ GraphicComponent,
10
+ GridSimpleComponent,
11
+ TitleComponent,
12
+ TooltipComponent,
13
+ } from 'echarts/components';
14
+ import * as echarts from 'echarts/core';
15
+ import { CanvasRenderer } from 'echarts/renderers';
16
+ import ReactEChartsCore from 'echarts-for-react/lib/core';
17
+ import React from 'react';
18
+
19
+ import { CHART_HEIGHT } from './constants';
14
20
  import { getOption } from './getOption';
15
- import { ChartProps } from './types';
21
+ import type { ChartProps } from './types';
16
22
 
17
23
  echarts.use([
18
24
  GridSimpleComponent,
@@ -28,19 +34,22 @@ echarts.registerTheme('light_theme', getChartTheme(Theme.Light));
28
34
 
29
35
  const Chart = ({ values, currency }: ChartProps) => {
30
36
  const { lang } = useLocale();
31
- const { isDark } = useContext(ThemeContext);
37
+ const { isDark } = useLayoutProvider();
32
38
 
33
39
  return (
34
40
  <ReactEChartsCore
35
41
  echarts={echarts}
36
- theme={isDark ? 'dark_theme' : 'light_theme'}
42
+ option={getOption({
43
+ values,
44
+ currency,
45
+ lang,
46
+ isDark,
47
+ })}
37
48
  style={{
38
49
  height: `${CHART_HEIGHT}px`,
39
50
  width: '100%',
40
51
  }}
41
- option={getOption({
42
- values, currency, lang, isDark,
43
- })}
52
+ theme={isDark ? 'dark_theme' : 'light_theme'}
44
53
  />
45
54
  );
46
55
  };
@@ -1,4 +1,5 @@
1
1
  import { colorPalette } from '@oanda/labs-widget-common';
2
+
2
3
  import { CurrencyName } from '../../../gql/types/graphql';
3
4
 
4
5
  export const X_LABEL_SIZE = 24;
@@ -1,5 +1,5 @@
1
1
  import { instrumentsConfig } from './constants';
2
- import { SortingParams, TooltipFormatterParams } from './types';
2
+ import type { SortingParams, TooltipFormatterParams } from './types';
3
3
 
4
4
  const tooltipFormatter = ({
5
5
  marker,
@@ -13,10 +13,7 @@ const tooltipFormatter = ({
13
13
  <div style="display:flex;align-items:center;">${marker} ${value}%</div>
14
14
  </div>`;
15
15
 
16
- const sortCurrencies = (a: SortingParams, b: SortingParams) => instrumentsConfig
17
- .indexOf(a.currency) - instrumentsConfig.indexOf(b.currency);
16
+ const sortCurrencies = (a: SortingParams, b: SortingParams) =>
17
+ instrumentsConfig.indexOf(a.currency) - instrumentsConfig.indexOf(b.currency);
18
18
 
19
- export {
20
- tooltipFormatter,
21
- sortCurrencies,
22
- };
19
+ export { sortCurrencies, tooltipFormatter };
@@ -1,17 +1,21 @@
1
1
  import { getGridLines } from '@oanda/labs-widget-common';
2
+
2
3
  import {
3
4
  CHART_HEIGHT,
4
5
  CHART_WIDTH,
5
- X_LABEL_SIZE,
6
- Y_LABEL_SIZE,
7
6
  darkBarColors,
8
7
  lightBarColors,
8
+ X_LABEL_SIZE,
9
+ Y_LABEL_SIZE,
9
10
  } from './constants';
10
- import { GetOptionProps } from './types';
11
11
  import { tooltipFormatter } from './formatters';
12
+ import type { GetOptionProps } from './types';
12
13
 
13
14
  export const getOption = ({
14
- values, currency, isDark, lang,
15
+ values,
16
+ currency,
17
+ isDark,
18
+ lang,
15
19
  }: GetOptionProps) => {
16
20
  const currencies = values.map((item) => item.currency);
17
21
  const percentages = values.map((item) => item.percentage);
@@ -45,21 +49,21 @@ export const getOption = ({
45
49
  bottom: `${X_LABEL_SIZE}px`,
46
50
  },
47
51
  ],
48
- graphic: [
49
- ...gridLines,
50
- ],
52
+ graphic: [...gridLines],
51
53
  tooltip: {
52
54
  trigger: 'axis',
53
- formatter: (
54
- [{ marker, name, value }]
55
- : { marker: string, name: string, value: number }[],
56
- ) => tooltipFormatter({
57
- lang,
58
- currency,
59
- marker,
60
- name,
61
- value,
62
- }),
55
+ formatter: ([{ marker, name, value }]: {
56
+ marker: string;
57
+ name: string;
58
+ value: number;
59
+ }[]) =>
60
+ tooltipFormatter({
61
+ lang,
62
+ currency,
63
+ marker,
64
+ name,
65
+ value,
66
+ }),
63
67
  axisPointer: {
64
68
  axis: 'x',
65
69
  },
@@ -97,7 +101,7 @@ export const getOption = ({
97
101
  },
98
102
  itemStyle: {
99
103
  opacity: 1,
100
- color: ({ data } : { data: number }) => {
104
+ color: ({ data }: { data: number }) => {
101
105
  if (data > 0) {
102
106
  return barColors.positive;
103
107
  }
@@ -1,4 +1,4 @@
1
- import { CurrencyName } from '../../../gql/types/graphql';
1
+ import type { CurrencyName } from '../../../gql/types/graphql';
2
2
 
3
3
  export interface CSChartDataValues {
4
4
  currency: CurrencyName;
@@ -17,13 +17,13 @@ export interface TooltipFormatterParams {
17
17
  lang: (label: string) => string;
18
18
  }
19
19
 
20
- export type GetOptionProps = {
21
- values: CSChartDataValues[],
22
- currency: CurrencyName,
23
- lang: (label: string) => string,
20
+ export interface GetOptionProps {
21
+ values: CSChartDataValues[];
22
+ currency: CurrencyName;
23
+ lang: (label: string) => string;
24
24
  isDark: boolean;
25
- };
25
+ }
26
26
 
27
- export type SortingParams = {
27
+ export interface SortingParams {
28
28
  currency: CurrencyName;
29
- };
29
+ }
@@ -1,38 +1,40 @@
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
- import { Theme, validateLocale, validateToolParams } from '@oanda/labs-widget-common';
5
+
4
6
  import { CurrencyStrengthWidget } from './CurrencyStrengthWidget';
5
7
 
6
- const {
7
- graphqlUrl,
8
- } = window.widgetsConfig || {};
8
+ const { graphqlUrl } = window.widgetsConfig || {};
9
9
 
10
- const currencyStrengthParamsElements = document.querySelectorAll('div[data-currency-strength-params]');
10
+ const currencyStrengthParamsElements = document.querySelectorAll(
11
+ 'div[data-currency-strength-params]'
12
+ );
11
13
 
12
14
  currencyStrengthParamsElements.forEach((element) => {
13
15
  const root = createRoot(element);
14
16
  const params = element.getAttribute('data-currency-strength-params');
15
17
  const mode = element.getAttribute('data-mode');
16
- const {
17
- currency, locale, logoLink,
18
- } = JSON.parse(params as string);
18
+ const { currency, locale, logoLink } = JSON.parse(params as string);
19
19
 
20
20
  const isParamError = validateToolParams({ locale, graphqlUrl }, [
21
21
  {
22
22
  name: 'locale',
23
- valueCheck: (value) => validateLocale(value),
24
- }, {
23
+ valueCheck: (value: string | undefined) => validateLocale(value),
24
+ },
25
+ {
25
26
  name: 'graphqlUrl',
26
- }]);
27
+ },
28
+ ]);
27
29
 
28
30
  root.render(
29
31
  <CurrencyStrengthWidget
32
+ currency={currency}
30
33
  graphqlUrl={graphqlUrl}
31
- locale={locale}
32
- theme={mode as Theme}
33
34
  isParamError={isParamError}
34
- currency={currency}
35
+ locale={locale}
35
36
  logoLink={logoLink}
36
- />,
37
+ theme={mode as Theme}
38
+ />
37
39
  );
38
40
  });
@@ -1,4 +1,4 @@
1
- import { Theme, WidgetConfig } from '@oanda/labs-widget-common';
1
+ import type { Theme, WidgetConfig } from '@oanda/labs-widget-common';
2
2
 
3
3
  export interface CurrencyStrengthConfig extends WidgetConfig {
4
4
  currency?: string;
@@ -1,18 +1,21 @@
1
- import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
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
- 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 } }
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: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
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: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
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: FragmentType<DocumentTypeDecoration<TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
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: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined
66
+ data:
67
+ | FragmentType<TypedDocumentNode<Incremental<TFrag>, any>>
68
+ | null
69
+ | undefined
55
70
  ): data is FragmentType<typeof fragmentNode> {
56
- const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__
57
- ?.deferredFields;
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 FragmentDefinitionNode | undefined;
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
  }
@@ -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
- "\n query GetCurrencyStrength {\n currencyStrength {\n currency\n strengthRelation {\n currency\n percentage\n }\n updatedAt\n }\n }\n": types.GetCurrencyStrengthDocument,
16
+ '\n query GetCurrencyStrength {\n currencyStrength {\n currency\n strengthRelation {\n currency\n percentage\n }\n updatedAt\n }\n }\n':
17
+ types.GetCurrencyStrengthDocument,
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(source: "\n query GetCurrencyStrength {\n currencyStrength {\n currency\n strengthRelation {\n currency\n percentage\n }\n updatedAt\n }\n }\n"): (typeof documents)["\n query GetCurrencyStrength {\n currencyStrength {\n currency\n strengthRelation {\n currency\n percentage\n }\n updatedAt\n }\n }\n"];
37
+ export function graphql(
38
+ source: '\n query GetCurrencyStrength {\n currencyStrength {\n currency\n strengthRelation {\n currency\n percentage\n }\n updatedAt\n }\n }\n'
39
+ ): (typeof documents)['\n query GetCurrencyStrength {\n currencyStrength {\n currency\n strengthRelation {\n currency\n percentage\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>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;
45
+ export type DocumentType<TDocumentNode extends DocumentNode<any, any>> =
46
+ TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;