@rainlanguage/ui-components 0.0.1-alpha.10 → 0.0.1-alpha.100

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 (163) 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 +87 -20
  9. package/dist/__mocks__/stores.js +30 -21
  10. package/dist/components/ButtonLoading.svelte +1 -1
  11. package/dist/components/ButtonVaultLink.svelte +3 -3
  12. package/dist/components/ButtonVaultLink.svelte.d.ts +1 -1
  13. package/dist/components/CheckboxMyItemsOnly.svelte +3 -2
  14. package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +2 -3
  15. package/dist/components/CheckboxZeroBalanceVault.svelte.d.ts +2 -2
  16. package/dist/components/CodeMirrorDotrain.svelte +4 -0
  17. package/dist/components/CodeMirrorDotrain.svelte.d.ts +1 -0
  18. package/dist/components/CodeMirrorRainlang.svelte +12 -4
  19. package/dist/components/CodeMirrorRainlang.svelte.d.ts +1 -1
  20. package/dist/components/EditableSpan.svelte +3 -14
  21. package/dist/components/EditableSpan.svelte.d.ts +0 -1
  22. package/dist/components/Hash.svelte +3 -3
  23. package/dist/components/License.svelte +5 -4
  24. package/dist/components/ListViewOrderbookFilters.svelte +15 -14
  25. package/dist/components/ListViewOrderbookFilters.svelte.d.ts +9 -13
  26. package/dist/components/OrderOrVaultHash.svelte +10 -7
  27. package/dist/components/OrderOrVaultHash.svelte.d.ts +1 -1
  28. package/dist/components/PageHeader.svelte +20 -22
  29. package/dist/components/PageHeader.svelte.d.ts +1 -0
  30. package/dist/components/TanstackAppTable.svelte +2 -3
  31. package/dist/components/TanstackAppTable.svelte.d.ts +1 -1
  32. package/dist/components/ToastDetail.svelte +16 -0
  33. package/dist/components/ToastDetail.svelte.d.ts +19 -0
  34. package/dist/components/Tooltip.svelte +8 -0
  35. package/dist/components/Tooltip.svelte.d.ts +21 -0
  36. package/dist/components/charts/OrderTradesChart.svelte +3 -2
  37. package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
  38. package/dist/components/charts/VaultBalanceChart.svelte +6 -6
  39. package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -1
  40. package/dist/components/charts/transformAndSortData.d.ts +24 -0
  41. package/dist/components/charts/transformAndSortData.js +111 -0
  42. package/dist/components/checkbox/CheckboxActiveOrders.svelte +11 -0
  43. package/dist/components/checkbox/CheckboxActiveOrders.svelte.d.ts +19 -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 +181 -155
  48. package/dist/components/deployment/DeploymentSteps.svelte.d.ts +6 -13
  49. package/dist/components/deployment/DeploymentsSection.svelte +18 -14
  50. package/dist/components/deployment/DepositInput.svelte +31 -14
  51. package/dist/components/deployment/DepositInput.svelte.d.ts +1 -2
  52. package/dist/components/deployment/FieldDefinitionInput.svelte +20 -14
  53. package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +1 -2
  54. package/dist/components/deployment/SelectToken.svelte +12 -3
  55. package/dist/components/deployment/SelectToken.svelte.d.ts +1 -2
  56. package/dist/components/deployment/StrategyPage.svelte +6 -2
  57. package/dist/components/deployment/TokenIOInput.svelte +15 -5
  58. package/dist/components/deployment/TokenIOInput.svelte.d.ts +1 -2
  59. package/dist/components/deployment/handleDeployment.d.ts +11 -0
  60. package/dist/components/deployment/handleDeployment.js +33 -0
  61. package/dist/components/detail/OrderDetail.svelte +51 -44
  62. package/dist/components/detail/OrderDetail.svelte.d.ts +11 -8
  63. package/dist/components/detail/TanstackOrderQuote.svelte +11 -7
  64. package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +1 -1
  65. package/dist/components/detail/VaultDetail.svelte +33 -42
  66. package/dist/components/detail/VaultDetail.svelte.d.ts +11 -11
  67. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +4 -4
  68. package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +3 -3
  69. package/dist/components/icon/Refresh.svelte +2 -1
  70. package/dist/components/icon/Refresh.svelte.d.ts +1 -0
  71. package/dist/components/input/InputOrderHash.svelte +1 -1
  72. package/dist/components/input/InputOrderHash.svelte.d.ts +2 -2
  73. package/dist/components/input/InputRegistryUrl.svelte +36 -14
  74. package/dist/components/input/InputToken.svelte +2 -2
  75. package/dist/components/input/InputTokenAmount.svelte +1 -1
  76. package/dist/components/tables/OrderAPY.svelte +4 -9
  77. package/dist/components/tables/OrderTradesListTable.svelte +7 -3
  78. package/dist/components/tables/OrderVaultsVolTable.svelte +11 -2
  79. package/dist/components/tables/OrdersListTable.svelte +24 -24
  80. package/dist/components/tables/OrdersListTable.svelte.d.ts +1 -7
  81. package/dist/components/tables/VaultBalanceChangesTable.svelte +8 -6
  82. package/dist/components/tables/VaultsListTable.svelte +48 -57
  83. package/dist/components/tables/VaultsListTable.svelte.d.ts +13 -20
  84. package/dist/components/wallet/WalletConnect.svelte +5 -4
  85. package/dist/components/wallet/WalletConnect.svelte.d.ts +0 -1
  86. package/dist/consts.d.ts +1 -0
  87. package/dist/consts.js +1 -0
  88. package/dist/errors/DeploymentStepsError.d.ts +5 -2
  89. package/dist/errors/DeploymentStepsError.js +4 -1
  90. package/dist/hooks/useGui.d.ts +3 -0
  91. package/dist/hooks/useGui.js +11 -0
  92. package/dist/index.d.ts +19 -7
  93. package/dist/index.js +21 -6
  94. package/dist/providers/GuiProvider.svelte +8 -0
  95. package/dist/providers/GuiProvider.svelte.d.ts +21 -0
  96. package/dist/providers/registry/RegistryManager.d.ts +65 -0
  97. package/dist/providers/registry/RegistryManager.js +133 -0
  98. package/dist/providers/registry/RegistryProvider.svelte +6 -0
  99. package/dist/providers/registry/RegistryProvider.svelte.d.ts +21 -0
  100. package/dist/providers/registry/context.d.ts +10 -0
  101. package/dist/providers/registry/context.js +46 -0
  102. package/dist/providers/registry/useRegistry.d.ts +7 -0
  103. package/dist/providers/registry/useRegistry.js +29 -0
  104. package/dist/providers/toasts/ToastProvider.svelte +17 -0
  105. package/dist/providers/toasts/ToastProvider.svelte.d.ts +22 -0
  106. package/dist/providers/toasts/context.d.ts +11 -0
  107. package/dist/providers/toasts/context.js +19 -0
  108. package/dist/providers/toasts/useToasts.d.ts +12 -0
  109. package/dist/providers/toasts/useToasts.js +54 -0
  110. package/dist/providers/wallet/WalletProvider.svelte +7 -0
  111. package/dist/providers/wallet/WalletProvider.svelte.d.ts +21 -0
  112. package/dist/providers/wallet/context.d.ts +10 -0
  113. package/dist/providers/wallet/context.js +47 -0
  114. package/dist/providers/wallet/useAccount.d.ts +8 -0
  115. package/dist/providers/wallet/useAccount.js +148 -0
  116. package/dist/queries/queryClient.d.ts +1 -1
  117. package/dist/queries/queryClient.js +11 -6
  118. package/dist/services/awaitTransactionIndexing.d.ts +163 -0
  119. package/dist/services/awaitTransactionIndexing.js +122 -0
  120. package/dist/services/handleShareChoices.d.ts +2 -2
  121. package/dist/services/handleShareChoices.js +7 -2
  122. package/dist/services/historicalOrderCharts.d.ts +1 -1
  123. package/dist/services/historicalOrderCharts.js +1 -1
  124. package/dist/services/index.d.ts +2 -1
  125. package/dist/services/index.js +2 -1
  126. package/dist/services/loadRegistryUrl.d.ts +2 -0
  127. package/dist/services/loadRegistryUrl.js +19 -0
  128. package/dist/services/registry.d.ts +6 -0
  129. package/dist/services/registry.js +33 -77
  130. package/dist/services/time.d.ts +12 -0
  131. package/dist/services/time.js +88 -6
  132. package/dist/stores/transactionStore.d.ts +9 -12
  133. package/dist/stores/transactionStore.js +38 -61
  134. package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
  135. package/dist/storesGeneric/cachedWritableStore.js +93 -0
  136. package/dist/types/account.d.ts +3 -0
  137. package/dist/types/account.js +1 -0
  138. package/dist/types/appStores.d.ts +5 -4
  139. package/dist/types/modal.d.ts +1 -1
  140. package/dist/types/strategy.d.ts +1 -1
  141. package/dist/types/toast.d.ts +6 -0
  142. package/dist/types/toast.js +1 -0
  143. package/dist/types/transaction.d.ts +3 -3
  144. package/dist/utils/constructHashLink.d.ts +23 -0
  145. package/dist/utils/constructHashLink.js +110 -0
  146. package/dist/utils/vault.d.ts +1 -1
  147. package/package.json +34 -34
  148. package/dist/components/deployment/DepositsSection.svelte +0 -8
  149. package/dist/components/deployment/DepositsSection.svelte.d.ts +0 -20
  150. package/dist/components/deployment/FieldDefinitionsSection.svelte +0 -9
  151. package/dist/components/deployment/FieldDefinitionsSection.svelte.d.ts +0 -20
  152. package/dist/components/deployment/SelectTokensSection.svelte +0 -17
  153. package/dist/components/deployment/SelectTokensSection.svelte.d.ts +0 -21
  154. package/dist/components/deployment/TokenIOSection.svelte +0 -17
  155. package/dist/components/deployment/TokenIOSection.svelte.d.ts +0 -21
  156. package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
  157. package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -24
  158. package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
  159. package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
  160. package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
  161. package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
  162. package/dist/utils/time.d.ts +0 -12
  163. package/dist/utils/time.js +0 -27
