@xyo-network/react-price-forecast-plugin 3.0.2 → 3.0.3

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.
@@ -0,0 +1,3 @@
1
+ import type { PayloadRenderPlugin } from '@xyo-network/react-payload-plugin';
2
+ export declare const PriceForecastRenderPlugin: PayloadRenderPlugin;
3
+ //# sourceMappingURL=Plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AAK5E,eAAO,MAAM,yBAAyB,EAAE,mBAMvC,CAAA"}
@@ -0,0 +1,9 @@
1
+ import 'chartjs-adapter-luxon';
2
+ import type { FlexBoxProps } from '@xylabs/react-flexbox';
3
+ import type { Payload } from '@xyo-network/payload-model';
4
+ import React from 'react';
5
+ export interface PriceForecastDetailsBoxProps extends FlexBoxProps {
6
+ payload?: Payload;
7
+ }
8
+ export declare const PriceForecastDetailsBox: React.FC<PriceForecastDetailsBoxProps>;
9
+ //# sourceMappingURL=DetailsBox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DetailsBox.d.ts","sourceRoot":"","sources":["../../../src/components/DetailsBox.tsx"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAA;AAI9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAGzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAgBzD,OAAO,KAAmB,MAAM,OAAO,CAAA;AAOvC,MAAM,WAAW,4BAA6B,SAAQ,YAAY;IAChE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC,4BAA4B,CAyB1E,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './DetailsBox.tsx';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -1,13 +1,3 @@
1
- import { FlexBoxProps } from '@xylabs/react-flexbox';
2
- import { Payload } from '@xyo-network/payload-model';
3
- import React from 'react';
4
- import { PayloadRenderPlugin } from '@xyo-network/react-payload-plugin';
5
-
6
- interface PriceForecastDetailsBoxProps extends FlexBoxProps {
7
- payload?: Payload;
8
- }
9
- declare const PriceForecastDetailsBox: React.FC<PriceForecastDetailsBoxProps>;
10
-
11
- declare const PriceForecastRenderPlugin: PayloadRenderPlugin;
12
-
13
- export { PriceForecastDetailsBox, type PriceForecastDetailsBoxProps, PriceForecastRenderPlugin };
1
+ export * from './components/index.ts';
2
+ export * from './Plugin.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA"}
@@ -1 +1 @@
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 type { FlexBoxProps } from '@xylabs/react-flexbox'\nimport { FlexCol } from '@xylabs/react-flexbox'\nimport type { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type {\n ChartData,\n ChartOptions } from 'chart.js'\nimport {\n CategoryScale,\n Chart as ChartJS,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n TimeScale,\n Title,\n Tooltip,\n} from 'chart.js'\nimport React, { useState } from 'react'\nimport { Line } from 'react-chartjs-2'\n\nimport { ForecastLineChartConfigBuilder } from '../lib/index.ts'\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\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\n ? <Line options={options} data={data} />\n : 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 = 600_000\n return [\n {\n baseFee: 38.901_553_878_25,\n feePerGas: { high: 47.994_586_439_6, low: 39.006_868_093, medium: 39.306_868_093, veryHigh: 44.453_843_805_25 },\n priorityFeePerGas: { high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now() - tenMin,\n },\n {\n baseFee: 38.901_553_878_25,\n feePerGas: { high: 47.994_586_439_6, low: 39.006_868_093, medium: 100, veryHigh: 44.453_843_805_25 },\n priorityFeePerGas: { high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1 },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now(),\n },\n ]\n}\n","import type { Payload } from '@xyo-network/payload-model'\nimport type { Point } from 'chart.js'\n\nimport { MockSourcePayloads } from './MockSourcePayloads.ts'\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 type { Theme } from '@mui/material'\nimport type { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport type { ChartData, ChartDataset, ChartOptions, LegendOptions, Point, ScaleChartOptions } from 'chart.js'\n\nimport { DataLineStyles } from './DataLineStyles.ts'\nimport { DataPointStyles } from './DataPointStyles.ts'\nimport { SourcePayloads } from './SourcePayloads.ts'\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\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 new 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() {\n return {\n labels: {\n pointStyle: 'circle',\n usePointStyle: true,\n },\n } as LegendOptions<'line'>\n }\n\n protected generateScales() {\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 } as unknown as ScaleChartOptions<'line'>['scales']\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 type { PayloadRenderPlugin } from '@xyo-network/react-payload-plugin'\nimport { createPayloadRenderPlugin } from '@xyo-network/react-payload-plugin'\n\nimport { PriceForecastDetailsBox } from './components/index.ts'\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,SAASA,gBAAgB;AACzB,SAASC,sBAAsB;AAE/B,SAASC,eAAe;AAMxB,SACEC,eACAC,SAASC,SACTC,QACAC,aACAC,aACAC,cACAC,WACAC,OACAC,eACK;AACP,OAAOC,SAASC,gBAAgB;AAChC,SAASC,YAAY;;;ACvBrB,SAASC,aAAa;AAEf,IAAMC,iBAAiB,wBAACC,WAAoB;EACjDC,iBAAiBD,QAAQE,MAAMF,OAAO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AAInC,IAAMC,4BAAiD;EAC5D,GAAGC,0BAA0B;IAC3BC,WAAW,6BAAM,MAAN;IACXC,YAAY;MACVC,KAAK;QACHC,YAAYC;MACd;IACF;IACAC,MAAM;EACR,CAAA;AACF;","names":["useTheme","useAsyncEffect","FlexCol","CategoryScale","Chart","ChartJS","Legend","LinearScale","LineElement","PointElement","TimeScale","Title","Tooltip","React","useState","Line","alpha","DataLineStyles","color","backgroundColor","alpha","undefined","borderColor","DataPointStyles","pointHoverBackgroundColor","pointHitRadius","pointHoverRadius","pointRadius","pointStyle","MockSourcePayloads","tenMin","baseFee","feePerGas","high","low","medium","veryHigh","priorityFeePerGas","schema","timestamp","Date","now","SourcePayloads","sourcePrices","constructor","sourcePayloads","payloads","build","jsonPath","fetchSourcePayloads","instance","paths","split","map","payload","x","timestamp","y","jsonPathTraverser","Promise","resolve","MockSourcePayloads","obj","path","result","key","foundKey","undefined","defaultOptions","plugins","legend","position","responsive","ForecastLineChartConfigBuilder","data","options","themeColors","constructor","theme","payload","datasets","parseTheme","forecastPayload","Error","create","sourcePayloadConfig","instance","build","fetch","refreshValues","includeSources","buildOptions","buildData","forecastData","generateDataSetForecastData","sourceData","generateDataSetSourcePayloads","unshift","lastSourceDataItem","at","title","generateTitle","generateLegend","scales","generateScales","labels","pointStyle","usePointStyle","x","grid","color","gridColor","time","unit","type","y","display","text","values","timestamp","Date","toLocaleDateString","dark","palette","mode","dataSetColorPrimary","primary","light","dataSetColorSecondary","secondary","grey","borderDash","borderDashOffset","map","price","value","label","DataPointStyles","DataLineStyles","sourcePrices","SourcePayloads","ChartJS","register","CategoryScale","TimeScale","PointElement","LineElement","LinearScale","Title","Tooltip","Legend","PriceForecastDetailsBox","payload","props","priceForecastPayload","theme","useTheme","data","setData","useState","datasets","options","setOptions","useAsyncEffect","mounted","ForecastLineChartConfigBuilder","create","fetch","FlexCol","busy","undefined","minHeight","Line","createPayloadRenderPlugin","PriceForecastRenderPlugin","createPayloadRenderPlugin","canRender","components","box","detailsBox","PriceForecastDetailsBox","name"]}
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 type { FlexBoxProps } from '@xylabs/react-flexbox'\nimport { FlexCol } from '@xylabs/react-flexbox'\nimport type { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type {\n ChartData,\n ChartOptions,\n} from 'chart.js'\nimport {\n CategoryScale,\n Chart as ChartJS,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n TimeScale,\n Title,\n Tooltip,\n} from 'chart.js'\nimport React, { useState } from 'react'\nimport { Line } from 'react-chartjs-2'\n\nimport { ForecastLineChartConfigBuilder } from '../lib/index.ts'\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\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\n ? <Line options={options} data={data} />\n : 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 = 600_000\n return [\n {\n baseFee: 38.901_553_878_25,\n feePerGas: {\n high: 47.994_586_439_6, low: 39.006_868_093, medium: 39.306_868_093, veryHigh: 44.453_843_805_25,\n },\n priorityFeePerGas: {\n high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1,\n },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now() - tenMin,\n },\n {\n baseFee: 38.901_553_878_25,\n feePerGas: {\n high: 47.994_586_439_6, low: 39.006_868_093, medium: 100, veryHigh: 44.453_843_805_25,\n },\n priorityFeePerGas: {\n high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1,\n },\n schema: 'network.xyo.blockchain.ethereum.gas',\n timestamp: Date.now(),\n },\n ]\n}\n","import type { Payload } from '@xyo-network/payload-model'\nimport type { Point } from 'chart.js'\n\nimport { MockSourcePayloads } from './MockSourcePayloads.ts'\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 type { Theme } from '@mui/material'\nimport type { ForecastPayload } from '@xyo-network/diviner-forecasting-model'\nimport type {\n ChartData, ChartDataset, ChartOptions, LegendOptions, Point, ScaleChartOptions,\n} from 'chart.js'\n\nimport { DataLineStyles } from './DataLineStyles.ts'\nimport { DataPointStyles } from './DataPointStyles.ts'\nimport { SourcePayloads } from './SourcePayloads.ts'\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: { legend: { position: 'top' as const } },\n responsive: true,\n})\n\nexport class ForecastLineChartConfigBuilder {\n data: ChartData<'line'> = { 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 new 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 = { datasets }\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() {\n return {\n labels: {\n pointStyle: 'circle',\n usePointStyle: true,\n },\n } as LegendOptions<'line'>\n }\n\n protected generateScales() {\n return {\n x: {\n grid: { color: this.themeColors?.gridColor },\n time: { unit: 'minute' },\n type: 'time',\n },\n y: { grid: { color: this.themeColors?.gridColor } },\n } as unknown as ScaleChartOptions<'line'>['scales']\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 type { PayloadRenderPlugin } from '@xyo-network/react-payload-plugin'\nimport { createPayloadRenderPlugin } from '@xyo-network/react-payload-plugin'\n\nimport { PriceForecastDetailsBox } from './components/index.ts'\n\nexport const PriceForecastRenderPlugin: PayloadRenderPlugin = {\n ...createPayloadRenderPlugin({\n canRender: () => true,\n components: { box: { detailsBox: PriceForecastDetailsBox } },\n name: 'PriceForecast',\n }),\n}\n"],"mappings":";;;;AAAA,OAAO;AAEP,SAASA,gBAAgB;AACzB,SAASC,sBAAsB;AAE/B,SAASC,eAAe;AAOxB,SACEC,eACAC,SAASC,SACTC,QACAC,aACAC,aACAC,cACAC,WACAC,OACAC,eACK;AACP,OAAOC,SAASC,gBAAgB;AAChC,SAASC,YAAY;;;ACxBrB,SAASC,aAAa;AAEf,IAAMC,iBAAiB,wBAACC,WAAoB;EACjDC,iBAAiBD,QAAQE,MAAMF,OAAO,GAAA,IAAOG;EAC7CC,aAAaJ;AACf,IAH8B;;;ACFvB,IAAMK,kBAAkB,wBAACC,+BAAwC;EACtEC,gBAAgB;EAChBD;EACAE,kBAAkB;EAClBC,aAAa;EACbC,YAAY;AACd,IAN+B;;;ACAxB,IAAMC,qBAAqB,6BAAA;AAChC,QAAMC,SAAS;AACf,SAAO;IACL;MACEC,SAAS;MACTC,WAAW;QACTC,MAAM;QAAkBC,KAAK;QAAgBC,QAAQ;QAAgBC,UAAU;MACjF;MACAC,mBAAmB;QACjBJ,MAAM;QAAyBC,KAAK;QAA2BC,QAAQ;QAAMC,UAAU;MACzF;MACAE,QAAQ;MACRC,WAAWC,KAAKC,IAAG,IAAKX;IAC1B;IACA;MACEC,SAAS;MACTC,WAAW;QACTC,MAAM;QAAkBC,KAAK;QAAgBC,QAAQ;QAAKC,UAAU;MACtE;MACAC,mBAAmB;QACjBJ,MAAM;QAAyBC,KAAK;QAA2BC,QAAQ;QAAMC,UAAU;MACzF;MACAE,QAAQ;MACRC,WAAWC,KAAKC,IAAG;IACrB;;AAEJ,GA1BkC;;;ACK3B,IAAMC,iBAAN,MAAMA;EAFb,OAEaA;;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AAA;EAAG,CAAA;AACnE,QAAM,CAACC,SAASC,UAAAA,IAAcH,SAA+B,CAAC,CAAA;AAE9DI,iBAEE,OAAOC,YAAAA;AACL,UAAM,EAAEP,MAAAA,OAAMI,SAAAA,SAAO,IAAK,MAAMI,+BAA+BC,OAAOX,OAAOD,sBAAsB;MAAEa,OAAO;IAAK,CAAA;AACjH,QAAIH,QAAAA,GAAW;AACbN,cAAQD,KAAAA;AACRK,iBAAWD,QAAAA;IACb;EACF,GACA;IAACP;IAAsBC;GAAM;AAG/B,SACE,sBAAA,cAACa,SAAAA;IAAS,GAAGf;IAAOgB,MAAMf,yBAAyBgB;IAAWC,WAAU;KACrEjB,uBACG,sBAAA,cAACkB,MAAAA;IAAKX;IAAkBJ;OACxB,IAAA;AAGV,GAzB+E;;;AMjC/E,SAASgB,iCAAiC;AAInC,IAAMC,4BAAiD;EAC5D,GAAGC,0BAA0B;IAC3BC,WAAW,6BAAM,MAAN;IACXC,YAAY;MAAEC,KAAK;QAAEC,YAAYC;MAAwB;IAAE;IAC3DC,MAAM;EACR,CAAA;AACF;","names":["useTheme","useAsyncEffect","FlexCol","CategoryScale","Chart","ChartJS","Legend","LinearScale","LineElement","PointElement","TimeScale","Title","Tooltip","React","useState","Line","alpha","DataLineStyles","color","backgroundColor","alpha","undefined","borderColor","DataPointStyles","pointHoverBackgroundColor","pointHitRadius","pointHoverRadius","pointRadius","pointStyle","MockSourcePayloads","tenMin","baseFee","feePerGas","high","low","medium","veryHigh","priorityFeePerGas","schema","timestamp","Date","now","SourcePayloads","sourcePrices","constructor","sourcePayloads","payloads","build","jsonPath","fetchSourcePayloads","instance","paths","split","map","payload","x","timestamp","y","jsonPathTraverser","Promise","resolve","MockSourcePayloads","obj","path","result","key","foundKey","undefined","defaultOptions","plugins","legend","position","responsive","ForecastLineChartConfigBuilder","data","options","themeColors","constructor","theme","payload","datasets","parseTheme","forecastPayload","Error","create","sourcePayloadConfig","instance","build","fetch","refreshValues","includeSources","buildOptions","buildData","forecastData","generateDataSetForecastData","sourceData","generateDataSetSourcePayloads","unshift","lastSourceDataItem","at","title","generateTitle","generateLegend","scales","generateScales","labels","pointStyle","usePointStyle","x","grid","color","gridColor","time","unit","type","y","display","text","values","timestamp","Date","toLocaleDateString","dark","palette","mode","dataSetColorPrimary","primary","light","dataSetColorSecondary","secondary","grey","borderDash","borderDashOffset","map","price","value","label","DataPointStyles","DataLineStyles","sourcePrices","SourcePayloads","ChartJS","register","CategoryScale","TimeScale","PointElement","LineElement","LinearScale","Title","Tooltip","Legend","PriceForecastDetailsBox","payload","props","priceForecastPayload","theme","useTheme","data","setData","useState","datasets","options","setOptions","useAsyncEffect","mounted","ForecastLineChartConfigBuilder","create","fetch","FlexCol","busy","undefined","minHeight","Line","createPayloadRenderPlugin","PriceForecastRenderPlugin","createPayloadRenderPlugin","canRender","components","box","detailsBox","PriceForecastDetailsBox","name"]}
@@ -0,0 +1,5 @@
1
+ export declare const DataLineStyles: (color?: string) => {
2
+ backgroundColor: string | undefined;
3
+ borderColor: string | undefined;
4
+ };
5
+ //# sourceMappingURL=DataLineStyles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataLineStyles.d.ts","sourceRoot":"","sources":["../../../src/lib/DataLineStyles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,WAAY,MAAM;;;CAG3C,CAAA"}
@@ -0,0 +1,8 @@
1
+ export declare const DataPointStyles: (pointHoverBackgroundColor?: string) => {
2
+ pointHitRadius: number;
3
+ pointHoverBackgroundColor: string | undefined;
4
+ pointHoverRadius: number;
5
+ pointRadius: number;
6
+ pointStyle: string;
7
+ };
8
+ //# sourceMappingURL=DataPointStyles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataPointStyles.d.ts","sourceRoot":"","sources":["../../../src/lib/DataPointStyles.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+BAAgC,MAAM;;;;;;CAMhE,CAAA"}
@@ -0,0 +1,44 @@
1
+ import type { Theme } from '@mui/material';
2
+ import type { ForecastPayload } from '@xyo-network/diviner-forecasting-model';
3
+ import type { ChartData, ChartOptions, LegendOptions, ScaleChartOptions } from 'chart.js';
4
+ interface SourcePayloadConfig {
5
+ fetch: boolean;
6
+ sampleSize?: number;
7
+ }
8
+ interface ThemeColors {
9
+ dataSetColorPrimary: string;
10
+ dataSetColorSecondary: string;
11
+ gridColor: string;
12
+ }
13
+ export declare class ForecastLineChartConfigBuilder {
14
+ private payload?;
15
+ data: ChartData<'line'>;
16
+ options: ChartOptions<'line'>;
17
+ themeColors: ThemeColors | undefined;
18
+ constructor(theme: Theme, payload?: ForecastPayload | undefined);
19
+ get forecastPayload(): import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
20
+ schema: import("@xyo-network/diviner-forecasting-model").ForecastPayloadSchema;
21
+ sources: string[];
22
+ values: import("@xyo-network/diviner-forecasting-model").Forecast[];
23
+ };
24
+ static create(theme: Theme, payload?: ForecastPayload, sourcePayloadConfig?: SourcePayloadConfig): Promise<ForecastLineChartConfigBuilder>;
25
+ build(includeSources?: boolean): Promise<this>;
26
+ buildData(includeSources?: boolean): Promise<this>;
27
+ buildOptions(): this;
28
+ refreshValues(): void;
29
+ protected generateLegend(): LegendOptions<"line">;
30
+ protected generateScales(): ScaleChartOptions<"line">["scales"];
31
+ protected generateTitle(): {
32
+ display: boolean;
33
+ text: string;
34
+ };
35
+ protected parseTheme(theme: Theme): {
36
+ dataSetColorPrimary: string;
37
+ dataSetColorSecondary: string;
38
+ gridColor: string;
39
+ };
40
+ private generateDataSetForecastData;
41
+ private generateDataSetSourcePayloads;
42
+ }
43
+ export {};
44
+ //# sourceMappingURL=ForecastLineChartConfigBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForecastLineChartConfigBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/ForecastLineChartConfigBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,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: {
4
+ high: number;
5
+ low: number;
6
+ medium: number;
7
+ veryHigh: number;
8
+ };
9
+ priorityFeePerGas: {
10
+ high: number;
11
+ low: number;
12
+ medium: number;
13
+ veryHigh: number;
14
+ };
15
+ schema: string;
16
+ timestamp: number;
17
+ }[];
18
+ //# sourceMappingURL=MockSourcePayloads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MockSourcePayloads.d.ts","sourceRoot":"","sources":["../../../src/lib/MockSourcePayloads.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;GA0B9B,CAAA"}
@@ -0,0 +1,30 @@
1
+ import type { Payload } from '@xyo-network/payload-model';
2
+ import type { Point } from 'chart.js';
3
+ export declare class SourcePayloads {
4
+ sourcePayloads: Payload[];
5
+ sourcePrices: Point[];
6
+ constructor(sourcePayloads: Payload[]);
7
+ get payloads(): ({
8
+ schema: string;
9
+ } & import("@xyo-network/payload-model").PayloadFields)[];
10
+ static build(jsonPath: string): Promise<SourcePayloads>;
11
+ static fetchSourcePayloads(): Promise<{
12
+ baseFee: number;
13
+ feePerGas: {
14
+ high: number;
15
+ low: number;
16
+ medium: number;
17
+ veryHigh: number;
18
+ };
19
+ priorityFeePerGas: {
20
+ high: number;
21
+ low: number;
22
+ medium: number;
23
+ veryHigh: number;
24
+ };
25
+ schema: string;
26
+ timestamp: number;
27
+ }[]>;
28
+ jsonPathTraverser(obj: Payload, path: string[]): any;
29
+ }
30
+ //# sourceMappingURL=SourcePayloads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SourcePayloads.d.ts","sourceRoot":"","sources":["../../../src/lib/SourcePayloads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAIrC,qBAAa,cAAc;IAGN,cAAc,EAAE,OAAO,EAAE;IAF5C,YAAY,EAAE,KAAK,EAAE,CAAK;gBAEP,cAAc,EAAE,OAAO,EAAE;IAE5C,IAAI,QAAQ;;8DAEX;WAEY,KAAK,CAAC,QAAQ,EAAE,MAAM;WAYtB,mBAAmB;;;;;;;;;;;;;;;;;IAKhC,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;CAe/C"}
@@ -0,0 +1,4 @@
1
+ export * from './ForecastLineChartConfigBuilder.ts';
2
+ export * from './MockSourcePayloads.ts';
3
+ export * from './SourcePayloads.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAA;AACnD,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA"}
package/package.json CHANGED
@@ -1,29 +1,70 @@
1
1
  {
2
2
  "name": "@xyo-network/react-price-forecast-plugin",
3
+ "version": "3.0.3",
4
+ "description": "Common React library for all XYO projects that use React",
5
+ "keywords": [
6
+ "xyo",
7
+ "utility",
8
+ "typescript",
9
+ "react"
10
+ ],
11
+ "homepage": "https://xyo.network",
12
+ "bugs": {
13
+ "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues",
14
+ "email": "support@xyo.network"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
19
+ },
20
+ "license": "LGPL-3.0-only",
3
21
  "author": {
4
- "email": "support@xyo.network",
5
22
  "name": "XYO Development Team",
23
+ "email": "support@xyo.network",
6
24
  "url": "https://xyo.network"
7
25
  },
8
- "bugs": {
9
- "email": "support@xyo.network",
10
- "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
26
+ "sideEffects": false,
27
+ "type": "module",
28
+ "exports": {
29
+ ".": {
30
+ "import": {
31
+ "types": "./dist/browser/index.d.ts",
32
+ "default": "./dist/browser/index.mjs"
33
+ },
34
+ "types": "./dist/browser/index.d.ts",
35
+ "default": "./dist/browser/index.mjs"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "module": "dist/browser/index.mjs",
40
+ "types": "dist/browser/index.d.ts",
41
+ "scripts": {
42
+ "license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\"",
43
+ "lint-pkg": "npmPkgJsonLint ."
11
44
  },
12
45
  "dependencies": {
13
46
  "@xylabs/react-async-effect": "^4.0.3",
14
47
  "@xylabs/react-flexbox": "^4.0.3",
15
- "@xyo-network/diviner-forecasting-model": "^3.0.3",
16
- "@xyo-network/payload-model": "^3.0.3",
17
- "@xyo-network/react-payload-plugin": "^3.0.2",
18
- "chart.js": "^4.4.3",
48
+ "@xyo-network/diviner-forecasting-model": "^3.0.15",
49
+ "@xyo-network/payload-model": "^3.0.15",
50
+ "@xyo-network/react-payload-plugin": "^3.0.3",
51
+ "chart.js": "^4.4.4",
19
52
  "chartjs-adapter-luxon": "^1.3.1",
20
53
  "luxon": "^3.5.0",
21
54
  "react-chartjs-2": "^5.2.0"
22
55
  },
23
56
  "devDependencies": {
57
+ "@emotion/react": "^11.13.3",
58
+ "@emotion/styled": "^11.13.0",
59
+ "@mui/icons-material": "^5.16.7",
60
+ "@mui/material": "^5.16.7",
61
+ "@mui/styles": "^5.16.7",
24
62
  "@storybook/react": "^8.2.9",
25
- "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.20",
26
- "@xylabs/tsconfig-react": "^4.0.0-rc.20",
63
+ "@xylabs/ts-scripts-yarn3": "^4.0.7",
64
+ "@xylabs/tsconfig-react": "^4.0.7",
65
+ "react": "^18.3.1",
66
+ "react-dom": "^18.3.1",
67
+ "storybook": "^8.2.9",
27
68
  "typescript": "^5.5.4"
28
69
  },
29
70
  "peerDependencies": {
@@ -35,41 +76,8 @@
35
76
  "react": "^18",
36
77
  "react-dom": "^18"
37
78
  },
38
- "description": "Common React library for all XYO projects that use React",
39
- "docs": "dist/docs.json",
40
- "exports": {
41
- ".": {
42
- "import": {
43
- "types": "./dist/browser/index.d.ts",
44
- "default": "./dist/browser/index.mjs"
45
- },
46
- "types": "./dist/browser/index.d.ts",
47
- "default": "./dist/browser/index.mjs"
48
- },
49
- "./package.json": "./package.json"
50
- },
51
- "module": "dist/browser/index.mjs",
52
- "homepage": "https://xyo.network",
53
- "keywords": [
54
- "xyo",
55
- "utility",
56
- "typescript",
57
- "react"
58
- ],
59
- "license": "LGPL-3.0-only",
60
79
  "publishConfig": {
61
80
  "access": "public"
62
81
  },
63
- "repository": {
64
- "type": "git",
65
- "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
66
- },
67
- "scripts": {
68
- "lint-pkg": "npmPkgJsonLint .",
69
- "license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\""
70
- },
71
- "sideEffects": false,
72
- "types": "dist/browser/index.d.ts",
73
- "version": "3.0.2",
74
- "type": "module"
82
+ "docs": "dist/docs.json"
75
83
  }
package/src/Plugin.ts CHANGED
@@ -6,11 +6,7 @@ import { PriceForecastDetailsBox } from './components/index.ts'
6
6
  export const PriceForecastRenderPlugin: PayloadRenderPlugin = {
7
7
  ...createPayloadRenderPlugin({
8
8
  canRender: () => true,
9
- components: {
10
- box: {
11
- detailsBox: PriceForecastDetailsBox,
12
- },
13
- },
9
+ components: { box: { detailsBox: PriceForecastDetailsBox } },
14
10
  name: 'PriceForecast',
15
11
  }),
16
12
  }
@@ -1,4 +1,6 @@
1
- import { Button, ButtonGroup, Typography } from '@mui/material'
1
+ import {
2
+ Button, ButtonGroup, Typography,
3
+ } from '@mui/material'
2
4
  import type { Meta, StoryFn } from '@storybook/react'
3
5
  import { FlexCol } from '@xylabs/react-flexbox'
4
6
  import { ForecastPayloadSchema } from '@xyo-network/diviner-forecasting-model'
@@ -22,11 +24,7 @@ const ForecastingDivinerPayload = {
22
24
  const StorybookEntry = {
23
25
  argTypes: {},
24
26
  component: PriceForecastDetailsBox,
25
- parameters: {
26
- docs: {
27
- page: null,
28
- },
29
- },
27
+ parameters: { docs: { page: null } },
30
28
  title: 'plugin/price-forecast/DetailsBox',
31
29
  } as Meta<typeof PriceForecastDetailsBox>
32
30
 
@@ -73,9 +71,7 @@ const Default = Template.bind({})
73
71
  Default.args = {}
74
72
 
75
73
  const WithData = Template.bind({})
76
- WithData.args = {
77
- payload: ForecastingDivinerPayload,
78
- }
74
+ WithData.args = { payload: ForecastingDivinerPayload }
79
75
 
80
76
  export { Default, WithData }
81
77
 
@@ -8,7 +8,8 @@ import type { ForecastPayload } from '@xyo-network/diviner-forecasting-model'
8
8
  import type { Payload } from '@xyo-network/payload-model'
9
9
  import type {
10
10
  ChartData,
11
- ChartOptions } from 'chart.js'
11
+ ChartOptions,
12
+ } from 'chart.js'
12
13
  import {
13
14
  CategoryScale,
14
15
  Chart as ChartJS,
@@ -1,6 +1,8 @@
1
1
  import type { Theme } from '@mui/material'
2
2
  import type { ForecastPayload } from '@xyo-network/diviner-forecasting-model'
3
- import type { ChartData, ChartDataset, ChartOptions, LegendOptions, Point, ScaleChartOptions } from 'chart.js'
3
+ import type {
4
+ ChartData, ChartDataset, ChartOptions, LegendOptions, Point, ScaleChartOptions,
5
+ } from 'chart.js'
4
6
 
5
7
  import { DataLineStyles } from './DataLineStyles.ts'
6
8
  import { DataPointStyles } from './DataPointStyles.ts'
@@ -18,18 +20,12 @@ interface ThemeColors {
18
20
  }
19
21
 
20
22
  const defaultOptions: () => ChartOptions<'line'> = () => ({
21
- plugins: {
22
- legend: {
23
- position: 'top' as const,
24
- },
25
- },
23
+ plugins: { legend: { position: 'top' as const } },
26
24
  responsive: true,
27
25
  })
28
26
 
29
27
  export class ForecastLineChartConfigBuilder {
30
- data: ChartData<'line'> = {
31
- datasets: [],
32
- }
28
+ data: ChartData<'line'> = { datasets: [] }
33
29
 
34
30
  options: ChartOptions<'line'> = defaultOptions()
35
31
  themeColors: ThemeColors | undefined
@@ -80,9 +76,7 @@ export class ForecastLineChartConfigBuilder {
80
76
  forecastData.data.unshift(lastSourceDataItem)
81
77
  }
82
78
 
83
- this.data = {
84
- datasets,
85
- }
79
+ this.data = { datasets }
86
80
 
87
81
  return this
88
82
  }
@@ -114,19 +108,11 @@ export class ForecastLineChartConfigBuilder {
114
108
  protected generateScales() {
115
109
  return {
116
110
  x: {
117
- grid: {
118
- color: this.themeColors?.gridColor,
119
- },
120
- time: {
121
- unit: 'minute',
122
- },
111
+ grid: { color: this.themeColors?.gridColor },
112
+ time: { unit: 'minute' },
123
113
  type: 'time',
124
114
  },
125
- y: {
126
- grid: {
127
- color: this.themeColors?.gridColor,
128
- },
129
- },
115
+ y: { grid: { color: this.themeColors?.gridColor } },
130
116
  } as unknown as ScaleChartOptions<'line'>['scales']
131
117
  }
132
118
 
@@ -3,15 +3,23 @@ export const MockSourcePayloads = () => {
3
3
  return [
4
4
  {
5
5
  baseFee: 38.901_553_878_25,
6
- feePerGas: { high: 47.994_586_439_6, low: 39.006_868_093, medium: 39.306_868_093, veryHigh: 44.453_843_805_25 },
7
- priorityFeePerGas: { high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1 },
6
+ feePerGas: {
7
+ high: 47.994_586_439_6, low: 39.006_868_093, medium: 39.306_868_093, veryHigh: 44.453_843_805_25,
8
+ },
9
+ priorityFeePerGas: {
10
+ high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1,
11
+ },
8
12
  schema: 'network.xyo.blockchain.ethereum.gas',
9
13
  timestamp: Date.now() - tenMin,
10
14
  },
11
15
  {
12
16
  baseFee: 38.901_553_878_25,
13
- feePerGas: { high: 47.994_586_439_6, low: 39.006_868_093, medium: 100, veryHigh: 44.453_843_805_25 },
14
- priorityFeePerGas: { high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1 },
17
+ feePerGas: {
18
+ high: 47.994_586_439_6, low: 39.006_868_093, medium: 100, veryHigh: 44.453_843_805_25,
19
+ },
20
+ priorityFeePerGas: {
21
+ high: 1.026_666_666_666_666_6, low: -0.410_000_000_000_000_03, medium: 0.38, veryHigh: 1.390_000_000_000_000_1,
22
+ },
15
23
  schema: 'network.xyo.blockchain.ethereum.gas',
16
24
  timestamp: Date.now(),
17
25
  },
package/xy.config.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
2
  const config: XyTsupConfig = {
3
3
  compile: {
4
- browser: {
5
- src: true,
6
- },
4
+ browser: { src: true },
7
5
  node: {},
8
6
  neutral: {},
9
7
  },