@rainlanguage/ui-components 0.0.1-alpha.13 → 0.0.1-alpha.130

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,111 @@
1
+ import { sortBy } from 'lodash';
2
+ /**
3
+ * Filters out data points with duplicate timestamps, keeping only the first occurrence.
4
+ *
5
+ * @param data Array of data points with time and value properties
6
+ * @returns A new array with only unique timestamps
7
+ */
8
+ export const deduplicateByTime = (data) => {
9
+ const uniqueData = [];
10
+ const seenTimes = new Set();
11
+ for (const dataPoint of data) {
12
+ if (!seenTimes.has(dataPoint.time)) {
13
+ uniqueData.push(dataPoint);
14
+ seenTimes.add(dataPoint.time);
15
+ }
16
+ }
17
+ return uniqueData;
18
+ };
19
+ /**
20
+ * Transforms and sorts data, ensuring unique timestamps.
21
+ *
22
+ * @param data The source data to transform
23
+ * @param options Configuration object with transform functions
24
+ * @returns Transformed, sorted, and deduplicated data
25
+ */
26
+ export const transformAndSortData = (data, options) => {
27
+ const { valueTransform, timeTransform } = options;
28
+ const transformedData = data.map((d) => ({
29
+ value: valueTransform(d),
30
+ time: timeTransform(d)
31
+ }));
32
+ const sortedData = sortBy(transformedData, (d) => d.time);
33
+ return deduplicateByTime(sortedData);
34
+ };
35
+ if (import.meta.vitest) {
36
+ const { it, expect, describe } = import.meta.vitest;
37
+ describe('deduplicateByTime', () => {
38
+ it('should remove entries with duplicate timestamps', () => {
39
+ const data = [
40
+ { time: 100, value: 10 },
41
+ { time: 200, value: 20 },
42
+ { time: 200, value: 25 }, // Duplicate timestamp
43
+ { time: 300, value: 30 }
44
+ ];
45
+ const result = deduplicateByTime(data);
46
+ const expected = [
47
+ { time: 100, value: 10 },
48
+ { time: 200, value: 20 }, // First occurrence kept
49
+ { time: 300, value: 30 }
50
+ ];
51
+ expect(result).toEqual(expected);
52
+ });
53
+ it('should handle multiple duplicate timestamps', () => {
54
+ const data = [
55
+ { time: 100, value: 10 },
56
+ { time: 100, value: 15 }, // Duplicate
57
+ { time: 100, value: 18 }, // Duplicate
58
+ { time: 200, value: 20 }
59
+ ];
60
+ const result = deduplicateByTime(data);
61
+ const expected = [
62
+ { time: 100, value: 10 }, // Only first one kept
63
+ { time: 200, value: 20 }
64
+ ];
65
+ expect(result).toEqual(expected);
66
+ });
67
+ it('should return original array if no duplicates', () => {
68
+ const data = [
69
+ { time: 100, value: 10 },
70
+ { time: 200, value: 20 },
71
+ { time: 300, value: 30 }
72
+ ];
73
+ const result = deduplicateByTime(data);
74
+ expect(result).toEqual(data);
75
+ expect(result).not.toBe(data);
76
+ });
77
+ it('should handle empty array', () => {
78
+ const data = [];
79
+ const result = deduplicateByTime(data);
80
+ expect(result).toEqual([]);
81
+ });
82
+ });
83
+ describe('transformAndSortData', () => {
84
+ it('should transform, sort, and deduplicate data', () => {
85
+ const rawData = [
86
+ { timestamp: 3000, price: 300 },
87
+ { timestamp: 1000, price: 100 },
88
+ { timestamp: 2000, price: 200 },
89
+ { timestamp: 2000, price: 250 } // Duplicate timestamp
90
+ ];
91
+ const result = transformAndSortData(rawData, {
92
+ valueTransform: (item) => item.price,
93
+ timeTransform: (item) => item.timestamp
94
+ });
95
+ const expected = [
96
+ { time: 1000, value: 100 },
97
+ { time: 2000, value: 200 }, // First occurrence kept after sorting
98
+ { time: 3000, value: 300 }
99
+ ];
100
+ expect(result).toEqual(expected);
101
+ });
102
+ it('should handle empty data array', () => {
103
+ const rawData = [];
104
+ const result = transformAndSortData(rawData, {
105
+ valueTransform: (item) => item.price,
106
+ timeTransform: (item) => item.timestamp
107
+ });
108
+ expect(result).toEqual([]);
109
+ });
110
+ });
111
+ }
@@ -0,0 +1,11 @@
1
+ <script>import { Checkbox } from "flowbite-svelte";
2
+ export let showInactiveOrders;
3
+ let checked = $showInactiveOrders ? true : false;
4
+ function handleChange() {
5
+ $showInactiveOrders = !$showInactiveOrders;
6
+ }
7
+ </script>
8
+
9
+ <div data-testid="order-status-checkbox">
10
+ <Checkbox {checked} on:change={handleChange}>Include inactive orders</Checkbox>
11
+ </div>
@@ -0,0 +1,19 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { AppStoresInterface } from '../../types/appStores';
3
+ declare const __propDef: {
4
+ props: {
5
+ showInactiveOrders: AppStoresInterface["showInactiveOrders"];
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ exports?: {} | undefined;
12
+ bindings?: string | undefined;
13
+ };
14
+ export type CheckboxActiveOrdersProps = typeof __propDef.props;
15
+ export type CheckboxActiveOrdersEvents = typeof __propDef.events;
16
+ export type CheckboxActiveOrdersSlots = typeof __propDef.slots;
17
+ export default class CheckboxActiveOrders extends SvelteComponent<CheckboxActiveOrdersProps, CheckboxActiveOrdersEvents, CheckboxActiveOrdersSlots> {
18
+ }
19
+ export {};
@@ -2,6 +2,7 @@
2
2
  export let active;
3
3
  export let buttonText;
4
4
  export let clickHandler;
5
+ export let dataTestId;
5
6
  </script>
6
7
 
7
8
  <Button
@@ -9,6 +10,7 @@ export let clickHandler;
9
10
  color="alternative"
10
11
  class={active ? 'border-2 border-blue-300 dark:border-blue-700' : 'border-2 border-transparent'}
11
12
  on:click={clickHandler}
13
+ data-testid={dataTestId}
12
14
  >
13
15
  {buttonText}
14
16
  </Button>
@@ -4,6 +4,7 @@ declare const __propDef: {
4
4
  active: boolean;
5
5
  buttonText: string;
6
6
  clickHandler: () => void;
7
+ dataTestId: string;
7
8
  };
8
9
  events: {
9
10
  [evt: string]: CustomEvent<any>;
@@ -2,15 +2,17 @@
2
2
  import { RainlangLR } from "codemirror-rainlang";
3
3
  import { lightCodeMirrorTheme } from "../../utils/codeMirrorThemes";
4
4
  import { Button, Modal } from "flowbite-svelte";
5
- export let gui;
5
+ import { useGui } from "../../hooks/useGui";
6
+ const gui = useGui();
6
7
  let rainlangText = null;
7
8
  let open = false;
8
9
  async function generateRainlang() {
9
- const rainlang = await gui.getComposedRainlang();
10
- if (rainlang) {
11
- rainlangText = rainlang;
12
- open = true;
10
+ let result = await gui.getComposedRainlang();
11
+ if (result.error) {
12
+ throw new Error(result.error.msg);
13
13
  }
14
+ rainlangText = result.value;
15
+ open = true;
14
16
  }
15
17
  </script>
16
18
 
@@ -1,9 +1,6 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { DotrainOrderGui } from '@rainlanguage/orderbook/js_api';
3
2
  declare const __propDef: {
4
- props: {
5
- gui: DotrainOrderGui;
6
- };
3
+ props: Record<string, never>;
7
4
  events: {
8
5
  [evt: string]: CustomEvent<any>;
9
6
  };
@@ -1,4 +1,5 @@
1
- <script>export let title;
1
+ <script>import Markdown from "svelte-markdown";
2
+ export let title;
2
3
  export let description = "";
3
4
  </script>
4
5
 
@@ -7,8 +8,10 @@ export let description = "";
7
8
  {title}
8
9
  </h1>
9
10
  {#if description}
10
- <p class="break-words text-sm font-light text-gray-600 lg:text-base dark:text-gray-400">
11
- {description}
12
- </p>
11
+ <div
12
+ class="prose prose-sm lg:prose-base prose-neutral dark:prose-invert text-gray-600 dark:text-gray-400"
13
+ >
14
+ <Markdown source={description} />
15
+ </div>
13
16
  {/if}
14
17
  </div>
@@ -1,252 +1,236 @@
1
- <script>import { Alert } from "flowbite-svelte";
2
- import TokenIOSection from "./TokenIOSection.svelte";
3
- import DepositsSection from "./DepositsSection.svelte";
4
- import SelectTokensSection from "./SelectTokensSection.svelte";
1
+ <script>import { Alert, Button, Spinner, Toggle } from "flowbite-svelte";
2
+ import TokenIOInput from "./TokenIOInput.svelte";
5
3
  import ComposedRainlangModal from "./ComposedRainlangModal.svelte";
6
- import FieldDefinitionsSection from "./FieldDefinitionsSection.svelte";
7
- import {} from "@rainlanguage/orderbook/js_api";
8
- import WalletConnect from "../wallet/WalletConnect.svelte";
9
4
  import {
10
5
  DotrainOrderGui
11
- } from "@rainlanguage/orderbook/js_api";
12
- import { fade } from "svelte/transition";
13
- import { Button, Toggle, Spinner } from "flowbite-svelte";
14
- import {} from "@wagmi/core";
6
+ } from "@rainlanguage/orderbook";
7
+ import WalletConnect from "../wallet/WalletConnect.svelte";
15
8
  import {} from "svelte/store";
16
- import ShareChoicesButton from "./ShareChoicesButton.svelte";
17
9
  import { handleShareChoices } from "../../services/handleShareChoices";
18
- import { getDeploymentTransactionArgs } from "./getDeploymentTransactionArgs";
19
10
  import { DeploymentStepsError, DeploymentStepsErrorCode } from "../../errors";
20
11
  import { onMount } from "svelte";
21
- export let settings;
22
- export let dotrain;
12
+ import FieldDefinitionInput from "./FieldDefinitionInput.svelte";
13
+ import DepositInput from "./DepositInput.svelte";
14
+ import SelectToken from "./SelectToken.svelte";
15
+ import DeploymentSectionHeader from "./DeploymentSectionHeader.svelte";
16
+ import { useGui } from "../../hooks/useGui";
17
+ import { fade } from "svelte/transition";
18
+ import ShareChoicesButton from "./ShareChoicesButton.svelte";
19
+ import { useRegistry } from "../../providers/registry/useRegistry";
23
20
  export let deployment;
24
21
  export let strategyDetail;
25
- export let gui;
26
- export let handleDeployModal;
27
- export let handleDisclaimerModal;
22
+ export let onDeploy;
23
+ export let wagmiConnected;
24
+ export let appKitModal;
25
+ export let settings;
26
+ export let account;
28
27
  let allDepositFields = [];
29
28
  let allTokenOutputs = [];
29
+ let allTokenInputs = [];
30
30
  let allFieldDefinitionsWithoutDefaults = [];
31
31
  let allFieldDefinitionsWithDefaults = [];
32
32
  let allTokensSelected = false;
33
33
  let showAdvancedOptions = false;
34
- let checkingDeployment = false;
35
34
  let allTokenInfos = [];
36
- const selectTokens = gui.getSelectTokens();
37
- const networkKey = gui.getNetworkKey();
38
- const subgraphUrl = $settings?.subgraphs?.[networkKey] ?? "";
35
+ let selectTokens = void 0;
36
+ let checkingDeployment = false;
37
+ let subgraphUrl = void 0;
38
+ const gui = useGui();
39
+ const registry = useRegistry();
39
40
  let deploymentStepsError = DeploymentStepsError.error;
40
- export let wagmiConfig;
41
- export let wagmiConnected;
42
- export let appKitModal;
43
- export let signerAddress;
44
41
  onMount(async () => {
45
- await areAllTokensSelected();
46
- });
47
- function getAllFieldDefinitions() {
48
- try {
49
- allFieldDefinitionsWithoutDefaults = gui.getAllFieldDefinitions(false);
50
- allFieldDefinitionsWithDefaults = gui.getAllFieldDefinitions(true);
51
- } catch (e) {
52
- DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_FIELD_DEFINITIONS);
42
+ const selectTokensResult = gui.getSelectTokens();
43
+ if (selectTokensResult.error) {
44
+ throw new Error(selectTokensResult.error.msg);
53
45
  }
54
- }
55
- async function getAllDepositFields() {
56
- try {
57
- let dep = gui.getCurrentDeployment();
58
- let depositFields = dep.deposits;
59
- allDepositFields = depositFields;
60
- } catch (e) {
61
- DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_DEPOSITS);
46
+ selectTokens = selectTokensResult.value;
47
+ const { value, error } = gui.getNetworkKey();
48
+ if (error) {
49
+ DeploymentStepsError.catch(error, DeploymentStepsErrorCode.NO_NETWORK_KEY);
50
+ } else if (value) {
51
+ subgraphUrl = $settings.orderbook.subgraphs[value].url;
62
52
  }
53
+ await areAllTokensSelected();
54
+ });
55
+ $: if (selectTokens?.length === 0 || allTokensSelected) {
56
+ updateFields();
63
57
  }
64
- let allTokenInputs = [];
65
- function getAllTokenInputs() {
58
+ function getAllGuiConfig() {
66
59
  try {
67
- allTokenInputs = gui.getCurrentDeployment().deployment.order.inputs;
60
+ let result = gui.getAllGuiConfig();
61
+ if (result.error) {
62
+ throw new Error(result.error.msg);
63
+ }
64
+ allFieldDefinitionsWithoutDefaults = result.value.fieldDefinitionsWithoutDefaults;
65
+ allFieldDefinitionsWithDefaults = result.value.fieldDefinitionsWithDefaults;
66
+ allDepositFields = result.value.deposits;
67
+ allTokenOutputs = result.value.orderOutputs;
68
+ allTokenInputs = result.value.orderInputs;
68
69
  } catch (e) {
69
- DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_TOKEN_INPUTS);
70
+ DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_GUI_CONFIG);
70
71
  }
71
72
  }
72
- function getAllTokenOutputs() {
73
- try {
74
- allTokenOutputs = gui.getCurrentDeployment().deployment.order.outputs;
75
- } catch (e) {
76
- DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_TOKEN_OUTPUTS);
77
- }
78
- }
79
- $: if (selectTokens?.length === 0 || allTokensSelected) {
80
- updateFields();
81
- }
82
- async function updateFields() {
73
+ function updateFields() {
83
74
  try {
84
75
  DeploymentStepsError.clear();
85
- getAllDepositFields();
86
- getAllFieldDefinitions();
87
- getAllTokenInputs();
88
- getAllTokenOutputs();
76
+ getAllGuiConfig();
89
77
  } catch (e) {
90
78
  DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_GUI);
91
79
  }
92
80
  }
93
81
  async function _handleShareChoices() {
94
- await handleShareChoices(gui);
82
+ await handleShareChoices(gui, registry.getCurrentRegistry());
95
83
  }
96
84
  async function onSelectTokenSelect() {
97
85
  await areAllTokensSelected();
98
86
  if (allTokensSelected) {
99
- let newAllTokenInfos = await gui.getAllTokenInfos();
87
+ let result = await gui.getAllTokenInfos();
88
+ if (result.error) {
89
+ throw new Error(result.error.msg);
90
+ }
91
+ let newAllTokenInfos = result.value;
100
92
  if (allTokenInfos !== newAllTokenInfos) {
101
93
  allTokenInfos = newAllTokenInfos;
102
- getAllDepositFields();
103
- getAllFieldDefinitions();
94
+ getAllGuiConfig();
104
95
  }
105
96
  }
106
97
  }
107
- async function handleDeployButtonClick() {
108
- DeploymentStepsError.clear();
109
- if (!allTokenOutputs) {
110
- DeploymentStepsError.catch(null, DeploymentStepsErrorCode.NO_TOKEN_OUTPUTS);
111
- return;
112
- }
113
- if (!wagmiConfig) {
114
- DeploymentStepsError.catch(null, DeploymentStepsErrorCode.NO_CHAIN);
115
- return;
98
+ const areAllTokensSelected = async () => {
99
+ try {
100
+ const areAllTokensSelectedResult = gui.areAllTokensSelected();
101
+ if (areAllTokensSelectedResult.error) {
102
+ throw new Error(areAllTokensSelectedResult.error.msg);
103
+ }
104
+ allTokensSelected = areAllTokensSelectedResult.value;
105
+ if (!allTokensSelected) return;
106
+ const getAllTokenInfosResult = await gui.getAllTokenInfos();
107
+ if (getAllTokenInfosResult.error) {
108
+ throw new Error(getAllTokenInfosResult.error.msg);
109
+ }
110
+ allTokenInfos = getAllTokenInfosResult.value;
111
+ const hasDepositsResult = gui.hasAnyDeposit();
112
+ if (hasDepositsResult.error) {
113
+ throw new Error(hasDepositsResult.error.msg);
114
+ }
115
+ const hasVaultIdsResult = gui.hasAnyVaultId();
116
+ if (hasVaultIdsResult.error) {
117
+ throw new Error(hasVaultIdsResult.error.msg);
118
+ }
119
+ if (hasDepositsResult.value || hasVaultIdsResult.value) {
120
+ showAdvancedOptions = true;
121
+ }
122
+ } catch (e) {
123
+ DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_SELECT_TOKENS);
116
124
  }
117
- if (!networkKey) {
118
- DeploymentStepsError.catch(null, DeploymentStepsErrorCode.NO_CHAIN);
125
+ };
126
+ async function handleDeployButtonClick() {
127
+ if (checkingDeployment) {
119
128
  return;
120
129
  }
121
- let result = null;
122
130
  checkingDeployment = true;
123
131
  try {
124
- result = await getDeploymentTransactionArgs(gui, $wagmiConfig);
132
+ if (!$account) {
133
+ DeploymentStepsError.catch(
134
+ "No wallet connected",
135
+ DeploymentStepsErrorCode.ADD_ORDER_FAILED
136
+ );
137
+ return;
138
+ }
139
+ DeploymentStepsError.clear();
140
+ return onDeploy(gui, subgraphUrl);
125
141
  } catch (e) {
126
- checkingDeployment = false;
127
142
  DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
128
- }
129
- if (!result) {
143
+ } finally {
130
144
  checkingDeployment = false;
131
- DeploymentStepsError.catch(null, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
132
- return;
133
145
  }
134
- checkingDeployment = false;
135
- const onAccept = () => {
136
- if (!networkKey) {
137
- DeploymentStepsError.catch(null, DeploymentStepsErrorCode.NO_CHAIN);
138
- return;
139
- }
140
- handleDeployModal({
141
- open: true,
142
- args: {
143
- ...result,
144
- subgraphUrl,
145
- network: networkKey
146
- }
147
- });
148
- };
149
- handleDisclaimerModal({
150
- open: true,
151
- onAccept
152
- });
153
146
  }
154
- const areAllTokensSelected = async () => {
155
- try {
156
- allTokensSelected = gui.areAllTokensSelected();
157
- if (!allTokensSelected) return;
158
- allTokenInfos = await gui.getAllTokenInfos();
159
- const hasDeposits = gui.hasAnyDeposit();
160
- const hasVaultIds = gui.hasAnyVaultId();
161
- if (hasDeposits || hasVaultIds) {
162
- showAdvancedOptions = true;
163
- }
164
- } catch (e) {
165
- DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_SELECT_TOKENS);
166
- }
167
- };
168
147
  </script>
169
148
 
170
149
  <div>
171
- {#if $deploymentStepsError}
172
- <Alert color="red">
173
- <p class="text-red-500">{$deploymentStepsError.code}</p>
174
- {#if $deploymentStepsError.details}
175
- <p class="text-red-500">{$deploymentStepsError.details}</p>
150
+ {#if gui}
151
+ <div class="flex max-w-3xl flex-col gap-12" in:fade>
152
+ {#if deployment}
153
+ <div class="flex max-w-2xl flex-col gap-4 text-start">
154
+ <h1 class="text-4xl font-semibold text-gray-900 lg:text-6xl dark:text-white">
155
+ {strategyDetail.name}
156
+ </h1>
157
+ <p class="text-xl text-gray-600 lg:text-2xl dark:text-gray-400">
158
+ {deployment.description}
159
+ </p>
160
+ </div>
161
+ {/if}
162
+
163
+ {#if selectTokens && selectTokens.length > 0}
164
+ <div class="flex w-full flex-col gap-4">
165
+ <DeploymentSectionHeader
166
+ title="Select Tokens"
167
+ description="Select the tokens that you want to use in your order."
168
+ />
169
+ {#each selectTokens as token}
170
+ <SelectToken {token} {onSelectTokenSelect} />
171
+ {/each}
172
+ </div>
176
173
  {/if}
177
- </Alert>
178
- {/if}
179
- {#if dotrain}
180
- {#if gui}
181
- <div class="flex max-w-3xl flex-col gap-12" in:fade>
182
- {#if deployment}
183
- <div class="flex max-w-2xl flex-col gap-4 text-start">
184
- <h1 class=" text-4xl font-semibold text-gray-900 lg:text-6xl dark:text-white">
185
- {strategyDetail.name}
186
- </h1>
187
- <p class="text-xl text-gray-600 lg:text-2xl dark:text-gray-400">
188
- {deployment.description}
189
- </p>
190
- </div>
191
- {/if}
192
174
 
193
- {#if selectTokens && selectTokens.length > 0}
194
- <SelectTokensSection {gui} {selectTokens} {onSelectTokenSelect} />
175
+ {#if allTokensSelected || selectTokens?.length === 0}
176
+ {#if allFieldDefinitionsWithoutDefaults.length > 0}
177
+ {#each allFieldDefinitionsWithoutDefaults as fieldDefinition}
178
+ <FieldDefinitionInput {fieldDefinition} />
179
+ {/each}
195
180
  {/if}
196
181
 
197
- {#if allTokensSelected || selectTokens?.length === 0}
198
- {#if allFieldDefinitionsWithoutDefaults.length > 0}
199
- <FieldDefinitionsSection
200
- allFieldDefinitions={allFieldDefinitionsWithoutDefaults}
201
- {gui}
202
- />
203
- {/if}
182
+ <Toggle bind:checked={showAdvancedOptions}>Show advanced options</Toggle>
204
183
 
205
- <Toggle bind:checked={showAdvancedOptions}>Show advanced options</Toggle>
184
+ {#if showAdvancedOptions}
185
+ {#each allFieldDefinitionsWithDefaults as fieldDefinition}
186
+ <FieldDefinitionInput {fieldDefinition} />
187
+ {/each}
206
188
 
207
- {#if allFieldDefinitionsWithDefaults.length > 0 && showAdvancedOptions}
208
- <FieldDefinitionsSection allFieldDefinitions={allFieldDefinitionsWithDefaults} {gui} />
209
- {/if}
189
+ {#each allDepositFields as deposit}
190
+ <DepositInput {deposit} />
191
+ {/each}
210
192
 
211
- {#if allDepositFields.length > 0 && showAdvancedOptions}
212
- <DepositsSection bind:allDepositFields {gui} />
213
- {/if}
214
-
215
- {#if allTokenInputs.length > 0 && allTokenOutputs.length > 0 && showAdvancedOptions}
216
- <TokenIOSection bind:allTokenInputs bind:allTokenOutputs {gui} />
217
- {/if}
193
+ {#each allTokenOutputs as output, i}
194
+ <TokenIOInput {i} label="Output" vault={output} />
195
+ {/each}
218
196
 
219
- {#if $deploymentStepsError}
220
- <Alert color="red">
221
- <p class="text-red-500">{$deploymentStepsError.code}</p>
222
- {#if $deploymentStepsError.details}
223
- <p class="text-red-500">{$deploymentStepsError.details}</p>
224
- {/if}
225
- </Alert>
226
- {/if}
197
+ {#each allTokenInputs as input, i}
198
+ <TokenIOInput {i} label="Input" vault={input} />
199
+ {/each}
200
+ {/if}
227
201
 
228
- <div class="flex flex-wrap items-start justify-start gap-2">
229
- {#if $wagmiConnected}
230
- <Button
231
- size="lg"
232
- on:click={handleDeployButtonClick}
233
- class="bg-gradient-to-br from-blue-600 to-violet-600"
234
- >
235
- {#if checkingDeployment}
236
- <Spinner size="4" color="white" />
237
- <span class="ml-2">Checking deployment...</span>
238
- {:else}
239
- Deploy Strategy
240
- {/if}
241
- </Button>
242
- {:else}
243
- <WalletConnect {appKitModal} connected={wagmiConnected} {signerAddress} />
202
+ {#if $deploymentStepsError}
203
+ <Alert color="red">
204
+ <p class="text-red-500">{$deploymentStepsError.code}</p>
205
+ {#if $deploymentStepsError.details}
206
+ <p class="text-red-500">{$deploymentStepsError.details}</p>
244
207
  {/if}
245
- <ComposedRainlangModal {gui} />
246
- <ShareChoicesButton handleShareChoices={_handleShareChoices} />
247
- </div>
208
+ </Alert>
248
209
  {/if}
249
- </div>
250
- {/if}
210
+
211
+ <div class="flex flex-wrap items-start justify-start gap-2">
212
+ {#if $account}
213
+ <Button
214
+ data-testid="deploy-button"
215
+ size="lg"
216
+ disabled={checkingDeployment}
217
+ on:click={handleDeployButtonClick}
218
+ class="bg-gradient-to-br from-blue-600 to-violet-600"
219
+ >
220
+ {#if checkingDeployment}
221
+ <Spinner size="4" color="white" />
222
+ <span class="ml-2">Checking deployment...</span>
223
+ {:else}
224
+ Deploy Strategy
225
+ {/if}
226
+ </Button>
227
+ {:else}
228
+ <WalletConnect {appKitModal} connected={wagmiConnected} />
229
+ {/if}
230
+ <ComposedRainlangModal />
231
+ <ShareChoicesButton handleShareChoices={_handleShareChoices} />
232
+ </div>
233
+ {/if}
234
+ </div>
251
235
  {/if}
252
236
  </div>