@rainlanguage/ui-components 0.0.1-alpha.150 → 0.0.1-alpha.152

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 (35) hide show
  1. package/dist/__mocks__/stores.d.ts +0 -21
  2. package/dist/__mocks__/stores.js +0 -19
  3. package/dist/components/ListViewOrderbookFilters.svelte +10 -8
  4. package/dist/components/ListViewOrderbookFilters.svelte.d.ts +0 -2
  5. package/dist/components/deployment/DeploymentSteps.svelte +70 -6
  6. package/dist/components/deployment/SelectToken.svelte +7 -3
  7. package/dist/components/deployment/SelectToken.svelte.d.ts +3 -1
  8. package/dist/components/deployment/TokenBalance.svelte +19 -0
  9. package/dist/components/deployment/TokenBalance.svelte.d.ts +19 -0
  10. package/dist/components/deployment/TokenIOInput.svelte +11 -5
  11. package/dist/components/deployment/TokenIOInput.svelte.d.ts +2 -0
  12. package/dist/components/deployment/VaultIdInformation.svelte +17 -0
  13. package/dist/components/deployment/VaultIdInformation.svelte.d.ts +21 -0
  14. package/dist/components/detail/OrderDetail.svelte +2 -2
  15. package/dist/components/detail/OrderDetail.svelte.d.ts +1 -1
  16. package/dist/components/dropdown/DropdownActiveNetworks.svelte +30 -38
  17. package/dist/components/dropdown/DropdownActiveNetworks.svelte.d.ts +0 -2
  18. package/dist/components/dropdown/DropdownOrderListAccounts.svelte +4 -2
  19. package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +0 -1
  20. package/dist/components/tables/OrderTradesListTable.svelte +3 -3
  21. package/dist/components/tables/OrderTradesListTable.svelte.d.ts +2 -2
  22. package/dist/components/tables/OrdersListTable.svelte +3 -6
  23. package/dist/components/tables/OrdersListTable.svelte.d.ts +0 -2
  24. package/dist/components/tables/VaultsListTable.svelte +5 -14
  25. package/dist/components/tables/VaultsListTable.svelte.d.ts +3 -4
  26. package/dist/index.d.ts +1 -2
  27. package/dist/index.js +1 -2
  28. package/dist/types/appStores.d.ts +1 -2
  29. package/dist/types/tokenBalance.d.ts +6 -0
  30. package/dist/types/tokenBalance.js +1 -0
  31. package/dist/utils/configHelpers.d.ts +1 -1
  32. package/dist/utils/configHelpers.js +7 -5
  33. package/package.json +2 -2
  34. package/dist/__mocks__/settings.d.ts +0 -7
  35. package/dist/__mocks__/settings.js +0 -72
@@ -1,10 +1,6 @@
1
- import type { AccountCfg, NewConfig } from '@rainlanguage/orderbook';
2
1
  import { type Config } from '@wagmi/core';
