@xyo-network/react-price-forecast-plugin 2.61.0 → 2.61.1

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.
@@ -1,2 +1,243 @@
1
- export * from "./DetailsBox";
1
+ // src/components/DetailsBox.tsx
2
+ import "chartjs-adapter-luxon";
3
+ import { useTheme } from "@mui/material";
4
+ import { useAsyncEffect } from "@xylabs/react-async-effect";
5
+ import { FlexCol } from "@xylabs/react-flexbox";
6
+ import {
7
+ CategoryScale,
8
+ Chart as ChartJS,
9
+ Legend,
10
+ LinearScale,
11
+ LineElement,
12
+ PointElement,
13
+ TimeScale,
14
+ Title,
15
+ Tooltip
16
+ } from "chart.js";
17
+ import { useState } from "react";
18
+ import { Line } from "react-chartjs-2";
19
+
20
+ // src/lib/DataLineStyles.ts
21
+ import { alpha } from "@mui/material";
22
+ var DataLineStyles = (color) => ({
23
+ backgroundColor: color ? alpha(color, 0.5) : void 0,
24
+ borderColor: color
25
+ });
26
+
27
+ // src/lib/DataPointStyles.ts
28
+ var DataPointStyles = (pointHoverBackgroundColor) => ({
29
+ pointHitRadius: 20,
30
+ pointHoverBackgroundColor,
31
+ pointHoverRadius: 10,
32
+ pointRadius: 5,
33
+ pointStyle: "circle"
34
+ });
35
+
36
+ // src/lib/MockSourcePayloads.ts
37
+ var MockSourcePayloads = () => {
38
+ const tenMin = 6e5;
39
+ return [
40
+ {
41
+ baseFee: 38.90155387825,
42
+ feePerGas: { high: 47.9945864396, low: 39.006868093, medium: 39.306868093, veryHigh: 44.45384380525 },
43
+ priorityFeePerGas: { high: 1.0266666666666666, low: -0.41000000000000003, medium: 0.38, veryHigh: 1.3900000000000001 },
44
+ schema: "network.xyo.blockchain.ethereum.gas",
45
+ timestamp: Date.now() - tenMin
46
+ },
47
+ {
48
+ baseFee: 38.90155387825,
49
+ feePerGas: { high: 47.9945864396, low: 39.006868093, medium: 100, veryHigh: 44.45384380525 },
50
+ priorityFeePerGas: { high: 1.0266666666666666, low: -0.41000000000000003, medium: 0.38, veryHigh: 1.3900000000000001 },
51
+ schema: "network.xyo.blockchain.ethereum.gas",
52
+ timestamp: Date.now()
53
+ }
54
+ ];
55
+ };
56
+
57
+ // src/lib/SourcePayloads.ts
58
+ var SourcePayloads = class {
59
+ constructor(sourcePayloads) {
60
+ this.sourcePayloads = sourcePayloads;
61
+ }
62
+ sourcePrices = [];
63
+ get payloads() {
64
+ return this.sourcePayloads;
65
+ }
66
+ static async build(jsonPath) {
67
+ const sourcePayloads = await this.fetchSourcePayloads();
68
+ const instance = new this(sourcePayloads);
69
+ const paths = jsonPath.split(".");
70
+ instance.sourcePrices = sourcePayloads.map((payload) => {
71
+ return { x: payload.timestamp, y: instance.jsonPathTraverser(payload, paths) };
72
+ });
73
+ return instance;
74
+ }
75
+ // TODO - fetch from archivist
76
+ static async fetchSourcePayloads() {
77
+ const payloads = await Promise.resolve(MockSourcePayloads());
78
+ return payloads;
79
+ }
80
+ jsonPathTraverser(obj, path) {
81
+ let result = obj;
82
+ for (const key of path) {
83
+ if (key in result) {
84
+ const foundKey = key;
85
+ result = result[foundKey];
86
+ } else {
87
+ result = void 0;
88
+ break;
89
+ }
90
+ }
91
+ return result;
92
+ }
93
+ };
94
+
95
+ // src/lib/ForecastLineChartConfigBuilder.ts
96
+ var defaultOptions = () => ({
97
+ plugins: {
98
+ legend: {
99
+ position: "top"
100
+ }
101
+ },
102
+ responsive: true
103
+ });
104
+ var ForecastLineChartConfigBuilder = class _ForecastLineChartConfigBuilder {
105
+ constructor(theme, payload) {
106
+ this.payload = payload;
107
+ this.themeColors = this.parseTheme(theme);
108
+ }
109
+ data = {
110
+ datasets: []
111
+ };
112
+ options = defaultOptions();
113
+ themeColors;
114
+ get forecastPayload() {
115
+ if (this.payload) {
116
+ return this.payload;
117
+ } else {
118
+ throw Error("ForecastPayload was not defined");
119
+ }
120
+ }
121
+ static async create(theme, payload, sourcePayloadConfig) {
122
+ const instance = new _ForecastLineChartConfigBuilder(theme, payload);
123
+ await instance.build(sourcePayloadConfig?.fetch);
124
+ instance.refreshValues();
125
+ return instance;
126
+ }
127
+ async build(includeSources) {
128
+ this.buildOptions();
129
+ await this.buildData(includeSources);
130
+ return this;
131
+ }
132
+ async buildData(includeSources) {
133
+ const forecastData = this.generateDataSetForecastData();
134
+ const datasets = [forecastData];
135
+ if (includeSources) {
136
+ const sourceData = await this.generateDataSetSourcePayloads();
137
+ datasets.unshift(sourceData);
138
+ const lastSourceDataItem = sourceData.data.at(-1);
139
+ forecastData.data.unshift(lastSourceDataItem);
140
+ }
141
+ this.data = {
142
+ datasets
143
+ };
144
+ return this;
145
+ }
146
+ buildOptions() {
147
+ if (this.options.plugins) {
148
+ this.options.plugins.title = this.generateTitle();
149
+ this.options.plugins.legend = this.generateLegend();
150
+ }
151
+ this.options.scales = this.generateScales();
152
+ return this;
153
+ }
154
+ refreshValues() {
155
+ this.data = { ...this.data };
156
+ this.options = { ...this.options };
157
+ }
158
+ generateLegend() {
159
+ return {
160
+ labels: {
161
+ pointStyle: "circle",
162
+ usePointStyle: true
163
+ }
164
+ };
165
+ }
166
+ generateScales() {
167
+ return {
168
+ x: {
169
+ grid: {
170
+ color: this.themeColors?.gridColor
171
+ },
172
+ time: {
173
+ unit: "minute"
174
+ },
175
+ type: "time"
176
+ },
177
+ y: {
178
+ grid: {
179
+ color: this.themeColors?.gridColor
180
+ }
181
+ }
182
+ };
183
+ }
184
+ generateTitle() {
185
+ return {
186
+ display: true,
187
+ text: `Gas Price Forecaster (GWEI over time from ${this.forecastPayload?.values[0].timestamp ? new Date(this.forecastPayload.values[0].timestamp).toLocaleDateString() : ""})`
188
+ };
189
+ }
190
+ parseTheme(theme) {
191
+ const dark = theme.palette.mode === "dark";
192
+ return {
193
+ dataSetColorPrimary: theme.palette.primary.light,
194
+ dataSetColorSecondary: theme.palette.secondary.light,
195
+ gridColor: dark ? theme.palette.grey[800] : theme.palette.grey[300]
196
+ };
197
+ }
198
+ generateDataSetForecastData() {
199
+ return {
200
+ borderDash: [5],
201
+ borderDashOffset: 0.5,
202
+ data: this.forecastPayload.values.map((price) => ({ x: price.timestamp ?? 0, y: price.value })),
203
+ label: "Forecast Price",
204
+ ...DataPointStyles(this.themeColors?.dataSetColorPrimary),
205
+ ...DataLineStyles(this.themeColors?.dataSetColorPrimary)
206
+ };
207
+ }
208
+ async generateDataSetSourcePayloads() {
209
+ const { sourcePrices } = await SourcePayloads.build("feePerGas.medium");
210
+ return {
211
+ data: sourcePrices,
212
+ label: "Source Prices",
213
+ ...DataLineStyles(this.themeColors?.dataSetColorSecondary),
214
+ ...DataPointStyles(this.themeColors?.dataSetColorSecondary)
215
+ };
216
+ }
217
+ };
218
+
219
+ // src/components/DetailsBox.tsx
220
+ import { jsx } from "react/jsx-runtime";
221
+ ChartJS.register(CategoryScale, TimeScale, PointElement, LineElement, LinearScale, Title, Tooltip, Legend);
222
+ var PriceForecastDetailsBox = ({ payload, ...props }) => {
223
+ const priceForecastPayload = payload;
224
+ const theme = useTheme();
225
+ const [data, setData] = useState({ datasets: [] });
226
+ const [options, setOptions] = useState({});
227
+ useAsyncEffect(
228
+ // eslint-disable-next-line react-hooks/exhaustive-deps
229
+ async (mounted) => {
230
+ const { data: data2, options: options2 } = await ForecastLineChartConfigBuilder.create(theme, priceForecastPayload, { fetch: true });
231
+ if (mounted()) {
232
+ setData(data2);
233
+ setOptions(options2);
234
+ }
235
+ },
236
+ [priceForecastPayload, theme]
237
+ );
238
+ return /* @__PURE__ */ jsx(FlexCol, { ...props, busy: priceForecastPayload === void 0, minHeight: "25vh", children: priceForecastPayload ? /* @__PURE__ */ jsx(Line, { options, data }) : null });
239
+ };
240
+ export {
241
+ PriceForecastDetailsBox
242
+ };
2
243
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/index.ts"],"sourcesContent":["export * from './DetailsBox'\n"],"mappings":"AAAA,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/DetailsBox.tsx","../../../src/lib/DataLineStyles.ts","../../../src/lib/DataPointStyles.ts","../../../src/lib/MockSourcePayloads.ts","../../../src/lib/SourcePayloads.ts","../../../src/lib/ForecastLineChartConfigBuilder.ts"],"sourcesContent":["import 'chartjs-adapter-luxon'\n\nimport { useTheme } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'\nimport { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n CategoryScale,\n Chart as ChartJS,\n ChartData,\n ChartOptions,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n TimeScale,\n Title,\n Tooltip,\n} from 'chart.js'\nimport { useState } from 'react'\nimport { Line } from 'react-chartjs-2'\n\nimport { ForecastLineChartConfigBuilder } from '../lib'\n\nChartJS.register(CategoryScale, TimeScale, PointElement, LineElement, LinearScale, Title, Tooltip, Legend)\n\nexport interface PriceForecastDetailsBoxProps extends FlexBoxProps {\n payload?: Payload\n}\n\nexport const PriceForecastDetailsBox: React.FC<PriceForecastDetailsBoxProps> = ({ payload, ...props }) => {\n const priceForecastPayload = payload as ForecastPayload | undefined\n const theme = useTheme()\n const [data, setData] = useState<ChartData<'line'>>({ datasets: [] })\n const [options, setOptions] = useState<ChartOptions<'line'>>({})\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n const { data, options } = await ForecastLineChartConfigBuilder.create(theme, priceForecastPayload, { fetch: true })\n if (mounted()) {\n setData(data)\n setOptions(options)\n }\n },\n [priceForecastPayload, theme],\n )\n\n return (\n <FlexCol {...props} busy={priceForecastPayload === undefined} minHeight=\"25vh\">\n {priceForecastPayload ? <Line options={options} data={data} /> : null}\n </FlexCol>\n )\n}\n","import { alpha } from '@mui/material'\n\nexport const DataLineStyles = (color?: string) => ({\n backgroundColor: color ? alpha(color, 0.5) : undefined,\n borderColor: color,\n})\n","export const DataPointStyles = (pointHoverBackgroundColor?: string) => ({\n pointHitRadius: 20,\n pointHoverBackgroundColor,\n pointHoverRadius: 10,\n pointRadius: 5,\n pointStyle: 'circle',\n})\n","export const MockSourcePayloads = () => {\n const tenMin = 600000\n return [\n {\n baseFee: 38.90155387825,\n feePerGas: { high: 47.9945864396, low: 39.006868093, medium: 39.306868093, veryHigh: 44.45384380525 },\n priorityFeePerGas: { high: 1.0266666666666666, low: -0.41000000000000003, medium: 0.38, veryHigh: 1.3900000000000001 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now() - tenMin,\n },\n {\n baseFee: 38.90155387825,\n feePerGas: { high: 47.9945864396, low: 39.006868093, medium: 100, veryHigh: 44.45384380525 },\n priorityFeePerGas: { high: 1.0266666666666666, low: -0.41000000000000003, medium: 0.38, veryHigh: 1.3900000000000001 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now(),\n },\n ]\n}\n","import { Payload } from '@xyo-network/payload-model'\nimport { Point } from 'chart.js'\n\nimport { MockSourcePayloads } from './MockSourcePayloads'\n\nexport class SourcePayloads {\n sourcePrices: Point[] = []\n\n constructor(public sourcePayloads: Payload[]) {}\n\n get payloads() {\n return this.sourcePayloads\n }\n\n static async build(jsonPath: string) {\n const sourcePayloads = await this.fetchSourcePayloads()\n const instance = new this(sourcePayloads)\n\n const paths = jsonPath.split('.')\n instance.sourcePrices = sourcePayloads.map((payload) => {\n return { x: payload.timestamp, y: instance.jsonPathTraverser(payload, paths) }\n })\n return instance\n }\n\n // TODO - fetch from archivist\n static async fetchSourcePayloads() {\n const payloads = await Promise.resolve(MockSourcePayloads())\n return payloads\n }\n\n jsonPathTraverser(obj: Payload, path: string[]) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let result: any = obj\n for (const key of path) {\n if (key in result) {\n const foundKey = key as keyof typeof result\n result = result[foundKey]\n } else {\n result = undefined\n break\n }\n }\n\n return result\n }\n}\n","import { Theme } from '@mui/material'\nimport { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport { ChartData, ChartDataset, ChartOptions, LegendOptions, Point, ScaleChartOptions } from 'chart.js'\n// eslint-disable-next-line import/no-unresolved\nimport { _DeepPartialObject } from 'chart.js/dist/types/utils'\n\nimport { DataLineStyles } from './DataLineStyles'\nimport { DataPointStyles } from './DataPointStyles'\nimport { SourcePayloads } from './SourcePayloads'\n\ninterface SourcePayloadConfig {\n fetch: boolean\n sampleSize?: number\n}\n\ninterface ThemeColors {\n dataSetColorPrimary: string\n dataSetColorSecondary: string\n gridColor: string\n}\n\nconst defaultOptions: () => ChartOptions<'line'> = () => ({\n plugins: {\n legend: {\n position: 'top' as const,\n },\n },\n responsive: true,\n})\n\nexport class ForecastLineChartConfigBuilder {\n data: ChartData<'line'> = {\n datasets: [],\n }\n options: ChartOptions<'line'> = defaultOptions()\n themeColors: ThemeColors | undefined\n\n constructor(\n theme: Theme,\n private payload?: ForecastPayload,\n ) {\n this.themeColors = this.parseTheme(theme)\n }\n\n get forecastPayload() {\n if (this.payload) {\n return this.payload\n } else {\n throw Error('ForecastPayload was not defined')\n }\n }\n\n static async create(theme: Theme, payload?: ForecastPayload, sourcePayloadConfig?: SourcePayloadConfig) {\n const instance = new ForecastLineChartConfigBuilder(theme, payload)\n\n await instance.build(sourcePayloadConfig?.fetch)\n\n instance.refreshValues()\n\n return instance\n }\n\n async build(includeSources?: boolean) {\n this.buildOptions()\n await this.buildData(includeSources)\n return this\n }\n\n async buildData(includeSources?: boolean) {\n const forecastData = this.generateDataSetForecastData()\n\n const datasets: ChartDataset<'line'>[] = [forecastData]\n\n if (includeSources) {\n // build data from sources in forecastPayload\n const sourceData = await this.generateDataSetSourcePayloads()\n datasets.unshift(sourceData)\n\n // add last source point as first item in prediction to connect the lines\n const lastSourceDataItem = sourceData.data.at(-1) as Point\n forecastData.data.unshift(lastSourceDataItem)\n }\n\n this.data = {\n datasets,\n }\n\n return this\n }\n\n buildOptions() {\n if (this.options.plugins) {\n this.options.plugins.title = this.generateTitle()\n this.options.plugins.legend = this.generateLegend()\n }\n this.options.scales = this.generateScales()\n\n return this\n }\n\n refreshValues() {\n this.data = { ...this.data }\n this.options = { ...this.options }\n }\n\n protected generateLegend(): _DeepPartialObject<LegendOptions<'line'>> {\n return {\n labels: {\n pointStyle: 'circle',\n usePointStyle: true,\n },\n }\n }\n\n protected generateScales(): _DeepPartialObject<ScaleChartOptions<'line'>['scales']> {\n return {\n x: {\n grid: {\n color: this.themeColors?.gridColor,\n },\n time: {\n unit: 'minute',\n },\n type: 'time',\n },\n y: {\n grid: {\n color: this.themeColors?.gridColor,\n },\n },\n }\n }\n\n protected generateTitle() {\n return {\n display: true,\n text: `Gas Price Forecaster (GWEI over time from ${\n this.forecastPayload?.values[0].timestamp ? new Date(this.forecastPayload.values[0].timestamp).toLocaleDateString() : ''\n })`,\n }\n }\n\n protected parseTheme(theme: Theme) {\n const dark = theme.palette.mode === 'dark'\n return {\n dataSetColorPrimary: theme.palette.primary.light,\n dataSetColorSecondary: theme.palette.secondary.light,\n gridColor: dark ? theme.palette.grey[800] : theme.palette.grey[300],\n }\n }\n\n private generateDataSetForecastData(): ChartDataset<'line'> {\n return {\n borderDash: [5],\n borderDashOffset: 0.5,\n data: this.forecastPayload.values.map((price) => ({ x: price.timestamp ?? 0, y: price.value })),\n label: 'Forecast Price',\n ...DataPointStyles(this.themeColors?.dataSetColorPrimary),\n ...DataLineStyles(this.themeColors?.dataSetColorPrimary),\n }\n }\n\n private async generateDataSetSourcePayloads(): Promise<ChartDataset<'line'>> {\n const { sourcePrices } = await SourcePayloads.build('feePerGas.medium')\n return {\n data: sourcePrices,\n label: 'Source Prices',\n ...DataLineStyles(this.themeColors?.dataSetColorSecondary),\n ...DataPointStyles(this.themeColors?.dataSetColorSecondary),\n }\n }\n}\n"],"mappings":";AAAA,OAAO;AAEP,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAuB,eAAe;AAGtC;AAAA,EACE;AAAA,EACA,SAAS;AAAA,EAGT;AA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AE/D;AAAA;AAAA,IAEE,OAAO,YAAY;AACjB,YAAM,EAAE,MAAAA,OAAM,SAAAC,SAAQ,IAAI,MAAM,+BAA+B,OAAO,OAAO,sBAAsB,EAAE,OAAO,KAAK,CAAC;AAClH,UAAI,QAAQ,GAAG;AACb,gBAAQD,KAAI;AACZ,mBAAWC,QAAO;AAAA,MACpB;AAAA,IACF;AAAA,IACA,CAAC,sBAAsB,KAAK;AAAA,EAC9B;AAEA,SACE,oBAAC,WAAS,GAAG,OAAO,MAAM,yBAAyB,QAAW,WAAU,QACrE,iCAAuB,oBAAC,QAAK,SAAkB,MAAY,IAAK,MACnE;AAEJ;","names":["data","options"]}
@@ -1,3 +1,258 @@
1
- export * from "./components";
2
- export * from "./Plugin";
1
+ // src/components/DetailsBox.tsx
2
+ import "chartjs-adapter-luxon";
3
+ import { useTheme } from "@mui/material";
4
+ import { useAsyncEffect } from "@xylabs/react-async-effect";
5
+ import { FlexCol } from "@xylabs/react-flexbox";
6
+ import {
7
+ CategoryScale,
8
+ Chart as ChartJS,
9
+ Legend,
10
+ LinearScale,
11
+ LineElement,
12
+ PointElement,
13
+ TimeScale,
14
+ Title,
15
+ Tooltip
16
+ } from "chart.js";
17
+ import { useState } from "react";
18
+ import { Line } from "react-chartjs-2";
19
+
20
+ // src/lib/DataLineStyles.ts
21
+ import { alpha } from "@mui/material";
22
+ var DataLineStyles = (color) => ({
23
+ backgroundColor: color ? alpha(color, 0.5) : void 0,
24
+ borderColor: color
25
+ });
26
+
27
+ // src/lib/DataPointStyles.ts
28
+ var DataPointStyles = (pointHoverBackgroundColor) => ({
29
+ pointHitRadius: 20,
30
+ pointHoverBackgroundColor,
31
+ pointHoverRadius: 10,
32
+ pointRadius: 5,
33
+ pointStyle: "circle"
34
+ });
35
+
36
+ // src/lib/MockSourcePayloads.ts
37
+ var MockSourcePayloads = () => {
38
+ const tenMin = 6e5;
39
+ return [
40
+ {
41
+ baseFee: 38.90155387825,
42
+ feePerGas: { high: 47.9945864396, low: 39.006868093, medium: 39.306868093, veryHigh: 44.45384380525 },
43
+ priorityFeePerGas: { high: 1.0266666666666666, low: -0.41000000000000003, medium: 0.38, veryHigh: 1.3900000000000001 },
44
+ schema: "network.xyo.blockchain.ethereum.gas",
45
+ timestamp: Date.now() - tenMin
46
+ },
47
+ {
48
+ baseFee: 38.90155387825,
49
+ feePerGas: { high: 47.9945864396, low: 39.006868093, medium: 100, veryHigh: 44.45384380525 },
50
+ priorityFeePerGas: { high: 1.0266666666666666, low: -0.41000000000000003, medium: 0.38, veryHigh: 1.3900000000000001 },
51
+ schema: "network.xyo.blockchain.ethereum.gas",
52
+ timestamp: Date.now()
53
+ }
54
+ ];
55
+ };
56
+
57
+ // src/lib/SourcePayloads.ts
58
+ var SourcePayloads = class {
59
+ constructor(sourcePayloads) {
60
+ this.sourcePayloads = sourcePayloads;
61
+ }
62
+ sourcePrices = [];
63
+ get payloads() {
64
+ return this.sourcePayloads;
65
+ }
66
+ static async build(jsonPath) {
67
+ const sourcePayloads = await this.fetchSourcePayloads();
68
+ const instance = new this(sourcePayloads);
69
+ const paths = jsonPath.split(".");
70
+ instance.sourcePrices = sourcePayloads.map((payload) => {
71
+ return { x: payload.timestamp, y: instance.jsonPathTraverser(payload, paths) };
72
+ });
73
+ return instance;
74
+ }
75
+ // TODO - fetch from archivist
76
+ static async fetchSourcePayloads() {
77
+ const payloads = await Promise.resolve(MockSourcePayloads());
78
+ return payloads;
79
+ }
80
+ jsonPathTraverser(obj, path) {
81
+ let result = obj;
82
+ for (const key of path) {
83
+ if (key in result) {
84
+ const foundKey = key;
85
+ result = result[foundKey];
86
+ } else {
87
+ result = void 0;
88
+ break;
89
+ }
90
+ }
91
+ return result;
92
+ }
93
+ };
94
+
95
+ // src/lib/ForecastLineChartConfigBuilder.ts
96
+ var defaultOptions = () => ({
97
+ plugins: {
98
+ legend: {
99
+ position: "top"
100
+ }
101
+ },
102
+ responsive: true
103
+ });
104
+ var ForecastLineChartConfigBuilder = class _ForecastLineChartConfigBuilder {
105
+ constructor(theme, payload) {
106
+ this.payload = payload;
107
+ this.themeColors = this.parseTheme(theme);
108
+ }
109
+ data = {
110
+ datasets: []
111
+ };
112
+ options = defaultOptions();
113
+ themeColors;
114
+ get forecastPayload() {
115
+ if (this.payload) {
116
+ return this.payload;
117
+ } else {
118
+ throw Error("ForecastPayload was not defined");
119
+ }
120
+ }
121
+ static async create(theme, payload, sourcePayloadConfig) {
122
+ const instance = new _ForecastLineChartConfigBuilder(theme, payload);
123
+ await instance.build(sourcePayloadConfig?.fetch);
124
+ instance.refreshValues();
125
+ return instance;
126
+ }
127
+ async build(includeSources) {
128
+ this.buildOptions();
129
+ await this.buildData(includeSources);
130
+ return this;
131
+ }
132
+ async buildData(includeSources) {
133
+ const forecastData = this.generateDataSetForecastData();
134
+ const datasets = [forecastData];
135
+ if (includeSources) {
136
+ const sourceData = await this.generateDataSetSourcePayloads();
137
+ datasets.unshift(sourceData);
138
+ const lastSourceDataItem = sourceData.data.at(-1);
139
+ forecastData.data.unshift(lastSourceDataItem);
140
+ }
141
+ this.data = {
142
+ datasets
143
+ };
144
+ return this;
145
+ }
146
+ buildOptions() {
147
+ if (this.options.plugins) {
148
+ this.options.plugins.title = this.generateTitle();
149
+ this.options.plugins.legend = this.generateLegend();
150
+ }
151
+ this.options.scales = this.generateScales();
152
+ return this;
153
+ }
154
+ refreshValues() {
155
+ this.data = { ...this.data };
156
+ this.options = { ...this.options };
157
+ }
158
+ generateLegend() {
159
+ return {
160
+ labels: {
161
+ pointStyle: "circle",
162
+ usePointStyle: true
163
+ }
164
+ };
165
+ }
166
+ generateScales() {
167
+ return {
168
+ x: {
169
+ grid: {
170
+ color: this.themeColors?.gridColor
171
+ },
172
+ time: {
173
+ unit: "minute"
174
+ },
175
+ type: "time"
176
+ },
177
+ y: {
178
+ grid: {
179
+ color: this.themeColors?.gridColor
180
+ }
181
+ }
182
+ };
183
+ }
184
+ generateTitle() {
185
+ return {
186
+ display: true,
187
+ text: `Gas Price Forecaster (GWEI over time from ${this.forecastPayload?.values[0].timestamp ? new Date(this.forecastPayload.values[0].timestamp).toLocaleDateString() : ""})`
188
+ };
189
+ }
190
+ parseTheme(theme) {
191
+ const dark = theme.palette.mode === "dark";
192
+ return {
193
+ dataSetColorPrimary: theme.palette.primary.light,
194
+ dataSetColorSecondary: theme.palette.secondary.light,
195
+ gridColor: dark ? theme.palette.grey[800] : theme.palette.grey[300]
196
+ };
197
+ }
198
+ generateDataSetForecastData() {
199
+ return {
200
+ borderDash: [5],
201
+ borderDashOffset: 0.5,
202
+ data: this.forecastPayload.values.map((price) => ({ x: price.timestamp ?? 0, y: price.value })),
203
+ label: "Forecast Price",
204
+ ...DataPointStyles(this.themeColors?.dataSetColorPrimary),
205
+ ...DataLineStyles(this.themeColors?.dataSetColorPrimary)
206
+ };
207
+ }
208
+ async generateDataSetSourcePayloads() {
209
+ const { sourcePrices } = await SourcePayloads.build("feePerGas.medium");
210
+ return {
211
+ data: sourcePrices,
212
+ label: "Source Prices",
213
+ ...DataLineStyles(this.themeColors?.dataSetColorSecondary),
214
+ ...DataPointStyles(this.themeColors?.dataSetColorSecondary)
215
+ };
216
+ }
217
+ };
218
+
219
+ // src/components/DetailsBox.tsx
220
+ import { jsx } from "react/jsx-runtime";
221
+ ChartJS.register(CategoryScale, TimeScale, PointElement, LineElement, LinearScale, Title, Tooltip, Legend);
222
+ var PriceForecastDetailsBox = ({ payload, ...props }) => {
223
+ const priceForecastPayload = payload;
224
+ const theme = useTheme();
225
+ const [data, setData] = useState({ datasets: [] });
226
+ const [options, setOptions] = useState({});
227
+ useAsyncEffect(
228
+ // eslint-disable-next-line react-hooks/exhaustive-deps
229
+ async (mounted) => {
230
+ const { data: data2, options: options2 } = await ForecastLineChartConfigBuilder.create(theme, priceForecastPayload, { fetch: true });
231
+ if (mounted()) {
232
+ setData(data2);
233
+ setOptions(options2);
234
+ }
235
+ },
236
+ [priceForecastPayload, theme]
237
+ );
238
+ return /* @__PURE__ */ jsx(FlexCol, { ...props, busy: priceForecastPayload === void 0, minHeight: "25vh", children: priceForecastPayload ? /* @__PURE__ */ jsx(Line, { options, data }) : null });
239
+ };
240
+
241
+ // src/Plugin.ts
242
+ import { createPayloadRenderPlugin } from "@xyo-network/react-payload-plugin";
243
+ var PriceForecastRenderPlugin = {
244
+ ...createPayloadRenderPlugin({
245
+ canRender: () => true,
246
+ components: {
247
+ box: {
248
+ detailsBox: PriceForecastDetailsBox
249
+ }
250
+ },
251
+ name: "PriceForecast"
252
+ })
253
+ };
254
+ export {
255
+ PriceForecastDetailsBox,
256
+ PriceForecastRenderPlugin
257
+ };
3
258
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './components'\nexport * from './Plugin'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/components/DetailsBox.tsx","../../src/lib/DataLineStyles.ts","../../src/lib/DataPointStyles.ts","../../src/lib/MockSourcePayloads.ts","../../src/lib/SourcePayloads.ts","../../src/lib/ForecastLineChartConfigBuilder.ts","../../src/Plugin.ts"],"sourcesContent":["import 'chartjs-adapter-luxon'\n\nimport { useTheme } from '@mui/material'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'\nimport { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n CategoryScale,\n Chart as ChartJS,\n ChartData,\n ChartOptions,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n TimeScale,\n Title,\n Tooltip,\n} from 'chart.js'\nimport { useState } from 'react'\nimport { Line } from 'react-chartjs-2'\n\nimport { ForecastLineChartConfigBuilder } from '../lib'\n\nChartJS.register(CategoryScale, TimeScale, PointElement, LineElement, LinearScale, Title, Tooltip, Legend)\n\nexport interface PriceForecastDetailsBoxProps extends FlexBoxProps {\n payload?: Payload\n}\n\nexport const PriceForecastDetailsBox: React.FC<PriceForecastDetailsBoxProps> = ({ payload, ...props }) => {\n const priceForecastPayload = payload as ForecastPayload | undefined\n const theme = useTheme()\n const [data, setData] = useState<ChartData<'line'>>({ datasets: [] })\n const [options, setOptions] = useState<ChartOptions<'line'>>({})\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n const { data, options } = await ForecastLineChartConfigBuilder.create(theme, priceForecastPayload, { fetch: true })\n if (mounted()) {\n setData(data)\n setOptions(options)\n }\n },\n [priceForecastPayload, theme],\n )\n\n return (\n <FlexCol {...props} busy={priceForecastPayload === undefined} minHeight=\"25vh\">\n {priceForecastPayload ? <Line options={options} data={data} /> : null}\n </FlexCol>\n )\n}\n","import { alpha } from '@mui/material'\n\nexport const DataLineStyles = (color?: string) => ({\n backgroundColor: color ? alpha(color, 0.5) : undefined,\n borderColor: color,\n})\n","export const DataPointStyles = (pointHoverBackgroundColor?: string) => ({\n pointHitRadius: 20,\n pointHoverBackgroundColor,\n pointHoverRadius: 10,\n pointRadius: 5,\n pointStyle: 'circle',\n})\n","export const MockSourcePayloads = () => {\n const tenMin = 600000\n return [\n {\n baseFee: 38.90155387825,\n feePerGas: { high: 47.9945864396, low: 39.006868093, medium: 39.306868093, veryHigh: 44.45384380525 },\n priorityFeePerGas: { high: 1.0266666666666666, low: -0.41000000000000003, medium: 0.38, veryHigh: 1.3900000000000001 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now() - tenMin,\n },\n {\n baseFee: 38.90155387825,\n feePerGas: { high: 47.9945864396, low: 39.006868093, medium: 100, veryHigh: 44.45384380525 },\n priorityFeePerGas: { high: 1.0266666666666666, low: -0.41000000000000003, medium: 0.38, veryHigh: 1.3900000000000001 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now(),\n },\n ]\n}\n","import { Payload } from '@xyo-network/payload-model'\nimport { Point } from 'chart.js'\n\nimport { MockSourcePayloads } from './MockSourcePayloads'\n\nexport class SourcePayloads {\n sourcePrices: Point[] = []\n\n constructor(public sourcePayloads: Payload[]) {}\n\n get payloads() {\n return this.sourcePayloads\n }\n\n static async build(jsonPath: string) {\n const sourcePayloads = await this.fetchSourcePayloads()\n const instance = new this(sourcePayloads)\n\n const paths = jsonPath.split('.')\n instance.sourcePrices = sourcePayloads.map((payload) => {\n return { x: payload.timestamp, y: instance.jsonPathTraverser(payload, paths) }\n })\n return instance\n }\n\n // TODO - fetch from archivist\n static async fetchSourcePayloads() {\n const payloads = await Promise.resolve(MockSourcePayloads())\n return payloads\n }\n\n jsonPathTraverser(obj: Payload, path: string[]) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let result: any = obj\n for (const key of path) {\n if (key in result) {\n const foundKey = key as keyof typeof result\n result = result[foundKey]\n } else {\n result = undefined\n break\n }\n }\n\n return result\n }\n}\n","import { Theme } from '@mui/material'\nimport { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport { ChartData, ChartDataset, ChartOptions, LegendOptions, Point, ScaleChartOptions } from 'chart.js'\n// eslint-disable-next-line import/no-unresolved\nimport { _DeepPartialObject } from 'chart.js/dist/types/utils'\n\nimport { DataLineStyles } from './DataLineStyles'\nimport { DataPointStyles } from './DataPointStyles'\nimport { SourcePayloads } from './SourcePayloads'\n\ninterface SourcePayloadConfig {\n fetch: boolean\n sampleSize?: number\n}\n\ninterface ThemeColors {\n dataSetColorPrimary: string\n dataSetColorSecondary: string\n gridColor: string\n}\n\nconst defaultOptions: () => ChartOptions<'line'> = () => ({\n plugins: {\n legend: {\n position: 'top' as const,\n },\n },\n responsive: true,\n})\n\nexport class ForecastLineChartConfigBuilder {\n data: ChartData<'line'> = {\n datasets: [],\n }\n options: ChartOptions<'line'> = defaultOptions()\n themeColors: ThemeColors | undefined\n\n constructor(\n theme: Theme,\n private payload?: ForecastPayload,\n ) {\n this.themeColors = this.parseTheme(theme)\n }\n\n get forecastPayload() {\n if (this.payload) {\n return this.payload\n } else {\n throw Error('ForecastPayload was not defined')\n }\n }\n\n static async create(theme: Theme, payload?: ForecastPayload, sourcePayloadConfig?: SourcePayloadConfig) {\n const instance = new ForecastLineChartConfigBuilder(theme, payload)\n\n await instance.build(sourcePayloadConfig?.fetch)\n\n instance.refreshValues()\n\n return instance\n }\n\n async build(includeSources?: boolean) {\n this.buildOptions()\n await this.buildData(includeSources)\n return this\n }\n\n async buildData(includeSources?: boolean) {\n const forecastData = this.generateDataSetForecastData()\n\n const datasets: ChartDataset<'line'>[] = [forecastData]\n\n if (includeSources) {\n // build data from sources in forecastPayload\n const sourceData = await this.generateDataSetSourcePayloads()\n datasets.unshift(sourceData)\n\n // add last source point as first item in prediction to connect the lines\n const lastSourceDataItem = sourceData.data.at(-1) as Point\n forecastData.data.unshift(lastSourceDataItem)\n }\n\n this.data = {\n datasets,\n }\n\n return this\n }\n\n buildOptions() {\n if (this.options.plugins) {\n this.options.plugins.title = this.generateTitle()\n this.options.plugins.legend = this.generateLegend()\n }\n this.options.scales = this.generateScales()\n\n return this\n }\n\n refreshValues() {\n this.data = { ...this.data }\n this.options = { ...this.options }\n }\n\n protected generateLegend(): _DeepPartialObject<LegendOptions<'line'>> {\n return {\n labels: {\n pointStyle: 'circle',\n usePointStyle: true,\n },\n }\n }\n\n protected generateScales(): _DeepPartialObject<ScaleChartOptions<'line'>['scales']> {\n return {\n x: {\n grid: {\n color: this.themeColors?.gridColor,\n },\n time: {\n unit: 'minute',\n },\n type: 'time',\n },\n y: {\n grid: {\n color: this.themeColors?.gridColor,\n },\n },\n }\n }\n\n protected generateTitle() {\n return {\n display: true,\n text: `Gas Price Forecaster (GWEI over time from ${\n this.forecastPayload?.values[0].timestamp ? new Date(this.forecastPayload.values[0].timestamp).toLocaleDateString() : ''\n })`,\n }\n }\n\n protected parseTheme(theme: Theme) {\n const dark = theme.palette.mode === 'dark'\n return {\n dataSetColorPrimary: theme.palette.primary.light,\n dataSetColorSecondary: theme.palette.secondary.light,\n gridColor: dark ? theme.palette.grey[800] : theme.palette.grey[300],\n }\n }\n\n private generateDataSetForecastData(): ChartDataset<'line'> {\n return {\n borderDash: [5],\n borderDashOffset: 0.5,\n data: this.forecastPayload.values.map((price) => ({ x: price.timestamp ?? 0, y: price.value })),\n label: 'Forecast Price',\n ...DataPointStyles(this.themeColors?.dataSetColorPrimary),\n ...DataLineStyles(this.themeColors?.dataSetColorPrimary),\n }\n }\n\n private async generateDataSetSourcePayloads(): Promise<ChartDataset<'line'>> {\n const { sourcePrices } = await SourcePayloads.build('feePerGas.medium')\n return {\n data: sourcePrices,\n label: 'Source Prices',\n ...DataLineStyles(this.themeColors?.dataSetColorSecondary),\n ...DataPointStyles(this.themeColors?.dataSetColorSecondary),\n }\n }\n}\n","import { createPayloadRenderPlugin, PayloadRenderPlugin } from '@xyo-network/react-payload-plugin'\n\nimport { PriceForecastDetailsBox } from './components'\n\nexport const PriceForecastRenderPlugin: PayloadRenderPlugin = {\n ...createPayloadRenderPlugin({\n canRender: () => true,\n components: {\n box: {\n detailsBox: PriceForecastDetailsBox,\n },\n },\n name: 'PriceForecast',\n }),\n}\n"],"mappings":";AAAA,OAAO;AAEP,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAuB,eAAe;AAGtC;AAAA,EACE;AAAA,EACA,SAAS;AAAA,EAGT;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB,SAAS,YAAY;;;ACrBrB,SAAS,aAAa;AAEf,IAAM,iBAAiB,CAAC,WAAoB;AAAA,EACjD,iBAAiB,QAAQ,MAAM,OAAO,GAAG,IAAI;AAAA,EAC7C,aAAa;AACf;;;ACLO,IAAM,kBAAkB,CAAC,+BAAwC;AAAA,EACtE,gBAAgB;AAAA,EAChB;AAAA,EACA,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,YAAY;AACd;;;ACNO,IAAM,qBAAqB,MAAM;AACtC,QAAM,SAAS;AACf,SAA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AIxD,IAAM,4BAAiD;AAAA,EAC5D,GAAG,0BAA0B;AAAA,IAC3B,WAAW,MAAM;AAAA,IACjB,YAAY;AAAA,MACV,KAAK;AAAA,QACH,YAAY;AAAA,MACd;AAAA,IACF;AAAA,IACA,MAAM;AAAA,EACR,CAAC;AACH;","names":["data","options"]}
@@ -1,5 +1,6 @@
1
+ // src/lib/DataLineStyles.ts
1
2
  import { alpha } from "@mui/material";
