@oanda/labs-order-book-widget 1.0.172 → 1.0.174

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 (94) hide show
  1. package/CHANGELOG.md +1364 -0
  2. package/dist/main/OrderBookWidget/ChartWithData.js +5 -7
  3. package/dist/main/OrderBookWidget/ChartWithData.js.map +1 -1
  4. package/dist/main/OrderBookWidget/Main.js +12 -12
  5. package/dist/main/OrderBookWidget/Main.js.map +1 -1
  6. package/dist/main/OrderBookWidget/OrderBookWidget.js +14 -19
  7. package/dist/main/OrderBookWidget/OrderBookWidget.js.map +1 -1
  8. package/dist/main/OrderBookWidget/components/Chart/Chart.js +15 -15
  9. package/dist/main/OrderBookWidget/components/Chart/Chart.js.map +1 -1
  10. package/dist/main/OrderBookWidget/components/Chart/formatters.js.map +1 -1
  11. package/dist/main/OrderBookWidget/components/Chart/getOption.js.map +1 -1
  12. package/dist/main/OrderBookWidget/components/Chart/types.js.map +1 -1
  13. package/dist/main/OrderBookWidget/config.js.map +1 -1
  14. package/dist/main/OrderBookWidget/render.js +9 -9
  15. package/dist/main/OrderBookWidget/render.js.map +1 -1
  16. package/dist/main/OrderBookWidget/types.js.map +1 -1
  17. package/dist/main/gql/getOrderPositionBooks.js +5 -1
  18. package/dist/main/gql/getOrderPositionBooks.js.map +1 -1
  19. package/dist/main/gql/types/fragment-masking.js.map +1 -1
  20. package/dist/main/gql/types/gql.js +1 -1
  21. package/dist/main/gql/types/gql.js.map +1 -1
  22. package/dist/main/gql/types/graphql.js +114 -114
  23. package/dist/main/gql/types/graphql.js.map +1 -1
  24. package/dist/main/gql/types/index.js.map +1 -1
  25. package/dist/main/index.js +8 -8
  26. package/dist/main/index.js.map +1 -1
  27. package/dist/main/translations/index.js +1 -1
  28. package/dist/main/translations/index.js.map +1 -1
  29. package/dist/main/translations/translations.js.map +1 -1
  30. package/dist/module/OrderBookWidget/ChartWithData.js +6 -6
  31. package/dist/module/OrderBookWidget/ChartWithData.js.map +1 -1
  32. package/dist/module/OrderBookWidget/Main.js +12 -12
  33. package/dist/module/OrderBookWidget/Main.js.map +1 -1
  34. package/dist/module/OrderBookWidget/OrderBookWidget.js +15 -20
  35. package/dist/module/OrderBookWidget/OrderBookWidget.js.map +1 -1
  36. package/dist/module/OrderBookWidget/components/Chart/Chart.js +15 -15
  37. package/dist/module/OrderBookWidget/components/Chart/Chart.js.map +1 -1
  38. package/dist/module/OrderBookWidget/components/Chart/formatters.js.map +1 -1
  39. package/dist/module/OrderBookWidget/components/Chart/getOption.js +1 -1
  40. package/dist/module/OrderBookWidget/components/Chart/getOption.js.map +1 -1
  41. package/dist/module/OrderBookWidget/components/Chart/types.js.map +1 -1
  42. package/dist/module/OrderBookWidget/config.js +1 -1
  43. package/dist/module/OrderBookWidget/config.js.map +1 -1
  44. package/dist/module/OrderBookWidget/render.js +10 -10
  45. package/dist/module/OrderBookWidget/render.js.map +1 -1
  46. package/dist/module/OrderBookWidget/types.js.map +1 -1
  47. package/dist/module/gql/getOrderPositionBooks.js +5 -1
  48. package/dist/module/gql/getOrderPositionBooks.js.map +1 -1
  49. package/dist/module/gql/types/fragment-masking.js.map +1 -1
  50. package/dist/module/gql/types/gql.js +1 -1
  51. package/dist/module/gql/types/gql.js.map +1 -1
  52. package/dist/module/gql/types/graphql.js +114 -114
  53. package/dist/module/gql/types/graphql.js.map +1 -1
  54. package/dist/module/gql/types/index.js +2 -2
  55. package/dist/module/gql/types/index.js.map +1 -1
  56. package/dist/module/index.js +1 -1
  57. package/dist/module/index.js.map +1 -1
  58. package/dist/module/translations/index.js +1 -1
  59. package/dist/module/translations/index.js.map +1 -1
  60. package/dist/module/translations/translations.js.map +1 -1
  61. package/dist/types/OrderBookWidget/ChartWithData.d.ts +2 -2
  62. package/dist/types/OrderBookWidget/Main.d.ts +1 -1
  63. package/dist/types/OrderBookWidget/OrderBookWidget.d.ts +1 -1
  64. package/dist/types/OrderBookWidget/components/Chart/Chart.d.ts +1 -1
  65. package/dist/types/OrderBookWidget/components/Chart/formatters.d.ts +1 -1
  66. package/dist/types/OrderBookWidget/components/Chart/getOption.d.ts +1 -1
  67. package/dist/types/OrderBookWidget/components/Chart/types.d.ts +2 -2
  68. package/dist/types/OrderBookWidget/config.d.ts +1 -1
  69. package/dist/types/OrderBookWidget/types.d.ts +2 -2
  70. package/dist/types/gql/types/gql.d.ts +2 -2
  71. package/dist/types/gql/types/index.d.ts +2 -2
  72. package/dist/types/index.d.ts +1 -1
  73. package/dist/types/translations/index.d.ts +2 -2
  74. package/package.json +3 -3
  75. package/src/OrderBookWidget/ChartWithData.tsx +42 -41
  76. package/src/OrderBookWidget/Main.tsx +49 -31
  77. package/src/OrderBookWidget/OrderBookWidget.tsx +19 -22
  78. package/src/OrderBookWidget/components/Chart/Chart.tsx +42 -30
  79. package/src/OrderBookWidget/components/Chart/formatters.ts +11 -4
  80. package/src/OrderBookWidget/components/Chart/getOption.ts +205 -188
  81. package/src/OrderBookWidget/components/Chart/types.ts +10 -13
  82. package/src/OrderBookWidget/config.ts +76 -53
  83. package/src/OrderBookWidget/render.tsx +81 -52
  84. package/src/OrderBookWidget/types.ts +3 -2
  85. package/src/gql/getOrderPositionBooks.ts +5 -1
  86. package/src/gql/types/fragment-masking.ts +41 -21
  87. package/src/gql/types/gql.ts +7 -3
  88. package/src/gql/types/graphql.ts +165 -44
  89. package/src/gql/types/index.ts +2 -2
  90. package/src/index.ts +1 -1
  91. package/src/translations/index.ts +4 -4
  92. package/src/translations/translations.ts +1 -3
  93. package/test/Main.test.tsx +17 -14
  94. package/test/chartOptions.test.ts +18 -12
