@rainlanguage/ui-components 0.0.1-alpha.90 → 0.0.1-alpha.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/dist/components/charts/VaultBalanceChart.svelte +1 -1
- package/dist/components/detail/OrderDetail.svelte +1 -1
- package/dist/components/tables/OrderTradesListTable.svelte +1 -1
- package/dist/components/tables/OrdersListTable.svelte +1 -1
- package/dist/components/tables/VaultBalanceChangesTable.svelte +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/services/historicalOrderCharts.js +1 -1
- package/dist/services/time.d.ts +12 -0
- package/dist/services/time.js +84 -6
- package/package.json +2 -2
- package/dist/utils/time.d.ts +0 -12
- package/dist/utils/time.js +0 -27
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script>import { timestampSecondsToUTCTimestamp } from "../../
|
|
1
|
+
<script>import { timestampSecondsToUTCTimestamp } from "../../services/time";
|
|
2
2
|
import { bigintToFloat } from "../../utils/number";
|
|
3
3
|
import { createQuery } from "@tanstack/svelte-query";
|
|
4
4
|
import {
|
|
@@ -5,7 +5,7 @@ import OrderTradesListTable from "../tables/OrderTradesListTable.svelte";
|
|
|
5
5
|
import TanstackOrderQuote from "./TanstackOrderQuote.svelte";
|
|
6
6
|
import TanstackPageContentDetail from "./TanstackPageContentDetail.svelte";
|
|
7
7
|
import CardProperty from "../CardProperty.svelte";
|
|
8
|
-
import { formatTimestampSecondsAsLocal } from "../../
|
|
8
|
+
import { formatTimestampSecondsAsLocal } from "../../services/time";
|
|
9
9
|
import ButtonVaultLink from "../ButtonVaultLink.svelte";
|
|
10
10
|
import OrderVaultsVolTable from "../tables/OrderVaultsVolTable.svelte";
|
|
11
11
|
import { QKEY_ORDER } from "../../queries/keys";
|
|
@@ -4,7 +4,7 @@ import { QKEY_ORDER_TRADES_LIST } from "../../queries/keys";
|
|
|
4
4
|
import { getOrderTradesList, getOrderTradesCount } from "@rainlanguage/orderbook";
|
|
5
5
|
import { DEFAULT_PAGE_SIZE } from "../../queries/constants";
|
|
6
6
|
import { TableBodyCell, TableHeadCell } from "flowbite-svelte";
|
|
7
|
-
import { formatTimestampSecondsAsLocal } from "../../
|
|
7
|
+
import { formatTimestampSecondsAsLocal } from "../../services/time";
|
|
8
8
|
import Hash, { HashType } from "../Hash.svelte";
|
|
9
9
|
import { formatUnits } from "viem";
|
|
10
10
|
import { BugOutline } from "flowbite-svelte-icons";
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
getOrders
|
|
6
6
|
} from "@rainlanguage/orderbook";
|
|
7
7
|
import TanstackAppTable from "../TanstackAppTable.svelte";
|
|
8
|
-
import { formatTimestampSecondsAsLocal } from "../../
|
|
8
|
+
import { formatTimestampSecondsAsLocal } from "../../services/time";
|
|
9
9
|
import ListViewOrderbookFilters from "../ListViewOrderbookFilters.svelte";
|
|
10
10
|
import Hash, { HashType } from "../Hash.svelte";
|
|
11
11
|
import { DEFAULT_PAGE_SIZE, DEFAULT_REFRESH_INTERVAL } from "../../queries/constants";
|
|
@@ -4,7 +4,7 @@ import { createInfiniteQuery } from "@tanstack/svelte-query";
|
|
|
4
4
|
import {
|
|
5
5
|
getVaultBalanceChanges
|
|
6
6
|
} from "@rainlanguage/orderbook";
|
|
7
|
-
import { formatTimestampSecondsAsLocal } from "../../
|
|
7
|
+
import { formatTimestampSecondsAsLocal } from "../../services/time";
|
|
8
8
|
import Hash, { HashType } from "../Hash.svelte";
|
|
9
9
|
import { QKEY_VAULT_CHANGES } from "../../queries/keys";
|
|
10
10
|
import { DEFAULT_PAGE_SIZE } from "../../queries/constants";
|
package/dist/index.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export type { DeploymentArgs, DepositOrWithdrawArgs, OrderRemoveArgs } from './t
|
|
|
71
71
|
export type { DepositOrWithdrawModalProps, OrderRemoveModalProps, QuoteDebugModalHandler, DebugTradeModalHandler, DeployModalProps, DisclaimerModalProps } from './types/modal';
|
|
72
72
|
export type { ValidStrategyDetail, InvalidStrategyDetail } from './types/strategy';
|
|
73
73
|
export { createResolvableQuery, createResolvableInfiniteQuery } from './__mocks__/queries';
|
|
74
|
-
export { formatTimestampSecondsAsLocal, timestampSecondsToUTCTimestamp, promiseTimeout } from './
|
|
74
|
+
export { formatTimestampSecondsAsLocal, timestampSecondsToUTCTimestamp, promiseTimeout } from './services/time';
|
|
75
75
|
export { bigintStringToHex, HEX_INPUT_REGEX } from './utils/hex';
|
|
76
76
|
export { vaultBalanceDisplay } from './utils/vault';
|
|
77
77
|
export { bigintToFloat } from './utils/number';
|
package/dist/index.js
CHANGED
|
@@ -68,7 +68,7 @@ export { default as InputRegistryUrl } from './components/input/InputRegistryUrl
|
|
|
68
68
|
export { TransactionStatus, TransactionErrorMessage } from './stores/transactionStore';
|
|
69
69
|
// Functions
|
|
70
70
|
export { createResolvableQuery, createResolvableInfiniteQuery } from './__mocks__/queries';
|
|
71
|
-
export { formatTimestampSecondsAsLocal, timestampSecondsToUTCTimestamp, promiseTimeout } from './
|
|
71
|
+
export { formatTimestampSecondsAsLocal, timestampSecondsToUTCTimestamp, promiseTimeout } from './services/time';
|
|
72
72
|
export { bigintStringToHex, HEX_INPUT_REGEX } from './utils/hex';
|
|
73
73
|
export { vaultBalanceDisplay } from './utils/vault';
|
|
74
74
|
export { bigintToFloat } from './utils/number';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { timestampSecondsToUTCTimestamp } from '../
|
|
1
|
+
import { timestampSecondsToUTCTimestamp } from '../services/time';
|
|
2
2
|
import { sortBy } from 'lodash';
|
|
3
3
|
import { formatUnits } from 'viem';
|
|
4
4
|
export function prepareHistoricalOrderChartData(takeOrderEntities, colorTheme) {
|
package/dist/services/time.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
import type { UTCTimestamp } from 'lightweight-charts';
|
|
1
2
|
export declare const TIME_DELTA_24_HOURS: number;
|
|
2
3
|
export declare const TIME_DELTA_48_HOURS: number;
|
|
3
4
|
export declare const TIME_DELTA_7_DAYS: number;
|
|
4
5
|
export declare const TIME_DELTA_30_DAYS: number;
|
|
5
6
|
export declare const TIME_DELTA_1_YEAR: number;
|
|
6
7
|
export declare function dateTimestamp(date: Date): number;
|
|
8
|
+
export declare function formatTimestampSecondsAsLocal(timestampSeconds: bigint): string;
|
|
9
|
+
export declare function timestampSecondsToUTCTimestamp(timestampSeconds: bigint): UTCTimestamp;
|
|
10
|
+
/**
|
|
11
|
+
* Method to put a timeout on a promise, throws the exception if promise is not settled within the time
|
|
12
|
+
* @param promise - The original promise
|
|
13
|
+
* @param time - The time in ms
|
|
14
|
+
* @param exception - The exception to reject with if time runs out before original promise settlement
|
|
15
|
+
* @returns A new promise that gets settled with initial promise settlement or rejected with exception value
|
|
16
|
+
* if the time runs out before the main promise settlement
|
|
17
|
+
*/
|
|
18
|
+
export declare function promiseTimeout<T>(promise: Promise<T>, time: number, exception: unknown): Promise<T>;
|
package/dist/services/time.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import bigIntSupport from 'dayjs/plugin/bigIntSupport';
|
|
3
|
+
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
4
|
+
dayjs.extend(bigIntSupport);
|
|
5
|
+
dayjs.extend(localizedFormat);
|
|
1
6
|
export const TIME_DELTA_24_HOURS = 60 * 60 * 24;
|
|
2
7
|
export const TIME_DELTA_48_HOURS = TIME_DELTA_24_HOURS * 2;
|
|
3
8
|
export const TIME_DELTA_7_DAYS = TIME_DELTA_24_HOURS * 7;
|
|
@@ -6,12 +11,85 @@ export const TIME_DELTA_1_YEAR = TIME_DELTA_24_HOURS * 365;
|
|
|
6
11
|
export function dateTimestamp(date) {
|
|
7
12
|
return Math.floor(date.getTime() / 1000);
|
|
8
13
|
}
|
|
14
|
+
export function formatTimestampSecondsAsLocal(timestampSeconds) {
|
|
15
|
+
return dayjs(timestampSeconds * BigInt('1000')).format('L LT');
|
|
16
|
+
}
|
|
17
|
+
export function timestampSecondsToUTCTimestamp(timestampSeconds) {
|
|
18
|
+
return dayjs(timestampSeconds * BigInt('1000')).unix();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Method to put a timeout on a promise, throws the exception if promise is not settled within the time
|
|
22
|
+
* @param promise - The original promise
|
|
23
|
+
* @param time - The time in ms
|
|
24
|
+
* @param exception - The exception to reject with if time runs out before original promise settlement
|
|
25
|
+
* @returns A new promise that gets settled with initial promise settlement or rejected with exception value
|
|
26
|
+
* if the time runs out before the main promise settlement
|
|
27
|
+
*/
|
|
28
|
+
export async function promiseTimeout(promise, time, exception) {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
let timeout;
|
|
31
|
+
return Promise.race([
|
|
32
|
+
promise,
|
|
33
|
+
new Promise((_resolve, reject) => (timeout = setTimeout(reject, time, exception)))
|
|
34
|
+
]).finally(() => clearTimeout(timeout));
|
|
35
|
+
}
|
|
9
36
|
if (import.meta.vitest) {
|
|
10
|
-
const { it, expect } = import.meta.vitest;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
37
|
+
const { describe, it, expect, vi } = import.meta.vitest;
|
|
38
|
+
describe('Date and timestamp utilities', () => {
|
|
39
|
+
describe('formatTimestampSecondsAsLocal', () => {
|
|
40
|
+
it('converts timestamp to local format', () => {
|
|
41
|
+
const result = formatTimestampSecondsAsLocal(BigInt('1672531200')); // Jan 1, 2023 01:00 AM
|
|
42
|
+
expect(result).toBe('01/01/2023 12:00 AM');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('timestampSecondsToUTCTimestamp', () => {
|
|
46
|
+
it('converts bigint timestamp to UTCTimestamp', () => {
|
|
47
|
+
const result = timestampSecondsToUTCTimestamp(BigInt('1672531200'));
|
|
48
|
+
expect(result).toBe(1672531200);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('promiseTimeout', () => {
|
|
53
|
+
it('resolves when promise resolves before timeout', async () => {
|
|
54
|
+
const testValue = 'test';
|
|
55
|
+
const promise = Promise.resolve(testValue);
|
|
56
|
+
const result = await promiseTimeout(promise, 100, new Error('Timeout'));
|
|
57
|
+
expect(result).toBe(testValue);
|
|
58
|
+
});
|
|
59
|
+
it('rejects when promise times out', async () => {
|
|
60
|
+
const promise = new Promise((resolve) => setTimeout(resolve, 200));
|
|
61
|
+
const exception = new Error('Timeout');
|
|
62
|
+
await expect(promiseTimeout(promise, 100, exception)).rejects.toThrow(exception);
|
|
63
|
+
});
|
|
64
|
+
it('rejects when original promise rejects', async () => {
|
|
65
|
+
const error = new Error('Original rejection');
|
|
66
|
+
const promise = Promise.reject(error);
|
|
67
|
+
await expect(promiseTimeout(promise, 100, new Error('Timeout'))).rejects.toThrow(error);
|
|
68
|
+
});
|
|
69
|
+
it('clears timeout after promise resolution', async () => {
|
|
70
|
+
vi.spyOn(global, 'clearTimeout');
|
|
71
|
+
const promise = Promise.resolve('test');
|
|
72
|
+
await promiseTimeout(promise, 100, new Error('Timeout'));
|
|
73
|
+
expect(clearTimeout).toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
it('clears timeout after promise rejection', async () => {
|
|
76
|
+
vi.spyOn(global, 'clearTimeout');
|
|
77
|
+
const promise = Promise.reject(new Error('Original rejection'));
|
|
78
|
+
try {
|
|
79
|
+
await promiseTimeout(promise, 100, new Error('Timeout'));
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Ignore the error
|
|
83
|
+
}
|
|
84
|
+
expect(clearTimeout).toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('dateTimestamp', () => {
|
|
88
|
+
it('should get date timestamp in seconds', () => {
|
|
89
|
+
const date = new Date(2022, 1, 16, 17, 32, 11, 168);
|
|
90
|
+
const result = dateTimestamp(date);
|
|
91
|
+
const expected = Math.floor(date.getTime() / 1000);
|
|
92
|
+
expect(result).toEqual(expected);
|
|
93
|
+
});
|
|
16
94
|
});
|
|
17
95
|
}
|
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.92",
|
|
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.92",
|
|
57
57
|
"@reown/appkit": "1.6.4",
|
|
58
58
|
"@reown/appkit-adapter-wagmi": "1.6.4",
|
|
59
59
|
"@sentry/sveltekit": "7.120.0",
|
package/dist/utils/time.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { UTCTimestamp } from 'lightweight-charts';
|
|
2
|
-
export declare function formatTimestampSecondsAsLocal(timestampSeconds: bigint): string;
|
|
3
|
-
export declare function timestampSecondsToUTCTimestamp(timestampSeconds: bigint): UTCTimestamp;
|
|
4
|
-
/**
|
|
5
|
-
* Method to put a timeout on a promise, throws the exception if promise is not settled within the time
|
|
6
|
-
* @param promise - The original promise
|
|
7
|
-
* @param time - The time in ms
|
|
8
|
-
* @param exception - The exception to reject with if time runs out before original promise settlement
|
|
9
|
-
* @returns A new promise that gets settled with initial promise settlement or rejected with exception value
|
|
10
|
-
* if the time runs out before the main promise settlement
|
|
11
|
-
*/
|
|
12
|
-
export declare function promiseTimeout<T>(promise: Promise<T>, time: number, exception: unknown): Promise<T>;
|
package/dist/utils/time.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
import bigIntSupport from 'dayjs/plugin/bigIntSupport';
|
|
3
|
-
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
4
|
-
dayjs.extend(bigIntSupport);
|
|
5
|
-
dayjs.extend(localizedFormat);
|
|
6
|
-
export function formatTimestampSecondsAsLocal(timestampSeconds) {
|
|
7
|
-
return dayjs(timestampSeconds * BigInt('1000')).format('L LT');
|
|
8
|
-
}
|
|
9
|
-
export function timestampSecondsToUTCTimestamp(timestampSeconds) {
|
|
10
|
-
return dayjs(timestampSeconds * BigInt('1000')).unix();
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Method to put a timeout on a promise, throws the exception if promise is not settled within the time
|
|
14
|
-
* @param promise - The original promise
|
|
15
|
-
* @param time - The time in ms
|
|
16
|
-
* @param exception - The exception to reject with if time runs out before original promise settlement
|
|
17
|
-
* @returns A new promise that gets settled with initial promise settlement or rejected with exception value
|
|
18
|
-
* if the time runs out before the main promise settlement
|
|
19
|
-
*/
|
|
20
|
-
export async function promiseTimeout(promise, time, exception) {
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
let timeout;
|
|
23
|
-
return Promise.race([
|
|
24
|
-
promise,
|
|
25
|
-
new Promise((_resolve, reject) => (timeout = setTimeout(reject, time, exception)))
|
|
26
|
-
]).finally(() => clearTimeout(timeout));
|
|
27
|
-
}
|