@rainlanguage/ui-components 0.0.1-alpha.8 → 0.0.1-alpha.80

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.
Files changed (132) hide show
  1. package/dist/__fixtures__/orderDetail.d.ts +1 -1
  2. package/dist/__mocks__/MockComponent.svelte +4 -0
  3. package/dist/__mocks__/MockComponent.svelte.d.ts +3 -1
  4. package/dist/__mocks__/mockTransactionStore.d.ts +3 -21
  5. package/dist/__mocks__/mockTransactionStore.js +26 -13
  6. package/dist/__mocks__/settings.d.ts +6 -2
  7. package/dist/__mocks__/settings.js +6 -1
  8. package/dist/__mocks__/stores.d.ts +86 -19
  9. package/dist/__mocks__/stores.js +26 -17
  10. package/dist/components/ButtonVaultLink.svelte +3 -3
  11. package/dist/components/ButtonVaultLink.svelte.d.ts +1 -1
  12. package/dist/components/CheckboxMyItemsOnly.svelte +3 -2
  13. package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +0 -1
  14. package/dist/components/CodeMirrorDotrain.svelte +4 -0
  15. package/dist/components/CodeMirrorDotrain.svelte.d.ts +1 -0
  16. package/dist/components/CodeMirrorRainlang.svelte +2 -2
  17. package/dist/components/CodeMirrorRainlang.svelte.d.ts +1 -1
  18. package/dist/components/Hash.svelte +3 -3
  19. package/dist/components/License.svelte +5 -4
  20. package/dist/components/ListViewOrderbookFilters.svelte +14 -13
  21. package/dist/components/ListViewOrderbookFilters.svelte.d.ts +2 -5
  22. package/dist/components/OrderOrVaultHash.svelte +10 -7
  23. package/dist/components/OrderOrVaultHash.svelte.d.ts +1 -1
  24. package/dist/components/PageHeader.svelte +20 -22
  25. package/dist/components/PageHeader.svelte.d.ts +1 -0
  26. package/dist/components/TanstackAppTable.svelte +2 -3
  27. package/dist/components/TanstackAppTable.svelte.d.ts +1 -1
  28. package/dist/components/Tooltip.svelte +8 -0
  29. package/dist/components/Tooltip.svelte.d.ts +21 -0
  30. package/dist/components/charts/OrderTradesChart.svelte +1 -1
  31. package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
  32. package/dist/components/charts/VaultBalanceChart.svelte +1 -1
  33. package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -1
  34. package/dist/components/charts/transformAndSortData.d.ts +24 -0
  35. package/dist/components/charts/transformAndSortData.js +111 -0
  36. package/dist/components/checkbox/CheckboxActiveOrders.svelte +11 -0
  37. package/dist/components/checkbox/CheckboxActiveOrders.svelte.d.ts +19 -0
  38. package/dist/components/deployment/ComposedRainlangModal.svelte +7 -5
  39. package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
  40. package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
  41. package/dist/components/deployment/DeploymentSteps.svelte +180 -155
  42. package/dist/components/deployment/DeploymentSteps.svelte.d.ts +7 -13
  43. package/dist/components/deployment/DeploymentsSection.svelte +18 -14
  44. package/dist/components/deployment/DepositInput.svelte +31 -14
  45. package/dist/components/deployment/DepositInput.svelte.d.ts +1 -2
  46. package/dist/components/deployment/FieldDefinitionInput.svelte +20 -14
  47. package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +1 -2
  48. package/dist/components/deployment/SelectToken.svelte +12 -3
  49. package/dist/components/deployment/SelectToken.svelte.d.ts +1 -2
  50. package/dist/components/deployment/StrategyPage.svelte +6 -2
  51. package/dist/components/deployment/TokenIOInput.svelte +15 -5
  52. package/dist/components/deployment/TokenIOInput.svelte.d.ts +1 -2
  53. package/dist/components/deployment/handleDeployment.d.ts +11 -0
  54. package/dist/components/deployment/handleDeployment.js +33 -0
  55. package/dist/components/detail/OrderDetail.svelte +46 -41
  56. package/dist/components/detail/OrderDetail.svelte.d.ts +11 -8
  57. package/dist/components/detail/TanstackOrderQuote.svelte +6 -6
  58. package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +1 -1
  59. package/dist/components/detail/VaultDetail.svelte +29 -40
  60. package/dist/components/detail/VaultDetail.svelte.d.ts +10 -10
  61. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +1 -1
  62. package/dist/components/icon/Refresh.svelte +2 -1
  63. package/dist/components/icon/Refresh.svelte.d.ts +1 -0
  64. package/dist/components/input/InputOrderHash.svelte +1 -1
  65. package/dist/components/input/InputRegistryUrl.svelte +2 -2
  66. package/dist/components/input/InputToken.svelte +2 -2
  67. package/dist/components/input/InputTokenAmount.svelte +1 -1
  68. package/dist/components/tables/OrderAPY.svelte +1 -1
  69. package/dist/components/tables/OrderTradesListTable.svelte +1 -1
  70. package/dist/components/tables/OrderVaultsVolTable.svelte +1 -1
  71. package/dist/components/tables/OrdersListTable.svelte +16 -18
  72. package/dist/components/tables/OrdersListTable.svelte.d.ts +0 -6
  73. package/dist/components/tables/VaultBalanceChangesTable.svelte +3 -3
  74. package/dist/components/tables/VaultsListTable.svelte +43 -52
  75. package/dist/components/tables/VaultsListTable.svelte.d.ts +3 -6
  76. package/dist/components/wallet/WalletConnect.svelte +5 -4
  77. package/dist/components/wallet/WalletConnect.svelte.d.ts +0 -1
  78. package/dist/consts.d.ts +1 -0
  79. package/dist/consts.js +1 -0
  80. package/dist/errors/DeploymentStepsError.d.ts +5 -2
  81. package/dist/errors/DeploymentStepsError.js +4 -1
  82. package/dist/hooks/useGui.d.ts +3 -0
  83. package/dist/hooks/useGui.js +11 -0
  84. package/dist/index.d.ts +12 -6
  85. package/dist/index.js +14 -5
  86. package/dist/providers/GuiProvider.svelte +8 -0
  87. package/dist/providers/GuiProvider.svelte.d.ts +21 -0
  88. package/dist/providers/wallet/WalletProvider.svelte +7 -0
  89. package/dist/providers/wallet/WalletProvider.svelte.d.ts +21 -0
  90. package/dist/providers/wallet/context.d.ts +10 -0
  91. package/dist/providers/wallet/context.js +47 -0
  92. package/dist/providers/wallet/useAccount.d.ts +8 -0
  93. package/dist/providers/wallet/useAccount.js +148 -0
  94. package/dist/queries/queryClient.d.ts +1 -1
  95. package/dist/queries/queryClient.js +3 -3
  96. package/dist/services/awaitTransactionIndexing.d.ts +163 -0
  97. package/dist/services/awaitTransactionIndexing.js +120 -0
  98. package/dist/services/handleShareChoices.d.ts +2 -2
  99. package/dist/services/handleShareChoices.js +7 -2
  100. package/dist/services/historicalOrderCharts.d.ts +1 -1
  101. package/dist/services/index.d.ts +1 -1
  102. package/dist/services/index.js +1 -1
  103. package/dist/services/registry.d.ts +6 -0
  104. package/dist/services/registry.js +156 -0
  105. package/dist/stores/transactionStore.d.ts +7 -10
  106. package/dist/stores/transactionStore.js +35 -61
  107. package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
  108. package/dist/storesGeneric/cachedWritableStore.js +93 -0
  109. package/dist/types/account.d.ts +3 -0
  110. package/dist/types/account.js +1 -0
  111. package/dist/types/appStores.d.ts +2 -2
  112. package/dist/types/modal.d.ts +1 -1
  113. package/dist/types/strategy.d.ts +1 -1
  114. package/dist/types/transaction.d.ts +3 -3
  115. package/dist/utils/constructHashLink.d.ts +23 -0
  116. package/dist/utils/constructHashLink.js +110 -0
  117. package/dist/utils/vault.d.ts +1 -1
  118. package/package.json +34 -34
  119. package/dist/components/deployment/DepositsSection.svelte +0 -8
  120. package/dist/components/deployment/DepositsSection.svelte.d.ts +0 -20
  121. package/dist/components/deployment/FieldDefinitionsSection.svelte +0 -9
  122. package/dist/components/deployment/FieldDefinitionsSection.svelte.d.ts +0 -20
  123. package/dist/components/deployment/SelectTokensSection.svelte +0 -17
  124. package/dist/components/deployment/SelectTokensSection.svelte.d.ts +0 -21
  125. package/dist/components/deployment/TokenIOSection.svelte +0 -17
  126. package/dist/components/deployment/TokenIOSection.svelte.d.ts +0 -21
  127. package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
  128. package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -24
  129. package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
  130. package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
  131. package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
  132. package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
