@oanda/labs-sentiment-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.
- package/CHANGELOG.md +1364 -0
- package/dist/main/SentimentWidget/SentimentWidget.js +18 -23
- package/dist/main/SentimentWidget/SentimentWidget.js.map +1 -1
- package/dist/main/SentimentWidget/Tool.js +18 -18
- package/dist/main/SentimentWidget/Tool.js.map +1 -1
- package/dist/main/SentimentWidget/Widget.js +15 -17
- package/dist/main/SentimentWidget/Widget.js.map +1 -1
- package/dist/main/SentimentWidget/components/SortSwitch/SortSwitch.js +14 -16
- package/dist/main/SentimentWidget/components/SortSwitch/SortSwitch.js.map +1 -1
- package/dist/main/SentimentWidget/render.js +9 -9
- package/dist/main/SentimentWidget/render.js.map +1 -1
- package/dist/main/SentimentWidget/types.js.map +1 -1
- package/dist/main/SentimentWidget/utils.js.map +1 -1
- package/dist/main/gql/getInstrumentSentiment.js +2 -8
- package/dist/main/gql/getInstrumentSentiment.js.map +1 -1
- package/dist/main/gql/getSentimentList.js +2 -6
- package/dist/main/gql/getSentimentList.js.map +1 -1
- package/dist/main/gql/types/fragment-masking.js.map +1 -1
- package/dist/main/gql/types/gql.js +2 -2
- package/dist/main/gql/types/gql.js.map +1 -1
- package/dist/main/gql/types/graphql.js +154 -154
- package/dist/main/gql/types/graphql.js.map +1 -1
- package/dist/main/gql/types/index.js.map +1 -1
- package/dist/main/index.js +8 -8
- package/dist/main/index.js.map +1 -1
- package/dist/main/translations/index.js +1 -1
- package/dist/main/translations/index.js.map +1 -1
- package/dist/main/translations/translations.js.map +1 -1
- package/dist/module/SentimentWidget/SentimentWidget.js +19 -24
- package/dist/module/SentimentWidget/SentimentWidget.js.map +1 -1
- package/dist/module/SentimentWidget/Tool.js +17 -17
- package/dist/module/SentimentWidget/Tool.js.map +1 -1
- package/dist/module/SentimentWidget/Widget.js +16 -16
- package/dist/module/SentimentWidget/Widget.js.map +1 -1
- package/dist/module/SentimentWidget/components/SortSwitch/SortSwitch.js +14 -14
- package/dist/module/SentimentWidget/components/SortSwitch/SortSwitch.js.map +1 -1
- package/dist/module/SentimentWidget/render.js +9 -9
- package/dist/module/SentimentWidget/render.js.map +1 -1
- package/dist/module/SentimentWidget/types.js.map +1 -1
- package/dist/module/SentimentWidget/utils.js.map +1 -1
- package/dist/module/gql/getInstrumentSentiment.js +2 -8
- package/dist/module/gql/getInstrumentSentiment.js.map +1 -1
- package/dist/module/gql/getSentimentList.js +2 -6
- package/dist/module/gql/getSentimentList.js.map +1 -1
- package/dist/module/gql/types/fragment-masking.js.map +1 -1
- package/dist/module/gql/types/gql.js +2 -2
- package/dist/module/gql/types/gql.js.map +1 -1
- package/dist/module/gql/types/graphql.js +154 -154
- package/dist/module/gql/types/graphql.js.map +1 -1
- package/dist/module/gql/types/index.js +2 -2
- package/dist/module/gql/types/index.js.map +1 -1
- package/dist/module/index.js +1 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/translations/index.js +1 -1
- package/dist/module/translations/index.js.map +1 -1
- package/dist/module/translations/translations.js.map +1 -1
- package/dist/types/SentimentWidget/SentimentWidget.d.ts +1 -1
- package/dist/types/SentimentWidget/Tool.d.ts +1 -1
- package/dist/types/SentimentWidget/Widget.d.ts +1 -1
- package/dist/types/SentimentWidget/components/SortSwitch/SortSwitch.d.ts +2 -2
- package/dist/types/SentimentWidget/types.d.ts +2 -2
- package/dist/types/SentimentWidget/utils.d.ts +2 -1
- package/dist/types/gql/types/gql.d.ts +4 -4
- package/dist/types/gql/types/index.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/translations/index.d.ts +2 -2
- package/package.json +3 -3
- package/src/SentimentWidget/SentimentWidget.tsx +28 -33
- package/src/SentimentWidget/Tool.tsx +96 -80
- package/src/SentimentWidget/Widget.tsx +72 -66
- package/src/SentimentWidget/components/SortSwitch/SortSwitch.tsx +42 -39
- package/src/SentimentWidget/render.tsx +40 -28
- package/src/SentimentWidget/types.ts +3 -2
- package/src/SentimentWidget/utils.ts +12 -4
- package/src/gql/getInstrumentSentiment.ts +2 -8
- package/src/gql/getSentimentList.ts +2 -6
- package/src/gql/types/fragment-masking.ts +41 -21
- package/src/gql/types/gql.ts +12 -5
- package/src/gql/types/graphql.ts +225 -47
- package/src/gql/types/index.ts +2 -2
- package/src/index.ts +1 -1
- package/src/translations/index.ts +4 -4
- package/src/translations/translations.ts +2 -1
- package/test/SortSwitch.test.tsx +36 -23
- package/test/Tool.test.tsx +13 -11
- package/test/Widget.test.tsx +31 -26
- package/test/sortData.test.ts +49 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SentimentConfig } from './types';
|
|
2
|
+
import type { SentimentConfig } from './types';
|
|
3
3
|
declare const SentimentWidget: ({ graphqlUrl, division, instrument, locale, theme, includeDescriptionLabels, isParamError, logoLink, }: SentimentConfig) => React.JSX.Element;
|
|
4
4
|
export { SentimentWidget };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SentimentWidgetConfig } from './types';
|
|
2
|
+
import type { SentimentWidgetConfig } from './types';
|
|
3
3
|
declare const Widget: ({ instrument, division, includeDescriptionLabels, }: SentimentWidgetConfig) => React.JSX.Element;
|
|
4
4
|
export { Widget };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SortSwitchProps } from './types';
|
|
2
|
+
import type { SortSwitchProps } from './types';
|
|
3
3
|
declare const SortSwitch: ({ onClickButtonDown, onClickButtonUp, selected, disabled, }: SortSwitchProps) => React.JSX.Element;
|
|
4
|
-
export { SortSwitch
|
|
4
|
+
export { SortSwitch };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WidgetConfig } from '@oanda/labs-widget-common';
|
|
2
|
-
import { Division } from '../gql/types/graphql';
|
|
1
|
+
import type { WidgetConfig } from '@oanda/labs-widget-common';
|
|
2
|
+
import type { Division } from '../gql/types/graphql';
|
|
3
3
|
export interface SentimentConfig extends WidgetConfig {
|
|
4
4
|
division: Division;
|
|
5
5
|
instrument?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { GetSentimentListQuery
|
|
1
|
+
import type { GetSentimentListQuery } from '../gql/types/graphql';
|
|
2
|
+
import { Sort } from '../gql/types/graphql';
|
|
2
3
|
export declare const sortData: ({ sentimentList }: GetSentimentListQuery, sort: Sort) => {
|
|
3
4
|
__typename?: "SentimentInstrument";
|
|
4
5
|
name: string;
|
|
@@ -11,11 +11,11 @@ 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
|
-
|
|
14
|
+
'\n query GetInstrumentSentiment(\n $name: String!\n $division: Division\n ) {\n sentiment(\n name: $name\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n': DocumentNode<types.GetInstrumentSentimentQuery, types.Exact<{
|
|
15
15
|
name: types.Scalars["String"]["input"];
|
|
16
16
|
division?: types.InputMaybe<types.Division>;
|
|
17
17
|
}>>;
|
|
18
|
-
|
|
18
|
+
'\n query GetSentimentList (\n $division: Division\n ) {\n sentimentList (\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n': DocumentNode<types.GetSentimentListQuery, types.Exact<{
|
|
19
19
|
division?: types.InputMaybe<types.Division>;
|
|
20
20
|
}>>;
|
|
21
21
|
};
|
|
@@ -35,10 +35,10 @@ export declare function graphql(source: string): unknown;
|
|
|
35
35
|
/**
|
|
36
36
|
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
37
37
|
*/
|
|
38
|
-
export declare function graphql(source:
|
|
38
|
+
export declare function graphql(source: '\n query GetInstrumentSentiment(\n $name: String!\n $division: Division\n ) {\n sentiment(\n name: $name\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n'): (typeof documents)['\n query GetInstrumentSentiment(\n $name: String!\n $division: Division\n ) {\n sentiment(\n name: $name\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n'];
|
|
39
39
|
/**
|
|
40
40
|
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
41
41
|
*/
|
|
42
|
-
export declare function graphql(source:
|
|
42
|
+
export declare function graphql(source: '\n query GetSentimentList (\n $division: Division\n ) {\n sentimentList (\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n'): (typeof documents)['\n query GetSentimentList (\n $division: Division\n ) {\n sentimentList (\n division: $division\n ) {\n name\n displayName\n sentiment {\n shortPercent\n longPercent\n }\n updatedAt\n }\n }\n'];
|
|
43
43
|
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;
|
|
44
44
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './fragment-masking';
|
|
2
|
+
export * from './gql';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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-sentiment-widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.174",
|
|
4
4
|
"description": "Labs Sentiment 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.
|
|
15
|
+
"@oanda/labs-widget-common": "^1.0.174",
|
|
16
16
|
"@oanda/mono-i18n": "10.0.1",
|
|
17
17
|
"graphql": "16.8.1"
|
|
18
18
|
},
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"@graphql-codegen/cli": "5.0.0",
|
|
21
21
|
"@graphql-codegen/client-preset": "4.1.0"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "4c5d84b00c7fbf3acd7ef27634fbd2a9ef0afd6b"
|
|
24
24
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import { ApolloClient, InMemoryCache } from '@apollo/client';
|
|
2
|
+
import { WidgetProvider, WidgetWrapper } from '@oanda/labs-widget-common';
|
|
1
3
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { LocaleProvider } from '@oanda/mono-i18n';
|
|
4
|
-
import {
|
|
5
|
-
ChartError, ThemeProvider, getLocale, renderComponent,
|
|
6
|
-
} from '@oanda/labs-widget-common';
|
|
7
|
-
import { Widget } from './Widget';
|
|
8
|
-
import { Tool } from './Tool';
|
|
9
|
-
import { SentimentConfig } from './types';
|
|
4
|
+
|
|
10
5
|
import { translations } from '../translations';
|
|
6
|
+
import { Tool } from './Tool';
|
|
7
|
+
import type { SentimentConfig } from './types';
|
|
8
|
+
import { Widget } from './Widget';
|
|
11
9
|
|
|
12
10
|
const SentimentWidget = ({
|
|
13
11
|
graphqlUrl,
|
|
@@ -25,31 +23,28 @@ const SentimentWidget = ({
|
|
|
25
23
|
});
|
|
26
24
|
|
|
27
25
|
return (
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
</ApolloProvider>
|
|
51
|
-
</LocaleProvider>
|
|
52
|
-
</ThemeProvider>
|
|
26
|
+
<WidgetProvider
|
|
27
|
+
client={client}
|
|
28
|
+
locale={locale}
|
|
29
|
+
theme={theme}
|
|
30
|
+
translations={translations}
|
|
31
|
+
>
|
|
32
|
+
<WidgetWrapper
|
|
33
|
+
isParamError={isParamError}
|
|
34
|
+
linkArea="logo"
|
|
35
|
+
logoLink={logoLink}
|
|
36
|
+
>
|
|
37
|
+
{instrument ? (
|
|
38
|
+
<Widget
|
|
39
|
+
division={division}
|
|
40
|
+
includeDescriptionLabels={includeDescriptionLabels}
|
|
41
|
+
instrument={instrument}
|
|
42
|
+
/>
|
|
43
|
+
) : (
|
|
44
|
+
<Tool division={division} />
|
|
45
|
+
)}
|
|
46
|
+
</WidgetWrapper>
|
|
47
|
+
</WidgetProvider>
|
|
53
48
|
);
|
|
54
49
|
};
|
|
55
50
|
|
|
@@ -1,37 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import classNames from 'classnames';
|
|
1
|
+
import { useQuery } from '@apollo/client';
|
|
3
2
|
import {
|
|
4
|
-
Sentiment,
|
|
5
|
-
SentimentHeight,
|
|
6
|
-
Loader,
|
|
7
|
-
LoaderSize,
|
|
8
3
|
ChartError,
|
|
9
|
-
Truncate,
|
|
10
|
-
Tooltip,
|
|
11
|
-
ThemeContext,
|
|
12
|
-
Size,
|
|
13
4
|
EMPTY_VALUE,
|
|
14
5
|
LastUpdated,
|
|
6
|
+
Loader,
|
|
7
|
+
LoaderSize,
|
|
8
|
+
Sentiment,
|
|
9
|
+
SentimentHeight,
|
|
10
|
+
Size,
|
|
11
|
+
Tooltip,
|
|
12
|
+
Truncate,
|
|
13
|
+
useLayoutProvider,
|
|
15
14
|
} from '@oanda/labs-widget-common';
|
|
16
|
-
import { useQuery } from '@apollo/client';
|
|
17
15
|
import { useLocale } from '@oanda/mono-i18n';
|
|
16
|
+
import classNames from 'classnames';
|
|
17
|
+
import React, { useEffect, useState } from 'react';
|
|
18
|
+
|
|
19
|
+
import { INSTRUMENT_TOOLTIP_ID } from '../constant';
|
|
18
20
|
import { getSentimentList } from '../gql/getSentimentList';
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
GetSentimentListQuery, GetSentimentListQueryVariables, SentimentInstrument, Sort,
|
|
21
|
+
import type {
|
|
22
|
+
GetSentimentListQuery,
|
|
23
|
+
GetSentimentListQueryVariables,
|
|
24
|
+
SentimentInstrument,
|
|
24
25
|
} from '../gql/types/graphql';
|
|
25
|
-
import {
|
|
26
|
+
import { Sort } from '../gql/types/graphql';
|
|
27
|
+
import { SelectedArrow, SortSwitch } from './components/SortSwitch';
|
|
28
|
+
import type { SentimentToolConfig } from './types';
|
|
29
|
+
import { sortData } from './utils';
|
|
26
30
|
|
|
27
31
|
const Tool = ({ division }: SentimentToolConfig) => {
|
|
28
|
-
const { size } =
|
|
32
|
+
const { size } = useLayoutProvider();
|
|
29
33
|
const isDesktop = size === Size.DESKTOP;
|
|
30
34
|
const [sort, setSort] = useState(Sort.Bullish);
|
|
31
|
-
const [sortedData, setSortedData] = useState<
|
|
35
|
+
const [sortedData, setSortedData] = useState<
|
|
36
|
+
Omit<SentimentInstrument, 'id'>[]
|
|
37
|
+
>(new Array(20).fill({}));
|
|
32
38
|
const { loading, data, error } = useQuery<
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
GetSentimentListQuery,
|
|
40
|
+
GetSentimentListQueryVariables
|
|
35
41
|
>(getSentimentList, {
|
|
36
42
|
variables: {
|
|
37
43
|
division,
|
|
@@ -47,75 +53,85 @@ const Tool = ({ division }: SentimentToolConfig) => {
|
|
|
47
53
|
setSortedData(sortData(data, sort));
|
|
48
54
|
setUpdatedTimestamp(data.sentimentList![0]?.updatedAt);
|
|
49
55
|
}
|
|
50
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
56
|
}, [data, sort]);
|
|
52
57
|
|
|
53
58
|
return (
|
|
54
59
|
<>
|
|
55
60
|
{size && (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
<div className="lw-flex lw-justify-end lw-pb-5">
|
|
64
|
-
<SortSwitch
|
|
65
|
-
disabled={loading}
|
|
66
|
-
selected={sort === Sort.Bullish ? SelectedArrow.UP : SelectedArrow.DOWN}
|
|
67
|
-
onClickButtonDown={() => setSort(Sort.Bearish)}
|
|
68
|
-
onClickButtonUp={() => setSort(Sort.Bullish)}
|
|
69
|
-
/>
|
|
61
|
+
<div
|
|
62
|
+
className="lw-relative lw-bg-bg-primary lw-text-sm lw-tracking-normal lw-text-text-primary"
|
|
63
|
+
data-testid="sentiment-tool"
|
|
64
|
+
>
|
|
65
|
+
{error || sortedData.length === 0 ? (
|
|
66
|
+
<div className="lw-flex lw-h-[200px] lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary lw-p-2">
|
|
67
|
+
<ChartError />
|
|
70
68
|
</div>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
{lang('net_long')}
|
|
85
|
-
</span>
|
|
69
|
+
) : (
|
|
70
|
+
<>
|
|
71
|
+
<div className="lw-flex lw-justify-end lw-pb-5">
|
|
72
|
+
<SortSwitch
|
|
73
|
+
disabled={loading}
|
|
74
|
+
selected={
|
|
75
|
+
sort === Sort.Bullish
|
|
76
|
+
? SelectedArrow.UP
|
|
77
|
+
: SelectedArrow.DOWN
|
|
78
|
+
}
|
|
79
|
+
onClickButtonDown={() => setSort(Sort.Bearish)}
|
|
80
|
+
onClickButtonUp={() => setSort(Sort.Bullish)}
|
|
81
|
+
/>
|
|
86
82
|
</div>
|
|
87
|
-
|
|
88
|
-
<div className="lw-
|
|
89
|
-
<
|
|
90
|
-
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
sentiment={item.sentiment}
|
|
105
|
-
/>
|
|
83
|
+
<div className="lw-flex lw-flex-col lw-border lw-border-solid lw-border-border-primary lw-p-2">
|
|
84
|
+
<div className="lw-mb-2 lw-flex lw-justify-between lw-font-semibold">
|
|
85
|
+
<span
|
|
86
|
+
className={classNames('lw-uppercase', {
|
|
87
|
+
'lw-ml-40': isDesktop,
|
|
88
|
+
'lw-ml-[7.5rem]': !isDesktop,
|
|
89
|
+
})}
|
|
90
|
+
>
|
|
91
|
+
{lang('net_short')}
|
|
92
|
+
</span>
|
|
93
|
+
<span
|
|
94
|
+
className={classNames('lw-text-right lw-uppercase', {
|
|
95
|
+
'lw-mr-10': isDesktop,
|
|
96
|
+
})}
|
|
97
|
+
>
|
|
98
|
+
{lang('net_long')}
|
|
99
|
+
</span>
|
|
106
100
|
</div>
|
|
107
|
-
|
|
101
|
+
{sortedData.map((item, index) => (
|
|
102
|
+
<div
|
|
103
|
+
key={item.name || index}
|
|
104
|
+
className="lw-flex lw-h-8 lw-w-full lw-items-center"
|
|
105
|
+
>
|
|
106
|
+
<div className="lw-w-[120px] lw-shrink-0">
|
|
107
|
+
{loading ? (
|
|
108
|
+
<Loader size={LoaderSize.md} />
|
|
109
|
+
) : (
|
|
110
|
+
<Truncate
|
|
111
|
+
className="lw-pr-2 lw-font-sans lw-text-sm lw-font-bold"
|
|
112
|
+
maxWidth={120}
|
|
113
|
+
text={item.displayName || '\u2014'}
|
|
114
|
+
tooltipId={INSTRUMENT_TOOLTIP_ID}
|
|
115
|
+
/>
|
|
116
|
+
)}
|
|
117
|
+
</div>
|
|
118
|
+
<Sentiment
|
|
119
|
+
height={SentimentHeight.md}
|
|
120
|
+
isLoading={loading}
|
|
121
|
+
sentiment={item.sentiment}
|
|
122
|
+
/>
|
|
123
|
+
</div>
|
|
124
|
+
))}
|
|
125
|
+
</div>
|
|
126
|
+
</>
|
|
127
|
+
)}
|
|
128
|
+
<Tooltip id={INSTRUMENT_TOOLTIP_ID} />
|
|
129
|
+
{!error && (
|
|
130
|
+
<div className="lw-mt-2 lw-h-8">
|
|
131
|
+
<LastUpdated labelCallback={lang} timestamp={updatedTimestamp} />
|
|
108
132
|
</div>
|
|
109
|
-
|
|
110
|
-
)}
|
|
111
|
-
<Tooltip id={INSTRUMENT_TOOLTIP_ID} />
|
|
112
|
-
{!error
|
|
113
|
-
&& (
|
|
114
|
-
<div className="lw-mt-2 lw-h-8">
|
|
115
|
-
<LastUpdated timestamp={updatedTimestamp} labelCallback={lang} />
|
|
133
|
+
)}
|
|
116
134
|
</div>
|
|
117
|
-
)}
|
|
118
|
-
</div>
|
|
119
135
|
)}
|
|
120
136
|
</>
|
|
121
137
|
);
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import classNames from 'classnames';
|
|
1
|
+
import { useQuery } from '@apollo/client';
|
|
3
2
|
import {
|
|
4
|
-
Sentiment,
|
|
5
|
-
SentimentHeight,
|
|
6
3
|
Error,
|
|
4
|
+
LastUpdated,
|
|
7
5
|
Loader,
|
|
8
6
|
LoaderSize,
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
Sentiment,
|
|
8
|
+
SentimentHeight,
|
|
11
9
|
Size,
|
|
12
|
-
|
|
10
|
+
Truncate,
|
|
11
|
+
useLayoutProvider,
|
|
13
12
|
} from '@oanda/labs-widget-common';
|
|
14
13
|
import { useLocale } from '@oanda/mono-i18n';
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
import { GetInstrumentSentimentQuery, GetInstrumentSentimentQueryVariables } from '../gql/types/graphql';
|
|
14
|
+
import classNames from 'classnames';
|
|
15
|
+
import React from 'react';
|
|
16
|
+
|
|
19
17
|
import { INSTRUMENT_TOOLTIP_ID } from '../constant';
|
|
18
|
+
import { getInstrumentSentiment } from '../gql/getInstrumentSentiment';
|
|
19
|
+
import type {
|
|
20
|
+
GetInstrumentSentimentQuery,
|
|
21
|
+
GetInstrumentSentimentQueryVariables,
|
|
22
|
+
} from '../gql/types/graphql';
|
|
23
|
+
import type { SentimentWidgetConfig } from './types';
|
|
20
24
|
|
|
21
25
|
const Widget = ({
|
|
22
26
|
instrument,
|
|
@@ -24,8 +28,8 @@ const Widget = ({
|
|
|
24
28
|
includeDescriptionLabels = false,
|
|
25
29
|
}: SentimentWidgetConfig) => {
|
|
26
30
|
const { loading, data, error } = useQuery<
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
GetInstrumentSentimentQuery,
|
|
32
|
+
GetInstrumentSentimentQueryVariables
|
|
29
33
|
>(getInstrumentSentiment, {
|
|
30
34
|
variables: {
|
|
31
35
|
name: instrument,
|
|
@@ -33,71 +37,73 @@ const Widget = ({
|
|
|
33
37
|
},
|
|
34
38
|
fetchPolicy: 'cache-and-network',
|
|
35
39
|
});
|
|
36
|
-
const { size } =
|
|
40
|
+
const { size } = useLayoutProvider();
|
|
37
41
|
const isDesktop = size === Size.DESKTOP;
|
|
38
42
|
const { lang } = useLocale();
|
|
39
43
|
|
|
40
44
|
const { displayName, sentiment, updatedAt } = data?.sentiment?.[0] || {};
|
|
41
45
|
|
|
42
|
-
const isError =
|
|
43
|
-
||
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
const isError =
|
|
47
|
+
error ||
|
|
48
|
+
(sentiment?.shortPercent === 0 && sentiment?.longPercent === 0) ||
|
|
49
|
+
sentiment?.shortPercent === undefined ||
|
|
50
|
+
sentiment?.longPercent === undefined;
|
|
46
51
|
|
|
47
52
|
return (
|
|
48
53
|
<>
|
|
49
54
|
{size && (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
<div className="lw-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
55
|
+
<>
|
|
56
|
+
<div
|
|
57
|
+
className="lw-border lw-border-solid lw-border-border-primary lw-bg-bg-primary lw-p-4 lw-text-sm lw-tracking-normal lw-text-text-primary"
|
|
58
|
+
data-testid="sentiment-widget"
|
|
59
|
+
>
|
|
60
|
+
{includeDescriptionLabels && !isError && (
|
|
61
|
+
<div className="lw-mb-2 lw-flex lw-justify-between lw-font-semibold">
|
|
62
|
+
<span
|
|
63
|
+
className={classNames('lw-uppercase', {
|
|
64
|
+
'lw-ml-40': isDesktop,
|
|
65
|
+
'lw-ml-[7.5rem]': !isDesktop,
|
|
66
|
+
})}
|
|
67
|
+
>
|
|
68
|
+
{lang('net_short')}
|
|
69
|
+
</span>
|
|
70
|
+
<span
|
|
71
|
+
className={classNames('lw-text-right lw-uppercase', {
|
|
72
|
+
'lw-mr-10': isDesktop,
|
|
73
|
+
})}
|
|
74
|
+
>
|
|
75
|
+
{lang('net_long')}
|
|
76
|
+
</span>
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
<div className="lw-flex lw-items-center lw-justify-between">
|
|
80
|
+
<div className="lw-w-[120px] lw-shrink-0">
|
|
81
|
+
{loading && <Loader size={LoaderSize.md} />}
|
|
82
|
+
{!loading && !isError && (
|
|
83
|
+
<Truncate
|
|
84
|
+
className="lw-pr-2 lw-font-sans lw-text-sm lw-font-bold"
|
|
85
|
+
maxWidth={120}
|
|
86
|
+
text={displayName || '\u2014'}
|
|
87
|
+
tooltipId={INSTRUMENT_TOOLTIP_ID}
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
</div>
|
|
91
|
+
<Sentiment
|
|
92
|
+
height={SentimentHeight.md}
|
|
93
|
+
isLoading={loading}
|
|
94
|
+
sentiment={sentiment}
|
|
95
|
+
withError={false}
|
|
82
96
|
/>
|
|
83
|
-
)}
|
|
84
97
|
</div>
|
|
85
|
-
<Sentiment
|
|
86
|
-
withError={false}
|
|
87
|
-
isLoading={loading}
|
|
88
|
-
height={SentimentHeight.md}
|
|
89
|
-
sentiment={sentiment}
|
|
90
|
-
/>
|
|
91
|
-
</div>
|
|
92
98
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
{!loading && isError && <Error />}
|
|
100
|
+
</div>
|
|
101
|
+
{!isError && updatedAt && (
|
|
102
|
+
<div className="lw-mt-2 lw-h-8">
|
|
103
|
+
<LastUpdated labelCallback={lang} timestamp={updatedAt} />
|
|
104
|
+
</div>
|
|
105
|
+
)}
|
|
106
|
+
</>
|
|
101
107
|
)}
|
|
102
108
|
</>
|
|
103
109
|
);
|