@@ -0,0 +1,54 @@
1
+ import { getToastsContext } from './context';
2
+ import { get } from 'svelte/store';
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ /**
5
+ * Hook for managing toast notifications in the application.
6
+ * Provides functionality to add, remove, and access toast notifications.
7
+ *
8
+ * @returns An object containing the toast store and methods to manipulate toasts
9
+ */
10
+ export function useToasts() {
11
+ const toasts = getToastsContext();
12
+ /**
13
+ * Removes a toast notification by its index
14
+ *
15
+ * @param index - The index of the toast to remove
16
+ */
17
+ const removeToast = (index) => {
18
+ toasts.update((toasts) => {
19
+ if (index < 0 || index >= toasts.length) {
20
+ return toasts;
21
+ }
22
+ return toasts.filter((_, i) => i !== index);
23
+ });
24
+ };
25
+ /**
26
+ * Adds a new toast notification and automatically removes it after 3 seconds
27
+ *
28
+ * @param toast - The toast properties (message and type)
29
+ */
30
+ const addToast = (toast) => {
31
+ const newToast = { ...toast, id: uuidv4() };
32
+ let addedToastIndex = -1;
33
+ toasts.update((toasts) => {
34
+ const updatedToasts = [...toasts, newToast];
35
+ addedToastIndex = updatedToasts.length - 1;
36
+ return updatedToasts;
37
+ });
38
+ const toastId = newToast.id;
39
+ if (addedToastIndex > -1) {
40
+ setTimeout(() => {
41
+ const currentToasts = get(toasts);
42
+ const currentIndex = currentToasts.findIndex((t) => t.id === toastId);
43
+ if (currentIndex > -1) {
44
+ removeToast(currentIndex);
45
+ }
46
+ }, 3000);
47
+ }
48
+ };
49
+ return {
50
+ toasts,
51
+ addToast,
52
+ removeToast
53
+ };
54
+ }
@@ -0,0 +1,7 @@
1
+ <script>import { readable } from "svelte/store";
2
+ import { setAccountContext } from "./context";
3
+ export let account = readable(null);
4
+ setAccountContext(account);
5
+ </script>
6
+
7
+ <slot />
@@ -0,0 +1,21 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { Account } from '../../types/account';
3
+ declare const __propDef: {
4
+ props: {
5
+ account?: Account;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {
11
+ default: {};
12
+ };
13
+ exports?: {} | undefined;
14
+ bindings?: string | undefined;
15
+ };
16
+ export type WalletProviderProps = typeof __propDef.props;
17
+ export type WalletProviderEvents = typeof __propDef.events;
18
+ export type WalletProviderSlots = typeof __propDef.slots;
19
+ export default class WalletProvider extends SvelteComponent<WalletProviderProps, WalletProviderEvents, WalletProviderSlots> {
20
+ }
21
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { Account } from '../../types/account';
2
+ export declare const ACCOUNT_KEY = "account_key";
3
+ /**
4
+ * Retrieves the account store directly from Svelte's context
5
+ */
6
+ export declare const getAccountContext: () => Account;
7
+ /**
8
+ * Sets the account store in Svelte's context
9
+ */
10
+ export declare const setAccountContext: (account: Account) => void;
@@ -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[]) => 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,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, WasmEncodedResult } 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<WasmEncodedResult<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<WasmEncodedResult<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,122 @@
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.value && isSuccess(data.value)) {
27
+ clearInterval(checkInterval);
28
+ let orderHash;
29
+ // Extract orderHash from order data if it exists in the expected format
30
+ if (Array.isArray(data.value) &&
31
+ data.value.length > 0 &&
32
+ data.value[0]?.order?.orderHash) {
33
+ orderHash = data.value[0].order.orderHash;
34
+ }
35
+ resolve({
36
+ value: {
37
+ txHash,
38
+ successMessage,
39
+ orderHash,
40
+ network,
41
+ data: data.value
42
+ }
43
+ });
44
+ return;
45
+ }
46
+ }
47
+ catch {
48
+ // Continue with the next attempt
49
+ }
50
+ if (attempts >= maxAttempts) {
51
+ clearInterval(checkInterval);
52
+ resolve({
53
+ error: TIMEOUT_ERROR
54
+ });
55
+ return;
56
+ }
57
+ }, interval);
58
+ });
59
+ };
60
+ /**
61
+ * Creates a configuration for checking general transaction indexing
62
+ *
63
+ * @param subgraphUrl URL of the subgraph to query
64
+ * @param txHash Transaction hash to check for indexing
65
+ * @param successMessage Message to display on successful indexing
66
+ * @param network Optional network key
67
+ * @param maxAttempts Maximum number of attempts before timing out
68
+ * @param interval Interval between attempts in milliseconds
69
+ * @returns Configuration for transaction indexing
70
+ */
71
+ export const getTransactionConfig = (subgraphUrl, txHash, successMessage, network, maxAttempts, interval) => ({
72
+ subgraphUrl,
73
+ txHash,
74
+ successMessage,
75
+ network,
76
+ maxAttempts,
77
+ interval,
78
+ fetchData: getTransaction,
79
+ isSuccess: (tx) => !!tx
80
+ });
81
+ /**
82
+ * Creates a configuration for checking new order indexing
83
+ *
84
+ * @param subgraphUrl URL of the subgraph to query
85
+ * @param txHash Transaction hash to check for indexing
86
+ * @param successMessage Message to display on successful indexing
87
+ * @param network Optional network key
88
+ * @param maxAttempts Maximum number of attempts before timing out
89
+ * @param interval Interval between attempts in milliseconds
90
+ * @returns Configuration for new order indexing
91
+ */
92
+ export const getNewOrderConfig = (subgraphUrl, txHash, successMessage, network, maxAttempts, interval) => ({
93
+ subgraphUrl,
94
+ txHash,
95
+ successMessage,
96
+ network,
97
+ maxAttempts,
98
+ interval,
99
+ fetchData: getTransactionAddOrders,
100
+ isSuccess: (addOrders) => addOrders?.length > 0
101
+ });
102
+ /**
103
+ * Creates a configuration for checking order removal indexing
104
+ *
105
+ * @param subgraphUrl URL of the subgraph to query
106
+ * @param txHash Transaction hash to check for indexing
107
+ * @param successMessage Message to display on successful indexing
108
+ * @param network Optional network key
109
+ * @param maxAttempts Maximum number of attempts before timing out
110
+ * @param interval Interval between attempts in milliseconds
111
+ * @returns Configuration for order removal indexing
112
+ */
113
+ export const getRemoveOrderConfig = (subgraphUrl, txHash, successMessage, network, maxAttempts, interval) => ({
114
+ subgraphUrl,
115
+ txHash,
116
+ successMessage,
117
+ network,
118
+ maxAttempts,
119
+ interval,
120
+ fetchData: getTransactionRemoveOrders,
121
+ isSuccess: (removeOrders) => removeOrders?.length > 0
122
+ });
@@ -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>;