@oanda/labs-currency-strength-widget 1.0.91 → 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.
- package/CHANGELOG.md +372 -0
- package/dist/main/CurrencyStrengthWidget/ChartsWithData.js +6 -6
- package/dist/main/CurrencyStrengthWidget/ChartsWithData.js.map +1 -1
- package/dist/main/CurrencyStrengthWidget/CurrencyStrengthWidget.js +6 -6
- package/dist/main/CurrencyStrengthWidget/CurrencyStrengthWidget.js.map +1 -1
- package/dist/main/CurrencyStrengthWidget/Main.js +2 -2
- package/dist/main/CurrencyStrengthWidget/Main.js.map +1 -1
- package/dist/main/CurrencyStrengthWidget/components/Chart/Chart.js +14 -14
- package/dist/main/CurrencyStrengthWidget/components/Chart/Chart.js.map +1 -1
- package/dist/main/CurrencyStrengthWidget/components/Chart/constants.js.map +1 -1
- package/dist/main/CurrencyStrengthWidget/components/Chart/formatters.js.map +1 -1
- package/dist/main/CurrencyStrengthWidget/components/Chart/getOption.js.map +1 -1
- package/dist/main/CurrencyStrengthWidget/components/Chart/types.js.map +1 -1
- package/dist/main/CurrencyStrengthWidget/render.js +5 -5
- package/dist/main/CurrencyStrengthWidget/render.js.map +1 -1
- package/dist/main/CurrencyStrengthWidget/types.js.map +1 -1
- package/dist/main/gql/types/fragment-masking.js.map +1 -1
- package/dist/main/gql/types/gql.js +1 -1
- package/dist/main/gql/types/gql.js.map +1 -1
- package/dist/main/gql/types/graphql.js +40 -40
- package/dist/main/gql/types/graphql.js.map +1 -1
- package/dist/main/gql/types/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/CurrencyStrengthWidget/ChartsWithData.js +6 -6
- package/dist/module/CurrencyStrengthWidget/ChartsWithData.js.map +1 -1
- package/dist/module/CurrencyStrengthWidget/CurrencyStrengthWidget.js +6 -6
- package/dist/module/CurrencyStrengthWidget/CurrencyStrengthWidget.js.map +1 -1
- package/dist/module/CurrencyStrengthWidget/Main.js +2 -2
- package/dist/module/CurrencyStrengthWidget/Main.js.map +1 -1
- package/dist/module/CurrencyStrengthWidget/components/Chart/Chart.js +12 -12
- package/dist/module/CurrencyStrengthWidget/components/Chart/Chart.js.map +1 -1
- package/dist/module/CurrencyStrengthWidget/components/Chart/constants.js.map +1 -1
- package/dist/module/CurrencyStrengthWidget/components/Chart/formatters.js +1 -1
- package/dist/module/CurrencyStrengthWidget/components/Chart/formatters.js.map +1 -1
- package/dist/module/CurrencyStrengthWidget/components/Chart/getOption.js +1 -1
- package/dist/module/CurrencyStrengthWidget/components/Chart/getOption.js.map +1 -1
- package/dist/module/CurrencyStrengthWidget/components/Chart/types.js.map +1 -1
- package/dist/module/CurrencyStrengthWidget/render.js +5 -5
- package/dist/module/CurrencyStrengthWidget/render.js.map +1 -1
- package/dist/module/CurrencyStrengthWidget/types.js.map +1 -1
- package/dist/module/gql/types/fragment-masking.js.map +1 -1
- package/dist/module/gql/types/gql.js +1 -1
- package/dist/module/gql/types/gql.js.map +1 -1
- package/dist/module/gql/types/graphql.js +40 -40
- 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/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/CurrencyStrengthWidget/ChartsWithData.d.ts +1 -1
- package/dist/types/CurrencyStrengthWidget/CurrencyStrengthWidget.d.ts +1 -1
- package/dist/types/CurrencyStrengthWidget/Main.d.ts +1 -1
- package/dist/types/CurrencyStrengthWidget/components/Chart/Chart.d.ts +1 -1
- package/dist/types/CurrencyStrengthWidget/components/Chart/formatters.d.ts +2 -2
- package/dist/types/CurrencyStrengthWidget/components/Chart/getOption.d.ts +1 -1
- package/dist/types/CurrencyStrengthWidget/components/Chart/types.d.ts +5 -5
- package/dist/types/CurrencyStrengthWidget/types.d.ts +1 -1
- package/dist/types/gql/types/gql.d.ts +2 -2
- package/dist/types/gql/types/index.d.ts +2 -2
- package/dist/types/translations/index.d.ts +2 -2
- package/package.json +3 -3
- package/src/CurrencyStrengthWidget/ChartsWithData.tsx +47 -28
- package/src/CurrencyStrengthWidget/CurrencyStrengthWidget.tsx +13 -7
- package/src/CurrencyStrengthWidget/Main.tsx +9 -8
- package/src/CurrencyStrengthWidget/components/Chart/Chart.tsx +24 -15
- package/src/CurrencyStrengthWidget/components/Chart/constants.tsx +1 -0
- package/src/CurrencyStrengthWidget/components/Chart/formatters.ts +4 -7
- package/src/CurrencyStrengthWidget/components/Chart/getOption.ts +22 -18
- package/src/CurrencyStrengthWidget/components/Chart/types.ts +8 -8
- package/src/CurrencyStrengthWidget/render.tsx +17 -15
- package/src/CurrencyStrengthWidget/types.ts +1 -1
- package/src/gql/types/fragment-masking.ts +41 -21
- package/src/gql/types/gql.ts +7 -3
- package/src/gql/types/graphql.ts +98 -45
- package/src/gql/types/index.ts +2 -2
- package/src/translations/index.ts +4 -4
- package/src/translations/translations.ts +1 -3
- package/test/Main.test.tsx +23 -11
- package/test/chartOptions.test.ts +9 -7
- package/test/mocks/currencyStrengthMock.ts +1 -3
- package/test/mocks/responsesMocks.ts +2 -4
- package/test/sortData.test.ts +10 -12
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { useQuery } from '@apollo/client';
|
|
3
|
-
import { useLocale } from '@oanda/mono-i18n';
|
|
4
2
|
import {
|
|
5
3
|
ChartError,
|
|
6
4
|
LastUpdated,
|
|
@@ -9,22 +7,29 @@ import {
|
|
|
9
7
|
SpinnerSize,
|
|
10
8
|
useLayoutProvider,
|
|
11
9
|
} from '@oanda/labs-widget-common';
|
|
10
|
+
import { useLocale } from '@oanda/mono-i18n';
|
|
12
11
|
import classnames from 'classnames';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
|
|
13
14
|
import { getCurrencyStrength } from '../gql/getCurrencyStrength';
|
|
14
|
-
import { GetCurrencyStrengthQuery } from '../gql/types/graphql';
|
|
15
|
+
import type { GetCurrencyStrengthQuery } from '../gql/types/graphql';
|
|
15
16
|
import { Chart } from './components/Chart';
|
|
16
17
|
import { sortCurrencies } from './components/Chart/formatters';
|
|
17
|
-
import { WidgetProps } from './types';
|
|
18
|
+
import type { WidgetProps } from './types';
|
|
18
19
|
|
|
19
20
|
const ChartWithData = ({ currency }: WidgetProps) => {
|
|
20
21
|
const { size } = useLayoutProvider();
|
|
21
22
|
const isDesktop = size === Size.DESKTOP;
|
|
22
23
|
const { lang } = useLocale();
|
|
23
|
-
const { loading, data, error } = useQuery<GetCurrencyStrengthQuery>(
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const { loading, data, error } = useQuery<GetCurrencyStrengthQuery>(
|
|
25
|
+
getCurrencyStrength,
|
|
26
|
+
{
|
|
27
|
+
fetchPolicy: 'cache-and-network',
|
|
28
|
+
}
|
|
29
|
+
);
|
|
26
30
|
|
|
27
|
-
const showChart =
|
|
31
|
+
const showChart =
|
|
32
|
+
data?.currencyStrength && data?.currencyStrength?.length > 0;
|
|
28
33
|
const showError = data?.currencyStrength?.length === 0 || error;
|
|
29
34
|
|
|
30
35
|
const currencyData = currency
|
|
@@ -33,46 +38,60 @@ const ChartWithData = ({ currency }: WidgetProps) => {
|
|
|
33
38
|
|
|
34
39
|
return (
|
|
35
40
|
<>
|
|
36
|
-
{loading
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
{loading && (
|
|
42
|
+
<div
|
|
43
|
+
className={classnames(
|
|
44
|
+
'lw-flex lw-w-full lw-items-center lw-border lw-border-solid lw-border-border-primary',
|
|
45
|
+
{
|
|
46
|
+
'lw-h-[461px]': !currency,
|
|
47
|
+
'lw-h-[135px]': currency,
|
|
48
|
+
}
|
|
49
|
+
)}
|
|
42
50
|
>
|
|
43
51
|
<Spinner size={SpinnerSize.lg} />
|
|
44
52
|
</div>
|
|
45
53
|
)}
|
|
46
54
|
{!loading && showChart && (
|
|
47
55
|
<div
|
|
48
|
-
data-testid="currency-strength-chart-wrapper"
|
|
49
56
|
className={classnames('lw-grid lw-place-content-center lw-gap-7', {
|
|
50
57
|
'lw-grid-cols-3 ': isDesktop && !currency,
|
|
51
58
|
'lw-grid-cols-1': !isDesktop || currency,
|
|
52
59
|
})}
|
|
60
|
+
data-testid="currency-strength-chart-wrapper"
|
|
53
61
|
>
|
|
54
|
-
{currencyData &&
|
|
55
|
-
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
{currencyData &&
|
|
63
|
+
currencyData.map((item) => (
|
|
64
|
+
<div
|
|
65
|
+
key={item.currency}
|
|
66
|
+
className="lw-flex lw-h-[135px] lw-flex-1 lw-items-center lw-justify-center"
|
|
67
|
+
>
|
|
68
|
+
<Chart
|
|
69
|
+
currency={item.currency}
|
|
70
|
+
values={item.strengthRelation?.slice().sort(sortCurrencies)!}
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
|
+
))}
|
|
62
74
|
</div>
|
|
63
75
|
)}
|
|
64
76
|
{!loading && showError && (
|
|
65
|
-
<div
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
<div
|
|
78
|
+
className={classnames(
|
|
79
|
+
'lw-flex lw-w-full lw-items-center lw-border lw-border-solid lw-border-border-primary',
|
|
80
|
+
{
|
|
81
|
+
'lw-h-[425px]': !currency,
|
|
82
|
+
'lw-h-[135px]': currency,
|
|
83
|
+
}
|
|
84
|
+
)}
|
|
69
85
|
>
|
|
70
86
|
<ChartError />
|
|
71
87
|
</div>
|
|
72
88
|
)}
|
|
73
89
|
{!loading && !showError && (
|
|
74
90
|
<div className="lw-mt-2 lw-h-8">
|
|
75
|
-
<LastUpdated
|
|
91
|
+
<LastUpdated
|
|
92
|
+
labelCallback={lang}
|
|
93
|
+
timestamp={data?.currencyStrength![0]?.updatedAt}
|
|
94
|
+
/>
|
|
76
95
|
</div>
|
|
77
96
|
)}
|
|
78
97
|
</>
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { ApolloClient, InMemoryCache } from '@apollo/client';
|
|
3
2
|
import { WidgetProvider, WidgetWrapper } from '@oanda/labs-widget-common';
|
|
4
|
-
import
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
5
|
import { translations } from '../translations';
|
|
6
6
|
import { Main } from './Main';
|
|
7
|
+
import type { CurrencyStrengthConfig } from './types';
|
|
7
8
|
|
|
8
9
|
const CurrencyStrengthWidget = ({
|
|
9
|
-
graphqlUrl,
|
|
10
|
+
graphqlUrl,
|
|
11
|
+
currency,
|
|
12
|
+
locale,
|
|
13
|
+
theme,
|
|
14
|
+
isParamError,
|
|
15
|
+
logoLink,
|
|
10
16
|
}: CurrencyStrengthConfig) => {
|
|
11
17
|
const client = new ApolloClient({
|
|
12
18
|
uri: graphqlUrl,
|
|
@@ -15,15 +21,15 @@ const CurrencyStrengthWidget = ({
|
|
|
15
21
|
|
|
16
22
|
return (
|
|
17
23
|
<WidgetProvider
|
|
18
|
-
locale={locale}
|
|
19
|
-
translations={translations}
|
|
20
24
|
client={client}
|
|
25
|
+
locale={locale}
|
|
21
26
|
theme={theme}
|
|
27
|
+
translations={translations}
|
|
22
28
|
>
|
|
23
29
|
<WidgetWrapper
|
|
24
|
-
logoLink={logoLink}
|
|
25
|
-
linkArea="logo"
|
|
26
30
|
isParamError={isParamError}
|
|
31
|
+
linkArea="logo"
|
|
32
|
+
logoLink={logoLink}
|
|
27
33
|
>
|
|
28
34
|
<Main currency={currency} theme={theme} />
|
|
29
35
|
</WidgetWrapper>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useLocale } from '@oanda/mono-i18n';
|
|
3
1
|
import { useLayoutProvider } from '@oanda/labs-widget-common';
|
|
2
|
+
import { useLocale } from '@oanda/mono-i18n';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
4
5
|
import { ChartWithData } from './ChartsWithData';
|
|
5
|
-
import { WidgetProps } from './types';
|
|
6
|
+
import type { WidgetProps } from './types';
|
|
6
7
|
|
|
7
8
|
const Main = ({ currency }: WidgetProps) => {
|
|
8
9
|
const { lang } = useLocale();
|
|
@@ -11,12 +12,12 @@ const Main = ({ currency }: WidgetProps) => {
|
|
|
11
12
|
return (
|
|
12
13
|
<>
|
|
13
14
|
{size && (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
<div data-testid="currency-strength-wrapper">
|
|
16
|
+
<div className="lw-mb-8 lw-flex lw-justify-center lw-font-sans lw-text-lg lw-font-bold">
|
|
17
|
+
<span>{`${lang('daily')} (${lang('minute', { count: 5 })})`}</span>
|
|
18
|
+
</div>
|
|
19
|
+
<ChartWithData currency={currency} />
|
|
17
20
|
</div>
|
|
18
|
-
<ChartWithData currency={currency} />
|
|
19
|
-
</div>
|
|
20
21
|
)}
|
|
21
22
|
</>
|
|
22
23
|
);
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import React 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
|
-
|
|
8
|
-
|
|
2
|
+
getChartTheme,
|
|
3
|
+
Theme,
|
|
4
|
+
useLayoutProvider,
|
|
5
|
+
} from '@oanda/labs-widget-common';
|
|
9
6
|
import { useLocale } from '@oanda/mono-i18n';
|
|
10
|
-
import {
|
|
7
|
+
import { BarChart } from 'echarts/charts';
|
|
11
8
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
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,
|
|
@@ -33,14 +39,17 @@ const Chart = ({ values, currency }: ChartProps) => {
|
|
|
33
39
|
return (
|
|
34
40
|
<ReactEChartsCore
|
|
35
41
|
echarts={echarts}
|
|
36
|
-
|
|
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
|
-
|
|
42
|
-
values, currency, lang, isDark,
|
|
43
|
-
})}
|
|
52
|
+
theme={isDark ? 'dark_theme' : 'light_theme'}
|
|
44
53
|
/>
|
|
45
54
|
);
|
|
46
55
|
};
|
|
@@ -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) =>
|
|
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,
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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 }
|
|
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
|
|
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
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
35
|
+
locale={locale}
|
|
35
36
|
logoLink={logoLink}
|
|
36
|
-
|
|
37
|
+
theme={mode as Theme}
|
|
38
|
+
/>
|
|
37
39
|
);
|
|
38
40
|
});
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
any
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
66
|
+
data:
|
|
67
|
+
| FragmentType<TypedDocumentNode<Incremental<TFrag>, any>>
|
|
68
|
+
| null
|
|
69
|
+
| undefined
|
|
55
70
|
): data is FragmentType<typeof fragmentNode> {
|
|
56
|
-
const deferredFields = (
|
|
57
|
-
|
|
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
|
|
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
|
}
|
package/src/gql/types/gql.ts
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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>> =
|
|
45
|
+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> =
|
|
46
|
+
TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;
|