@@ -0,0 +1,47 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ import { readable } from 'svelte/store';
3
+ export const ACCOUNT_KEY = 'account_key';
4
+ /**
5
+ * Retrieves the account store directly from Svelte's context
6
+ */
7
+ export const getAccountContext = () => {
8
+ const account = getContext(ACCOUNT_KEY);
9
+ if (!account) {
10
+ throw new Error('No account was found in Svelte context. Did you forget to wrap your component with WalletProvider?');
11
+ }
12
+ return account;
13
+ };
14
+ /**
15
+ * Sets the account store in Svelte's context
16
+ */
17
+ export const setAccountContext = (account) => {
18
+ setContext(ACCOUNT_KEY, account);
19
+ };
20
+ if (import.meta.vitest) {
21
+ const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
22
+ vi.mock('svelte', async (importOriginal) => ({
23
+ ...(await importOriginal()),
24
+ getContext: vi.fn()
25
+ }));
26
+ describe('getAccountContext', () => {
27
+ const mockGetContext = vi.mocked(getContext);
28
+ beforeEach(() => {
29
+ mockGetContext.mockReset();
30
+ });
31
+ it('should return the account from context when it exists', () => {
32
+ const mockAccount = readable('0x456');
33
+ mockGetContext.mockImplementation((key) => {
34
+ if (key === ACCOUNT_KEY)
35
+ return mockAccount;
36
+ return undefined;
37
+ });
38
+ const result = getAccountContext();
39
+ expect(mockGetContext).toHaveBeenCalledWith(ACCOUNT_KEY);
40
+ expect(result).toEqual(mockAccount);
41
+ });
42
+ it('should throw an error when account is not in context', () => {
43
+ mockGetContext.mockReturnValue(undefined);
44
+ expect(() => getAccountContext()).toThrow('No account was found in Svelte context. Did you forget to wrap your component with WalletProvider?');
45
+ });
46
+ });
47
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Hook to access wallet account information from context
3
+ * Must be used within a component that is a child of WalletProvider
4
+ */
5
+ export declare function useAccount(): {
6
+ account: import("../../types/account").Account;
7
+ matchesAccount: (otherAddress: string) => boolean;
8
+ };
@@ -0,0 +1,148 @@
1
+ import { get } from 'svelte/store';
2
+ import { isAddress, isAddressEqual } from 'viem';
3
+ import { getAccountContext } from './context';
4
+ import { readable } from 'svelte/store';
5
+ /**
6
+ * Hook to access wallet account information from context
7
+ * Must be used within a component that is a child of WalletProvider
8
+ */
9
+ export function useAccount() {
10
+ /**
11
+ * The account store containing the current wallet address (as a Hex string) or null if not connected.
12
+ * This is a readable Svelte store that can be subscribed to for reactive updates.
13
+ * @type {import('svelte/store').Readable<Hex | null>}
14
+ */
15
+ const account = getAccountContext();
16
+ /**
17
+ * Checks if the provided address matches the currently connected account.
18
+ * Returns false if no account is connected or if the provided address is invalid.
19
+ */
20
+ const matchesAccount = (otherAddress) => {
21
+ if (!otherAddress)
22
+ return false;
23
+ const currentAccount = get(account);
24
+ if (!currentAccount) {
25
+ return false;
26
+ }
27
+ if (isAddress(currentAccount) &&
28
+ isAddress(otherAddress) &&
29
+ isAddressEqual(currentAccount, otherAddress)) {
30
+ return true;
31
+ }
32
+ return false;
33
+ };
34
+ return {
35
+ account,
36
+ matchesAccount
37
+ };
38
+ }
39
+ if (import.meta.vitest) {
40
+ const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
41
+ vi.mock('viem', async () => {
42
+ const actual = await vi.importActual('viem');
43
+ return {
44
+ ...actual,
45
+ isAddress: vi.fn(),
46
+ isAddressEqual: vi.fn()
47
+ };
48
+ });
49
+ vi.mock('./context', () => ({
50
+ getAccountContext: vi.fn()
51
+ }));
52
+ vi.mock('svelte/store', async () => {
53
+ const actual = await vi.importActual('svelte/store');
54
+ return {
55
+ ...actual,
56
+ get: vi.fn()
57
+ };
58
+ });
59
+ describe('useAccount', () => {
60
+ const mockGetAccountContext = vi.mocked(getAccountContext);
61
+ const mockGet = vi.mocked(get);
62
+ const mockIsAddress = vi.mocked(isAddress);
63
+ const mockIsAddressEqual = vi.mocked(isAddressEqual);
64
+ beforeEach(() => {
65
+ vi.clearAllMocks();
66
+ });
67
+ it('should return account wrapped in an object', () => {
68
+ const mockAccountStore = readable('0x123');
69
+ mockGetAccountContext.mockReturnValue(mockAccountStore);
70
+ const result = useAccount();
71
+ expect(mockGetAccountContext).toHaveBeenCalled();
72
+ expect(result.account).toBe(mockAccountStore);
73
+ expect(result.matchesAccount).toBeInstanceOf(Function);
74
+ });
75
+ describe('matchesAccount', () => {
76
+ const mockAccountStore = readable('0x123');
77
+ const currentAccount = '0x123';
78
+ const testAddress1 = '0x123';
79
+ const testAddress2 = '0xdef';
80
+ const invalidAddress = 'invalid';
81
+ beforeEach(() => {
82
+ mockGetAccountContext.mockReturnValue(mockAccountStore);
83
+ });
84
+ it('should return true if addresses are valid and equal', () => {
85
+ // Setup mocks
86
+ mockGet.mockReturnValue(currentAccount);
87
+ mockIsAddress.mockReturnValue(true);
88
+ mockIsAddressEqual.mockReturnValue(true);
89
+ const { matchesAccount } = useAccount();
90
+ const result = matchesAccount(testAddress1);
91
+ expect(mockGet).toHaveBeenCalledWith(mockAccountStore);
92
+ expect(mockIsAddress).toHaveBeenCalledWith(currentAccount);
93
+ expect(mockIsAddress).toHaveBeenCalledWith(testAddress1);
94
+ expect(mockIsAddressEqual).toHaveBeenCalledWith(currentAccount, testAddress1);
95
+ expect(result).toBe(true);
96
+ });
97
+ it('should return false if addresses are valid but not equal', () => {
98
+ // Setup mocks
99
+ mockGet.mockReturnValue(currentAccount);
100
+ mockIsAddress.mockReturnValue(true);
101
+ mockIsAddressEqual.mockReturnValue(false);
102
+ const { matchesAccount } = useAccount();
103
+ const result = matchesAccount(testAddress2);
104
+ expect(mockGet).toHaveBeenCalledWith(mockAccountStore);
105
+ expect(mockIsAddress).toHaveBeenCalledWith(currentAccount);
106
+ expect(mockIsAddress).toHaveBeenCalledWith(testAddress2);
107
+ expect(mockIsAddressEqual).toHaveBeenCalledWith(currentAccount, testAddress2);
108
+ expect(result).toBe(false);
109
+ });
110
+ it('should return false if current account is not set', () => {
111
+ // Setup mocks
112
+ mockGet.mockReturnValue(null);
113
+ const { matchesAccount } = useAccount();
114
+ const result = matchesAccount(testAddress1);
115
+ expect(mockGet).toHaveBeenCalledWith(mockAccountStore);
116
+ expect(mockIsAddress).not.toHaveBeenCalled();
117
+ expect(mockIsAddressEqual).not.toHaveBeenCalled();
118
+ expect(result).toBe(false);
119
+ });
120
+ it('should return false if provided address is invalid', () => {
121
+ // Setup mocks
122
+ mockGet.mockReturnValue(currentAccount);
123
+ // This is crucial: we need to ensure short-circuit evaluation works correctly
124
+ mockIsAddress.mockImplementation((address) => {
125
+ return address !== invalidAddress; // Only the invalid address returns false
126
+ });
127
+ // This should never be called due to short-circuit evaluation
128
+ mockIsAddressEqual.mockReturnValue(false);
129
+ const { matchesAccount } = useAccount();
130
+ const result = matchesAccount(invalidAddress);
131
+ expect(mockGet).toHaveBeenCalledWith(mockAccountStore);
132
+ expect(mockIsAddress).toHaveBeenCalledWith(currentAccount);
133
+ expect(mockIsAddress).toHaveBeenCalledWith(invalidAddress);
134
+ expect(mockIsAddressEqual).not.toHaveBeenCalled(); // This should now pass
135
+ expect(result).toBe(false);
136
+ });
137
+ it('should return false if provided address is null', () => {
138
+ // Setup mocks
139
+ mockGet.mockReturnValue(currentAccount);
140
+ const { matchesAccount } = useAccount();
141
+ const result = matchesAccount(null);
142
+ expect(mockIsAddress).not.toHaveBeenCalled();
143
+ expect(mockIsAddressEqual).not.toHaveBeenCalled();
144
+ expect(result).toBe(false);
145
+ });
146
+ });
147
+ });
148
+ }
@@ -1,3 +1,3 @@
1
1
  import { QueryClient } from '@tanstack/svelte-query';
2
2
  export declare const queryClient: QueryClient;
3
- export declare const invalidateIdQuery: (queryClient: QueryClient, id: string) => Promise<void>;
3
+ export declare const invalidateTanstackQueries: (queryClient: QueryClient, queryKey: string[]) => void;
@@ -7,9 +7,9 @@ export const queryClient = new QueryClient({
7
7
  }
8
8
  }
9
9
  });
