@rainlanguage/ui-components 0.0.1-alpha.37 → 0.0.1-alpha.39
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,17 +1,13 @@
|
|
|
1
1
|
<script generics="T">import LightweightChart from "./LightweightChart.svelte";
|
|
2
|
-
import {
|
|
2
|
+
import { transformAndSortData } from "./transformAndSortData";
|
|
3
3
|
export let query;
|
|
4
4
|
export let timeTransform;
|
|
5
5
|
export let valueTransform;
|
|
6
6
|
export let lightweightChartsTheme;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}));
|
|
12
|
-
return sortBy(transformedData, (d) => d.time);
|
|
13
|
-
};
|
|
14
|
-
$: data = transformAndSortData($query.data ?? []);
|
|
7
|
+
$: data = transformAndSortData($query.data ?? [], {
|
|
8
|
+
valueTransform,
|
|
9
|
+
timeTransform
|
|
10
|
+
});
|
|
15
11
|
const createSeries = (chart) => chart.addLineSeries({ lineWidth: 1 });
|
|
16
12
|
</script>
|
|
17
13
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { UTCTimestamp } from 'lightweight-charts';
|
|
2
|
+
/**
|
|
3
|
+
* Filters out data points with duplicate timestamps, keeping only the first occurrence.
|
|
4
|
+
*
|
|
5
|
+
* @param data Array of data points with time and value properties
|
|
6
|
+
* @returns A new array with only unique timestamps
|
|
7
|
+
*/
|
|
8
|
+
export declare const deduplicateByTime: <T extends {
|
|
9
|
+
time: UTCTimestamp;
|
|
10
|
+
}>(data: T[]) => T[];
|
|
11
|
+
/**
|
|
12
|
+
* Transforms and sorts data, ensuring unique timestamps.
|
|
13
|
+
*
|
|
14
|
+
* @param data The source data to transform
|
|
15
|
+
* @param options Configuration object with transform functions
|
|
16
|
+
* @returns Transformed, sorted, and deduplicated data
|
|
17
|
+
*/
|
|
18
|
+
export declare const transformAndSortData: <T>(data: T[], options: {
|
|
19
|
+
valueTransform: (item: T) => number;
|
|
20
|
+
timeTransform: (item: T) => UTCTimestamp;
|
|
21
|
+
}) => Array<{
|
|
22
|
+
value: number;
|
|
23
|
+
time: UTCTimestamp;
|
|
24
|
+
}>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { sortBy } from 'lodash';
|
|
2
|
+
/**
|
|
3
|
+
* Filters out data points with duplicate timestamps, keeping only the first occurrence.
|
|
4
|
+
*
|
|
5
|
+
* @param data Array of data points with time and value properties
|
|
6
|
+
* @returns A new array with only unique timestamps
|
|
7
|
+
*/
|
|
8
|
+
export const deduplicateByTime = (data) => {
|
|
9
|
+
const uniqueData = [];
|
|
10
|
+
const seenTimes = new Set();
|
|
11
|
+
for (const dataPoint of data) {
|
|
12
|
+
if (!seenTimes.has(dataPoint.time)) {
|
|
13
|
+
uniqueData.push(dataPoint);
|
|
14
|
+
seenTimes.add(dataPoint.time);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return uniqueData;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Transforms and sorts data, ensuring unique timestamps.
|
|
21
|
+
*
|
|
22
|
+
* @param data The source data to transform
|
|
23
|
+
* @param options Configuration object with transform functions
|
|
24
|
+
* @returns Transformed, sorted, and deduplicated data
|
|
25
|
+
*/
|
|
26
|
+
export const transformAndSortData = (data, options) => {
|
|
27
|
+
const { valueTransform, timeTransform } = options;
|
|
28
|
+
const transformedData = data.map((d) => ({
|
|
29
|
+
value: valueTransform(d),
|
|
30
|
+
time: timeTransform(d)
|
|
31
|
+
}));
|
|
32
|
+
const sortedData = sortBy(transformedData, (d) => d.time);
|
|
33
|
+
return deduplicateByTime(sortedData);
|
|
34
|
+
};
|
|
35
|
+
if (import.meta.vitest) {
|
|
36
|
+
const { it, expect, describe } = import.meta.vitest;
|
|
37
|
+
describe('deduplicateByTime', () => {
|
|
38
|
+
it('should remove entries with duplicate timestamps', () => {
|
|
39
|
+
const data = [
|
|
40
|
+
{ time: 100, value: 10 },
|
|
41
|
+
{ time: 200, value: 20 },
|
|
42
|
+
{ time: 200, value: 25 }, // Duplicate timestamp
|
|
43
|
+
{ time: 300, value: 30 }
|
|
44
|
+
];
|
|
45
|
+
const result = deduplicateByTime(data);
|
|
46
|
+
const expected = [
|
|
47
|
+
{ time: 100, value: 10 },
|
|
48
|
+
{ time: 200, value: 20 }, // First occurrence kept
|
|
49
|
+
{ time: 300, value: 30 }
|
|
50
|
+
];
|
|
51
|
+
expect(result).toEqual(expected);
|
|
52
|
+
});
|
|
53
|
+
it('should handle multiple duplicate timestamps', () => {
|
|
54
|
+
const data = [
|
|
55
|
+
{ time: 100, value: 10 },
|
|
56
|
+
{ time: 100, value: 15 }, // Duplicate
|
|
57
|
+
{ time: 100, value: 18 }, // Duplicate
|
|
58
|
+
{ time: 200, value: 20 }
|
|
59
|
+
];
|
|
60
|
+
const result = deduplicateByTime(data);
|
|
61
|
+
const expected = [
|
|
62
|
+
{ time: 100, value: 10 }, // Only first one kept
|
|
63
|
+
{ time: 200, value: 20 }
|
|
64
|
+
];
|
|
65
|
+
expect(result).toEqual(expected);
|
|
66
|
+
});
|
|
67
|
+
it('should return original array if no duplicates', () => {
|
|
68
|
+
const data = [
|
|
69
|
+
{ time: 100, value: 10 },
|
|
70
|
+
{ time: 200, value: 20 },
|
|
71
|
+
{ time: 300, value: 30 }
|
|
72
|
+
];
|
|
73
|
+
const result = deduplicateByTime(data);
|
|
74
|
+
expect(result).toEqual(data);
|
|
75
|
+
expect(result).not.toBe(data);
|
|
76
|
+
});
|
|
77
|
+
it('should handle empty array', () => {
|
|
78
|
+
const data = [];
|
|
79
|
+
const result = deduplicateByTime(data);
|
|
80
|
+
expect(result).toEqual([]);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('transformAndSortData', () => {
|
|
84
|
+
it('should transform, sort, and deduplicate data', () => {
|
|
85
|
+
const rawData = [
|
|
86
|
+
{ timestamp: 3000, price: 300 },
|
|
87
|
+
{ timestamp: 1000, price: 100 },
|
|
88
|
+
{ timestamp: 2000, price: 200 },
|
|
89
|
+
{ timestamp: 2000, price: 250 } // Duplicate timestamp
|
|
90
|
+
];
|
|
91
|
+
const result = transformAndSortData(rawData, {
|
|
92
|
+
valueTransform: (item) => item.price,
|
|
93
|
+
timeTransform: (item) => item.timestamp
|
|
94
|
+
});
|
|
95
|
+
const expected = [
|
|
96
|
+
{ time: 1000, value: 100 },
|
|
97
|
+
{ time: 2000, value: 200 }, // First occurrence kept after sorting
|
|
98
|
+
{ time: 3000, value: 300 }
|
|
99
|
+
];
|
|
100
|
+
expect(result).toEqual(expected);
|
|
101
|
+
});
|
|
102
|
+
it('should handle empty data array', () => {
|
|
103
|
+
const rawData = [];
|
|
104
|
+
const result = transformAndSortData(rawData, {
|
|
105
|
+
valueTransform: (item) => item.price,
|
|
106
|
+
timeTransform: (item) => item.timestamp
|
|
107
|
+
});
|
|
108
|
+
expect(result).toEqual([]);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -74,7 +74,6 @@ export { createResolvableQuery, createResolvableInfiniteQuery } from './__mocks_
|
|
|
74
74
|
export { formatTimestampSecondsAsLocal, timestampSecondsToUTCTimestamp, promiseTimeout } from './utils/time';
|
|
75
75
|
export { bigintStringToHex, HEX_INPUT_REGEX } from './utils/hex';
|
|
76
76
|
export { vaultBalanceDisplay } from './utils/vault';
|
|
77
|
-
export { prepareHistoricalOrderChartData } from './services/historicalOrderCharts';
|
|
78
77
|
export { bigintToFloat } from './utils/number';
|
|
79
78
|
export { getExplorerLink } from './services/getExplorerLink';
|
|
80
79
|
export { DEFAULT_PAGE_SIZE, DEFAULT_REFRESH_INTERVAL } from './queries/constants';
|
package/dist/index.js
CHANGED
|
@@ -71,7 +71,6 @@ export { createResolvableQuery, createResolvableInfiniteQuery } from './__mocks_
|
|
|
71
71
|
export { formatTimestampSecondsAsLocal, timestampSecondsToUTCTimestamp, promiseTimeout } from './utils/time';
|
|
72
72
|
export { bigintStringToHex, HEX_INPUT_REGEX } from './utils/hex';
|
|
73
73
|
export { vaultBalanceDisplay } from './utils/vault';
|
|
74
|
-
export { prepareHistoricalOrderChartData } from './services/historicalOrderCharts';
|
|
75
74
|
export { bigintToFloat } from './utils/number';
|
|
76
75
|
export { getExplorerLink } from './services/getExplorerLink';
|
|
77
76
|
// Constants
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rainlanguage/ui-components",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.39",
|
|
4
4
|
"description": "A component library for building Svelte applications to be used with Raindex.",
|
|
5
5
|
"license": "LicenseRef-DCL-1.0",
|
|
6
6
|
"author": "Rain Open Source Software Ltd",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@fontsource/dm-sans": "5.1.0",
|
|
54
54
|
"@imask/svelte": "7.6.1",
|
|
55
55
|
"@observablehq/plot": "0.6.16",
|
|
56
|
-
"@rainlanguage/orderbook": "0.0.1-alpha.
|
|
56
|
+
"@rainlanguage/orderbook": "0.0.1-alpha.39",
|
|
57
57
|
"@reown/appkit": "1.6.4",
|
|
58
58
|
"@reown/appkit-adapter-wagmi": "1.6.4",
|
|
59
59
|
"@sentry/sveltekit": "7.120.0",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"tailwind-merge": "2.5.4",
|
|
81
81
|
"thememirror": "2.0.1",
|
|
82
82
|
"uuid": "9.0.1",
|
|
83
|
-
"viem": "2.
|
|
83
|
+
"viem": "2.24.3",
|
|
84
84
|
"wagmi": "2.14.7"
|
|
85
85
|
}
|
|
86
86
|
}
|