@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.
Files changed (188) hide show
  1. package/dist/__fixtures__/orderDetail.d.ts +1 -1
  2. package/dist/__fixtures__/settings.yaml +183 -0
  3. package/dist/__mocks__/MockComponent.svelte +4 -0
  4. package/dist/__mocks__/MockComponent.svelte.d.ts +3 -1
  5. package/dist/__mocks__/settings.d.ts +7 -3
  6. package/dist/__mocks__/settings.js +68 -33
  7. package/dist/__mocks__/stores.d.ts +94 -27
  8. package/dist/__mocks__/stores.js +45 -22
  9. package/dist/components/ButtonLoading.svelte +1 -1
  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 +2 -3
  14. package/dist/components/CheckboxZeroBalanceVault.svelte.d.ts +2 -2
  15. package/dist/components/CodeMirrorDotrain.svelte +4 -0
  16. package/dist/components/CodeMirrorDotrain.svelte.d.ts +1 -0
  17. package/dist/components/CodeMirrorRainlang.svelte +11 -3
  18. package/dist/components/CodeMirrorRainlang.svelte.d.ts +1 -1
  19. package/dist/components/EditableSpan.svelte +3 -14
  20. package/dist/components/EditableSpan.svelte.d.ts +0 -1
  21. package/dist/components/Hash.svelte +3 -3
  22. package/dist/components/License.svelte +5 -4
  23. package/dist/components/ListViewOrderbookFilters.svelte +16 -15
  24. package/dist/components/ListViewOrderbookFilters.svelte.d.ts +9 -13
  25. package/dist/components/OrderOrVaultHash.svelte +10 -7
  26. package/dist/components/OrderOrVaultHash.svelte.d.ts +1 -1
  27. package/dist/components/PageHeader.svelte +1 -1
  28. package/dist/components/TanstackAppTable.svelte +2 -3
  29. package/dist/components/TanstackAppTable.svelte.d.ts +1 -1
  30. package/dist/components/ToastDetail.svelte +42 -0
  31. package/dist/components/ToastDetail.svelte.d.ts +20 -0
  32. package/dist/components/Tooltip.svelte +8 -0
  33. package/dist/components/Tooltip.svelte.d.ts +21 -0
  34. package/dist/components/charts/OrderTradesChart.svelte +3 -2
  35. package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
  36. package/dist/components/charts/VaultBalanceChart.svelte +6 -6
  37. package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -1
  38. package/dist/components/charts/transformAndSortData.d.ts +24 -0
  39. package/dist/components/charts/transformAndSortData.js +111 -0
  40. package/dist/components/checkbox/CheckboxActiveOrders.svelte +11 -0
  41. package/dist/components/checkbox/CheckboxActiveOrders.svelte.d.ts +19 -0
  42. package/dist/components/deployment/ButtonSelectOption.svelte +2 -0
  43. package/dist/components/deployment/ButtonSelectOption.svelte.d.ts +1 -0
  44. package/dist/components/deployment/ComposedRainlangModal.svelte +7 -5
  45. package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
  46. package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
  47. package/dist/components/deployment/DeploymentSteps.svelte +169 -185
  48. package/dist/components/deployment/DeploymentSteps.svelte.d.ts +7 -13
  49. package/dist/components/deployment/DeploymentsSection.svelte +18 -14
  50. package/dist/components/deployment/DepositInput.svelte +32 -14
  51. package/dist/components/deployment/DepositInput.svelte.d.ts +1 -2
  52. package/dist/components/deployment/DisclaimerModal.svelte +1 -0
  53. package/dist/components/deployment/FieldDefinitionInput.svelte +22 -14
  54. package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +1 -2
  55. package/dist/components/deployment/SelectToken.svelte +16 -4
  56. package/dist/components/deployment/SelectToken.svelte.d.ts +1 -2
  57. package/dist/components/deployment/StrategyPage.svelte +6 -2
  58. package/dist/components/deployment/TokenIOInput.svelte +16 -5
  59. package/dist/components/deployment/TokenIOInput.svelte.d.ts +1 -2
  60. package/dist/components/detail/OrderDetail.svelte +60 -44
  61. package/dist/components/detail/OrderDetail.svelte.d.ts +11 -8
  62. package/dist/components/detail/TanstackOrderQuote.svelte +17 -7
  63. package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +1 -1
  64. package/dist/components/detail/VaultDetail.svelte +43 -43
  65. package/dist/components/detail/VaultDetail.svelte.d.ts +11 -11
  66. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte +2 -2
  67. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +4 -4
  68. package/dist/components/dropdown/DropdownOrderListAccounts.svelte +2 -1
  69. package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +3 -3
  70. package/dist/components/icon/Refresh.svelte +2 -1
  71. package/dist/components/icon/Refresh.svelte.d.ts +1 -0
  72. package/dist/components/input/InputOrderHash.svelte +1 -1
  73. package/dist/components/input/InputOrderHash.svelte.d.ts +2 -2
  74. package/dist/components/input/InputRegistryUrl.svelte +36 -14
  75. package/dist/components/input/InputToken.svelte +2 -2
  76. package/dist/components/input/InputTokenAmount.svelte +1 -1
  77. package/dist/components/tables/OrderAPY.svelte +4 -9
  78. package/dist/components/tables/OrderTradesListTable.svelte +7 -3
  79. package/dist/components/tables/OrderVaultsVolTable.svelte +11 -2
  80. package/dist/components/tables/OrdersListTable.svelte +27 -31
  81. package/dist/components/tables/OrdersListTable.svelte.d.ts +2 -8
  82. package/dist/components/tables/VaultBalanceChangesTable.svelte +8 -6
  83. package/dist/components/tables/VaultsListTable.svelte +53 -67
  84. package/dist/components/tables/VaultsListTable.svelte.d.ts +12 -20
  85. package/dist/components/transactions/FixedBottomTransaction.svelte +63 -0
  86. package/dist/components/transactions/FixedBottomTransaction.svelte.d.ts +16 -0
  87. package/dist/components/transactions/TransactionDetail.svelte +31 -0
  88. package/dist/components/transactions/TransactionDetail.svelte.d.ts +20 -0
  89. package/dist/components/transactions/TransactionList.svelte +17 -0
  90. package/dist/components/transactions/TransactionList.svelte.d.ts +16 -0
  91. package/dist/components/transactions/getStatusEmoji.d.ts +2 -0
  92. package/dist/components/transactions/getStatusEmoji.js +20 -0
  93. package/dist/components/wallet/WalletConnect.svelte +5 -4
  94. package/dist/components/wallet/WalletConnect.svelte.d.ts +0 -1
  95. package/dist/consts.d.ts +1 -0
  96. package/dist/consts.js +1 -0
  97. package/dist/errors/DeploymentStepsError.d.ts +6 -2
  98. package/dist/errors/DeploymentStepsError.js +5 -1
  99. package/dist/hooks/useGui.d.ts +3 -0
  100. package/dist/hooks/useGui.js +11 -0
  101. package/dist/index.d.ts +27 -11
  102. package/dist/index.js +28 -8
  103. package/dist/models/Transaction.d.ts +80 -0
  104. package/dist/models/Transaction.js +134 -0
  105. package/dist/providers/GuiProvider.svelte +8 -0
  106. package/dist/providers/GuiProvider.svelte.d.ts +21 -0
  107. package/dist/providers/registry/RegistryManager.d.ts +65 -0
  108. package/dist/providers/registry/RegistryManager.js +133 -0
  109. package/dist/providers/registry/RegistryProvider.svelte +6 -0
  110. package/dist/providers/registry/RegistryProvider.svelte.d.ts +21 -0
  111. package/dist/providers/registry/context.d.ts +10 -0
  112. package/dist/providers/registry/context.js +46 -0
  113. package/dist/providers/registry/useRegistry.d.ts +7 -0
  114. package/dist/providers/registry/useRegistry.js +29 -0
  115. package/dist/providers/toasts/ToastProvider.svelte +17 -0
  116. package/dist/providers/toasts/ToastProvider.svelte.d.ts +18 -0
  117. package/dist/providers/toasts/context.d.ts +14 -0
  118. package/dist/providers/toasts/context.js +22 -0
  119. package/dist/providers/toasts/useToasts.d.ts +16 -0
  120. package/dist/providers/toasts/useToasts.js +63 -0
  121. package/dist/providers/transactions/TransactionManager.d.ts +183 -0
  122. package/dist/providers/transactions/TransactionManager.js +353 -0
  123. package/dist/providers/transactions/TransactionProvider.svelte +11 -0
  124. package/dist/providers/transactions/TransactionProvider.svelte.d.ts +24 -0
  125. package/dist/providers/transactions/context.d.ts +19 -0
  126. package/dist/providers/transactions/context.js +28 -0
  127. package/dist/providers/transactions/useTransactions.d.ts +13 -0
  128. package/dist/providers/transactions/useTransactions.js +18 -0
  129. package/dist/providers/wallet/WalletProvider.svelte +7 -0
  130. package/dist/providers/wallet/WalletProvider.svelte.d.ts +21 -0
  131. package/dist/providers/wallet/context.d.ts +10 -0
  132. package/dist/providers/wallet/context.js +47 -0
  133. package/dist/providers/wallet/useAccount.d.ts +8 -0
  134. package/dist/providers/wallet/useAccount.js +148 -0
  135. package/dist/queries/queryClient.d.ts +1 -1
  136. package/dist/queries/queryClient.js +11 -6
  137. package/dist/services/awaitTransactionIndexing.d.ts +100 -0
  138. package/dist/services/awaitTransactionIndexing.js +57 -0
  139. package/dist/services/handleShareChoices.d.ts +2 -2
  140. package/dist/services/handleShareChoices.js +7 -2
  141. package/dist/services/historicalOrderCharts.d.ts +1 -1
  142. package/dist/services/historicalOrderCharts.js +1 -1
  143. package/dist/services/index.d.ts +2 -1
  144. package/dist/services/index.js +2 -1
  145. package/dist/services/loadRegistryUrl.d.ts +2 -0
  146. package/dist/services/loadRegistryUrl.js +19 -0
  147. package/dist/services/registry.d.ts +6 -0
  148. package/dist/services/registry.js +33 -77
  149. package/dist/services/time.d.ts +12 -0
  150. package/dist/services/time.js +88 -6
  151. package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
  152. package/dist/storesGeneric/cachedWritableStore.js +93 -0
  153. package/dist/types/account.d.ts +3 -0
  154. package/dist/types/account.js +1 -0
  155. package/dist/types/appStores.d.ts +10 -9
  156. package/dist/types/modal.d.ts +24 -12
  157. package/dist/types/strategy.d.ts +1 -1
  158. package/dist/types/toast.d.ts +11 -0
  159. package/dist/types/toast.js +1 -0
  160. package/dist/types/transaction.d.ts +54 -15
  161. package/dist/types/transaction.js +29 -1
  162. package/dist/utils/configHelpers.d.ts +8 -0
  163. package/dist/utils/configHelpers.js +38 -0
  164. package/dist/utils/constructHashLink.d.ts +23 -0
  165. package/dist/utils/constructHashLink.js +110 -0
  166. package/dist/utils/vault.d.ts +1 -1
  167. package/package.json +34 -34
  168. package/dist/__fixtures__/settings-12-11-24.json +0 -160
  169. package/dist/__mocks__/mockTransactionStore.d.ts +0 -22
  170. package/dist/__mocks__/mockTransactionStore.js +0 -56
  171. package/dist/components/deployment/DepositsSection.svelte +0 -8
  172. package/dist/components/deployment/DepositsSection.svelte.d.ts +0 -20
  173. package/dist/components/deployment/FieldDefinitionsSection.svelte +0 -9
  174. package/dist/components/deployment/FieldDefinitionsSection.svelte.d.ts +0 -20
  175. package/dist/components/deployment/SelectTokensSection.svelte +0 -17
  176. package/dist/components/deployment/SelectTokensSection.svelte.d.ts +0 -21
  177. package/dist/components/deployment/TokenIOSection.svelte +0 -17
  178. package/dist/components/deployment/TokenIOSection.svelte.d.ts +0 -21
  179. package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
  180. package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -24
  181. package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
  182. package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
  183. package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
  184. package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
  185. package/dist/stores/transactionStore.d.ts +0 -98
  186. package/dist/stores/transactionStore.js +0 -303
  187. package/dist/utils/time.d.ts +0 -12
  188. package/dist/utils/time.js +0 -27