2
- const DataLineStyles = (color) => ({
3
+ var DataLineStyles = (color) => ({
3
4
  backgroundColor: color ? alpha(color, 0.5) : void 0,
4
5
  borderColor: color
5
6
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/DataLineStyles.ts"],"sourcesContent":["import { alpha } from '@mui/material'\n\nexport const DataLineStyles = (color?: string) => ({\n backgroundColor: color ? alpha(color, 0.5) : undefined,\n borderColor: color,\n})\n"],"mappings":"AAAA,SAAS,aAAa;AAEf,MAAM,iBAAiB,CAAC,WAAoB;AAAA,EACjD,iBAAiB,QAAQ,MAAM,OAAO,GAAG,IAAI;AAAA,EAC7C,aAAa;AACf;","names":[]}
1
+ {"version":3,"sources":["../../../src/lib/DataLineStyles.ts"],"sourcesContent":["import { alpha } from '@mui/material'\n\nexport const DataLineStyles = (color?: string) => ({\n backgroundColor: color ? alpha(color, 0.5) : undefined,\n borderColor: color,\n})\n"],"mappings":";AAAA,SAAS,aAAa;AAEf,IAAM,iBAAiB,CAAC,WAAoB;AAAA,EACjD,iBAAiB,QAAQ,MAAM,OAAO,GAAG,IAAI;AAAA,EAC7C,aAAa;AACf;","names":[]}
@@ -1,4 +1,5 @@
1
- const DataPointStyles = (pointHoverBackgroundColor) => ({
1
+ // src/lib/DataPointStyles.ts
2
+ var DataPointStyles = (pointHoverBackgroundColor) => ({
2
3
  pointHitRadius: 20,
3
4
  pointHoverBackgroundColor,
4
5
  pointHoverRadius: 10,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/DataPointStyles.ts"],"sourcesContent":["export const DataPointStyles = (pointHoverBackgroundColor?: string) => ({\n pointHitRadius: 20,\n pointHoverBackgroundColor,\n pointHoverRadius: 10,\n pointRadius: 5,\n pointStyle: 'circle',\n})\n"],"mappings":"AAAO,MAAM,kBAAkB,CAAC,+BAAwC;AAAA,EACtE,gBAAgB;AAAA,EAChB;AAAA,EACA,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,YAAY;AACd;","names":[]}
1
+ {"version":3,"sources":["../../../src/lib/DataPointStyles.ts"],"sourcesContent":["export const DataPointStyles = (pointHoverBackgroundColor?: string) => ({\n pointHitRadius: 20,\n pointHoverBackgroundColor,\n pointHoverRadius: 10,\n pointRadius: 5,\n pointStyle: 'circle',\n})\n"],"mappings":";AAAO,IAAM,kBAAkB,CAAC,+BAAwC;AAAA,EACtE,gBAAgB;AAAA,EAChB;AAAA,EACA,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,YAAY;AACd;","names":[]}