@rainlanguage/ui-components 0.0.1-alpha.21 → 0.0.1-alpha.210

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 (260) hide show
  1. package/dist/__fixtures__/settings.yaml +125 -0
  2. package/dist/__mocks__/CodeMirrorRainlang.svelte +4 -0
  3. package/dist/__mocks__/CodeMirrorRainlang.svelte.d.ts +18 -0
  4. package/dist/__mocks__/MockComponent.svelte +4 -0
  5. package/dist/__mocks__/MockComponent.svelte.d.ts +3 -1
  6. package/dist/__mocks__/stores.d.ts +47 -33
  7. package/dist/__mocks__/stores.js +61 -38
  8. package/dist/components/ButtonLoading.svelte +1 -1
  9. package/dist/components/ButtonVaultLink.svelte +11 -11
  10. package/dist/components/ButtonVaultLink.svelte.d.ts +4 -3
  11. package/dist/components/CheckboxInactiveOrdersVault.svelte +20 -0
  12. package/dist/components/CheckboxInactiveOrdersVault.svelte.d.ts +19 -0
  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 +3 -12
  19. package/dist/components/CodeMirrorRainlang.svelte.d.ts +2 -2
  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 +45 -23
  25. package/dist/components/ListViewOrderbookFilters.svelte.d.ts +27 -22
  26. package/dist/components/LocalDbStatusBadge.svelte +27 -0
  27. package/dist/components/LocalDbStatusBadge.svelte.d.ts +19 -0
  28. package/dist/components/LocalDbStatusCard.svelte +40 -0
  29. package/dist/components/LocalDbStatusCard.svelte.d.ts +20 -0
  30. package/dist/components/LocalDbStatusModal.svelte +103 -0
  31. package/dist/components/LocalDbStatusModal.svelte.d.ts +21 -0
  32. package/dist/components/OrderOrVaultHash.svelte +12 -12
  33. package/dist/components/OrderOrVaultHash.svelte.d.ts +4 -4
  34. package/dist/components/PageHeader.svelte +1 -1
  35. package/dist/components/TanstackAppTable.svelte +179 -28
  36. package/dist/components/TanstackAppTable.svelte.d.ts +14 -8
  37. package/dist/components/ToastDetail.svelte +42 -0
  38. package/dist/components/ToastDetail.svelte.d.ts +20 -0
  39. package/dist/components/Tooltip.svelte +8 -0
  40. package/dist/components/Tooltip.svelte.d.ts +21 -0
  41. package/dist/components/VaultBalanceChangeTypeFilter.svelte +23 -0
  42. package/dist/components/VaultBalanceChangeTypeFilter.svelte.d.ts +19 -0
  43. package/dist/components/VaultCard.svelte +18 -0
  44. package/dist/components/VaultCard.svelte.d.ts +19 -0
  45. package/dist/components/charts/LightweightChart.svelte +1 -1
  46. package/dist/components/charts/LightweightChart.svelte.d.ts +5 -5
  47. package/dist/components/charts/OrderTradesChart.svelte +300 -28
  48. package/dist/components/charts/OrderTradesChart.svelte.d.ts +4 -4
  49. package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
  50. package/dist/components/charts/VaultBalanceChart.svelte +8 -26
  51. package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -7
  52. package/dist/components/charts/transformAndSortData.d.ts +24 -0
  53. package/dist/components/charts/transformAndSortData.js +111 -0
  54. package/dist/components/checkbox/CheckboxActiveOrders.svelte +11 -0
  55. package/dist/components/checkbox/CheckboxActiveOrders.svelte.d.ts +19 -0
  56. package/dist/components/deployment/ButtonSelectOption.svelte +2 -0
  57. package/dist/components/deployment/ButtonSelectOption.svelte.d.ts +1 -0
  58. package/dist/components/deployment/ComposedRainlangModal.svelte +2 -1
  59. package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
  60. package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
  61. package/dist/components/deployment/DeploymentSteps.svelte +209 -216
  62. package/dist/components/deployment/DeploymentSteps.svelte.d.ts +6 -12
  63. package/dist/components/deployment/DeploymentTile.svelte +2 -2
  64. package/dist/components/deployment/DeploymentTile.svelte.d.ts +1 -1
  65. package/dist/components/deployment/DeploymentsSection.svelte +15 -22
  66. package/dist/components/deployment/DeploymentsSection.svelte.d.ts +3 -2
  67. package/dist/components/deployment/DepositInput.svelte +8 -10
  68. package/dist/components/deployment/DepositInput.svelte.d.ts +1 -2
  69. package/dist/components/deployment/DisclaimerModal.svelte +6 -7
  70. package/dist/components/deployment/FieldDefinitionInput.svelte +7 -11
  71. package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +1 -2
  72. package/dist/components/deployment/InvalidOrdersSection.svelte +17 -0
  73. package/dist/components/deployment/InvalidOrdersSection.svelte.d.ts +19 -0
  74. package/dist/components/deployment/{StrategyPage.svelte → OrderPage.svelte} +15 -24
  75. package/dist/components/deployment/OrderPage.svelte.d.ts +21 -0
  76. package/dist/components/deployment/SelectToken.svelte +125 -48
  77. package/dist/components/deployment/SelectToken.svelte.d.ts +4 -3
  78. package/dist/components/deployment/TokenBalance.svelte +19 -0
  79. package/dist/components/deployment/TokenBalance.svelte.d.ts +19 -0
  80. package/dist/components/deployment/TokenIOInput.svelte +25 -15
  81. package/dist/components/deployment/TokenIOInput.svelte.d.ts +3 -3
  82. package/dist/components/deployment/TokenSelectionModal.svelte +148 -0
  83. package/dist/components/deployment/TokenSelectionModal.svelte.d.ts +20 -0
  84. package/dist/components/deployment/{ValidStrategiesSection.svelte → ValidOrdersSection.svelte} +7 -7
  85. package/dist/components/deployment/ValidOrdersSection.svelte.d.ts +19 -0
  86. package/dist/components/deployment/VaultIdInformation.svelte +17 -0
  87. package/dist/components/deployment/VaultIdInformation.svelte.d.ts +21 -0
  88. package/dist/components/detail/OrderDetail.svelte +184 -80
  89. package/dist/components/detail/OrderDetail.svelte.d.ts +21 -15
  90. package/dist/components/detail/TanstackOrderQuote.svelte +92 -46
  91. package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +14 -16
  92. package/dist/components/detail/VaultDetail.svelte +78 -77
  93. package/dist/components/detail/VaultDetail.svelte.d.ts +12 -18
  94. package/dist/components/dropdown/DropdownActiveNetworks.svelte +44 -0
  95. package/dist/components/dropdown/DropdownActiveNetworks.svelte.d.ts +19 -0
  96. package/dist/components/dropdown/DropdownCheckbox.svelte +4 -4
  97. package/dist/components/dropdown/DropdownOrderListAccounts.svelte +5 -2
  98. package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +2 -3
  99. package/dist/components/dropdown/DropdownOrderbooksFilter.svelte +172 -0
  100. package/dist/components/dropdown/DropdownOrderbooksFilter.svelte.d.ts +25 -0
  101. package/dist/components/dropdown/DropdownTokensFilter.svelte +152 -0
  102. package/dist/components/dropdown/DropdownTokensFilter.svelte.d.ts +28 -0
  103. package/dist/components/icon/Refresh.svelte +2 -1
  104. package/dist/components/icon/Refresh.svelte.d.ts +1 -0
  105. package/dist/components/input/InputOrderHash.svelte +1 -1
  106. package/dist/components/input/InputOrderHash.svelte.d.ts +3 -3
  107. package/dist/components/input/InputRegistryUrl.svelte +36 -14
  108. package/dist/components/input/InputToken.svelte +2 -2
  109. package/dist/components/input/InputTokenAmount.svelte +16 -21
  110. package/dist/components/input/InputTokenAmount.svelte.d.ts +3 -3
  111. package/dist/components/tables/OrderAPY.svelte +6 -33
  112. package/dist/components/tables/OrderAPY.svelte.d.ts +1 -4
  113. package/dist/components/tables/OrderTradesListTable.svelte +84 -81
  114. package/dist/components/tables/OrderTradesListTable.svelte.d.ts +4 -4
  115. package/dist/components/tables/OrderVaultsVolTable.svelte +17 -22
  116. package/dist/components/tables/OrderVaultsVolTable.svelte.d.ts +2 -2
  117. package/dist/components/tables/OrdersListTable.svelte +200 -108
  118. package/dist/components/tables/OrdersListTable.svelte.d.ts +17 -21
  119. package/dist/components/tables/VaultBalanceChangesTable.svelte +83 -43
  120. package/dist/components/tables/VaultBalanceChangesTable.svelte.d.ts +13 -11
  121. package/dist/components/tables/VaultsListTable.svelte +268 -145
  122. package/dist/components/tables/VaultsListTable.svelte.d.ts +24 -32
  123. package/dist/components/transactions/FixedBottomTransaction.svelte +63 -0
  124. package/dist/components/transactions/FixedBottomTransaction.svelte.d.ts +16 -0
  125. package/dist/components/transactions/TransactionDetail.svelte +31 -0
  126. package/dist/components/transactions/TransactionDetail.svelte.d.ts +20 -0
  127. package/dist/components/transactions/TransactionList.svelte +17 -0
  128. package/dist/components/transactions/TransactionList.svelte.d.ts +16 -0
  129. package/dist/components/transactions/getStatusEmoji.d.ts +2 -0
  130. package/dist/components/transactions/getStatusEmoji.js +20 -0
  131. package/dist/components/wallet/WalletConnect.svelte +5 -4
  132. package/dist/components/wallet/WalletConnect.svelte.d.ts +0 -1
  133. package/dist/consts.d.ts +1 -0
  134. package/dist/consts.js +1 -0
  135. package/dist/errors/DeploymentStepsError.d.ts +8 -2
  136. package/dist/errors/DeploymentStepsError.js +7 -1
  137. package/dist/hooks/useGui.d.ts +1 -1
  138. package/dist/hooks/useGui.js +1 -1
  139. package/dist/hooks/useLocalDb.d.ts +3 -0
  140. package/dist/hooks/useLocalDb.js +10 -0
  141. package/dist/hooks/useRaindexClient.d.ts +3 -0
  142. package/dist/hooks/useRaindexClient.js +11 -0
  143. package/dist/index.d.ts +42 -19
  144. package/dist/index.js +41 -16
  145. package/dist/models/Transaction.d.ts +75 -0
  146. package/dist/models/Transaction.js +100 -0
  147. package/dist/providers/GuiProvider.svelte +1 -1
  148. package/dist/providers/GuiProvider.svelte.d.ts +1 -1
  149. package/dist/providers/LocalDbProvider.svelte +8 -0
  150. package/dist/providers/LocalDbProvider.svelte.d.ts +21 -0
  151. package/dist/providers/RaindexClientProvider.svelte +8 -0
  152. package/dist/providers/RaindexClientProvider.svelte.d.ts +21 -0
  153. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte +8 -0
  154. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte.d.ts +24 -0
  155. package/dist/providers/dotrainRegistry/context.d.ts +9 -0
  156. package/dist/providers/dotrainRegistry/context.js +40 -0
  157. package/dist/providers/dotrainRegistry/useDotrainRegistry.d.ts +5 -0
  158. package/dist/providers/dotrainRegistry/useDotrainRegistry.js +35 -0
  159. package/dist/providers/registry/RegistryManager.d.ts +65 -0
  160. package/dist/providers/registry/RegistryManager.js +133 -0
  161. package/dist/providers/registry/RegistryProvider.svelte +6 -0
  162. package/dist/providers/registry/RegistryProvider.svelte.d.ts +21 -0
  163. package/dist/providers/registry/context.d.ts +10 -0
  164. package/dist/providers/registry/context.js +46 -0
  165. package/dist/providers/registry/useRegistry.d.ts +7 -0
  166. package/dist/providers/registry/useRegistry.js +29 -0
  167. package/dist/providers/toasts/ToastProvider.svelte +17 -0
  168. package/dist/providers/toasts/ToastProvider.svelte.d.ts +18 -0
  169. package/dist/providers/toasts/context.d.ts +14 -0
  170. package/dist/providers/toasts/context.js +22 -0
  171. package/dist/providers/toasts/useToasts.d.ts +16 -0
  172. package/dist/providers/toasts/useToasts.js +63 -0
  173. package/dist/providers/transactions/TransactionManager.d.ts +235 -0
  174. package/dist/providers/transactions/TransactionManager.js +509 -0
  175. package/dist/providers/transactions/TransactionProvider.svelte +11 -0
  176. package/dist/providers/transactions/TransactionProvider.svelte.d.ts +24 -0
  177. package/dist/providers/transactions/context.d.ts +19 -0
  178. package/dist/providers/transactions/context.js +28 -0
  179. package/dist/providers/transactions/useTransactions.d.ts +13 -0
  180. package/dist/providers/transactions/useTransactions.js +18 -0
  181. package/dist/providers/wallet/WalletProvider.svelte +7 -0
  182. package/dist/providers/wallet/WalletProvider.svelte.d.ts +21 -0
  183. package/dist/providers/wallet/context.d.ts +10 -0
  184. package/dist/providers/wallet/context.js +47 -0
  185. package/dist/providers/wallet/useAccount.d.ts +8 -0
  186. package/dist/providers/wallet/useAccount.js +148 -0
  187. package/dist/queries/keys.d.ts +1 -0
  188. package/dist/queries/keys.js +1 -0
  189. package/dist/queries/queryClient.d.ts +1 -1
  190. package/dist/queries/queryClient.js +11 -6
  191. package/dist/services/awaitTransactionIndexing.d.ts +107 -0
  192. package/dist/services/awaitTransactionIndexing.js +58 -0
  193. package/dist/services/getExplorerLink.d.ts +1 -1
  194. package/dist/services/getExplorerLink.js +2 -4
  195. package/dist/services/handleShareChoices.d.ts +2 -2
  196. package/dist/services/handleShareChoices.js +7 -2
  197. package/dist/services/historicalOrderCharts.d.ts +2 -2
  198. package/dist/services/historicalOrderCharts.js +267 -333
  199. package/dist/services/index.d.ts +2 -1
  200. package/dist/services/index.js +2 -1
  201. package/dist/services/loadRegistryUrl.d.ts +2 -0
  202. package/dist/services/loadRegistryUrl.js +22 -0
  203. package/dist/services/pairTradesChartData.d.ts +47 -0
  204. package/dist/services/pairTradesChartData.js +190 -0
  205. package/dist/services/registry.d.ts +5 -5
  206. package/dist/services/registry.js +8 -208
  207. package/dist/services/time.d.ts +12 -0
  208. package/dist/services/time.js +88 -6
  209. package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
  210. package/dist/storesGeneric/cachedWritableStore.js +93 -0
  211. package/dist/types/account.d.ts +3 -0
  212. package/dist/types/appStores.d.ts +9 -14
  213. package/dist/types/modal.d.ts +26 -14
  214. package/dist/types/{strategy.d.ts → order.d.ts} +3 -3
  215. package/dist/types/order.js +1 -0
  216. package/dist/types/toast.d.ts +11 -0
  217. package/dist/types/toast.js +1 -0
  218. package/dist/types/tokenBalance.d.ts +6 -0
  219. package/dist/types/tokenBalance.js +1 -0
  220. package/dist/types/transaction.d.ts +66 -21
  221. package/dist/types/transaction.js +31 -1
  222. package/dist/utils/configHelpers.d.ts +4 -0
  223. package/dist/utils/configHelpers.js +21 -0
  224. package/dist/utils/constructHashLink.d.ts +24 -0
  225. package/dist/utils/constructHashLink.js +115 -0
  226. package/dist/utils/getNetworkName.d.ts +1 -0
  227. package/dist/utils/getNetworkName.js +13 -0
  228. package/dist/utils/number.d.ts +0 -7
  229. package/dist/utils/number.js +0 -27
  230. package/dist/utils/tokens.d.ts +2 -0
  231. package/dist/utils/tokens.js +3 -0
  232. package/dist/utils/vaultBalanceChangeLabels.d.ts +4 -0
  233. package/dist/utils/vaultBalanceChangeLabels.js +18 -0
  234. package/package.json +39 -34
  235. package/dist/__fixtures__/orderDetail.d.ts +0 -99
  236. package/dist/__fixtures__/orderDetail.js +0 -204
  237. package/dist/__fixtures__/settings-12-11-24.json +0 -160
  238. package/dist/__mocks__/mockTransactionStore.d.ts +0 -22
  239. package/dist/__mocks__/mockTransactionStore.js +0 -56
  240. package/dist/__mocks__/settings.d.ts +0 -3
  241. package/dist/__mocks__/settings.js +0 -37
  242. package/dist/components/deployment/InvalidStrategiesSection.svelte +0 -19
  243. package/dist/components/deployment/InvalidStrategiesSection.svelte.d.ts +0 -19
  244. package/dist/components/deployment/StrategyPage.svelte.d.ts +0 -19
  245. package/dist/components/deployment/ValidStrategiesSection.svelte.d.ts +0 -19
  246. package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
  247. package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -28
  248. package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
  249. package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
  250. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte +0 -38
  251. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +0 -21
  252. package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
  253. package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
  254. package/dist/stores/transactionStore.d.ts +0 -98
  255. package/dist/stores/transactionStore.js +0 -303
  256. package/dist/utils/time.d.ts +0 -12
  257. package/dist/utils/time.js +0 -27
  258. package/dist/utils/vault.d.ts +0 -2
  259. package/dist/utils/vault.js +0 -29
  260. /package/dist/types/{strategy.js → account.js} +0 -0