3
2
  declare const initialPageState: {
4
3
  data: {
5
- stores: {
6
- settings: {};
7
- };
8
4
  dotrain: string;
9
5
  deployment: {
10
6
  key: string;
@@ -20,14 +16,6 @@ declare const initialPageState: {
20
16
  id: null;
21
17
  };
22
18
  };
23
- export declare const mockSettingsStore: {
24
- subscribe: (this: void, run: import("svelte/store").Subscriber<NewConfig>, invalidate?: import("svelte/store").Invalidator<NewConfig> | undefined) => import("svelte/store").Unsubscriber;
25
- set: (this: void, value: NewConfig) => void;
26
- mockSetSubscribeValue: (value: NewConfig) => void;
27
- };
28
- export declare const mockAccountsStore: {
29
- subscribe: (this: void, run: import("svelte/store").Subscriber<Record<string, AccountCfg>>, invalidate?: import("svelte/store").Invalidator<Record<string, AccountCfg>> | undefined) => import("svelte/store").Unsubscriber;
30
- };
31
19
  export declare const mockActiveAccountsItemsStore: {
32
20
  subscribe: (this: void, run: import("svelte/store").Subscriber<Record<string, string>>, invalidate?: import("svelte/store").Invalidator<Record<string, string>> | undefined) => import("svelte/store").Unsubscriber;
33
21
  set: (this: void, value: Record<string, string>) => void;
@@ -98,9 +86,6 @@ export declare const mockSelectedChainIdsStore: {
98
86
  export declare const mockPageStore: {
99
87
  subscribe: (this: void, run: import("svelte/store").Subscriber<{
100
88
  data: {
101
- stores: {
102
- settings: {};
103
- };
104
89
  dotrain: string;
105
90
  deployment: {
106
91
  key: string;
@@ -117,9 +102,6 @@ export declare const mockPageStore: {
117
102
  };
118
103
  }>, invalidate?: import("svelte/store").Invalidator<{
119
104
  data: {
120
- stores: {
121
- settings: {};
122
- };
123
105
  dotrain: string;
124
106
  deployment: {
125
107
  key: string;
@@ -137,9 +119,6 @@ export declare const mockPageStore: {
137
119
  }> | undefined) => import("svelte/store").Unsubscriber;
138
120
  set: (this: void, value: {
139
121
  data: {
140
- stores: {
141
- settings: {};
142
- };
143
122
  dotrain: string;
144
123
  deployment: {
145
124
  key: string;
@@ -1,6 +1,4 @@
1
- import { parseYaml } from '@rainlanguage/orderbook';
2
1
  import { writable } from 'svelte/store';
3
- import settingsYamlContent from '../__fixtures__/settings.yaml?raw';
4
2
  import {} from '@wagmi/core';
5
3
  import { mockWeb3Config } from './mockWeb3Config';
6
4
  if (import.meta.vitest) {
@@ -11,15 +9,8 @@ if (import.meta.vitest) {
11
9
  };
12
10
  });
13
11
  }
14
- // Parse the YAML settings
15
- const parseResult = parseYaml([settingsYamlContent]);
16
- if (parseResult.error) {
17
- throw new Error(`Failed to parse settings YAML: ${parseResult.error.readableMsg}`);
18
- }
19
- const settingsFixture = parseResult.value;
20
12
  const initialPageState = {
21
13
  data: {
22
- stores: { settings: {} },
23
14
  dotrain: 'some dotrain content',
24
15
  deployment: { key: 'deploy-key' },
25
16
  orderDetail: {}
@@ -34,8 +25,6 @@ const initialPageState = {
34
25
  }
35
26
  };
36
27
  const mockPageWritable = writable(initialPageState);
37
- const mockSettingsWritable = writable(settingsFixture);
38
- const mockAccountsWritable = writable({});
39
28
  const mockActiveAccountsItemsWritable = writable({});
40
29
  const mockShowInactiveOrdersWritable = writable(true);
41
30
  const mockOrderHashWritable = writable('');
@@ -49,14 +38,6 @@ const mockConnectedWritable = writable(true);
49
38
  const mockWagmiConfigWritable = writable(mockWeb3Config);
50
39
  const mockShowMyItemsOnlyWritable = writable(false);
51
40
  const mockSelectedChainIdsWritable = writable([]);
52
- export const mockSettingsStore = {
53
- subscribe: mockSettingsWritable.subscribe,
54
- set: mockSettingsWritable.set,
55
- mockSetSubscribeValue: (value) => mockSettingsWritable.set(value)
56
- };
57
- export const mockAccountsStore = {
58
- subscribe: mockAccountsWritable.subscribe
59
- };
60
41
  export const mockActiveAccountsItemsStore = {
61
42
  subscribe: mockActiveAccountsItemsWritable.subscribe,
62
43
  set: mockActiveAccountsItemsWritable.set,
@@ -1,4 +1,5 @@
1
- <script generics="T">import DropdownActiveNetworks from "./dropdown/DropdownActiveNetworks.svelte";
1
+ <script generics="T">import { useRaindexClient } from "../hooks/useRaindexClient";
2
+ import DropdownActiveNetworks from "./dropdown/DropdownActiveNetworks.svelte";
2
3
  import { page } from "$app/stores";
3
4
  import { isEmpty } from "lodash";
4
5
  import { Alert } from "flowbite-svelte";
@@ -10,8 +11,6 @@ import InputOrderHash from "./input/InputOrderHash.svelte";
10
11
  import CheckboxZeroBalanceVault from "./CheckboxZeroBalanceVault.svelte";
11
12
  import CheckboxMyItemsOnly from "./CheckboxMyItemsOnly.svelte";
12
13
  import { useAccount } from "../providers/wallet/useAccount";
13
- export let settings;
14
- export let accounts;
15
14
  export let hideZeroBalanceVaults;
16
15
  export let activeAccountsItems;
17
16
  export let showMyItemsOnly;
@@ -24,18 +23,21 @@ export let tokensQuery;
24
23
  $: isVaultsPage = $page.url.pathname === "/vaults";
25
24
  $: isOrdersPage = $page.url.pathname === "/orders";
26
25
  const { account } = useAccount();
26
+ const raindexClient = useRaindexClient();
27
+ $: networks = raindexClient.getAllNetworks();
28
+ $: accounts = raindexClient.getAllAccounts();
27
29
  </script>
28
30
 
29
31
  <div
30
32
  class="grid w-full items-center gap-4 md:flex md:justify-end lg:min-w-[600px]"
31
33
  style="grid-template-columns: repeat(2, minmax(0, 1fr));"
32
34
  >
33
- {#if isEmpty($settings.orderbook.networks)}
35
+ {#if networks.error || isEmpty(networks.value)}
34
36
  <Alert color="gray" data-testid="no-networks-alert" class="w-full">
35
37
  No networks added to <a class="underline" href="/settings">settings</a>
36
38
  </Alert>
37
39
  {:else}
38
- {#if $accounts && !Object.values($accounts).length}
40
+ {#if !accounts.error && accounts.value.size === 0}
39
41
  <div class="mt-4 w-full lg:w-auto" data-testid="my-items-only">
40
42
  <CheckboxMyItemsOnly context={isVaultsPage ? 'vaults' : 'orders'} {showMyItemsOnly} />
41
43
  {#if !$account}
@@ -55,10 +57,10 @@ const { account } = useAccount();
55
57
  <CheckboxActiveOrders {showInactiveOrders} />
56
58
  </div>
57
59
  {/if}
58
- {#if $accounts && Object.values($accounts).length > 0}
59
- <DropdownOrderListAccounts {accounts} {activeAccountsItems} />
60
+ {#if !accounts.error && accounts.value.size > 0}
61
+ <DropdownOrderListAccounts {activeAccountsItems} />
60
62
  {/if}
61
63
  <DropdownTokensFilter {tokensQuery} {activeTokens} {selectedTokens} label="Tokens" />
62
- <DropdownActiveNetworks settings={$settings} {selectedChainIds} />
64
+ <DropdownActiveNetworks {selectedChainIds} />
63
65
  {/if}
64
66
  </div>
@@ -5,8 +5,6 @@ import type { Address, RaindexVaultToken } from '@rainlanguage/orderbook';
5
5
  import type { AppStoresInterface } from '../types/appStores';
6
6
  declare class __sveltets_Render<T> {
7
7
  props(): {
8
- settings: AppStoresInterface["settings"];
9
- accounts: AppStoresInterface["accounts"];
10
8
  hideZeroBalanceVaults: AppStoresInterface["hideZeroBalanceVaults"];
11
9
  activeAccountsItems: AppStoresInterface["activeAccountsItems"];
12
10
  showMyItemsOnly: AppStoresInterface["showMyItemsOnly"];
@@ -3,13 +3,14 @@ import TokenIOInput from "./TokenIOInput.svelte";
3
3
  import ComposedRainlangModal from "./ComposedRainlangModal.svelte";
4
4
  import {
5
5
  DotrainOrderGui,
6
- RaindexClient
6
+ RaindexClient,
7
+ AccountBalance
7
8
  } from "@rainlanguage/orderbook";
8
9
  import WalletConnect from "../wallet/WalletConnect.svelte";
9
10
  import {} from "svelte/store";
10
11
  import { handleShareChoices } from "../../services/handleShareChoices";
11
12
  import { DeploymentStepsError, DeploymentStepsErrorCode } from "../../errors";
12
- import { onMount } from "svelte";
13
+ import { onDestroy, onMount } from "svelte";
13
14
  import FieldDefinitionInput from "./FieldDefinitionInput.svelte";
14
15
  import DepositInput from "./DepositInput.svelte";
15
16
  import SelectToken from "./SelectToken.svelte";
@@ -37,6 +38,7 @@ let selectTokens = void 0;
37
38
  let checkingDeployment = false;
38
39
  let availableTokens = [];
39
40
  let loadingTokens = false;
41
+ let tokenBalances = /* @__PURE__ */ new Map();
40
42
  const gui = useGui();
41
43
  const registry = useRegistry();
42
44
  const raindexClient = useRaindexClient();
@@ -53,6 +55,22 @@ onMount(async () => {
53
55
  $: if (selectTokens?.length === 0 || allTokensSelected) {
54
56
  updateFields();
55
57
  }
58
+ let unsubscribeAccount = account.subscribe((account2) => {
59
+ if (!account2) {
60
+ const balances = tokenBalances;
61
+ balances.clear();
62
+ tokenBalances = balances;
63
+ return;
64
+ }
65
+ if (selectTokens) {
66
+ selectTokens.forEach(async (selectToken) => {
67
+ await getTokenInfoAndFetchBalance(selectToken.key);
68
+ });
69
+ }
70
+ });
71
+ onDestroy(() => {
72
+ unsubscribeAccount();
73
+ });
56
74
  async function loadAvailableTokens() {
57
75
  if (loadingTokens) return;
58
76
  loadingTokens = true;
@@ -95,8 +113,48 @@ function updateFields() {
95
113
  async function _handleShareChoices() {
96
114
  await handleShareChoices(gui, registry.getCurrentRegistry());
97
115
  }
98
- async function onSelectTokenSelect() {
116
+ async function fetchTokenBalance(tokenInfo) {
117
+ if (!$account) return;
118
+ const balances = tokenBalances;
119
+ balances.set(tokenInfo.key, {
120
+ value: { balance: BigInt(0), formattedBalance: "0" },
121
+ loading: true,
122
+ error: ""
123
+ });
124
+ const { value: accountBalance, error } = await gui.getAccountBalance(
125
+ tokenInfo.address,
126
+ $account
127
+ );
128
+ if (error) {
129
+ balances.set(tokenInfo.key, {
130
+ value: { balance: BigInt(0), formattedBalance: "0" },
131
+ loading: false,
132
+ error: error.readableMsg
133
+ });
134
+ tokenBalances = balances;
135
+ return;
136
+ }
137
+ balances.set(tokenInfo.key, {
138
+ value: accountBalance,
139
+ loading: false,
140
+ error: ""
141
+ });
142
+ tokenBalances = balances;
143
+ }
144
+ async function getTokenInfoAndFetchBalance(key) {
145
+ const tokenInfoResult = await gui.getTokenInfo(key);
146
+ if (tokenInfoResult.error) {
147
+ throw new Error(tokenInfoResult.error.msg);
148
+ }
149
+ const tokenInfo = tokenInfoResult.value;
150
+ if (!tokenInfo || !tokenInfo.address) {
151
+ return;
152
+ }
153
+ await fetchTokenBalance(tokenInfo);
154
+ }
155
+ async function onSelectTokenSelect(key) {
99
156
  await areAllTokensSelected();
157
+ await getTokenInfoAndFetchBalance(key);
100
158
  if (allTokensSelected) {
101
159
  let result = await gui.getAllTokenInfos();
102
160
  if (result.error) {
@@ -181,7 +239,13 @@ async function handleDeployButtonClick() {
181
239
  description="Select the tokens that you want to use in your order."
182
240
  />
183
241
  {#each selectTokens as token}
184
- <SelectToken {token} {onSelectTokenSelect} {availableTokens} loading={loadingTokens} />
242
+ <SelectToken
243
+ {token}
244
+ {onSelectTokenSelect}
245
+ {availableTokens}
246
+ loading={loadingTokens}
247
+ {tokenBalances}
248
+ />
185
249
  {/each}
186
250
  </div>
187
251
  {/if}
@@ -205,11 +269,11 @@ async function handleDeployButtonClick() {
205
269
  {/each}
206
270
 
207
271
  {#each allTokenOutputs as output}
208
- <TokenIOInput label="Output" vault={output} />
272
+ <TokenIOInput label="Output" vault={output} {tokenBalances} />
209
273
  {/each}
210
274
 
211
275
  {#each allTokenInputs as input}
212
- <TokenIOInput label="Input" vault={input} />
276
+ <TokenIOInput label="Input" vault={input} {tokenBalances} />
213
277
  {/each}
214
278
  {/if}
215
279
 
@@ -5,10 +5,12 @@ import { onMount } from "svelte";
5
5
  import { useGui } from "../../hooks/useGui";
6
6
  import ButtonSelectOption from "./ButtonSelectOption.svelte";
7
7
  import TokenSelectionModal from "./TokenSelectionModal.svelte";
8
+ import TokenBalanceComponent from "./TokenBalance.svelte";
8
9
  export let token;
9
10
  export let onSelectTokenSelect;
10
11
  export let availableTokens = [];
11
12
  export let loading = false;
13
+ export let tokenBalances = /* @__PURE__ */ new Map();
12
14
  let inputValue = null;
13
15
  let tokenInfo = null;
14
16
  let error = "";
@@ -24,8 +26,9 @@ onMount(async () => {
24
26
  throw new Error(result.error.msg);
25
27
  }
26
28
  tokenInfo = result.value;
27
- if (result.value?.address) {
29
+ if (result.value.address) {
28
30
  inputValue = result.value.address;
31
+ onSelectTokenSelect(token.key);
29
32
  }
30
33
  } catch {
31
34
  }
@@ -93,12 +96,12 @@ async function saveTokenSelection(address) {
93
96
  error = errorMessage;
94
97
  } finally {
95
98
  checking = false;
96
- onSelectTokenSelect();
99
+ onSelectTokenSelect(token.key);
97
100
  }
98
101
  }
99
102
  function clearTokenSelection() {
100
103
  gui.unsetSelectToken(token.key);
101
- onSelectTokenSelect();
104
+ onSelectTokenSelect(token.key);
102
105
  }
103
106
  async function getInfoForSelectedToken() {
104
107
  error = "";
@@ -207,6 +210,7 @@ async function handleInput(event) {
207
210
  >
208
211
  <CheckCircleSolid class="h-5 w-5" color="green" />
209
212
  <span>{tokenInfo.name}</span>
213
+ <TokenBalanceComponent tokenBalance={tokenBalances.get(token.key)} />
210
214
  </div>
211
215
  {:else if error}
212
216
  <div class="flex h-5 flex-row items-center gap-2" data-testid="error">
@@ -1,11 +1,13 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import type { GuiSelectTokensCfg, TokenInfo } from '@rainlanguage/orderbook';
3
+ import type { TokenBalance } from '../../types/tokenBalance';
3
4
  declare const __propDef: {
4
5
  props: {
5
6
  token: GuiSelectTokensCfg;
6
- onSelectTokenSelect: () => void;
7
+ onSelectTokenSelect: (key: string) => void;
7
8
  availableTokens?: TokenInfo[];
8
9
  loading?: boolean;
10
+ tokenBalances?: Map<string, TokenBalance>;
9
11
  };
10
12
  events: {
11
13
  [evt: string]: CustomEvent<any>;
@@ -0,0 +1,19 @@
1
+ <script>import { Spinner } from "flowbite-svelte";
2
+ export let tokenBalance;
3
+ </script>
4
+
5
+ {#if tokenBalance}
6
+ {#if tokenBalance.loading}
7
+ <div class="flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400">
8
+ <Spinner class="h-4 w-4" />
9
+ </div>
10
+ {:else if !tokenBalance.error}
11
+ <div class="text-sm text-gray-600 dark:text-gray-400">
12
+ Balance: {tokenBalance.value.formattedBalance}
13
+ </div>
14
+ {:else if tokenBalance.error}
15
+ <div class="text-sm text-red-600 dark:text-red-400">
16
+ {tokenBalance.error}
17
+ </div>
18
+ {/if}
19
+ {/if}
@@ -0,0 +1,19 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { TokenBalance } from '../../types/tokenBalance';
3
+ declare const __propDef: {
4
+ props: {
5
+ tokenBalance: TokenBalance | undefined;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ exports?: {} | undefined;
12
+ bindings?: string | undefined;
13
+ };
14
+ export type TokenBalanceProps = typeof __propDef.props;
15
+ export type TokenBalanceEvents = typeof __propDef.events;
16
+ export type TokenBalanceSlots = typeof __propDef.slots;
17
+ export default class TokenBalance extends SvelteComponent<TokenBalanceProps, TokenBalanceEvents, TokenBalanceSlots> {
18
+ }
19
+ export {};
@@ -1,11 +1,12 @@
1
1
  <script>import { Input } from "flowbite-svelte";
2
2
  import {} from "@rainlanguage/orderbook";
3
- import DeploymentSectionHeader from "./DeploymentSectionHeader.svelte";
4
3
  import { onMount } from "svelte";
5
4
  import { useGui } from "../../hooks/useGui";
5
+ import VaultIdInformation from "./VaultIdInformation.svelte";
6
6
  const gui = useGui();
7
7
  export let label;
8
8
  export let vault;
9
+ export let tokenBalances = /* @__PURE__ */ new Map();
9
10
  let tokenInfo = null;
10
11
  let inputValue = "";
11
12
  let error = "";
@@ -56,10 +57,15 @@ $: if (vault.token?.key) {
56
57
  </script>
57
58
 
58
59
  <div class="flex w-full flex-col gap-6">
59
- <DeploymentSectionHeader
60
- title={`${label} ${tokenInfo?.symbol ? `(${tokenInfo.symbol})` : ''}`}
61
- description={`${tokenInfo?.symbol || 'Token'} vault ID`}
62
- />
60
+ <div class="flex w-full flex-col gap-2">
61
+ <div class="flex items-center gap-2">
62
+ <VaultIdInformation
63
+ title={`${label} ${tokenInfo?.symbol ? `(${tokenInfo.symbol})` : ''}`}
64
+ description={`${tokenInfo?.symbol || 'Token'} vault ID`}
65
+ tokenBalance={tokenBalances.get(vault.token?.key || '')}
66
+ />
67
+ </div>
68
+ </div>
63
69
  <div class="flex flex-col gap-2">
64
70
  <Input
65
71
  data-testid="vault-id-input"
@@ -1,9 +1,11 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import { type OrderIOCfg } from '@rainlanguage/orderbook';
3
+ import type { TokenBalance } from '../../types/tokenBalance';
3
4
  declare const __propDef: {
4
5
  props: {
5
6
  label: "Input" | "Output";
6
7
  vault: OrderIOCfg;
8
+ tokenBalances?: Map<string, TokenBalance>;
7
9
  };
8
10
  events: {
9
11
  [evt: string]: CustomEvent<any>;
@@ -0,0 +1,17 @@
1
+ <script>import TokenBalanceComponent from "./TokenBalance.svelte";
2
+ export let title;
3
+ export let description;
4
+ export let tokenBalance;
5
+ </script>
6
+
7
+ <div class="flex max-w-xl flex-grow flex-col gap-y-4 text-left">
8
+ <h1 class="break-words text-xl font-semibold text-gray-900 lg:text-2xl dark:text-white">
9
+ {title}
10
+ </h1>
11
+ <div class="flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400">
12
+ <div class="text-gray-600 dark:text-gray-400">
13
+ {description}
14
+ </div>
15
+ <TokenBalanceComponent {tokenBalance} />
16
+ </div>
17
+ </div>
@@ -0,0 +1,21 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { TokenBalance } from '../../types/tokenBalance';
3
+ declare const __propDef: {
4
+ props: {
5
+ title: string;
6
+ description: string;
7
+ tokenBalance: TokenBalance | undefined;
8
+ };
9
+ events: {
10
+ [evt: string]: CustomEvent<any>;
11
+ };
12
+ slots: {};
13
+ exports?: {} | undefined;
14
+ bindings?: string | undefined;
15
+ };
16
+ export type VaultIdInformationProps = typeof __propDef.props;
17
+ export type VaultIdInformationEvents = typeof __propDef.events;
18
+ export type VaultIdInformationSlots = typeof __propDef.slots;
19
+ export default class VaultIdInformation extends SvelteComponent<VaultIdInformationProps, VaultIdInformationEvents, VaultIdInformationSlots> {
20
+ }
21
+ export {};
@@ -37,7 +37,7 @@ export let lightweightChartsTheme;
37
37
  export let orderbookAddress;
38
38
  export let orderHash;
39
39
  export let chainId;
40
- export let rpcUrls = void 0;
40
+ export let rpcs = void 0;
41
41
  export let onRemove;
42
42
  export let onDeposit;
43
43
  export let onWithdraw;
@@ -194,7 +194,7 @@ const handleRefresh = async () => {
194
194
  </div>
195
195
  </TabItem>
196
196
  <TabItem open title="Trades">
197
- <OrderTradesListTable order={data} {handleDebugTradeModal} {rpcUrls} />
197
+ <OrderTradesListTable order={data} {handleDebugTradeModal} {rpcs} />
198
198
  </TabItem>
199
199
  <TabItem title="Volume">
200
200
  <OrderVaultsVolTable order={data} />
@@ -11,7 +11,7 @@ declare const __propDef: {
11
11
  orderbookAddress: Address;
12
12
  orderHash: Hex;
13
13
  chainId: number;
14
- rpcUrls?: string[] | undefined;
14
+ rpcs?: string[] | undefined;
15
15
  /** Callback function when remove action is triggered for an order
16
16
  * @param order The order to remove
17
17
  */ onRemove: (raindexClient: RaindexClient, order: RaindexOrder) => void;
@@ -1,48 +1,40 @@
1
1
  <script>import DropdownCheckbox from "./DropdownCheckbox.svelte";
2
2
  import { getNetworkName } from "../../utils/getNetworkName";
3
- export let settings;
3
+ import { useRaindexClient } from "../../hooks/useRaindexClient";
4
+ const raindexClient = useRaindexClient();
4
5
  export let selectedChainIds;
5
- $: dropdownOptions = Object.keys(settings.orderbook.networks ?? {}).reduce((acc, key) => {
6
- const networkCfg = (settings.orderbook.networks ?? {})[key];
7
- const networkName = getNetworkName(Number(networkCfg.chainId)) ?? key;
8
- const existingKey = Object.keys(acc).find((existingKey2) => {
9
- const existingNetworkCfg = (settings.orderbook.networks ?? {})[existingKey2];
10
- return existingNetworkCfg.chainId === networkCfg.chainId;
11
- });
12
- if (!existingKey) {
13
- return {
14
- ...acc,
15
- [key]: networkName
16
- };
6
+ let dropdownOptions = {};
7
+ $: {
8
+ const uniqueChainIds = raindexClient.getUniqueChainIds();
9
+ if (uniqueChainIds.error) {
10
+ dropdownOptions = {};
11
+ } else {
12
+ dropdownOptions = Object.fromEntries(
13
+ uniqueChainIds.value.map((chainId) => [
14
+ String(chainId),
15
+ getNetworkName(chainId) ?? `Chain ${chainId}`
16
+ ])
17
+ );
17
18
  }
18
- return acc;
19
- }, {});
19
+ }
20
20
  function handleStatusChange(event) {
21
- let items = Object.keys(event.detail);
22
- const chainIds = Array.from(
23
- new Set(
24
- Object.values(items).map((key) => {
25
- const networkCfg = (settings.orderbook.networks ?? {})[key];
26
- return networkCfg.chainId;
27
- })
28
- )
29
- );
21
+ const chainIds = Object.keys(event.detail).map(Number);
30
22
  selectedChainIds.set(chainIds);
31
23
  }
32
- $: value = $selectedChainIds.reduce(
33
- (acc, chainId) => {
34
- const networkKey = Object.keys(settings.orderbook.networks ?? {}).find((key) => {
35
- const networkCfg = (settings.orderbook.networks ?? {})[key];
36
- return networkCfg.chainId === chainId;
37
- });
38
- if (networkKey) {
39
- const networkName = getNetworkName(chainId) ?? networkKey;
40
- acc[networkKey] = networkName;
41
- }
42
- return acc;
43
- },
44
- {}
45
- );
24
+ let value = {};
25
+ $: {
26
+ const networks = raindexClient.getAllNetworks();
27
+ if (networks.error) {
28
+ value = {};
29
+ } else {
30
+ value = Object.fromEntries(
31
+ $selectedChainIds.map((chainId) => [
32
+ String(chainId),
33
+ getNetworkName(chainId) ?? `Chain ${chainId}`
34
+ ])
35
+ );
36
+ }
37
+ }
46
38
  </script>
47
39
 
48
40
  <div data-testid="subgraphs-dropdown">
@@ -1,9 +1,7 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { NewConfig } from '@rainlanguage/orderbook';
3
2
  import type { AppStoresInterface } from '../../types/appStores';
4
3
  declare const __propDef: {
5
4
  props: {
6
- settings: NewConfig;
7
5
  selectedChainIds: AppStoresInterface["selectedChainIds"];
8
6
  };
9
7
  events: {
@@ -1,8 +1,10 @@
1
1
  <script>import DropdownCheckbox from "./DropdownCheckbox.svelte";
2
2
  import { getAccountsAsOptions } from "../../utils/configHelpers";
3
- export let accounts;
3
+ import { useRaindexClient } from "../../hooks/useRaindexClient";
4
4
  export let activeAccountsItems;
5
- $: options = getAccountsAsOptions($accounts);
5
+ const raindexClient = useRaindexClient();
6
+ $: accounts = raindexClient.getAllAccounts();
7
+ $: options = getAccountsAsOptions(accounts.value);
6
8
  </script>
7
9
 
8
10
  <div data-testid="accounts-dropdown">
@@ -2,7 +2,6 @@ import { SvelteComponent } from "svelte";
2
2
  import type { AppStoresInterface } from '../../types/appStores';
3
3
  declare const __propDef: {
4
4
  props: {
5
- accounts: AppStoresInterface["accounts"];
6
5
  activeAccountsItems: AppStoresInterface["activeAccountsItems"];
7
6
  };
8
7
  events: {
@@ -8,7 +8,7 @@ import Hash, { HashType } from "../Hash.svelte";
8
8
  import { BugOutline } from "flowbite-svelte-icons";
9
9
  import TableTimeFilters from "../charts/TableTimeFilters.svelte";
10
10
  export let order;
11
- export let rpcUrls = void 0;
11
+ export let rpcs = void 0;
12
12
  export let handleDebugTradeModal = void 0;
13
13
  let startTimestamp;
14
14
  let endTimestamp;
@@ -98,13 +98,13 @@ $: orderTradesQuery = createInfiniteQuery({
98
98
  )})
99
99
  </span>
100
100
  </TableBodyCell>
101
- {#if rpcUrls && handleDebugTradeModal}
101
+ {#if rpcs && handleDebugTradeModal}
102
102
  <TableBodyCell tdClass="py-2">
103
103
  <button
104
104
  data-testid="debug-trade-button"
105
105
  class="text-gray-500 hover:text-gray-700"
106
106
  on:click={() => {
107
- if (rpcUrls) handleDebugTradeModal(item.transaction.id, rpcUrls);
107
+ if (rpcs) handleDebugTradeModal(item.transaction.id, rpcs);
108
108
  }}
109
109
  >
110
110
  <BugOutline size="xs" />
@@ -3,8 +3,8 @@ import type { RaindexOrder } from '@rainlanguage/orderbook';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  order: RaindexOrder;
6
- rpcUrls?: string[] | undefined;
7
- handleDebugTradeModal?: ((hash: string, rpcUrls: string[]) => void) | undefined;
6
+ rpcs?: string[] | undefined;
7
+ handleDebugTradeModal?: ((hash: string, rpcs: string[]) => void) | undefined;
8
8
  };
9
9
  events: {
10
10
  [evt: string]: CustomEvent<any>;
@@ -19,10 +19,10 @@ import {
19
19
  } from "flowbite-svelte";
20
20
  import { useAccount } from "../../providers/wallet/useAccount";
21
21
  import { useRaindexClient } from "../../hooks/useRaindexClient";
22
+ import { getAllContexts } from "svelte";
23
+ const context = getAllContexts();
22
24
  export let handleOrderRemoveModal = void 0;
23
- export let settings;
24
25
  export let selectedChainIds;
25
- export let accounts;
26
26
  export let activeAccountsItems;
27
27
  export let showInactiveOrders;
28
28
  export let orderHash;
@@ -48,7 +48,6 @@ $: query = createInfiniteQuery({
48
48
  queryKey: [
49
49
  QKEY_ORDERS,
50
50
  $selectedChainIds,
51
- $settings,
52
51
  owners,
53
52
  $showInactiveOrders,
54
53
  $orderHash,
@@ -80,8 +79,6 @@ const AppTable = TanstackAppTable;
80
79
 
81
80
  <ListViewOrderbookFilters
82
81
  {selectedChainIds}
83
- {settings}
84
- {accounts}
85
82
  {activeAccountsItems}
86
83
  {showMyItemsOnly}
87
84
  {showInactiveOrders}
@@ -178,7 +175,7 @@ const AppTable = TanstackAppTable;
178
175
  <DropdownItem
179
176
  on:click={(e) => {
180
177
  e.stopPropagation();
181
- handleOrderRemoveModal(item, $query.refetch);
178
+ handleOrderRemoveModal(item, $query.refetch, context);
182
179
  }}>Remove</DropdownItem
183
180
  >
184
181
  </Dropdown>
@@ -3,9 +3,7 @@ import type { AppStoresInterface } from '../../types/appStores';
3
3
  declare class __sveltets_Render<T> {
4
4
  props(): {
5
5
  handleOrderRemoveModal?: any;
6
- settings: AppStoresInterface["settings"];
7
6
  selectedChainIds: AppStoresInterface["selectedChainIds"];
8
- accounts: AppStoresInterface["accounts"];
9
7
  activeAccountsItems: AppStoresInterface["activeAccountsItems"] | undefined;
10
8
  showInactiveOrders: AppStoresInterface["showInactiveOrders"];
11
9
  orderHash: AppStoresInterface["orderHash"];
@@ -13,10 +13,10 @@ import { RaindexVault } from "@rainlanguage/orderbook";
13
13
  import { QKEY_TOKENS, QKEY_VAULTS } from "../../queries/keys";
14
14
  import { useAccount } from "../../providers/wallet/useAccount";
15
15
  import { getNetworkName } from "../../utils/getNetworkName";
16
- export let accounts;
16
+ import { getAllContexts } from "svelte";
17
+ const context = getAllContexts();
17
18
  export let activeAccountsItems;
18
19
  export let orderHash;
19
- export let settings;
20
20
  export let showInactiveOrders;
21
21
  export let hideZeroBalanceVaults;
22
22
  export let activeTokens;
@@ -40,14 +40,7 @@ $: selectedTokens = $activeTokens?.filter(
40
40
  (address) => !$tokensQuery.data || $tokensQuery.data.some((t) => t.address === address)
41
41
  ) ?? [];
42
42
  $: query = createInfiniteQuery({
43
- queryKey: [
44
- QKEY_VAULTS,
45
- $hideZeroBalanceVaults,
46
- $selectedChainIds,
47
- $settings,
48
- owners,
49
- selectedTokens
50
- ],
43
+ queryKey: [QKEY_VAULTS, $hideZeroBalanceVaults, $selectedChainIds, owners, selectedTokens],
51
44
  queryFn: async ({ pageParam }) => {
52
45
  const result = await raindexClient.getVaults(
53
46
  $selectedChainIds,
@@ -74,8 +67,6 @@ const AppTable = TanstackAppTable;
74
67
  {#if $query}
75
68
  <ListViewOrderbookFilters
76
69
  {selectedChainIds}
77
- {settings}
78
- {accounts}
79
70
  {activeAccountsItems}
80
71
  {showMyItemsOnly}
81
72
  {showInactiveOrders}
@@ -186,7 +177,7 @@ const AppTable = TanstackAppTable;
186
177
  data-testid="deposit-button"
187
178
  on:click={(e) => {
188
179
  e.stopPropagation();
189
- handleDepositModal(item, $query.refetch);
180
+ handleDepositModal(item, $query.refetch, context);
190
181
  }}
191
182
  >Deposit
192
183
  </DropdownItem>
@@ -194,7 +185,7 @@ const AppTable = TanstackAppTable;
194
185
  data-testid="withdraw-button"
195
186
  on:click={(e) => {
196
187
  e.stopPropagation();
197
- handleWithdrawModal(item, $query.refetch);
188
+ handleWithdrawModal(item, $query.refetch, context);
198
189
  }}
199
190
  >Withdraw
200
191
  </DropdownItem>
@@ -1,19 +1,18 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import { RaindexVault } from '@rainlanguage/orderbook';
3
3
  import type { AppStoresInterface } from '../../types/appStores.ts';
4
+ import { getAllContexts } from 'svelte';
4
5
  declare class __sveltets_Render<T> {
5
6
  props(): {
6
- accounts: AppStoresInterface["accounts"];
7
7
  activeAccountsItems: AppStoresInterface["activeAccountsItems"];
8
8
  orderHash: AppStoresInterface["orderHash"];
9
- settings: AppStoresInterface["settings"];
10
9
  showInactiveOrders: AppStoresInterface["showInactiveOrders"];
11
10
  hideZeroBalanceVaults: AppStoresInterface["hideZeroBalanceVaults"];
12
11
  activeTokens: AppStoresInterface["activeTokens"];
13
12
  selectedChainIds: AppStoresInterface["selectedChainIds"];
14
13
  showMyItemsOnly: AppStoresInterface["showMyItemsOnly"];
15
- handleDepositModal?: ((vault: RaindexVault, refetch: () => void) => void) | undefined;
16
- handleWithdrawModal?: ((vault: RaindexVault, refetch: () => void) => void) | undefined;
14
+ handleDepositModal?: ((vault: RaindexVault, refetch: () => void, context: ReturnType<typeof getAllContexts>) => void) | undefined;
15
+ handleWithdrawModal?: ((vault: RaindexVault, refetch: () => void, context: ReturnType<typeof getAllContexts>) => void) | undefined;
17
16
  };
18
17
  events(): {} & {
19
18
  [evt: string]: CustomEvent<any>;
package/dist/index.d.ts CHANGED
@@ -93,6 +93,7 @@ export { default as RegistryProvider } from './providers/registry/RegistryProvid
93
93
  export { default as ToastProvider } from './providers/toasts/ToastProvider.svelte';
94
94
  export { default as TransactionProvider } from './providers/transactions/TransactionProvider.svelte';
95
95
  export { useGui } from './hooks/useGui';
96
+ export { useRaindexClient, RAINDEX_CLIENT_CONTEXT_KEY } from './hooks/useRaindexClient';
96
97
  export { useAccount } from './providers/wallet/useAccount';
97
98
  export { useRegistry } from './providers/registry/useRegistry';
98
99
  export { useToasts } from './providers/toasts/useToasts';
@@ -101,5 +102,3 @@ export { RegistryManager } from './providers/registry/RegistryManager';
101
102
  export { TransactionStore } from './models/Transaction';
102
103
  export { TransactionManager } from './providers/transactions/TransactionManager';
103
104
  export { mockPageStore } from './__mocks__/stores';
104
- export { mockConfig } from './__mocks__/settings';
105
- export { mockSettingsStore } from './__mocks__/settings';
package/dist/index.js CHANGED
@@ -95,6 +95,7 @@ export { default as ToastProvider } from './providers/toasts/ToastProvider.svelt
95
95
  export { default as TransactionProvider } from './providers/transactions/TransactionProvider.svelte';
96
96
  // Hooks
97
97
  export { useGui } from './hooks/useGui';
98
+ export { useRaindexClient, RAINDEX_CLIENT_CONTEXT_KEY } from './hooks/useRaindexClient';
98
99
  export { useAccount } from './providers/wallet/useAccount';
99
100
  export { useRegistry } from './providers/registry/useRegistry';
100
101
  export { useToasts } from './providers/toasts/useToasts';
@@ -105,5 +106,3 @@ export { TransactionStore } from './models/Transaction';
105
106
  export { TransactionManager } from './providers/transactions/TransactionManager';
106
107
  // Mocks
107
108
  export { mockPageStore } from './__mocks__/stores';
108
- export { mockConfig } from './__mocks__/settings';
109
- export { mockSettingsStore } from './__mocks__/settings';
@@ -1,7 +1,6 @@
1
1
  import type { Readable, Writable } from 'svelte/store';
2
- import type { AccountCfg, Address, Hex, NewConfig } from '@rainlanguage/orderbook';
2
+ import type { AccountCfg, Address, Hex } from '@rainlanguage/orderbook';
3
3
  export interface AppStoresInterface {
4
- settings: Writable<NewConfig>;
5
4
  selectedChainIds: Writable<number[]>;
6
5
  accounts: Readable<Record<string, AccountCfg>>;
7
6
  activeAccountsItems: Writable<Record<string, Address>> | undefined;
@@ -0,0 +1,6 @@
1
+ import type { AccountBalance } from '@rainlanguage/orderbook';
2
+ export interface TokenBalance {
3
+ value: AccountBalance;
4
+ loading: boolean;
5
+ error: string;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
1
  import type { AccountCfg } from '@rainlanguage/orderbook';
2
- export declare function getAccountsAsOptions(accounts: Record<string, AccountCfg>): {
2
+ export declare function getAccountsAsOptions(accounts?: Map<string, AccountCfg>): {
3
3
  [k: string]: string;
4
4
  };
@@ -1,14 +1,16 @@
1
1
  export function getAccountsAsOptions(accounts) {
2
- return Object.fromEntries(Object.entries(accounts).map(([key, value]) => [key, value.address]));
2
+ if (!accounts)
3
+ return {};
4
+ return Object.fromEntries(Array.from(accounts.entries()).map(([key, value]) => [key, value.address]));
3
5
  }
4
6
  if (import.meta.vitest) {
5
7
  const { expect, it, describe } = import.meta.vitest;
6
8
  describe('getAccountsAsOptions', () => {
7
9
  it('should return the correct accounts as options', () => {
8
- const accounts = {
9
- account1: { address: '0x1234567890abcdef', key: 'account1' },
10
- account2: { address: '0xabcdef1234567890', key: 'account2' }
11
- };
10
+ const accounts = new Map([
11
+ ['account1', { address: '0x1234567890abcdef', key: 'account1' }],
12
+ ['account2', { address: '0xabcdef1234567890', key: 'account2' }]
13
+ ]);
12
14
  const result = getAccountsAsOptions(accounts);
13
15
  expect(result).toEqual({
14
16
  account1: '0x1234567890abcdef',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainlanguage/ui-components",
3
- "version": "0.0.1-alpha.150",
3
+ "version": "0.0.1-alpha.152",
4
4
  "description": "A component library for building Svelte applications to be used with Raindex.",
5
5
  "license": "LicenseRef-DCL-1.0",
6
6
  "author": "Rain Open Source Software Ltd",
@@ -53,7 +53,7 @@
53
53
  "@fontsource/dm-sans": "5.1.0",
54
54
  "@imask/svelte": "7.6.1",
55
55
  "@observablehq/plot": "0.6.16",
56
- "@rainlanguage/orderbook": "0.0.1-alpha.150",
56
+ "@rainlanguage/orderbook": "0.0.1-alpha.152",
57
57
  "@reown/appkit": "1.6.4",
58
58
  "@reown/appkit-adapter-wagmi": "1.6.4",
59
59
  "@sentry/sveltekit": "7.120.0",
@@ -1,7 +0,0 @@
1
- import type { NewConfig } from '@rainlanguage/orderbook';
2
- export declare const mockConfig: NewConfig;
3
- export declare const mockSettingsStore: {
4
- subscribe: (this: void, run: import("svelte/store").Subscriber<NewConfig>, invalidate?: import("svelte/store").Invalidator<NewConfig> | undefined) => import("svelte/store").Unsubscriber;
5
- set: (this: void, value: NewConfig) => void;
6
- mockSetSubscribeValue: (value: NewConfig) => void;
7
- };
@@ -1,72 +0,0 @@
1
- import { writable } from 'svelte/store';
2
- export const mockConfig = {
3
- orderbook: {
4
- networks: {
5
- mainnet: {
6
- key: 'mainnet',
7
- rpcs: ['https://mainnet.infura.io/v3/YOUR-PROJECT-ID'],
8
- chainId: 1,
9
- label: 'Ethereum Mainnet',
10
- currency: 'ETH'
11
- }
12
- },
13
- subgraphs: {
14
- mainnet: {
15
- key: 'mainnet',
16
- url: 'https://api.thegraph.com/subgraphs/name/mainnet'
17
- },
18
- flare: {
19
- key: 'flare',
20
- url: 'https://api.thegraph.com/subgraphs/name/flare'
21
- },
22
- testnet: {
23
- key: 'testnet',
24
- url: 'https://api.thegraph.com/subgraphs/name/testnet'
25
- }
26
- },
27
- orderbooks: {
28
- orderbook1: {
29
- key: 'orderbook1',
30
- address: '0xOrderbookAddress1',
31
- network: {
32
- key: 'mainnet',
33
- rpc: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
34
- chainId: 1,
35
- label: 'Ethereum Mainnet',
36
- currency: 'ETH'
37
- },
38
- subgraph: {
39
- key: 'uniswap',
40
- url: 'https://api.thegraph.com/subgraphs/name/uniswap'
41
- },
42
- label: 'Orderbook 1'
43
- }
44
- },
45
- deployers: {
46
- deployer1: {
47
- key: 'deployer1',
48
- address: '0xDeployerAddress1',
49
- network: {
50
- key: 'mainnet',
51
- rpc: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
52
- chainId: 1,
53
- label: 'Ethereum Mainnet',
54
- currency: 'ETH'
55
- }
56
- }
57
- },
58
- metaboards: {
59
- metaboard1: 'https://example.com/metaboard1'
60
- },
61
- accounts: {
62
- name_one: 'address_one',
63
- name_two: 'address_two'
64
- }
65
- }
66
- };
67
- const mockSettingsStoreWritable = writable(mockConfig);
68
- export const mockSettingsStore = {
69
- subscribe: mockSettingsStoreWritable.subscribe,
70
- set: mockSettingsStoreWritable.set,
71
- mockSetSubscribeValue: (value) => mockSettingsStoreWritable.set(value)
72
- };