@@ -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[]) => Promise<void>;
@@ -7,10 +7,15 @@ 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],
13
- refetchType: 'all',
14
- exact: false
15
- });
10
+ export const invalidateTanstackQueries = async (queryClient, queryKey) => {
11
+ try {
12
+ await queryClient.invalidateQueries({
13
+ queryKey,
14
+ refetchType: 'all',
15
+ exact: false
16
+ });
17
+ }
18
+ catch {
19
+ throw new Error('Failed to refresh data.');
20
+ }
16
21
  };
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @module awaitTransactionIndexing
3
+ * @description Utilities for waiting for transactions to be indexed by a subgraph
4
+ */
5
+ import type { getTransactionRemoveOrders, getTransaction, getTransactionAddOrders, WasmEncodedResult, SgTransaction, SgRemoveOrderWithOrder } from '@rainlanguage/orderbook';
6
+ export type AwaitSubgraphConfig = {
7
+ subgraphUrl: string;
8
+ txHash: string;
9
+ successMessage: string;
10
+ fetchEntityFn: typeof getTransaction | typeof getTransactionRemoveOrders | typeof getTransactionAddOrders;
11
+ isSuccess: (data: SgTransaction | SgRemoveOrderWithOrder[]) => boolean;
12
+ };
13
+ /**
14
+ * Result of a subgraph indexing operation
15
+ * @template T The type of data returned by the subgraph
16
+ */
17
+ export type IndexingResult<T> = {
18
+ /**
19
+ * The successful result of the indexing operation
20
+ */
21
+ value?: {
22
+ /**
23
+ * The transaction hash
24
+ */
25
+ txHash: string;
26
+ /**
27
+ * Message to display on successful indexing
28
+ */
29
+ successMessage: string;
30
+ /**
31
+ * Optional order hash if available
32
+ */
33
+ orderHash?: string;
34
+ /**
35
+ * Optional network key
36
+ */
37
+ network?: string;
38
+ /**
39
+ * Optional data returned from the subgraph
40
+ */
41
+ data?: T;
42
+ };
43
+ /**
44
+ * Error message if indexing failed
45
+ */
46
+ error?: string;
47
+ };
48
+ /**
49
+ * Generic function to handle waiting for subgraph indexing
50
+ * Returns a promise that resolves with an object containing either value or error
51
+ *
52
+ * @template T The type of data returned by the subgraph
53
+ * @param options Configuration options for the indexing operation
54
+ * @param options.subgraphUrl URL of the subgraph to query
55
+ * @param options.txHash Transaction hash to check for indexing
56
+ * @param options.successMessage Message to display on successful indexing
57
+ * @param options.maxAttempts Maximum number of attempts before timing out (default: 10)
58
+ * @param options.interval Interval between attempts in milliseconds (default: 1000)
59
+ * @param options.network Optional network identifier
60
+ * @param options.fetchEntityFn Function to fetch data from the subgraph
61
+ * @param options.isSuccess Function to determine if the fetched data indicates success
62
+ * @returns Promise resolving to an IndexingResult
63
+ */
64
+ export declare const awaitSubgraphIndexing: <T>(options: {
65
+ /**
66
+ * URL of the subgraph to query
67
+ */
68
+ subgraphUrl: string;
69
+ /**
70
+ * Transaction hash to check for indexing
71
+ */
72
+ txHash: string;
73
+ /**
74
+ * Message to display on successful indexing
75
+ */
76
+ successMessage: string;
77
+ /**
78
+ * Maximum number of attempts before timing out
79
+ */
80
+ maxAttempts?: number;
81
+ /**
82
+ * Interval between attempts in milliseconds
83
+ */
84
+ interval?: number;
85
+ /**
86
+ * Optional network identifier
87
+ */
88
+ network?: string;
89
+ /**
90
+ * Function to fetch data from the subgraph
91
+ * @param subgraphUrl URL of the subgraph
92
+ * @param txHash Transaction hash to query
93
+ */
94
+ fetchEntityFn: (subgraphUrl: string, txHash: string) => Promise<WasmEncodedResult<T | null | undefined>>;
95
+ /**
96
+ * Function to determine if the fetched data indicates success
97
+ * @param data The data returned from the subgraph
98
+ */
99
+ isSuccess: (data: T) => boolean;
100
+ }) => Promise<IndexingResult<T>>;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @module awaitTransactionIndexing
3
+ * @description Utilities for waiting for transactions to be indexed by a subgraph
4
+ */
5
+ import { TransactionStoreErrorMessage } from '../types/transaction';
6
+ /**
7
+ * Generic function to handle waiting for subgraph indexing
8
+ * Returns a promise that resolves with an object containing either value or error
9
+ *
10
+ * @template T The type of data returned by the subgraph
11
+ * @param options Configuration options for the indexing operation
12
+ * @param options.subgraphUrl URL of the subgraph to query
13
+ * @param options.txHash Transaction hash to check for indexing
14
+ * @param options.successMessage Message to display on successful indexing
15
+ * @param options.maxAttempts Maximum number of attempts before timing out (default: 10)
16
+ * @param options.interval Interval between attempts in milliseconds (default: 1000)
17
+ * @param options.network Optional network identifier
18
+ * @param options.fetchEntityFn Function to fetch data from the subgraph
19
+ * @param options.isSuccess Function to determine if the fetched data indicates success
20
+ * @returns Promise resolving to an IndexingResult
21
+ */
22
+ export const awaitSubgraphIndexing = async (options) => {
23
+ const { subgraphUrl, txHash, successMessage, maxAttempts = 10, interval = 1000, network, fetchEntityFn, isSuccess } = options;
24
+ const checkIndexing = async (attempt) => {
25
+ try {
26
+ const data = await fetchEntityFn(subgraphUrl, txHash);
27
+ if (data.value && isSuccess(data.value)) {
28
+ let newOrderHash;
29
+ // Extract orderHash from order data if it exists in the expected format
30
+ // This only applies to addOrder transactions
31
+ if (Array.isArray(data.value) && data.value.length > 0 && data.value[0]?.order?.orderHash) {
32
+ newOrderHash = data.value[0].order.orderHash;
33
+ }
34
+ return {
35
+ value: {
36
+ txHash,
37
+ successMessage,
38
+ orderHash: newOrderHash,
39
+ network,
40
+ data: data.value
41
+ }
42
+ };
43
+ }
44
+ }
45
+ catch {
46
+ // Continue with the next attempt
47
+ }
48
+ if (attempt >= maxAttempts) {
49
+ return {
50
+ error: TransactionStoreErrorMessage.SUBGRAPH_TIMEOUT_ERROR
51
+ };
52
+ }
53
+ await new Promise((resolve) => setTimeout(resolve, interval));
54
+ return checkIndexing(attempt + 1);
55
+ };
56
+ return checkIndexing(1);
57
+ };
@@ -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,4 +1,4 @@
1
- import { timestampSecondsToUTCTimestamp } from '../utils/time';
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) {
@@ -1,2 +1,3 @@
1
- export { fetchParseRegistry, fetchRegistryDotrains } from './registry';
1
+ export { fetchParseRegistry, fetchRegistryDotrains, validateStrategies } from './registry';
2
+ export { loadRegistryUrl } from './loadRegistryUrl';
2
3
  export type { RegistryDotrain, RegistryFile } from './registry';
@@ -1 +1,2 @@
1
- export { fetchParseRegistry, fetchRegistryDotrains } from './registry';
1
+ export { fetchParseRegistry, fetchRegistryDotrains, validateStrategies } from './registry';
2
+ export { loadRegistryUrl } from './loadRegistryUrl';
@@ -0,0 +1,2 @@
1
+ import { RegistryManager } from '../providers/registry/RegistryManager';
2
+ export declare function loadRegistryUrl(url: string, registryManager: RegistryManager): Promise<void>;
@@ -0,0 +1,19 @@
1
+ import { RegistryManager } from '../providers/registry/RegistryManager';
2
+ import { fetchRegistryDotrains } from './registry';
3
+ export async function loadRegistryUrl(url, registryManager) {
4
+ if (!url) {
5
+ throw new Error('No URL provided');
6
+ }
7
+ if (!registryManager) {
8
+ throw new Error('Registry manager is required');
9
+ }
10
+ try {
11
+ await fetchRegistryDotrains(url);
12
+ registryManager.setRegistry(url);
13
+ window.location.reload();
14
+ }
15
+ catch (e) {
16
+ const errorMessage = e instanceof Error ? e.message : 'Failed to update registry URL';
17
+ throw new Error(errorMessage);
18
+ }
19
+ }
@@ -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>;
@@ -1,3 +1,4 @@
1
+ import { DotrainOrderGui } from '@rainlanguage/orderbook';
1
2
  /**
2
3
  * Fetches and parses a file registry from a given URL.
3
4
  * The registry is expected to be a text file where each line contains a file name and URL separated by a space.
@@ -52,82 +53,37 @@ export const fetchRegistryDotrains = async (url) => {
52
53
  }));
53
54
  return dotrains;
54
55
  };
55
- if (import.meta.vitest) {
56
- const { describe, it, expect, vi } = import.meta.vitest;
57
- describe('getFileRegistry', () => {
58
- it('should parse registry file content correctly', async () => {
59
- const mockResponse = `file1.js https://example.com/file1.js
60
- file2.js https://example.com/file2.js`;
61
- global.fetch = vi.fn().mockResolvedValue({
62
- ok: true,
63
- text: () => Promise.resolve(mockResponse)
64
- });
65
- const result = await fetchParseRegistry('https://example.com/registry');
66
- expect(result).toEqual([
67
- { name: 'file1.js', url: 'https://example.com/file1.js' },
68
- { name: 'file2.js', url: 'https://example.com/file2.js' }
69
- ]);
70
- });
71
- it('should handle failed fetch response', async () => {
72
- global.fetch = vi.fn().mockResolvedValue({
73
- ok: false
74
- });
75
- await expect(fetchParseRegistry('https://example.com/registry')).rejects.toThrow('Failed to fetch registry');
76
- });
77
- it('should handle network errors', async () => {
78
- global.fetch = vi.fn().mockRejectedValue(new Error('Network error'));
79
- await expect(fetchParseRegistry('https://example.com/registry')).rejects.toThrow('Network error');
80
- });
81
- });
82
- describe('fetchRegistryDotrains', () => {
83
- it('should fetch and parse dotrains correctly', async () => {
84
- const mockRegistry = `file1.rain https://example.com/file1.rain
85
- file2.rain https://example.com/file2.rain`;
86
- const mockDotrain1 = 'content of file1';
87
- const mockDotrain2 = 'content of file2';
88
- global.fetch = vi
89
- .fn()
90
- .mockResolvedValueOnce({
91
- ok: true,
92
- text: () => Promise.resolve(mockRegistry)
93
- })
94
- .mockResolvedValueOnce({
95
- ok: true,
96
- text: () => Promise.resolve(mockDotrain1)
97
- })
98
- .mockResolvedValueOnce({
99
- ok: true,
100
- text: () => Promise.resolve(mockDotrain2)
101
- });
102
- const result = await fetchRegistryDotrains('https://example.com/registry');
103
- expect(result).toEqual([
104
- { name: 'file1.rain', dotrain: mockDotrain1 },
105
- { name: 'file2.rain', dotrain: mockDotrain2 }
106
- ]);
107
- });
108
- it('should handle failed dotrain fetch', async () => {
109
- const mockRegistry = `file1.rain https://example.com/file1.rain`;
110
- global.fetch = vi
111
- .fn()
112
- .mockResolvedValueOnce({
113
- ok: true,
114
- text: () => Promise.resolve(mockRegistry)
115
- })
116
- .mockResolvedValueOnce({
117
- ok: false
118
- });
119
- await expect(fetchRegistryDotrains('https://example.com/registry')).rejects.toThrow('Failed to fetch dotrain for file1.rain');
120
- });
121
- it('should handle network errors during dotrain fetch', async () => {
122
- const mockRegistry = `file1.rain https://example.com/file1.rain`;
123
- global.fetch = vi
124
- .fn()
125
- .mockResolvedValueOnce({
126
- ok: true,
127
- text: () => Promise.resolve(mockRegistry)
128
- })
129
- .mockRejectedValueOnce(new Error('Network error'));
130
- await expect(fetchRegistryDotrains('https://example.com/registry')).rejects.toThrow('Error fetching dotrain for file1.rain: Network error');
131
- });
56
+ export async function validateStrategies(registryDotrains) {
57
+ const strategiesPromises = registryDotrains.map(async (registryDotrain) => {
58
+ try {
59
+ const result = await DotrainOrderGui.getStrategyDetails(registryDotrain.dotrain);
60
+ if (result.error) {
61
+ throw new Error(result.error.msg);
62
+ }
63
+ return {
64
+ valid: true,
65
+ data: {
66
+ ...registryDotrain,
67
+ details: result.value
68
+ }
69
+ };
70
+ }
71
+ catch (error) {
72
+ return {
73
+ valid: false,
74
+ data: {
75
+ name: registryDotrain.name,
76
+ error: error instanceof Error ? error.message : String(error)
77
+ }
78
+ };
79
+ }
132
80
  });
81
+ const strategiesResults = await Promise.all(strategiesPromises);
82
+ const validStrategies = strategiesResults
83
+ .filter((result) => result.valid)
84
+ .map((result) => result.data);
85
+ const invalidStrategies = strategiesResults
86
+ .filter((result) => !result.valid)
87
+ .map((result) => result.data);
88
+ return { validStrategies, invalidStrategies };
133
89
  }
@@ -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>;