@@ -1,4 +1,4 @@
1
- import { GetOptionType, GetResponsiveOptionsProps } from './types';
1
+ import type { GetOptionType, GetResponsiveOptionsProps } from './types';
2
2
  export declare const getResponsiveOption: ({ isDark, isOrderBook, isDesktop, lang, }: GetResponsiveOptionsProps) => {
3
3
  grid: {
4
4
  name: string;
@@ -1,5 +1,5 @@
1
- import { EChartsOption } from 'echarts';
2
- import { GetOrderPositionBooksQuery } from '../../../gql/types/graphql';
1
+ import type { EChartsOption } from 'echarts';
2
+ import type { GetOrderPositionBooksQuery } from '../../../gql/types/graphql';
3
3
  export interface ChartProps {
4
4
  data: GetOrderPositionBooksQuery;
5
5
  isOrderBook: boolean;
@@ -13,4 +13,4 @@ declare const instrumentSelectConfig: {
13
13
  label: string;
14
14
  }[];
15
15
  declare const instrumentPrecisionConfig: Record<InstrumentId, number>;
16
- export { navigationConfig, instrumentSelectConfig, instrumentPrecisionConfig, instrumentSelectConfigOC, };
16
+ export { instrumentPrecisionConfig, instrumentSelectConfig, instrumentSelectConfigOC, navigationConfig, };
@@ -1,5 +1,5 @@
1
- import { WidgetConfig } from '@oanda/labs-widget-common';
2
- import { BookType, Division } from '../gql/types/graphql';
1
+ import type { WidgetConfig } from '@oanda/labs-widget-common';
2
+ import type { BookType, Division } from '../gql/types/graphql';
3
3
  export interface OrderBookWidgetConfig extends WidgetConfig {
4
4
  instrument: InstrumentId;
5
5
  division: Division;
@@ -11,7 +11,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
11
11
  * Therefore it is highly recommended to use the babel or swc plugin for production.
12
12
  */
13
13
  declare const documents: {
14
- "\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n time\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n": DocumentNode<types.GetOrderPositionBooksQuery, types.Exact<{
14
+ '\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n time\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n': DocumentNode<types.GetOrderPositionBooksQuery, types.Exact<{
15
15
  instrument: types.Scalars["String"]["input"];
16
16
  bookType: types.BookType;
17
17
  recentHours?: types.InputMaybe<types.Scalars["Int"]["input"]>;
@@ -33,6 +33,6 @@ export declare function graphql(source: string): unknown;
33
33
  /**
34
34
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
35
35
  */
36
- export declare function graphql(source: "\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n time\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n"): (typeof documents)["\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n time\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n"];
36
+ export declare function graphql(source: '\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n time\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n'): (typeof documents)['\n query GetOrderPositionBooks($instrument: String!, $bookType: BookType!, $recentHours: Int) {\n orderPositionBooks(\n instrument: $instrument\n bookType: $bookType\n recentHours: $recentHours\n ) {\n bucketWidth\n price\n time\n buckets {\n price\n longCountPercent\n shortCountPercent\n }\n }\n }\n'];
37
37
  export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;
38
38
  export {};
@@ -1,2 +1,2 @@
1
- export * from "./fragment-masking";
2
- export * from "./gql";
1
+ export * from './fragment-masking';
2
+ export * from './gql';
@@ -1,2 +1,2 @@
1
- export * from './OrderBookWidget/types';
2
1
  export * from './OrderBookWidget/OrderBookWidget';
2
+ export * from './OrderBookWidget/types';
@@ -1,4 +1,4 @@
1
- import { Translations } from '@oanda/mono-i18n';
2
- import { defaultTranslations } from './translations';
1
+ import type { Translations } from '@oanda/mono-i18n';
2
+ import type { defaultTranslations } from './translations';
3
3
  export type TranslationKey = keyof typeof defaultTranslations;
4
4
  export declare const translations: Translations;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oanda/labs-order-book-widget",
3
- "version": "1.0.172",
3
+ "version": "1.0.174",
4
4
  "description": "Labs Order Book Widget",
5
5
  "main": "dist/main/index.js",
6
6
  "module": "dist/module/index.js",
@@ -12,7 +12,7 @@
12
12
  "author": "OANDA",
13
13
  "license": "UNLICENSED",
14
14
  "dependencies": {
15
- "@oanda/labs-widget-common": "^1.0.172",
15
+ "@oanda/labs-widget-common": "^1.0.174",
16
16
  "@oanda/mono-i18n": "10.0.1",
17
17
  "echarts": "5.5.0",
18
18
  "echarts-for-react": "3.0.2",
@@ -23,5 +23,5 @@
23
23
  "@graphql-codegen/client-preset": "4.1.0",
24
24
  "@graphql-codegen/typescript": "4.0.1"
25
25
  },
26
- "gitHead": "f3c94dbb01bc271f175ba95700c51001c4099a52"
26
+ "gitHead": "4c5d84b00c7fbf3acd7ef27634fbd2a9ef0afd6b"
27
27
  }
@@ -1,32 +1,34 @@
1
- import React, { useContext } from 'react';
2
1
  import { useQuery } from '@apollo/client';
3
- import classnames from 'classnames';
4
2
  import {
5
3
  ChartError,
6
4
  LastUpdated,
7
5
  Size,
8
6
  Spinner,
9
7
  SpinnerSize,
10
- ThemeContext,
8
+ useLayoutProvider,
11
9
  } from '@oanda/labs-widget-common';
12
10
  import { useLocale } from '@oanda/mono-i18n';
13
- import { ChartWithDataProps } from './types';
11
+ import classnames from 'classnames';
12
+ import React from 'react';
13
+
14
14
  import { getOrderPositionBooks } from '../gql/getOrderPositionBooks';
15
- import { GetOrderPositionBooksQuery, GetOrderPositionBooksQueryVariables, BookType } from '../gql/types/graphql';
15
+ import type {
16
+ GetOrderPositionBooksQuery,
17
+ GetOrderPositionBooksQueryVariables,
18
+ } from '../gql/types/graphql';
19
+ import { BookType } from '../gql/types/graphql';
16
20
  import { Chart } from './components/Chart/Chart';
17
21
  import { instrumentPrecisionConfig } from './config';
22
+ import type { ChartWithDataProps } from './types';
18
23
 
19
- const ChartWithData = ({
20
- instrument,
21
- bookType,
22
- }: ChartWithDataProps) => {
24
+ const ChartWithData = ({ instrument, bookType }: ChartWithDataProps) => {
23
25
  const { lang } = useLocale();
24
- const { size } = useContext(ThemeContext);
26
+ const { size } = useLayoutProvider();
25
27
  const isDesktop = size === Size.DESKTOP;
26
28
 
27
29
  const { loading, data, error } = useQuery<
28
- GetOrderPositionBooksQuery,
29
- GetOrderPositionBooksQueryVariables
30
+ GetOrderPositionBooksQuery,
31
+ GetOrderPositionBooksQueryVariables
30
32
  >(getOrderPositionBooks, {
31
33
  variables: {
32
34
  instrument,
@@ -41,38 +43,37 @@ const ChartWithData = ({
41
43
 
42
44
  return (
43
45
  <>
44
- <div className={classnames('lw-relative lw-w-full', {
45
- 'lw-h-[450px]': isDesktop,
46
- 'lw-h-[390px]': !isDesktop,
47
- })}
46
+ <div
47
+ className={classnames('lw-relative lw-w-full', {
48
+ 'lw-h-[450px]': isDesktop,
49
+ 'lw-h-[390px]': !isDesktop,
50
+ })}
48
51
  >
49
52
  {isError && (
50
- <div className={
51
- classnames(
52
- 'lw-absolute lw-left-0 lw-top-0 lw-flex lw-w-full lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary',
53
- {
54
- 'lw-h-full': isDesktop,
55
- 'lw-h-[calc(100%-40px)]': !isDesktop,
56
- },
57
- )
58
- }
59
- >
60
- <ChartError />
61
- </div>
53
+ <div
54
+ className={classnames(
55
+ 'lw-absolute lw-left-0 lw-top-0 lw-flex lw-w-full lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary',
56
+ {
57
+ 'lw-h-full': isDesktop,
58
+ 'lw-h-[calc(100%-40px)]': !isDesktop,
59
+ }
60
+ )}
61
+ >
62
+ <ChartError />
63
+ </div>
62
64
  )}
63
65
  {loading && (
64
- <div className={
65
- classnames(
66
- 'lw-absolute lw-left-0 lw-top-0 lw-flex lw-w-full lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary',
67
- {
68
- 'lw-h-full': isDesktop,
69
- 'lw-h-[calc(100%-40px)]': !isDesktop,
70
- },
71
- )
72
- }
73
- >
74
- <Spinner size={SpinnerSize.lg} />
75
- </div>
66
+ <div
67
+ className={classnames(
68
+ 'lw-absolute lw-left-0 lw-top-0 lw-flex lw-w-full lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary',
69
+ {
70
+ 'lw-h-full': isDesktop,
71
+ 'lw-h-[calc(100%-40px)]': !isDesktop,
72
+ }
73
+ )}
74
+ >
75
+ <Spinner size={SpinnerSize.lg} />
76
+ </div>
76
77
  )}
77
78
  {!isError && data && (
78
79
  <div className="lw-absolute lw-left-0 lw-top-0 lw-flex lw-h-full lw-w-full">
@@ -86,7 +87,7 @@ const ChartWithData = ({
86
87
  </div>
87
88
  <div className="lw-mt-2 lw-h-8">
88
89
  {!loading && !isError && (
89
- <LastUpdated timestamp={updatedAt} labelCallback={lang} />
90
+ <LastUpdated labelCallback={lang} timestamp={updatedAt} />
90
91
  )}
91
92
  </div>
92
93
  </>
@@ -1,17 +1,28 @@
1
- import React, { useState, useContext } from 'react';
2
- import classnames from 'classnames';
3
1
  import {
4
- Select, Size, Tabs, ThemeContext,
2
+ Select,
3
+ Size,
4
+ Tabs,
5
+ useLayoutProvider,
5
6
  } from '@oanda/labs-widget-common';
6
7
  import { useLocale } from '@oanda/mono-i18n';
7
- import { InstrumentId, MainProps } from './types';
8
+ import classnames from 'classnames';
9
+ import React, { useState } from 'react';
10
+
8
11
  import { BookType, Division } from '../gql/types/graphql';
9
- import { instrumentSelectConfig, instrumentSelectConfigOC, navigationConfig } from './config';
10
12
  import { ChartWithData } from './ChartWithData';
13
+ import {
14
+ instrumentSelectConfig,
15
+ instrumentSelectConfigOC,
16
+ navigationConfig,
17
+ } from './config';
18
+ import type { InstrumentId, MainProps } from './types';
11
19
 
12
20
  const Main = ({ instrument, division }: MainProps) => {
13
- const selectConfig = division === Division.Oc ? instrumentSelectConfigOC : instrumentSelectConfig;
14
- const { size } = useContext(ThemeContext);
21
+ const selectConfig =
22
+ division === Division.Oc
23
+ ? instrumentSelectConfigOC
24
+ : instrumentSelectConfig;
25
+ const { size } = useLayoutProvider();
15
26
  const isDesktop = size === Size.DESKTOP;
16
27
  const [bookType, setBookType] = useState(BookType.Order);
17
28
  const [toolInstrument, setToolInstrument] = useState(selectConfig[0]);
@@ -20,33 +31,40 @@ const Main = ({ instrument, division }: MainProps) => {
20
31
  return (
21
32
  <>
22
33
  {size && (
23
- <div data-testid="order-book-widget" className="lw-text-sm lw-tracking-normal">
24
- <Tabs
25
- activeTab={bookType}
26
- handleClick={(e) => setBookType(e.currentTarget.value as BookType)}
27
- labelCallback={lang}
28
- items={navigationConfig}
29
- mobileFullWidth
30
- />
31
- {!instrument && (
32
- <div className={classnames('lw-mb-6 lw-mt-12 ', {
33
- 'lw-w-full': !isDesktop,
34
- 'lw-w-[280px]': isDesktop,
35
- })}
34
+ <div
35
+ className="lw-text-sm lw-tracking-normal"
36
+ data-testid="order-book-widget"
36
37
  >
37
- <Select
38
- searchPlaceholder={lang('search')}
39
- selectLabel={lang('instrument')}
40
- options={selectConfig}
41
- selectedOption={toolInstrument}
42
- setSelectedOption={
43
- (val) => setToolInstrument(val as { id: InstrumentId; label: string })
44
- }
38
+ <Tabs
39
+ mobileFullWidth
40
+ activeTab={bookType}
41
+ handleClick={(e) => setBookType(e.currentTarget.value as BookType)}
42
+ items={navigationConfig}
43
+ labelCallback={lang}
44
+ />
45
+ {!instrument && (
46
+ <div
47
+ className={classnames('lw-mb-6 lw-mt-12 ', {
48
+ 'lw-w-full': !isDesktop,
49
+ 'lw-w-[280px]': isDesktop,
50
+ })}
51
+ >
52
+ <Select
53
+ options={selectConfig}
54
+ searchPlaceholder={lang('search')}
55
+ selectLabel={lang('instrument')}
56
+ selectedOption={toolInstrument}
57
+ setSelectedOption={(val) =>
58
+ setToolInstrument(val as { id: InstrumentId; label: string })
59
+ }
60
+ />
61
+ </div>
62
+ )}
63
+ <ChartWithData
64
+ bookType={bookType}
65
+ instrument={instrument || toolInstrument.id}
45
66
  />
46
67
  </div>
47
- )}
48
- <ChartWithData instrument={instrument || toolInstrument.id} bookType={bookType} />
49
- </div>
50
68
  )}
51
69
  </>
52
70
  );
@@ -1,12 +1,10 @@
1
+ import { ApolloClient, InMemoryCache } from '@apollo/client';
2
+ import { WidgetProvider, WidgetWrapper } from '@oanda/labs-widget-common';
1
3
  import React from 'react';
2
- import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
3
- import { LocaleProvider } from '@oanda/mono-i18n';
4
- import {
5
- ChartError, ThemeProvider, getLocale, renderComponent,
6
- } from '@oanda/labs-widget-common';
7
- import { Main } from './Main';
8
- import { OrderBookWidgetConfig } from './types';
4
+
9
5
  import { translations } from '../translations';
6
+ import { Main } from './Main';
7
+ import type { OrderBookWidgetConfig } from './types';
10
8
 
11
9
  const OrderBookWidget = ({
12
10
  graphqlUrl,
@@ -23,21 +21,20 @@ const OrderBookWidget = ({
23
21
  });
24
22
 
25
23
  return (
26
- <ThemeProvider theme={theme}>
27
- <LocaleProvider locale={getLocale(locale)} translations={translations}>
28
- <ApolloProvider client={client}>
29
- {isParamError ? (
30
- <div className="lw-flex lw-h-[425px] lw-w-full lw-items-center lw-border lw-border-solid lw-border-border-primary">
31
- <ChartError />
32
- </div>
33
- ) : renderComponent({
34
- Component: <Main instrument={instrument} division={division} />,
35
- logoLink,
36
- linkArea: 'logo',
37
- })}
38
- </ApolloProvider>
39
- </LocaleProvider>
40
- </ThemeProvider>
24
+ <WidgetProvider
25
+ client={client}
26
+ locale={locale}
27
+ theme={theme}
28
+ translations={translations}
29
+ >
30
+ <WidgetWrapper
31
+ isParamError={isParamError}
32
+ linkArea="logo"
33
+ logoLink={logoLink}
34
+ >
35
+ <Main division={division} instrument={instrument} />
36
+ </WidgetWrapper>
37
+ </WidgetProvider>
41
38
  );
42
39
  };
43
40
 
@@ -1,24 +1,29 @@
1
- import React, { useRef, useEffect, useContext } from 'react';
2
- import ReactEChartsCore from 'echarts-for-react/lib/core';
3
- import * as echarts from 'echarts/core';
1
+ import {
2
+ colorPalette,
3
+ getChartTheme,
4
+ Size,
5
+ Theme,
6
+ useLayoutProvider,
7
+ } from '@oanda/labs-widget-common';
8
+ import { useLocale } from '@oanda/mono-i18n';
4
9
  import { CustomChart } from 'echarts/charts';
5
- import { CanvasRenderer } from 'echarts/renderers';
6
10
  import {
7
- GridSimpleComponent,
11
+ DatasetComponent,
12
+ DataZoomInsideComponent,
8
13
  GraphicComponent,
9
- TooltipComponent,
10
- TitleComponent,
14
+ GridSimpleComponent,
11
15
  MarkLineComponent,
16
+ TitleComponent,
12
17
  ToolboxComponent,
13
- DataZoomInsideComponent,
14
- DatasetComponent,
18
+ TooltipComponent,
15
19
  } from 'echarts/components';
16
- import {
17
- Theme, ThemeContext, colorPalette, getChartTheme, Size,
18
- } from '@oanda/labs-widget-common';
19
- import { useLocale } from '@oanda/mono-i18n';
20
- import { getResponsiveOption, getOption } from './getOption';
21
- import { ChartProps } from './types';
20
+ import * as echarts from 'echarts/core';
21
+ import { CanvasRenderer } from 'echarts/renderers';
22
+ import ReactEChartsCore from 'echarts-for-react/lib/core';
23
+ import React, { useEffect, useRef } from 'react';
24
+
25
+ import { getOption, getResponsiveOption } from './getOption';
26
+ import type { ChartProps } from './types';
22
27
 
23
28
  echarts.use([
24
29
  GridSimpleComponent,
@@ -38,19 +43,19 @@ echarts.registerTheme('light_theme', getChartTheme(Theme.Light));
38
43
 
39
44
  export const Chart = ({ data, isOrderBook, precision }: ChartProps) => {
40
45
  const { lang } = useLocale();
41
- const { isDark, size } = useContext(ThemeContext);
46
+ const { isDark, size } = useLayoutProvider();
42
47
  const isDesktop = size === Size.DESKTOP;
43
48
 
44
- const echartRef = useRef(null);
49
+ const echartRef = useRef<ReactEChartsCore | null>(null);
45
50
 
46
51
  useEffect(() => {
47
52
  if (echartRef.current) {
48
- // @ts-ignore
49
- const echartInstance = echartRef.current.getEchartsInstance() as echarts.EChartsType;
53
+ const echartInstance = echartRef.current.getEchartsInstance();
50
54
 
51
55
  echartInstance.on('highlight', () => {
52
- if ((
53
- echartInstance.getOption().color as echarts.Color[])[0] === colorPalette.bottleGreenLight
56
+ if (
57
+ (echartInstance.getOption().color as echarts.Color[])[0] ===
58
+ colorPalette.bottleGreenLight
54
59
  ) {
55
60
  echartInstance.setOption({
56
61
  color: [
@@ -74,13 +79,15 @@ export const Chart = ({ data, isOrderBook, precision }: ChartProps) => {
74
79
 
75
80
  useEffect(() => {
76
81
  if (echartRef.current) {
77
- // @ts-ignore
78
- const echartInstance = echartRef.current.getEchartsInstance() as echarts.EChartsType;
82
+ const echartInstance = echartRef.current.getEchartsInstance();
79
83
 
80
84
  echartInstance.setOption(
81
85
  getResponsiveOption({
82
- isDark, isOrderBook, isDesktop, lang,
83
- }),
86
+ isDark,
87
+ isOrderBook,
88
+ isDesktop,
89
+ lang,
90
+ })
84
91
  );
85
92
  }
86
93
  }, [echartRef, isDesktop, isDark, isOrderBook, lang]);
@@ -90,16 +97,21 @@ export const Chart = ({ data, isOrderBook, precision }: ChartProps) => {
90
97
  <div>
91
98
  {data && (
92
99
  <ReactEChartsCore
93
- echarts={echarts}
94
100
  ref={echartRef}
95
- theme={isDark ? 'dark_theme' : 'light_theme'}
101
+ echarts={echarts}
102
+ option={getOption({
103
+ data,
104
+ precision,
105
+ isDark,
106
+ isOrderBook,
107
+ isDesktop,
108
+ lang,
109
+ })}
96
110
  style={{
97
111
  height: isDesktop ? '450px' : '390px',
98
112
  width: '100%',
99
113
  }}
100
- option={getOption({
101
- data, precision, isDark, isOrderBook, isDesktop, lang,
102
- })}
114
+ theme={isDark ? 'dark_theme' : 'light_theme'}
103
115
  />
104
116
  )}
105
117
  </div>
@@ -1,11 +1,18 @@
1
- import { TooltipFormatterType } from './types';
1
+ import type { TooltipFormatterType } from './types';
2
2
 
3
3
  const tooltipFormatter: TooltipFormatterType = ({
4
- data, precision, isOrderBook, lang,
4
+ data,
5
+ precision,
6
+ isOrderBook,
7
+ lang,
5
8
  }) => {
6
9
  const priceText = `${lang('price')}: ${data[0].toFixed(precision)}`;
7
- const buyText = data[1] ? `<br />${lang(isOrderBook ? 'buy' : 'long_positions')}: ${data[1]}%` : '';
8
- const sellText = data[2] ? `<br />${lang(isOrderBook ? 'sell' : 'short_positions')}: ${data[2] * -1}%` : '';
10
+ const buyText = data[1]
11
+ ? `<br />${lang(isOrderBook ? 'buy' : 'long_positions')}: ${data[1]}%`
12
+ : '';
13
+ const sellText = data[2]
14
+ ? `<br />${lang(isOrderBook ? 'sell' : 'short_positions')}: ${data[2] * -1}%`
15
+ : '';
9
16
 
10
17
  return priceText + buyText + sellText;
11
18
  };