10
- export const invalidateIdQuery = async (queryClient, id) => {
11
- await queryClient.invalidateQueries({
12
- queryKey: [id],
10
+ export const invalidateTanstackQueries = (queryClient, queryKey) => {
11
+ queryClient.invalidateQueries({
12
+ queryKey,
13
13
  refetchType: 'all',
14
14
  exact: false
15
15
  });
@@ -0,0 +1,163 @@
1
+ /**
2
+ * @module awaitTransactionIndexing
3
+ * @description Utilities for waiting for transactions to be indexed by a subgraph
4
+ */
5
+ import type { SgAddOrderWithOrder, SgRemoveOrderWithOrder, SgTransaction } from '@rainlanguage/orderbook';
6
+ /**
7
+ * Error message when subgraph indexing times out
8
+ */
9
+ export declare const TIMEOUT_ERROR = "The subgraph took too long to respond. Your transaction may still be processing.";
10
+ /**
11
+ * Result of a subgraph indexing operation
12
+ * @template T The type of data returned by the subgraph
13
+ */
14
+ export type IndexingResult<T> = {
15
+ /**
16
+ * The successful result of the indexing operation
17
+ */
18
+ value?: {
19
+ /**
20
+ * The transaction hash
21
+ */
22
+ txHash: string;
23
+ /**
24
+ * Message to display on successful indexing
25
+ */
26
+ successMessage: string;
27
+ /**
28
+ * Optional order hash if available
29
+ */
30
+ orderHash?: string;
31
+ /**
32
+ * Optional network key
33
+ */
34
+ network?: string;
35
+ /**
36
+ * Optional data returned from the subgraph
37
+ */
38
+ data?: T;
39
+ };
40
+ /**
41
+ * Error message if indexing failed
42
+ */
43
+ error?: string;
44
+ };
45
+ /**
46
+ * Generic function to handle waiting for subgraph indexing
47
+ * Returns a promise that resolves with an object containing either value or error
48
+ *
49
+ * @template T The type of data returned by the subgraph
50
+ * @param options Configuration options for the indexing operation
51
+ * @returns Promise resolving to an IndexingResult
52
+ */
53
+ export declare const awaitSubgraphIndexing: <T>(options: {
54
+ /**
55
+ * URL of the subgraph to query
56
+ */
57
+ subgraphUrl: string;
58
+ /**
59
+ * Transaction hash to check for indexing
60
+ */
61
+ txHash: string;
62
+ /**
63
+ * Message to display on successful indexing
64
+ */
65
+ successMessage: string;
66
+ /**
67
+ * Maximum number of attempts before timing out
68
+ */
69
+ maxAttempts?: number;
70
+ /**
71
+ * Interval between attempts in milliseconds
72
+ */
73
+ interval?: number;
74
+ /**
75
+ * Optional network identifier
76
+ */
77
+ network?: string;
78
+ /**
79
+ * Function to fetch data from the subgraph
80
+ * @param subgraphUrl URL of the subgraph
81
+ * @param txHash Transaction hash to query
82
+ */
83
+ fetchData: (subgraphUrl: string, txHash: string) => Promise<T | null | undefined>;
84
+ /**
85
+ * Function to determine if the fetched data indicates success
86
+ * @param data The data returned from the subgraph
87
+ */
88
+ isSuccess: (data: T) => boolean;
89
+ }) => Promise<IndexingResult<T>>;
90
+ /**
91
+ * Configuration for transaction indexing
92
+ * @template T The type of data returned by the subgraph
93
+ */
94
+ export interface TransactionConfig<T> {
95
+ /**
96
+ * URL of the subgraph to query
97
+ */
98
+ subgraphUrl: string;
99
+ /**
100
+ * Transaction hash to check for indexing
101
+ */
102
+ txHash: string;
103
+ /**
104
+ * Message to display on successful indexing
105
+ */
106
+ successMessage: string;
107
+ /**
108
+ * Optional network key
109
+ */
110
+ network?: string;
111
+ /**
112
+ * Maximum number of attempts before timing out
113
+ */
114
+ maxAttempts?: number;
115
+ /**
116
+ * Interval between attempts in milliseconds
117
+ */
118
+ interval?: number;
119
+ /**
120
+ * Function to fetch data from the subgraph
121
+ */
122
+ fetchData: (subgraphUrl: string, txHash: string) => Promise<T>;
123
+ /**
124
+ * Function to determine if the fetched data indicates success
125
+ */
126
+ isSuccess: (data: T) => boolean;
127
+ }
128
+ /**
129
+ * Creates a configuration for checking general transaction indexing
130
+ *
131
+ * @param subgraphUrl URL of the subgraph to query
132
+ * @param txHash Transaction hash to check for indexing
133
+ * @param successMessage Message to display on successful indexing
134
+ * @param network Optional network key
135
+ * @param maxAttempts Maximum number of attempts before timing out
136
+ * @param interval Interval between attempts in milliseconds
137
+ * @returns Configuration for transaction indexing
138
+ */
139
+ export declare const getTransactionConfig: (subgraphUrl: string, txHash: string, successMessage: string, network?: string, maxAttempts?: number, interval?: number) => TransactionConfig<SgTransaction>;
140
+ /**
141
+ * Creates a configuration for checking new order indexing
142
+ *
143
+ * @param subgraphUrl URL of the subgraph to query
144
+ * @param txHash Transaction hash to check for indexing
145
+ * @param successMessage Message to display on successful indexing
146
+ * @param network Optional network key
147
+ * @param maxAttempts Maximum number of attempts before timing out
148
+ * @param interval Interval between attempts in milliseconds
149
+ * @returns Configuration for new order indexing
150
+ */
151
+ export declare const getNewOrderConfig: (subgraphUrl: string, txHash: string, successMessage: string, network?: string, maxAttempts?: number, interval?: number) => TransactionConfig<SgAddOrderWithOrder[]>;
152
+ /**
153
+ * Creates a configuration for checking order removal indexing
154
+ *
155
+ * @param subgraphUrl URL of the subgraph to query
156
+ * @param txHash Transaction hash to check for indexing
157
+ * @param successMessage Message to display on successful indexing
158
+ * @param network Optional network key
159
+ * @param maxAttempts Maximum number of attempts before timing out
160
+ * @param interval Interval between attempts in milliseconds
161
+ * @returns Configuration for order removal indexing
162
+ */
163
+ export declare const getRemoveOrderConfig: (subgraphUrl: string, txHash: string, successMessage: string, network?: string, maxAttempts?: number, interval?: number) => TransactionConfig<SgRemoveOrderWithOrder[]>;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @module awaitTransactionIndexing
3
+ * @description Utilities for waiting for transactions to be indexed by a subgraph
4
+ */
5
+ import { getTransaction, getTransactionAddOrders, getTransactionRemoveOrders } from '@rainlanguage/orderbook';
6
+ /**
7
+ * Error message when subgraph indexing times out
8
+ */
9
+ export const TIMEOUT_ERROR = 'The subgraph took too long to respond. Your transaction may still be processing.';
10
+ /**
11
+ * Generic function to handle waiting for subgraph indexing
12
+ * Returns a promise that resolves with an object containing either value or error
13
+ *
14
+ * @template T The type of data returned by the subgraph
15
+ * @param options Configuration options for the indexing operation
16
+ * @returns Promise resolving to an IndexingResult
17
+ */
18
+ export const awaitSubgraphIndexing = async (options) => {
19
+ const { subgraphUrl, txHash, successMessage, maxAttempts = 10, interval = 1000, network, fetchData, isSuccess } = options;
20
+ return new Promise((resolve) => {
21
+ let attempts = 0;
22
+ const checkInterval = setInterval(async () => {
23
+ attempts++;
24
+ try {
25
+ const data = await fetchData(subgraphUrl, txHash);
26
+ if (data && isSuccess(data)) {
27
+ clearInterval(checkInterval);
28
+ let orderHash;
29
+ // Extract orderHash from order data if it exists in the expected format
30
+ if (Array.isArray(data) && data.length > 0 && data[0]?.order?.orderHash) {
31
+ orderHash = data[0].order.orderHash;
32
+ }
33
+ resolve({
34
+ value: {
35
+ txHash,
36
+ successMessage,
37
+ orderHash,
38
+ network,
39
+ data
40
+ }
41
+ });
42
+ return;
43
+ }
44
+ }
45
+ catch {
46
+ // Continue with the next attempt
47
+ }
48
+ if (attempts >= maxAttempts) {
49
+ clearInterval(checkInterval);
50
+ resolve({
51
+ error: TIMEOUT_ERROR
52
+ });
53
+ return;
54
+ }
55
+ }, interval);
56
+ });
57
+ };
58
+ /**
59
+ * Creates a configuration for checking general transaction indexing
60
+ *
61
+ * @param subgraphUrl URL of the subgraph to query
62
+ * @param txHash Transaction hash to check for indexing
63
+ * @param successMessage Message to display on successful indexing
64
+ * @param network Optional network key
65
+ * @param maxAttempts Maximum number of attempts before timing out
66
+ * @param interval Interval between attempts in milliseconds
67
+ * @returns Configuration for transaction indexing
68
+ */
69
+ export const getTransactionConfig = (subgraphUrl, txHash, successMessage, network, maxAttempts, interval) => ({
70
+ subgraphUrl,
71
+ txHash,
72
+ successMessage,
73
+ network,
74
+ maxAttempts,
75
+ interval,
76
+ fetchData: getTransaction,
77
+ isSuccess: (tx) => !!tx
78
+ });
79
+ /**
80
+ * Creates a configuration for checking new order indexing
81
+ *
82
+ * @param subgraphUrl URL of the subgraph to query
83
+ * @param txHash Transaction hash to check for indexing
84
+ * @param successMessage Message to display on successful indexing
85
+ * @param network Optional network key
86
+ * @param maxAttempts Maximum number of attempts before timing out
87
+ * @param interval Interval between attempts in milliseconds
88
+ * @returns Configuration for new order indexing
89
+ */
90
+ export const getNewOrderConfig = (subgraphUrl, txHash, successMessage, network, maxAttempts, interval) => ({
91
+ subgraphUrl,
92
+ txHash,
93
+ successMessage,
94
+ network,
95
+ maxAttempts,
96
+ interval,
97
+ fetchData: getTransactionAddOrders,
98
+ isSuccess: (addOrders) => addOrders?.length > 0
99
+ });
100
+ /**
101
+ * Creates a configuration for checking order removal indexing
102
+ *
103
+ * @param subgraphUrl URL of the subgraph to query
104
+ * @param txHash Transaction hash to check for indexing
105
+ * @param successMessage Message to display on successful indexing
106
+ * @param network Optional network key
107
+ * @param maxAttempts Maximum number of attempts before timing out
108
+ * @param interval Interval between attempts in milliseconds
109
+ * @returns Configuration for order removal indexing
110
+ */
111
+ export const getRemoveOrderConfig = (subgraphUrl, txHash, successMessage, network, maxAttempts, interval) => ({
112
+ subgraphUrl,
113
+ txHash,
114
+ successMessage,
115
+ network,
116
+ maxAttempts,
117
+ interval,
118
+ fetchData: getTransactionRemoveOrders,
119
+ isSuccess: (removeOrders) => removeOrders?.length > 0
120
+ });
@@ -1,2 +1,2 @@
1
- import type { DotrainOrderGui } from '@rainlanguage/orderbook/js_api';
2
- export declare function handleShareChoices(gui: DotrainOrderGui): Promise<void>;
1
+ import type { DotrainOrderGui } from '@rainlanguage/orderbook';
2
+ export declare function handleShareChoices(gui: DotrainOrderGui, registryUrl: string): Promise<void>;
@@ -1,10 +1,15 @@
1
1
  import { page } from '$app/stores';
2
2
  import { get } from 'svelte/store';
3
- export async function handleShareChoices(gui) {
3
+ export async function handleShareChoices(gui, registryUrl) {
4
4
  // get the current url
5
5
  const url = get(page).url;
6
6
  // get the current state
7
- const state = gui?.serializeState();
7
+ const result = gui.serializeState();
8
+ if (result.error) {
9
+ throw new Error(result.error.msg);
10
+ }
11
+ const state = result.value;
8
12
  url.searchParams.set('state', state || '');
13
+ url.searchParams.set('registry', registryUrl);
9
14
  navigator.clipboard.writeText(url.toString());
10
15
  }
@@ -1,4 +1,4 @@
1
- import type { SgTrade } from '@rainlanguage/orderbook/js_api';
1
+ import type { SgTrade } from '@rainlanguage/orderbook';
2
2
  import type { UTCTimestamp } from 'lightweight-charts';
3
3
  export type HistoricalOrderChartData = {
4
4
  value: number;
@@ -1,2 +1,2 @@
1
- export { fetchParseRegistry, fetchRegistryDotrains } from './registry';
1
+ export { fetchParseRegistry, fetchRegistryDotrains, validateStrategies } from './registry';
2
2
  export type { RegistryDotrain, RegistryFile } from './registry';
@@ -1 +1 @@
1
- export { fetchParseRegistry, fetchRegistryDotrains } from './registry';
1
+ export { fetchParseRegistry, fetchRegistryDotrains, validateStrategies } from './registry';
@@ -1,3 +1,4 @@
1
+ import type { InvalidStrategyDetail, ValidStrategyDetail } from '../types/strategy';
1
2
  export type RegistryFile = {
2
3
  name: string;
3
4
  url: string;
@@ -6,6 +7,10 @@ export type RegistryDotrain = {
6
7
  name: string;
7
8
  dotrain: string;
8
9
  };
10
+ export interface StrategyValidationResult {
11
+ validStrategies: ValidStrategyDetail[];
12
+ invalidStrategies: InvalidStrategyDetail[];
13
+ }
9
14
  /**
10
15
  * Fetches and parses a file registry from a given URL.
11
16
  * The registry is expected to be a text file where each line contains a file name and URL separated by a space.
@@ -23,3 +28,4 @@ export declare const fetchParseRegistry: (url: string) => Promise<{
23
28
  url: string;
24
29
  }[]>;
25
30
  export declare const fetchRegistryDotrains: (url: string) => Promise<RegistryDotrain[]>;
31
+ export declare function validateStrategies(registryDotrains: RegistryDotrain[]): Promise<StrategyValidationResult>;