@@ -0,0 +1,509 @@
1
+ import { writable } from 'svelte/store';
2
+ import { TransactionStore } from '../../models/Transaction';
3
+ import { TransactionName, TransactionStatusMessage, TransactionStoreErrorMessage } from '../../types/transaction';
4
+ import { getExplorerLink } from '../../services/getExplorerLink';
5
+ import { RaindexClient, Float } from '@rainlanguage/orderbook';
6
+ /**
7
+ * Creates an indexing function that wraps SDK-based polling logic.
8
+ * The SDK handles local-DB-first polling followed by subgraph fallback internally,
9
+ * so we only need to call it once.
10
+ *
11
+ * @param options Configuration for SDK-based indexing
12
+ * @param options.call Function that calls the SDK method (e.g. getAddOrdersForTransaction)
13
+ * @param options.isSuccess Function to determine if the result indicates success
14
+ * @param options.buildLinks Optional function to generate toast links from the result
15
+ * @returns An indexing function compatible with TransactionStore
16
+ */
17
+ export function createSdkIndexingFn(options) {
18
+ return async (ctx) => {
19
+ ctx.updateState({ status: TransactionStatusMessage.PENDING_SUBGRAPH });
20
+ try {
21
+ const result = await options.call();
22
+ if (result.error) {
23
+ const errorMsg = result.error.readableMsg?.toLowerCase() ?? '';
24
+ if (errorMsg.includes('timeout')) {
25
+ ctx.updateState({
26
+ status: TransactionStatusMessage.ERROR,
27
+ errorDetails: TransactionStoreErrorMessage.SUBGRAPH_TIMEOUT_ERROR
28
+ });
29
+ }
30
+ else {
31
+ ctx.updateState({
32
+ status: TransactionStatusMessage.ERROR,
33
+ errorDetails: TransactionStoreErrorMessage.SUBGRAPH_FAILED
34
+ });
35
+ }
36
+ return ctx.onError();
37
+ }
38
+ const value = result.value;
39
+ if (value && options.isSuccess(value)) {
40
+ const extraLinks = options.buildLinks?.(value) ?? [];
41
+ if (extraLinks.length > 0) {
42
+ ctx.updateState({ links: [...extraLinks, ...ctx.links] });
43
+ }
44
+ ctx.updateState({ status: TransactionStatusMessage.SUCCESS });
45
+ return ctx.onSuccess();
46
+ }
47
+ // No valid data after polling
48
+ ctx.updateState({
49
+ status: TransactionStatusMessage.ERROR,
50
+ errorDetails: TransactionStoreErrorMessage.SUBGRAPH_FAILED
51
+ });
52
+ return ctx.onError();
53
+ }
54
+ catch {
55
+ ctx.updateState({
56
+ status: TransactionStatusMessage.ERROR,
57
+ errorDetails: TransactionStoreErrorMessage.SUBGRAPH_FAILED
58
+ });
59
+ return ctx.onError();
60
+ }
61
+ };
62
+ }
63
+ /**
64
+ * Manages blockchain transactions with toast notifications and query invalidation.
65
+ * Handles transaction lifecycle, status updates, and UI feedback.
66
+ * Provides functionality for creating, tracking, and managing blockchain transactions.
67
+ */
68
+ export class TransactionManager {
69
+ /** Writable store tracking all active transactions. */
70
+ transactions;
71
+ /** Query client for cache invalidation after successful transactions. */
72
+ queryClient;
73
+ /** Function to display toast notifications in the UI. */
74
+ addToast;
75
+ /** Wagmi configuration for blockchain interactions. */
76
+ wagmiConfig;
77
+ /**
78
+ * Initializes a new TransactionManager instance.
79
+ * @param queryClient - Query client for cache invalidation.
80
+ * @param addToast - Function to display toast notifications.
81
+ * @param wagmiConfig - Wagmi configuration for blockchain interactions.
82
+ */
83
+ constructor(queryClient, addToast, wagmiConfig) {
84
+ this.queryClient = queryClient;
85
+ this.addToast = addToast;
86
+ this.wagmiConfig = wagmiConfig;
87
+ this.transactions = writable([]);
88
+ }
89
+ /**
90
+ * Creates and initializes a new transaction for removing an order from the orderbook.
91
+ * @param args - Configuration for the remove order transaction.
92
+ * @param args.txHash - Hash of the transaction to track.
93
+ * @param args.chainId - Chain ID where the transaction is being executed.
94
+ * @param args.queryKey - The hash of the order to be removed (used for query invalidation and UI links).
95
+ * @param args.entity - The `SgOrder` entity associated with this transaction.
96
+ * @returns A new Transaction instance configured for order removal.
97
+ * @example
98
+ * const tx = await manager.createRemoveOrderTransaction({
99
+ * txHash: '0x123...',
100
+ * chainId: 1,
101
+ * queryKey: '0x456...', // Order hash
102
+ * entity: sgOrderInstance
103
+ * });
104
+ */
105
+ async createRemoveOrderTransaction(args) {
106
+ const name = TransactionName.REMOVAL;
107
+ const errorMessage = 'Order removal failed.';
108
+ const successMessage = 'Order removed successfully.';
109
+ const { chainId, entity: { orderbook }, queryKey, txHash, raindexClient } = args;
110
+ const explorerLink = await getExplorerLink(txHash, chainId, 'tx');
111
+ const toastLinks = [
112
+ {
113
+ link: explorerLink,
114
+ label: 'View on explorer'
115
+ }
116
+ ];
117
+ const awaitIndexingFn = createSdkIndexingFn({
118
+ call: () => raindexClient.getRemoveOrdersForTransaction(chainId, orderbook, txHash),
119
+ isSuccess: (orders) => Array.isArray(orders) && orders.length > 0
120
+ });
121
+ return this.createTransaction({
122
+ ...args,
123
+ name,
124
+ errorMessage,
125
+ successMessage,
126
+ queryKey,
127
+ toastLinks,
128
+ awaitIndexingFn
129
+ });
130
+ }
131
+ /**
132
+ * Creates and initializes a new transaction for withdrawing funds from a vault.
133
+ * @param args - Configuration for the withdrawal transaction.
134
+ * @param args.txHash - Hash of the transaction to track.
135
+ * @param args.chainId - Chain ID where the transaction is being executed.
136
+ * @param args.queryKey - The ID of the vault from which funds are withdrawn (used for query invalidation and UI links).
137
+ * @param args.entity - The `SgVault` entity associated with this transaction.
138
+ * @returns A new Transaction instance configured for withdrawal.
139
+ * @example
140
+ * const tx = await manager.createWithdrawTransaction({
141
+ * txHash: '0x123...',
142
+ * chainId: 1,
143
+ * queryKey: '0x789...', // Vault ID
144
+ * entity: sgVaultInstance
145
+ * });
146
+ */
147
+ async createWithdrawTransaction(args) {
148
+ const name = TransactionName.WITHDRAWAL;
149
+ const errorMessage = 'Withdrawal failed.';
150
+ const successMessage = 'Withdrawal successful.';
151
+ const { chainId, entity: { orderbook }, queryKey, txHash, raindexClient } = args;
152
+ const explorerLink = await getExplorerLink(txHash, chainId, 'tx');
153
+ const toastLinks = [
154
+ {
155
+ link: `/vaults/${chainId}-${orderbook}-${queryKey}`,
156
+ label: 'View vault'
157
+ },
158
+ {
159
+ link: explorerLink,
160
+ label: 'View on explorer'
161
+ }
162
+ ];
163
+ const awaitIndexingFn = createSdkIndexingFn({
164
+ call: () => raindexClient.getTransaction(chainId, orderbook, txHash),
165
+ isSuccess: (tx) => !!tx
166
+ });
167
+ return this.createTransaction({
168
+ ...args,
169
+ name,
170
+ errorMessage,
171
+ successMessage,
172
+ queryKey,
173
+ toastLinks,
174
+ awaitIndexingFn
175
+ });
176
+ }
177
+ /**
178
+ * Creates a multicall withdrawal transaction.
179
+ *
180
+ * Precondition: all provided vaults must share the same Raindex orderbook.
181
+ * This is enforced upstream in handleVaultsWithdrawAll.ts:
182
+ * if (vaults.some(v => v.orderbook !== vaults[0].orderbook)) { … }
183
+ *
184
+ * @param args.chainId the target chain ID
185
+ * @param args.vaults list of RaindexVault instances (must share an orderbook)
186
+ * @param args.txHash the transaction hash to wrap
187
+ * @param args.queryKey cache key for invalidation
188
+ * @param args.raindexClient Raindex API client * @example
189
+ * const tx = await manager.createVaultsWithdrawAllTransaction({
190
+ * txHash: '0x123...',
191
+ * chainId: 1,
192
+ * queryKey: 'QKEY_VAULTS',
193
+ * vaults: [vault1, vault2, vault3],
194
+ * raindexClient: clientInstance
195
+ * });
196
+ */
197
+ async createVaultsWithdrawAllTransaction(args) {
198
+ const name = TransactionName.WITHDRAWAL_MULTIPLE;
199
+ const errorMessage = 'Withdrawal failed.';
200
+ const successMessage = 'Withdrawal successful.';
201
+ const { chainId, vaults, txHash, queryKey, raindexClient } = args;
202
+ if (vaults.length === 0) {
203
+ throw new Error('At least one vault is required for withdrawal');
204
+ }
205
+ // All vaults must share the same orderbook for multicall transactions
206
+ // It should be validated before calling this method
207
+ const orderbook = vaults[0].orderbook;
208
+ const explorerLink = await getExplorerLink(txHash, chainId, 'tx');
209
+ const toastLinks = [
210
+ {
211
+ link: '/vaults/',
212
+ label: 'View all vaults'
213
+ },
214
+ {
215
+ link: explorerLink,
216
+ label: 'View on explorer'
217
+ }
218
+ ];
219
+ const awaitIndexingFn = createSdkIndexingFn({
220
+ call: () => raindexClient.getTransaction(chainId, orderbook, txHash),
221
+ isSuccess: (tx) => !!tx
222
+ });
223
+ return this.createTransaction({
224
+ ...args,
225
+ name,
226
+ errorMessage,
227
+ successMessage,
228
+ toastLinks,
229
+ queryKey,
230
+ awaitIndexingFn
231
+ });
232
+ }
233
+ /**
234
+ * Creates and initializes a new transaction for approving token spend.
235
+ * @param args - Configuration for the approval transaction.
236
+ * @param args.txHash - Hash of the transaction to track.
237
+ * @param args.chainId - Chain ID where the transaction is being executed.
238
+ * @param args.queryKey - The ID of the vault or context for which approval is made (used for query invalidation and UI links).
239
+ * @param args.tokenSymbol - The symbol of the token being approved.
240
+ * @param args.entity - The `SgVault` entity associated with this transaction. (Optional, used for approvals to pre-existing vaults).
241
+ * @returns A new Transaction instance configured for token approval.
242
+ * @example
243
+ * const tx = await manager.createApprovalTransaction({
244
+ * txHash: '0xabc...',
245
+ * chainId: 1,
246
+ * queryKey: '0x789...', // Vault ID
247
+ * entity: sgVaultInstance
248
+ * });
249
+ */
250
+ async createApprovalTransaction(args) {
251
+ const { entity, queryKey, chainId } = args;
252
+ const tokenSymbol = entity?.token.symbol || 'token';
253
+ const name = `Approving ${tokenSymbol} spend`;
254
+ const errorMessage = 'Approval failed.';
255
+ const successMessage = 'Approval successful.';
256
+ const explorerLink = await getExplorerLink(args.txHash, args.chainId, 'tx');
257
+ let toastLinks = [
258
+ {
259
+ link: explorerLink,
260
+ label: 'View on explorer'
261
+ }
262
+ ];
263
+ if (entity) {
264
+ toastLinks = [
265
+ {
266
+ link: `/vaults/${chainId}-${entity.orderbook}-${queryKey}`,
267
+ label: 'View vault'
268
+ },
269
+ ...toastLinks
270
+ ];
271
+ }
272
+ return this.createTransaction({
273
+ ...args,
274
+ name,
275
+ errorMessage,
276
+ successMessage,
277
+ toastLinks
278
+ });
279
+ }
280
+ /**
281
+ * Creates and initializes a new transaction for publishing metadata to the metaboard.
282
+ * @param args - Configuration for the metadata transaction.
283
+ * @param args.txHash - Hash of the metadata transaction.
284
+ * @param args.chainId - Chain ID where the transaction is executed.
285
+ * @param args.queryKey - Identifier used for query invalidation, typically the order hash.
286
+ */
287
+ async createMetaTransaction(args) {
288
+ const name = 'Publishing metadata';
289
+ const errorMessage = 'Metadata publication failed.';
290
+ const successMessage = 'Metadata published.';
291
+ const explorerLink = await getExplorerLink(args.txHash, args.chainId, 'tx');
292
+ const toastLinks = [
293
+ {
294
+ link: explorerLink,
295
+ label: 'View on explorer'
296
+ }
297
+ ];
298
+ return this.createTransaction({
299
+ ...args,
300
+ name,
301
+ errorMessage,
302
+ successMessage,
303
+ toastLinks
304
+ });
305
+ }
306
+ /**
307
+ * Creates and initializes a new transaction for depositing funds into a vault.
308
+ * @param args - Configuration for the deposit transaction.
309
+ * @param args.txHash - Hash of the transaction to track.
310
+ * @param args.chainId - Chain ID where the transaction is being executed.
311
+ * @param args.queryKey - The ID of the vault into which funds are deposited (used for query invalidation and UI links).
312
+ * @param args.entity - The `SgVault` entity associated with this transaction.
313
+ * @param args.amount - The amount of tokens being deposited.
314
+ * @returns A new Transaction instance configured for deposit.
315
+ * @example
316
+ * const tx = await manager.createDepositTransaction({
317
+ * txHash: '0xdef...',
318
+ * chainId: 1,
319
+ * queryKey: '0x789...', // Vault ID
320
+ * entity: sgVaultInstance,
321
+ * amount: 1000n
322
+ * });
323
+ */
324
+ async createDepositTransaction(args) {
325
+ const tokenSymbol = args.entity.token.symbol;
326
+ const name = `Depositing ${args.amount.format().value} ${tokenSymbol}`;
327
+ const errorMessage = 'Deposit failed.';
328
+ const successMessage = 'Deposit successful.';
329
+ const { chainId, entity: { orderbook }, txHash, queryKey, raindexClient } = args;
330
+ const explorerLink = await getExplorerLink(txHash, chainId, 'tx');
331
+ const toastLinks = [
332
+ {
333
+ link: `/vaults/${chainId}-${orderbook}-${queryKey}`,
334
+ label: 'View vault'
335
+ },
336
+ {
337
+ link: explorerLink,
338
+ label: 'View on explorer'
339
+ }
340
+ ];
341
+ const awaitIndexingFn = createSdkIndexingFn({
342
+ call: () => raindexClient.getTransaction(chainId, orderbook, txHash),
343
+ isSuccess: (tx) => !!tx
344
+ });
345
+ return this.createTransaction({
346
+ ...args,
347
+ name,
348
+ errorMessage,
349
+ successMessage,
350
+ queryKey,
351
+ toastLinks,
352
+ awaitIndexingFn
353
+ });
354
+ }
355
+ /**
356
+ * Creates and initializes a new transaction for deploying an order.
357
+ * @param args - Configuration for the deployment transaction.
358
+ * @param args.txHash - Hash of the transaction to track.
359
+ * @param args.chainId - Chain ID where the transaction is being executed.
360
+ * @param args.queryKey - The ID of the vault into which funds are deposited (used for query invalidation and UI links).
361
+ * @returns A new Transaction instance configured for deposit.
362
+ * @example
363
+ * const tx = await manager.createAddOrderTransaction({
364
+ * txHash: '0xdeploytxhash',
365
+ * chainId: 1,
366
+ * queryKey: '0x789...', // Vault ID
367
+ * });
368
+ */
369
+ async createAddOrderTransaction(args) {
370
+ const { queryKey, txHash, chainId, orderbook, raindexClient } = args;
371
+ const name = 'Deploying order';
372
+ const errorMessage = 'Deployment failed.';
373
+ const successMessage = 'Order deployed successfully.';
374
+ const explorerLink = await getExplorerLink(txHash, chainId, 'tx');
375
+ const toastLinks = [
376
+ {
377
+ link: explorerLink,
378
+ label: 'View on explorer'
379
+ }
380
+ ];
381
+ // SDK-based indexing - the SDK's getAddOrdersForTransaction handles
382
+ // local-DB-first polling followed by subgraph fallback internally
383
+ const awaitIndexingFn = createSdkIndexingFn({
384
+ call: () => raindexClient.getAddOrdersForTransaction(chainId, orderbook, txHash),
385
+ isSuccess: (orders) => Array.isArray(orders) && orders.length > 0,
386
+ buildLinks: (orders) => {
387
+ if (!Array.isArray(orders) || orders.length === 0)
388
+ return [];
389
+ const firstOrder = orders[0];
390
+ if (!firstOrder?.orderHash)
391
+ return [];
392
+ return [
393
+ {
394
+ link: `/orders/${chainId}-${orderbook}-${firstOrder.orderHash}`,
395
+ label: 'View order'
396
+ }
397
+ ];
398
+ }
399
+ });
400
+ return this.createTransaction({
401
+ ...args,
402
+ name,
403
+ errorMessage,
404
+ successMessage,
405
+ queryKey,
406
+ toastLinks,
407
+ awaitIndexingFn
408
+ });
409
+ }
410
+ /**
411
+ * Creates and initializes a new transaction for taking orders.
412
+ * @param args - Configuration for the take order transaction.
413
+ * @param args.txHash - Hash of the transaction to track.
414
+ * @param args.chainId - Chain ID where the transaction is being executed.
415
+ * @param args.queryKey - The hash of the order being taken (used for query invalidation).
416
+ * @param args.entity - The `RaindexOrder` entity associated with this transaction.
417
+ * @returns A new Transaction instance configured for taking orders.
418
+ * @example
419
+ * const tx = await manager.createTakeOrderTransaction({
420
+ * txHash: '0x123...',
421
+ * chainId: 1,
422
+ * queryKey: '0x456...', // Order hash
423
+ * entity: raindexOrderInstance,
424
+ * raindexClient: clientInstance
425
+ * });
426
+ */
427
+ async createTakeOrderTransaction(args) {
428
+ const name = TransactionName.TAKE_ORDER;
429
+ const errorMessage = 'Take order failed.';
430
+ const successMessage = 'Order taken successfully.';
431
+ const { chainId, entity: { orderbook }, queryKey, txHash, raindexClient } = args;
432
+ const explorerLink = await getExplorerLink(txHash, chainId, 'tx');
433
+ const toastLinks = [
434
+ {
435
+ link: explorerLink,
436
+ label: 'View on explorer'
437
+ }
438
+ ];
439
+ const awaitIndexingFn = createSdkIndexingFn({
440
+ call: () => raindexClient.getTransaction(chainId, orderbook, txHash),
441
+ isSuccess: (tx) => !!tx
442
+ });
443
+ return this.createTransaction({
444
+ ...args,
445
+ name,
446
+ errorMessage,
447
+ successMessage,
448
+ queryKey,
449
+ toastLinks,
450
+ awaitIndexingFn
451
+ });
452
+ }
453
+ /**
454
+ * Creates, initializes, and executes a new transaction instance.
455
+ * @param args - Configuration for the transaction.
456
+ * @param args.name - Name or title of the transaction.
457
+ * @param args.errorMessage - Message to display on transaction failure.
458
+ * @param args.successMessage - Message to display on transaction success.
459
+ * @param args.queryKey - Key used for query invalidation.
460
+ * @param args.toastLinks - Array of links to display in toast notifications.
461
+ * @param args.awaitIndexingFn - Optional function to await transaction indexing.
462
+ * @returns A new Transaction instance that has been initialized and started.
463
+ * @private
464
+ */
465
+ async createTransaction(args) {
466
+ const createTransactionArgs = {
467
+ ...args,
468
+ config: this.wagmiConfig
469
+ };
470
+ const onSuccess = () => {
471
+ if (args.queryKey) {
472
+ this.queryClient.invalidateQueries({ queryKey: [args.queryKey] });
473
+ }
474
+ };
475
+ const onError = () => {
476
+ this.addToast({
477
+ message: args.errorMessage,
478
+ type: 'error',
479
+ color: 'red',
480
+ links: args.toastLinks
481
+ });
482
+ };
483
+ const transactionInstance = new TransactionStore(createTransactionArgs, onSuccess, onError);
484
+ this.transactions.update((currentTransactions) => [
485
+ ...currentTransactions,
486
+ transactionInstance
487
+ ]);
488
+ await transactionInstance.execute();
489
+ return transactionInstance;
490
+ }
491
+ /**
492
+ * Retrieves the store containing all active transactions.
493
+ * @returns A readable store containing all active Transaction instances.
494
+ * @example
495
+ * const transactionsStore = manager.getTransactions();
496
+ * transactionsStore.subscribe(transactions => console.log(transactions));
497
+ */
498
+ getTransactions() {
499
+ return this.transactions;
500
+ }
501
+ /**
502
+ * Removes all transactions from the store, resetting the transaction tracking state.
503
+ * @example
504
+ * manager.clearTransactions(); // Clear all tracked transactions
505
+ */
506
+ clearTransactions() {
507
+ this.transactions.set([]);
508
+ }
509
+ }
@@ -0,0 +1,11 @@
1
+ <script>import { setTransactionManagerContext } from "./context";
2
+ import { TransactionManager } from "./TransactionManager";
3
+ import { useQueryClient } from "@tanstack/svelte-query";
4
+ export let addToast;
5
+ export let wagmiConfig;
6
+ const queryClient = useQueryClient();
7
+ const manager = new TransactionManager(queryClient, addToast, $wagmiConfig);
8
+ setTransactionManagerContext(manager);
9
+ </script>
10
+
11
+ <slot />
@@ -0,0 +1,24 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { Config } from '@wagmi/core';
3
+ import type { ToastProps } from '../../types/toast';
4
+ import type { Writable } from 'svelte/store';
5
+ declare const __propDef: {
6
+ props: {
7
+ addToast: (toast: ToastProps) => void;
8
+ wagmiConfig: Writable<Config>;
9
+ };
10
+ events: {
11
+ [evt: string]: CustomEvent<any>;
12
+ };
13
+ slots: {
14
+ default: {};
15
+ };
16
+ exports?: {} | undefined;
17
+ bindings?: string | undefined;
18
+ };
19
+ export type TransactionProviderProps = typeof __propDef.props;
20
+ export type TransactionProviderEvents = typeof __propDef.events;
21
+ export type TransactionProviderSlots = typeof __propDef.slots;
22
+ export default class TransactionProvider extends SvelteComponent<TransactionProviderProps, TransactionProviderEvents, TransactionProviderSlots> {
23
+ }
24
+ export {};
@@ -0,0 +1,19 @@
1
+ import { TransactionManager } from './TransactionManager';
2
+ /**
3
+ * The context key used to store and retrieve the TransactionManager instance
4
+ */
5
+ export declare const TRANSACTION_MANAGER_CONTEXT_KEY = "rain:ui-components:transactionManager";
6
+ /**
7
+ * Sets the TransactionManager instance in Svelte's context
8
+ *
9
+ * @param {TransactionManager} manager - The TransactionManager instance to store in context
10
+ * @returns {void}
11
+ */
12
+ export declare function setTransactionManagerContext(manager: TransactionManager): void;
13
+ /**
14
+ * Retrieves the TransactionManager instance from Svelte's context
15
+ *
16
+ * @returns {TransactionManager} The TransactionManager instance
17
+ * @throws {Error} If no TransactionManager is found in context
18
+ */
19
+ export declare function getTransactionManagerContext(): TransactionManager;
@@ -0,0 +1,28 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ import { TransactionManager } from './TransactionManager';
3
+ /**
4
+ * The context key used to store and retrieve the TransactionManager instance
5
+ */
6
+ export const TRANSACTION_MANAGER_CONTEXT_KEY = 'rain:ui-components:transactionManager';
7
+ /**
8
+ * Sets the TransactionManager instance in Svelte's context
9
+ *
10
+ * @param {TransactionManager} manager - The TransactionManager instance to store in context
11
+ * @returns {void}
12
+ */
13
+ export function setTransactionManagerContext(manager) {
14
+ setContext(TRANSACTION_MANAGER_CONTEXT_KEY, manager);
15
+ }
16
+ /**
17
+ * Retrieves the TransactionManager instance from Svelte's context
18
+ *
19
+ * @returns {TransactionManager} The TransactionManager instance
20
+ * @throws {Error} If no TransactionManager is found in context
21
+ */
22
+ export function getTransactionManagerContext() {
23
+ const manager = getContext(TRANSACTION_MANAGER_CONTEXT_KEY);
24
+ if (!manager) {
25
+ throw new Error('TransactionManager not found. Did you forget to setTransactionManagerContext?');
26
+ }
27
+ return manager;
28
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Hook for accessing the transaction manager in the application.
3
+ * Provides access to the transactions store for monitoring transaction states.
4
+ *
5
+ * This hook connects to the TransactionManager context which handles order removal
6
+ * transactions and related operations.
7
+ *
8
+ * @returns An object containing the transactions store that can be subscribed to
9
+ */
10
+ export declare function useTransactions(): {
11
+ manager: import("./TransactionManager").TransactionManager;
12
+ transactions: import("svelte/store").Readable<import("../../models/Transaction").Transaction[]>;
13
+ };
@@ -0,0 +1,18 @@
1
+ import { getTransactionManagerContext } from './context';
2
+ /**
3
+ * Hook for accessing the transaction manager in the application.
4
+ * Provides access to the transactions store for monitoring transaction states.
5
+ *
6
+ * This hook connects to the TransactionManager context which handles order removal
7
+ * transactions and related operations.
8
+ *
9
+ * @returns An object containing the transactions store that can be subscribed to
10
+ */
11
+ export function useTransactions() {
12
+ const manager = getTransactionManagerContext();
13
+ const transactions = manager.getTransactions();
14
+ return {
15
+ manager,
16
+ transactions
17
+ };
18
+ }
@@ -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;