@rainlanguage/ui-components 0.0.1-alpha.13 → 0.0.1-alpha.131
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/__fixtures__/orderDetail.d.ts +1 -1
- package/dist/__fixtures__/settings.yaml +183 -0
- package/dist/__mocks__/MockComponent.svelte +4 -0
- package/dist/__mocks__/MockComponent.svelte.d.ts +3 -1
- package/dist/__mocks__/settings.d.ts +7 -3
- package/dist/__mocks__/settings.js +68 -33
- package/dist/__mocks__/stores.d.ts +94 -27
- package/dist/__mocks__/stores.js +45 -22
- package/dist/components/ButtonLoading.svelte +1 -1
- package/dist/components/ButtonVaultLink.svelte +3 -3
- package/dist/components/ButtonVaultLink.svelte.d.ts +1 -1
- package/dist/components/CheckboxMyItemsOnly.svelte +3 -2
- package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +2 -3
- package/dist/components/CheckboxZeroBalanceVault.svelte.d.ts +2 -2
- package/dist/components/CodeMirrorDotrain.svelte +4 -0
- package/dist/components/CodeMirrorDotrain.svelte.d.ts +1 -0
- package/dist/components/CodeMirrorRainlang.svelte +11 -3
- package/dist/components/CodeMirrorRainlang.svelte.d.ts +1 -1
- package/dist/components/EditableSpan.svelte +3 -14
- package/dist/components/EditableSpan.svelte.d.ts +0 -1
- package/dist/components/Hash.svelte +3 -3
- package/dist/components/License.svelte +5 -4
- package/dist/components/ListViewOrderbookFilters.svelte +16 -15
- package/dist/components/ListViewOrderbookFilters.svelte.d.ts +9 -13
- package/dist/components/OrderOrVaultHash.svelte +10 -7
- package/dist/components/OrderOrVaultHash.svelte.d.ts +1 -1
- package/dist/components/PageHeader.svelte +1 -1
- package/dist/components/TanstackAppTable.svelte +2 -3
- package/dist/components/TanstackAppTable.svelte.d.ts +1 -1
- package/dist/components/ToastDetail.svelte +42 -0
- package/dist/components/ToastDetail.svelte.d.ts +20 -0
- package/dist/components/Tooltip.svelte +8 -0
- package/dist/components/Tooltip.svelte.d.ts +21 -0
- package/dist/components/charts/OrderTradesChart.svelte +3 -2
- package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
- package/dist/components/charts/VaultBalanceChart.svelte +6 -6
- package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -1
- package/dist/components/charts/transformAndSortData.d.ts +24 -0
- package/dist/components/charts/transformAndSortData.js +111 -0
- package/dist/components/checkbox/CheckboxActiveOrders.svelte +11 -0
- package/dist/components/checkbox/CheckboxActiveOrders.svelte.d.ts +19 -0
- package/dist/components/deployment/ButtonSelectOption.svelte +2 -0
- package/dist/components/deployment/ButtonSelectOption.svelte.d.ts +1 -0
- package/dist/components/deployment/ComposedRainlangModal.svelte +7 -5
- package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
- package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
- package/dist/components/deployment/DeploymentSteps.svelte +169 -185
- package/dist/components/deployment/DeploymentSteps.svelte.d.ts +7 -13
- package/dist/components/deployment/DeploymentsSection.svelte +18 -14
- package/dist/components/deployment/DepositInput.svelte +32 -14
- package/dist/components/deployment/DepositInput.svelte.d.ts +1 -2
- package/dist/components/deployment/DisclaimerModal.svelte +1 -0
- package/dist/components/deployment/FieldDefinitionInput.svelte +22 -14
- package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +1 -2
- package/dist/components/deployment/SelectToken.svelte +16 -4
- package/dist/components/deployment/SelectToken.svelte.d.ts +1 -2
- package/dist/components/deployment/StrategyPage.svelte +6 -2
- package/dist/components/deployment/TokenIOInput.svelte +16 -5
- package/dist/components/deployment/TokenIOInput.svelte.d.ts +1 -2
- package/dist/components/detail/OrderDetail.svelte +60 -44
- package/dist/components/detail/OrderDetail.svelte.d.ts +11 -8
- package/dist/components/detail/TanstackOrderQuote.svelte +17 -7
- package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +1 -1
- package/dist/components/detail/VaultDetail.svelte +43 -43
- package/dist/components/detail/VaultDetail.svelte.d.ts +11 -11
- package/dist/components/dropdown/DropdownActiveSubgraphs.svelte +2 -2
- package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +4 -4
- package/dist/components/dropdown/DropdownOrderListAccounts.svelte +2 -1
- package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +3 -3
- package/dist/components/icon/Refresh.svelte +2 -1
- package/dist/components/icon/Refresh.svelte.d.ts +1 -0
- package/dist/components/input/InputOrderHash.svelte +1 -1
- package/dist/components/input/InputOrderHash.svelte.d.ts +2 -2
- package/dist/components/input/InputRegistryUrl.svelte +36 -14
- package/dist/components/input/InputToken.svelte +2 -2
- package/dist/components/input/InputTokenAmount.svelte +1 -1
- package/dist/components/tables/OrderAPY.svelte +4 -9
- package/dist/components/tables/OrderTradesListTable.svelte +7 -3
- package/dist/components/tables/OrderVaultsVolTable.svelte +11 -2
- package/dist/components/tables/OrdersListTable.svelte +27 -31
- package/dist/components/tables/OrdersListTable.svelte.d.ts +2 -8
- package/dist/components/tables/VaultBalanceChangesTable.svelte +8 -6
- package/dist/components/tables/VaultsListTable.svelte +53 -67
- package/dist/components/tables/VaultsListTable.svelte.d.ts +12 -20
- package/dist/components/transactions/FixedBottomTransaction.svelte +63 -0
- package/dist/components/transactions/FixedBottomTransaction.svelte.d.ts +16 -0
- package/dist/components/transactions/TransactionDetail.svelte +31 -0
- package/dist/components/transactions/TransactionDetail.svelte.d.ts +20 -0
- package/dist/components/transactions/TransactionList.svelte +17 -0
- package/dist/components/transactions/TransactionList.svelte.d.ts +16 -0
- package/dist/components/transactions/getStatusEmoji.d.ts +2 -0
- package/dist/components/transactions/getStatusEmoji.js +20 -0
- package/dist/components/wallet/WalletConnect.svelte +5 -4
- package/dist/components/wallet/WalletConnect.svelte.d.ts +0 -1
- package/dist/consts.d.ts +1 -0
- package/dist/consts.js +1 -0
- package/dist/errors/DeploymentStepsError.d.ts +6 -2
- package/dist/errors/DeploymentStepsError.js +5 -1
- package/dist/hooks/useGui.d.ts +3 -0
- package/dist/hooks/useGui.js +11 -0
- package/dist/index.d.ts +27 -11
- package/dist/index.js +28 -8
- package/dist/models/Transaction.d.ts +80 -0
- package/dist/models/Transaction.js +134 -0
- package/dist/providers/GuiProvider.svelte +8 -0
- package/dist/providers/GuiProvider.svelte.d.ts +21 -0
- package/dist/providers/registry/RegistryManager.d.ts +65 -0
- package/dist/providers/registry/RegistryManager.js +133 -0
- package/dist/providers/registry/RegistryProvider.svelte +6 -0
- package/dist/providers/registry/RegistryProvider.svelte.d.ts +21 -0
- package/dist/providers/registry/context.d.ts +10 -0
- package/dist/providers/registry/context.js +46 -0
- package/dist/providers/registry/useRegistry.d.ts +7 -0
- package/dist/providers/registry/useRegistry.js +29 -0
- package/dist/providers/toasts/ToastProvider.svelte +17 -0
- package/dist/providers/toasts/ToastProvider.svelte.d.ts +18 -0
- package/dist/providers/toasts/context.d.ts +14 -0
- package/dist/providers/toasts/context.js +22 -0
- package/dist/providers/toasts/useToasts.d.ts +16 -0
- package/dist/providers/toasts/useToasts.js +63 -0
- package/dist/providers/transactions/TransactionManager.d.ts +183 -0
- package/dist/providers/transactions/TransactionManager.js +353 -0
- package/dist/providers/transactions/TransactionProvider.svelte +11 -0
- package/dist/providers/transactions/TransactionProvider.svelte.d.ts +24 -0
- package/dist/providers/transactions/context.d.ts +19 -0
- package/dist/providers/transactions/context.js +28 -0
- package/dist/providers/transactions/useTransactions.d.ts +13 -0
- package/dist/providers/transactions/useTransactions.js +18 -0
- package/dist/providers/wallet/WalletProvider.svelte +7 -0
- package/dist/providers/wallet/WalletProvider.svelte.d.ts +21 -0
- package/dist/providers/wallet/context.d.ts +10 -0
- package/dist/providers/wallet/context.js +47 -0
- package/dist/providers/wallet/useAccount.d.ts +8 -0
- package/dist/providers/wallet/useAccount.js +148 -0
- package/dist/queries/queryClient.d.ts +1 -1
- package/dist/queries/queryClient.js +11 -6
- package/dist/services/awaitTransactionIndexing.d.ts +100 -0
- package/dist/services/awaitTransactionIndexing.js +57 -0
- package/dist/services/handleShareChoices.d.ts +2 -2
- package/dist/services/handleShareChoices.js +7 -2
- package/dist/services/historicalOrderCharts.d.ts +1 -1
- package/dist/services/historicalOrderCharts.js +1 -1
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +2 -1
- package/dist/services/loadRegistryUrl.d.ts +2 -0
- package/dist/services/loadRegistryUrl.js +19 -0
- package/dist/services/registry.d.ts +6 -0
- package/dist/services/registry.js +33 -77
- package/dist/services/time.d.ts +12 -0
- package/dist/services/time.js +88 -6
- package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
- package/dist/storesGeneric/cachedWritableStore.js +93 -0
- package/dist/types/account.d.ts +3 -0
- package/dist/types/account.js +1 -0
- package/dist/types/appStores.d.ts +10 -9
- package/dist/types/modal.d.ts +24 -12
- package/dist/types/strategy.d.ts +1 -1
- package/dist/types/toast.d.ts +11 -0
- package/dist/types/toast.js +1 -0
- package/dist/types/transaction.d.ts +54 -15
- package/dist/types/transaction.js +29 -1
- package/dist/utils/configHelpers.d.ts +8 -0
- package/dist/utils/configHelpers.js +38 -0
- package/dist/utils/constructHashLink.d.ts +23 -0
- package/dist/utils/constructHashLink.js +110 -0
- package/dist/utils/vault.d.ts +1 -1
- package/package.json +34 -34
- package/dist/__fixtures__/settings-12-11-24.json +0 -160
- package/dist/__mocks__/mockTransactionStore.d.ts +0 -22
- package/dist/__mocks__/mockTransactionStore.js +0 -56
- package/dist/components/deployment/DepositsSection.svelte +0 -8
- package/dist/components/deployment/DepositsSection.svelte.d.ts +0 -20
- package/dist/components/deployment/FieldDefinitionsSection.svelte +0 -9
- package/dist/components/deployment/FieldDefinitionsSection.svelte.d.ts +0 -20
- package/dist/components/deployment/SelectTokensSection.svelte +0 -17
- package/dist/components/deployment/SelectTokensSection.svelte.d.ts +0 -21
- package/dist/components/deployment/TokenIOSection.svelte +0 -17
- package/dist/components/deployment/TokenIOSection.svelte.d.ts +0 -21
- package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
- package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -24
- package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
- package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
- package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
- package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
- package/dist/stores/transactionStore.d.ts +0 -98
- package/dist/stores/transactionStore.js +0 -303
- package/dist/utils/time.d.ts +0 -12
- package/dist/utils/time.js +0 -27
package/dist/services/time.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import bigIntSupport from 'dayjs/plugin/bigIntSupport';
|
|
3
|
+
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
4
|
+
import utc from 'dayjs/plugin/utc';
|
|
5
|
+
dayjs.extend(bigIntSupport);
|
|
6
|
+
dayjs.extend(localizedFormat);
|
|
7
|
+
dayjs.extend(utc);
|
|
1
8
|
export const TIME_DELTA_24_HOURS = 60 * 60 * 24;
|
|
2
9
|
export const TIME_DELTA_48_HOURS = TIME_DELTA_24_HOURS * 2;
|
|
3
10
|
export const TIME_DELTA_7_DAYS = TIME_DELTA_24_HOURS * 7;
|
|
@@ -6,12 +13,87 @@ export const TIME_DELTA_1_YEAR = TIME_DELTA_24_HOURS * 365;
|
|
|
6
13
|
export function dateTimestamp(date) {
|
|
7
14
|
return Math.floor(date.getTime() / 1000);
|
|
8
15
|
}
|
|
16
|
+
export function formatTimestampSecondsAsLocal(timestampSeconds) {
|
|
17
|
+
return dayjs(timestampSeconds * BigInt('1000'))
|
|
18
|
+
.utc()
|
|
19
|
+
.format('L LT');
|
|
20
|
+
}
|
|
21
|
+
export function timestampSecondsToUTCTimestamp(timestampSeconds) {
|
|
22
|
+
return dayjs(timestampSeconds * BigInt('1000')).unix();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Method to put a timeout on a promise, throws the exception if promise is not settled within the time
|
|
26
|
+
* @param promise - The original promise
|
|
27
|
+
* @param time - The time in ms
|
|
28
|
+
* @param exception - The exception to reject with if time runs out before original promise settlement
|
|
29
|
+
* @returns A new promise that gets settled with initial promise settlement or rejected with exception value
|
|
30
|
+
* if the time runs out before the main promise settlement
|
|
31
|
+
*/
|
|
32
|
+
export async function promiseTimeout(promise, time, exception) {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
let timeout;
|
|
35
|
+
return Promise.race([
|
|
36
|
+
promise,
|
|
37
|
+
new Promise((_resolve, reject) => (timeout = setTimeout(reject, time, exception)))
|
|
38
|
+
]).finally(() => clearTimeout(timeout));
|
|
39
|
+
}
|
|
9
40
|
if (import.meta.vitest) {
|
|
10
|
-
const { it, expect } = import.meta.vitest;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
41
|
+
const { describe, it, expect, vi } = import.meta.vitest;
|
|
42
|
+
describe('Date and timestamp utilities', () => {
|
|
43
|
+
describe('formatTimestampSecondsAsLocal', () => {
|
|
44
|
+
it('converts timestamp to local format', () => {
|
|
45
|
+
const result = formatTimestampSecondsAsLocal(BigInt('1672531200')); // Jan 1, 2023 12:00 AM
|
|
46
|
+
expect(result).toBe('01/01/2023 12:00 AM');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('timestampSecondsToUTCTimestamp', () => {
|
|
50
|
+
it('converts bigint timestamp to UTCTimestamp', () => {
|
|
51
|
+
const result = timestampSecondsToUTCTimestamp(BigInt('1672531200'));
|
|
52
|
+
expect(result).toBe(1672531200);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe('promiseTimeout', () => {
|
|
57
|
+
it('resolves when promise resolves before timeout', async () => {
|
|
58
|
+
const testValue = 'test';
|
|
59
|
+
const promise = Promise.resolve(testValue);
|
|
60
|
+
const result = await promiseTimeout(promise, 100, new Error('Timeout'));
|
|
61
|
+
expect(result).toBe(testValue);
|
|
62
|
+
});
|
|
63
|
+
it('rejects when promise times out', async () => {
|
|
64
|
+
const promise = new Promise((resolve) => setTimeout(resolve, 200));
|
|
65
|
+
const exception = new Error('Timeout');
|
|
66
|
+
await expect(promiseTimeout(promise, 100, exception)).rejects.toThrow(exception);
|
|
67
|
+
});
|
|
68
|
+
it('rejects when original promise rejects', async () => {
|
|
69
|
+
const error = new Error('Original rejection');
|
|
70
|
+
const promise = Promise.reject(error);
|
|
71
|
+
await expect(promiseTimeout(promise, 100, new Error('Timeout'))).rejects.toThrow(error);
|
|
72
|
+
});
|
|
73
|
+
it('clears timeout after promise resolution', async () => {
|
|
74
|
+
vi.spyOn(global, 'clearTimeout');
|
|
75
|
+
const promise = Promise.resolve('test');
|
|
76
|
+
await promiseTimeout(promise, 100, new Error('Timeout'));
|
|
77
|
+
expect(clearTimeout).toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
it('clears timeout after promise rejection', async () => {
|
|
80
|
+
vi.spyOn(global, 'clearTimeout');
|
|
81
|
+
const promise = Promise.reject(new Error('Original rejection'));
|
|
82
|
+
try {
|
|
83
|
+
await promiseTimeout(promise, 100, new Error('Timeout'));
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Ignore the error
|
|
87
|
+
}
|
|
88
|
+
expect(clearTimeout).toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe('dateTimestamp', () => {
|
|
92
|
+
it('should get date timestamp in seconds', () => {
|
|
93
|
+
const date = new Date(2022, 1, 16, 17, 32, 11, 168);
|
|
94
|
+
const result = dateTimestamp(date);
|
|
95
|
+
const expected = Math.floor(date.getTime() / 1000);
|
|
96
|
+
expect(result).toEqual(expected);
|
|
97
|
+
});
|
|
16
98
|
});
|
|
17
99
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a writable Svelte store that persists its value to localStorage.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the value stored in the store
|
|
5
|
+
* @param {string} key - The localStorage key used to store the value
|
|
6
|
+
* @param {T} defaultValue - The default value to use when no value is found in localStorage
|
|
7
|
+
* @param {function(T): string} serialize - Function to convert the store value to a string for storage
|
|
8
|
+
* @param {function(string): T} deserialize - Function to convert the stored string back to the original type
|
|
9
|
+
* @returns {import('svelte/store').Writable<T>} A writable store that automatically syncs with localStorage
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Create a store for a boolean value
|
|
13
|
+
* const darkMode = cachedWritableStore(
|
|
14
|
+
* 'darkMode',
|
|
15
|
+
* false,
|
|
16
|
+
* value => JSON.stringify(value),
|
|
17
|
+
* str => JSON.parse(str)
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* // Create a store for a complex object
|
|
21
|
+
* const userPreferences = cachedWritableStore(
|
|
22
|
+
* 'userPrefs',
|
|
23
|
+
* { theme: 'light', fontSize: 14 },
|
|
24
|
+
* value => JSON.stringify(value),
|
|
25
|
+
* str => JSON.parse(str)
|
|
26
|
+
* );
|
|
27
|
+
*/
|
|
28
|
+
export declare function cachedWritableStore<T>(key: string, defaultValue: T, serialize: (value: T) => string, deserialize: (serialized: string) => T): import("svelte/store").Writable<T>;
|
|
29
|
+
export declare const cachedWritableString: (key: string, defaultValue?: string) => import("svelte/store").Writable<string>;
|
|
30
|
+
export declare const cachedWritableInt: (key: string, defaultValue?: number) => import("svelte/store").Writable<number>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a writable store that can hold an optional value of type T and persists to localStorage.
|
|
33
|
+
*
|
|
34
|
+
* @template T - The type of the value stored
|
|
35
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
36
|
+
* @param {T | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
37
|
+
* @param {function} serialize - Function to convert the value to a string for storage
|
|
38
|
+
* @param {function} deserialize - Function to convert the stored string back to a value
|
|
39
|
+
* @returns A writable store that persists to localStorage and can hold undefined values
|
|
40
|
+
*/
|
|
41
|
+
export declare const cachedWritableOptionalStore: <T>(key: string, defaultValue: T | undefined, serialize: (value: T) => string, deserialize: (serialized: string) => T) => import("svelte/store").Writable<T | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a writable store that can hold an optional number value and persists to localStorage.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
46
|
+
* @param {number | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
47
|
+
* @returns A writable store that persists to localStorage and can hold an optional number
|
|
48
|
+
*/
|
|
49
|
+
export declare const cachedWritableIntOptional: (key: string, defaultValue?: undefined) => import("svelte/store").Writable<number | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a writable store that can hold an optional string value and persists to localStorage.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
54
|
+
* @param {string | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
55
|
+
* @returns A writable store that persists to localStorage and can hold an optional string
|
|
56
|
+
*/
|
|
57
|
+
export declare const cachedWritableStringOptional: (key: string, defaultValue?: undefined) => import("svelte/store").Writable<string | undefined>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { writable } from 'svelte/store';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a writable Svelte store that persists its value to localStorage.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the value stored in the store
|
|
6
|
+
* @param {string} key - The localStorage key used to store the value
|
|
7
|
+
* @param {T} defaultValue - The default value to use when no value is found in localStorage
|
|
8
|
+
* @param {function(T): string} serialize - Function to convert the store value to a string for storage
|
|
9
|
+
* @param {function(string): T} deserialize - Function to convert the stored string back to the original type
|
|
10
|
+
* @returns {import('svelte/store').Writable<T>} A writable store that automatically syncs with localStorage
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Create a store for a boolean value
|
|
14
|
+
* const darkMode = cachedWritableStore(
|
|
15
|
+
* 'darkMode',
|
|
16
|
+
* false,
|
|
17
|
+
* value => JSON.stringify(value),
|
|
18
|
+
* str => JSON.parse(str)
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* // Create a store for a complex object
|
|
22
|
+
* const userPreferences = cachedWritableStore(
|
|
23
|
+
* 'userPrefs',
|
|
24
|
+
* { theme: 'light', fontSize: 14 },
|
|
25
|
+
* value => JSON.stringify(value),
|
|
26
|
+
* str => JSON.parse(str)
|
|
27
|
+
* );
|
|
28
|
+
*/
|
|
29
|
+
export function cachedWritableStore(key, defaultValue, serialize, deserialize) {
|
|
30
|
+
const getCache = () => {
|
|
31
|
+
try {
|
|
32
|
+
const cached = localStorage.getItem(key);
|
|
33
|
+
return cached !== null ? deserialize(cached) : defaultValue;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return defaultValue;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const setCache = (value) => {
|
|
40
|
+
try {
|
|
41
|
+
if (value !== undefined) {
|
|
42
|
+
localStorage.setItem(key, serialize(value));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
localStorage.removeItem(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Silently ignore localStorage errors to allow the application to function
|
|
50
|
+
// without persistence in environments where localStorage is unavailable
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const data = writable(getCache());
|
|
54
|
+
data.subscribe((value) => {
|
|
55
|
+
setCache(value);
|
|
56
|
+
});
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
export const cachedWritableString = (key, defaultValue = '') => cachedWritableStore(key, defaultValue, (v) => v, (v) => v);
|
|
60
|
+
export const cachedWritableInt = (key, defaultValue = 0) => cachedWritableStore(key, defaultValue, (v) => v.toString(), (v) => {
|
|
61
|
+
const parsed = Number.parseInt(v);
|
|
62
|
+
return isNaN(parsed) ? defaultValue : parsed;
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Creates a writable store that can hold an optional value of type T and persists to localStorage.
|
|
66
|
+
*
|
|
67
|
+
* @template T - The type of the value stored
|
|
68
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
69
|
+
* @param {T | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
70
|
+
* @param {function} serialize - Function to convert the value to a string for storage
|
|
71
|
+
* @param {function} deserialize - Function to convert the stored string back to a value
|
|
72
|
+
* @returns A writable store that persists to localStorage and can hold undefined values
|
|
73
|
+
*/
|
|
74
|
+
export const cachedWritableOptionalStore = (key, defaultValue = undefined, serialize, deserialize) => cachedWritableStore(key, defaultValue, (v) => (v !== undefined ? serialize(v) : ''), (v) => (v !== '' ? deserialize(v) : undefined));
|
|
75
|
+
/**
|
|
76
|
+
* Creates a writable store that can hold an optional number value and persists to localStorage.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
79
|
+
* @param {number | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
80
|
+
* @returns A writable store that persists to localStorage and can hold an optional number
|
|
81
|
+
*/
|
|
82
|
+
export const cachedWritableIntOptional = (key, defaultValue = undefined) => cachedWritableOptionalStore(key, defaultValue, (v) => v.toString(), (v) => {
|
|
83
|
+
const parsed = Number.parseInt(v);
|
|
84
|
+
return isNaN(parsed) ? (defaultValue ?? 0) : parsed;
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* Creates a writable store that can hold an optional string value and persists to localStorage.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
90
|
+
* @param {string | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
91
|
+
* @returns A writable store that persists to localStorage and can hold an optional string
|
|
92
|
+
*/
|
|
93
|
+
export const cachedWritableStringOptional = (key, defaultValue = undefined) => cachedWritableOptionalStore(key, defaultValue, (v) => v, (v) => v);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { Readable, Writable } from 'svelte/store';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AccountCfg, NewConfig, OrderbookCfg, SubgraphCfg } from '@rainlanguage/orderbook';
|
|
3
3
|
export interface AppStoresInterface {
|
|
4
|
-
settings: Writable<
|
|
5
|
-
activeSubgraphs: Writable<Record<string,
|
|
6
|
-
accounts: Readable<Record<string,
|
|
7
|
-
activeAccountsItems: Writable<Record<string, string
|
|
8
|
-
|
|
4
|
+
settings: Writable<NewConfig>;
|
|
5
|
+
activeSubgraphs: Writable<Record<string, SubgraphCfg>>;
|
|
6
|
+
accounts: Readable<Record<string, AccountCfg>>;
|
|
7
|
+
activeAccountsItems: Writable<Record<string, string>> | undefined;
|
|
8
|
+
showInactiveOrders: Writable<boolean>;
|
|
9
9
|
orderHash: Writable<string>;
|
|
10
10
|
hideZeroBalanceVaults: Writable<boolean>;
|
|
11
11
|
activeNetworkRef: Writable<string | undefined>;
|
|
12
12
|
activeOrderbookRef: Writable<string | undefined>;
|
|
13
|
-
activeOrderbook: Readable<
|
|
14
|
-
|
|
13
|
+
activeOrderbook: Readable<OrderbookCfg | undefined>;
|
|
14
|
+
subgraph: Readable<SubgraphCfg | undefined>;
|
|
15
15
|
activeAccounts: Readable<{
|
|
16
|
-
[k: string]:
|
|
16
|
+
[k: string]: AccountCfg;
|
|
17
17
|
}>;
|
|
18
18
|
showMyItemsOnly: Writable<boolean>;
|
|
19
|
+
activeNetworkOrderbooks: Readable<Record<string, OrderbookCfg>>;
|
|
19
20
|
}
|
package/dist/types/modal.d.ts
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
|
-
import type { SgOrder } from '@rainlanguage/orderbook
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { SgOrder, SgVault } from '@rainlanguage/orderbook';
|
|
2
|
+
import type { VaultActionArgs } from './transaction';
|
|
3
|
+
import type { Hex } from 'viem';
|
|
4
|
+
export type VaultActionModalProps = {
|
|
4
5
|
open: boolean;
|
|
5
|
-
args:
|
|
6
|
-
|
|
7
|
-
export type OrderRemoveModalProps = {
|
|
8
|
-
open: boolean;
|
|
9
|
-
args: OrderRemoveArgs;
|
|
10
|
-
};
|
|
11
|
-
export type DeployModalProps = {
|
|
12
|
-
open: boolean;
|
|
13
|
-
args: DeploymentArgs;
|
|
6
|
+
args: VaultActionArgs;
|
|
7
|
+
onSubmit: (amount: bigint) => void;
|
|
14
8
|
};
|
|
15
9
|
export type DisclaimerModalProps = {
|
|
16
10
|
open: boolean;
|
|
17
11
|
onAccept: () => void;
|
|
18
12
|
};
|
|
13
|
+
export type TransactionConfirmationProps = {
|
|
14
|
+
open: boolean;
|
|
15
|
+
modalTitle: string;
|
|
16
|
+
closeOnConfirm?: boolean;
|
|
17
|
+
args: {
|
|
18
|
+
chainId: number;
|
|
19
|
+
toAddress: Hex;
|
|
20
|
+
onConfirm: (hash: Hex) => void;
|
|
21
|
+
entity?: SgOrder | SgVault;
|
|
22
|
+
calldata: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
19
25
|
export type QuoteDebugModalHandler = (order: SgOrder, rpcUrl: string, orderbook: string, inputIOIndex: number, outputIOIndex: number, pair: string, blockNumber?: number) => void;
|
|
20
26
|
export type DebugTradeModalHandler = (hash: string, rpcUrl: string) => void;
|
|
27
|
+
export type HandleTransactionConfirmationModal = (props: TransactionConfirmationProps, options?: {
|
|
28
|
+
timeout?: number;
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
success: boolean;
|
|
31
|
+
hash?: string;
|
|
32
|
+
}>;
|
package/dist/types/strategy.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,27 +1,66 @@
|
|
|
1
|
-
import type { ExtendedApprovalCalldata } from '../stores/transactionStore';
|
|
2
|
-
import type { DepositAndAddOrderCalldataResult } from '@rainlanguage/orderbook/js_api';
|
|
3
1
|
import type { Hex } from 'viem';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
chainId: number;
|
|
2
|
+
import type { SgVault, VaultCalldataResult, DeploymentTransactionArgs } from '@rainlanguage/orderbook';
|
|
3
|
+
import type { Config } from '@wagmi/core';
|
|
4
|
+
import type { ToastLink } from './toast';
|
|
5
|
+
import type { AwaitSubgraphConfig } from '../services/awaitTransactionIndexing';
|
|
6
|
+
export type DeploymentArgs = DeploymentTransactionArgs & {
|
|
10
7
|
subgraphUrl: string;
|
|
11
8
|
network: string;
|
|
12
9
|
};
|
|
13
|
-
export type
|
|
10
|
+
export type VaultActionArgs = {
|
|
14
11
|
vault: SgVault;
|
|
15
|
-
onDepositOrWithdraw: () => void;
|
|
16
|
-
action: 'deposit' | 'withdraw';
|
|
17
12
|
chainId: number;
|
|
13
|
+
onDeposit?: () => void;
|
|
18
14
|
rpcUrl: string;
|
|
19
15
|
subgraphUrl: string;
|
|
16
|
+
account: Hex;
|
|
20
17
|
};
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
export declare enum TransactionName {
|
|
19
|
+
REMOVAL = "Order Removal",
|
|
20
|
+
WITHDRAWAL = "Vault Withdrawal",
|
|
21
|
+
APPROVAL = "Token Approval",
|
|
22
|
+
DEPOSIT = "Vault Deposit"
|
|
23
|
+
}
|
|
24
|
+
export declare enum TransactionStatusMessage {
|
|
25
|
+
IDLE = "Idle",
|
|
26
|
+
STARTING = "Starting transaction...",
|
|
27
|
+
CHECKING_ALLOWANCE = "Checking your allowance...",
|
|
28
|
+
PENDING_WALLET = "Waiting for wallet confirmation...",
|
|
29
|
+
PENDING_APPROVAL = "Approving token spend...",
|
|
30
|
+
PENDING_RECEIPT = "Waiting for transaction receipt...",
|
|
31
|
+
PENDING_DEPLOYMENT = "Deploying your order...",
|
|
32
|
+
PENDING_WITHDRAWAL = "Withdrawing tokens...",
|
|
33
|
+
PENDING_DEPOSIT = "Depositing tokens...",
|
|
34
|
+
PENDING_SUBGRAPH = "Awaiting transaction indexing...",
|
|
35
|
+
SUCCESS = "Transaction confirmed",
|
|
36
|
+
ERROR = "Something went wrong"
|
|
37
|
+
}
|
|
38
|
+
export declare enum TransactionStoreErrorMessage {
|
|
39
|
+
SWITCH_CHAIN_FAILED = "Failed to switch chain.",
|
|
40
|
+
SUBGRAPH_TIMEOUT_ERROR = "The subgraph took too long to respond. Your transaction may still be processing.",
|
|
41
|
+
SUBGRAPH_FAILED = "Failed to index transaction.",
|
|
42
|
+
RECEIPT_FAILED = "Failed to get transaction receipt."
|
|
43
|
+
}
|
|
44
|
+
export type DepositOrWithdrawTransactionArgs = {
|
|
45
|
+
config: Config;
|
|
46
|
+
approvalCalldata?: VaultCalldataResult;
|
|
47
|
+
transactionCalldata: VaultCalldataResult;
|
|
48
|
+
action: 'deposit' | 'withdraw';
|
|
24
49
|
chainId: number;
|
|
25
|
-
|
|
50
|
+
vault: SgVault;
|
|
26
51
|
subgraphUrl: string;
|
|
27
52
|
};
|
|
53
|
+
export type InternalTransactionArgs = {
|
|
54
|
+
chainId: number;
|
|
55
|
+
txHash: Hex;
|
|
56
|
+
networkKey: string;
|
|
57
|
+
queryKey: string;
|
|
58
|
+
};
|
|
59
|
+
export type TransactionArgs = InternalTransactionArgs & {
|
|
60
|
+
name: string;
|
|
61
|
+
errorMessage: string;
|
|
62
|
+
successMessage: string;
|
|
63
|
+
queryKey: string;
|
|
64
|
+
toastLinks: ToastLink[];
|
|
65
|
+
awaitSubgraphConfig?: AwaitSubgraphConfig;
|
|
66
|
+
};
|
|
@@ -1 +1,29 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var TransactionName;
|
|
2
|
+
(function (TransactionName) {
|
|
3
|
+
TransactionName["REMOVAL"] = "Order Removal";
|
|
4
|
+
TransactionName["WITHDRAWAL"] = "Vault Withdrawal";
|
|
5
|
+
TransactionName["APPROVAL"] = "Token Approval";
|
|
6
|
+
TransactionName["DEPOSIT"] = "Vault Deposit";
|
|
7
|
+
})(TransactionName || (TransactionName = {}));
|
|
8
|
+
export var TransactionStatusMessage;
|
|
9
|
+
(function (TransactionStatusMessage) {
|
|
10
|
+
TransactionStatusMessage["IDLE"] = "Idle";
|
|
11
|
+
TransactionStatusMessage["STARTING"] = "Starting transaction...";
|
|
12
|
+
TransactionStatusMessage["CHECKING_ALLOWANCE"] = "Checking your allowance...";
|
|
13
|
+
TransactionStatusMessage["PENDING_WALLET"] = "Waiting for wallet confirmation...";
|
|
14
|
+
TransactionStatusMessage["PENDING_APPROVAL"] = "Approving token spend...";
|
|
15
|
+
TransactionStatusMessage["PENDING_RECEIPT"] = "Waiting for transaction receipt...";
|
|
16
|
+
TransactionStatusMessage["PENDING_DEPLOYMENT"] = "Deploying your order...";
|
|
17
|
+
TransactionStatusMessage["PENDING_WITHDRAWAL"] = "Withdrawing tokens...";
|
|
18
|
+
TransactionStatusMessage["PENDING_DEPOSIT"] = "Depositing tokens...";
|
|
19
|
+
TransactionStatusMessage["PENDING_SUBGRAPH"] = "Awaiting transaction indexing...";
|
|
20
|
+
TransactionStatusMessage["SUCCESS"] = "Transaction confirmed";
|
|
21
|
+
TransactionStatusMessage["ERROR"] = "Something went wrong";
|
|
22
|
+
})(TransactionStatusMessage || (TransactionStatusMessage = {}));
|
|
23
|
+
export var TransactionStoreErrorMessage;
|
|
24
|
+
(function (TransactionStoreErrorMessage) {
|
|
25
|
+
TransactionStoreErrorMessage["SWITCH_CHAIN_FAILED"] = "Failed to switch chain.";
|
|
26
|
+
TransactionStoreErrorMessage["SUBGRAPH_TIMEOUT_ERROR"] = "The subgraph took too long to respond. Your transaction may still be processing.";
|
|
27
|
+
TransactionStoreErrorMessage["SUBGRAPH_FAILED"] = "Failed to index transaction.";
|
|
28
|
+
TransactionStoreErrorMessage["RECEIPT_FAILED"] = "Failed to get transaction receipt.";
|
|
29
|
+
})(TransactionStoreErrorMessage || (TransactionStoreErrorMessage = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AccountCfg, SubgraphCfg } from '@rainlanguage/orderbook';
|
|
2
|
+
export declare function getMultiSubgraphArgs(subgraphs: Record<string, SubgraphCfg>): {
|
|
3
|
+
name: string;
|
|
4
|
+
url: string;
|
|
5
|
+
}[];
|
|
6
|
+
export declare function getAccountsAsOptions(accounts: Record<string, AccountCfg>): {
|
|
7
|
+
[k: string]: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export function getMultiSubgraphArgs(subgraphs) {
|
|
2
|
+
return Object.entries(subgraphs).map(([name, value]) => ({
|
|
3
|
+
name,
|
|
4
|
+
url: value.url
|
|
5
|
+
}));
|
|
6
|
+
}
|
|
7
|
+
export function getAccountsAsOptions(accounts) {
|
|
8
|
+
return Object.fromEntries(Object.entries(accounts).map(([key, value]) => [key, value.address]));
|
|
9
|
+
}
|
|
10
|
+
if (import.meta.vitest) {
|
|
11
|
+
const { expect, it, describe } = import.meta.vitest;
|
|
12
|
+
describe('getMultiSubgraphArgs', () => {
|
|
13
|
+
it('should return the correct multi subgraph args', () => {
|
|
14
|
+
const subgraphs = {
|
|
15
|
+
subgraph1: { url: 'https://subgraph1.com', key: 'subgraph1' },
|
|
16
|
+
subgraph2: { url: 'https://subgraph2.com', key: 'subgraph2' }
|
|
17
|
+
};
|
|
18
|
+
const result = getMultiSubgraphArgs(subgraphs);
|
|
19
|
+
expect(result).toEqual([
|
|
20
|
+
{ name: 'subgraph1', url: 'https://subgraph1.com' },
|
|
21
|
+
{ name: 'subgraph2', url: 'https://subgraph2.com' }
|
|
22
|
+
]);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('getAccountsAsOptions', () => {
|
|
26
|
+
it('should return the correct accounts as options', () => {
|
|
27
|
+
const accounts = {
|
|
28
|
+
account1: { address: '0x1234567890abcdef', key: 'account1' },
|
|
29
|
+
account2: { address: '0xabcdef1234567890', key: 'account2' }
|
|
30
|
+
};
|
|
31
|
+
const result = getAccountsAsOptions(accounts);
|
|
32
|
+
expect(result).toEqual({
|
|
33
|
+
account1: '0x1234567890abcdef',
|
|
34
|
+
account2: '0xabcdef1234567890'
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SgOrder, SgOrderAsIO, SgVault } from '@rainlanguage/orderbook';
|
|
2
|
+
type OrderOrVault = SgOrder | SgOrderAsIO | SgVault;
|
|
3
|
+
/**
|
|
4
|
+
* Constructs a link path for an order or vault based on its type and network
|
|
5
|
+
* @param orderOrVault - The order or vault object
|
|
6
|
+
* @param type - The type of resource ('orders' or 'vaults')
|
|
7
|
+
* @param network - The network name
|
|
8
|
+
* @returns The constructed link path
|
|
9
|
+
*/
|
|
10
|
+
export declare function constructHashLink(orderOrVault: OrderOrVault, type: 'orders' | 'vaults', network: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Determines if an order or vault is active
|
|
13
|
+
* @param orderOrVault - The order or vault object
|
|
14
|
+
* @returns True if the order is active, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
export declare function isOrderOrVaultActive(orderOrVault: OrderOrVault): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Extracts the hash value from an order or vault
|
|
19
|
+
* @param orderOrVault - The order or vault object
|
|
20
|
+
* @returns The hash value
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractHash(orderOrVault: OrderOrVault): string;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import fc from 'fast-check';
|
|
2
|
+
import { test } from '@fast-check/vitest';
|
|
3
|
+
function isOrder(obj) {
|
|
4
|
+
return obj && 'orderHash' in obj;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Constructs a link path for an order or vault based on its type and network
|
|
8
|
+
* @param orderOrVault - The order or vault object
|
|
9
|
+
* @param type - The type of resource ('orders' or 'vaults')
|
|
10
|
+
* @param network - The network name
|
|
11
|
+
* @returns The constructed link path
|
|
12
|
+
*/
|
|
13
|
+
export function constructHashLink(orderOrVault, type, network) {
|
|
14
|
+
if (!orderOrVault) {
|
|
15
|
+
return `/${type}/${network}`;
|
|
16
|
+
}
|
|
17
|
+
const slug = isOrder(orderOrVault) ? orderOrVault.orderHash : orderOrVault?.id;
|
|
18
|
+
return `/${type}/${network}-${slug || ''}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Determines if an order or vault is active
|
|
22
|
+
* @param orderOrVault - The order or vault object
|
|
23
|
+
* @returns True if the order is active, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
export function isOrderOrVaultActive(orderOrVault) {
|
|
26
|
+
const _isOrder = isOrder(orderOrVault);
|
|
27
|
+
return _isOrder ? orderOrVault.active : false;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extracts the hash value from an order or vault
|
|
31
|
+
* @param orderOrVault - The order or vault object
|
|
32
|
+
* @returns The hash value
|
|
33
|
+
*/
|
|
34
|
+
export function extractHash(orderOrVault) {
|
|
35
|
+
const _isOrder = isOrder(orderOrVault);
|
|
36
|
+
return _isOrder ? orderOrVault.orderHash : orderOrVault?.id || '';
|
|
37
|
+
}
|
|
38
|
+
if (import.meta.vitest) {
|
|
39
|
+
const { expect, it, describe } = import.meta.vitest;
|
|
40
|
+
describe('constructHashLink', () => {
|
|
41
|
+
test.prop([
|
|
42
|
+
fc.record({
|
|
43
|
+
orderHash: fc.string(),
|
|
44
|
+
active: fc.boolean()
|
|
45
|
+
}),
|
|
46
|
+
fc.oneof(fc.constant('orders'), fc.constant('vaults')),
|
|
47
|
+
fc.string()
|
|
48
|
+
])('constructs correct link for orders', (order, type, network) => {
|
|
49
|
+
const result = constructHashLink(order, type, network);
|
|
50
|
+
expect(result).toBe(`/${type}/${network}-${order.orderHash}`);
|
|
51
|
+
});
|
|
52
|
+
test.prop([
|
|
53
|
+
fc.record({
|
|
54
|
+
id: fc.string(),
|
|
55
|
+
owner: fc.string()
|
|
56
|
+
}),
|
|
57
|
+
fc.oneof(fc.constant('orders'), fc.constant('vaults')),
|
|
58
|
+
fc.string()
|
|
59
|
+
])('constructs correct link for vaults', (vault, type, network) => {
|
|
60
|
+
const result = constructHashLink(vault, type, network);
|
|
61
|
+
expect(result).toBe(`/${type}/${network}-${vault.id}`);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('isOrderOrVaultActive', () => {
|
|
65
|
+
test.prop([
|
|
66
|
+
fc.record({
|
|
67
|
+
orderHash: fc.string(),
|
|
68
|
+
active: fc.boolean()
|
|
69
|
+
})
|
|
70
|
+
])('returns correct active status for orders', (order) => {
|
|
71
|
+
const result = isOrderOrVaultActive(order);
|
|
72
|
+
expect(result).toBe(order.active);
|
|
73
|
+
});
|
|
74
|
+
test.prop([
|
|
75
|
+
fc.record({
|
|
76
|
+
id: fc.string(),
|
|
77
|
+
owner: fc.string()
|
|
78
|
+
})
|
|
79
|
+
])('returns false for vaults', (vault) => {
|
|
80
|
+
const result = isOrderOrVaultActive(vault);
|
|
81
|
+
expect(result).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('extractHash', () => {
|
|
85
|
+
test.prop([
|
|
86
|
+
fc.record({
|
|
87
|
+
orderHash: fc.string(),
|
|
88
|
+
active: fc.boolean()
|
|
89
|
+
})
|
|
90
|
+
])('extracts hash from orders', (order) => {
|
|
91
|
+
const result = extractHash(order);
|
|
92
|
+
expect(result).toBe(order.orderHash);
|
|
93
|
+
});
|
|
94
|
+
test.prop([
|
|
95
|
+
fc.record({
|
|
96
|
+
id: fc.string(),
|
|
97
|
+
owner: fc.string()
|
|
98
|
+
})
|
|
99
|
+
])('extracts hash from vaults', (vault) => {
|
|
100
|
+
const result = extractHash(vault);
|
|
101
|
+
expect(result).toBe(vault.id);
|
|
102
|
+
});
|
|
103
|
+
it('handles undefined vault id', () => {
|
|
104
|
+
// Create a partial vault object with undefined id
|
|
105
|
+
const vault = { id: undefined };
|
|
106
|
+
const result = extractHash(vault);
|
|
107
|
+
expect(result).toBe('');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|