From 3ea855a3ffadf5571709f0a12d775d32d7e7b72d Mon Sep 17 00:00:00 2001 From: findolor Date: Mon, 9 Sep 2024 10:49:34 +0300 Subject: [PATCH 1/2] refactor: rename watchlist naming to accounts --- crates/settings/src/config.rs | 20 +++---- crates/settings/src/config_source.rs | 10 ++-- crates/settings/src/merge.rs | 52 +++++++++---------- crates/settings/src/scenario.rs | 2 +- .../ListViewOrderbookSelector.svelte | 4 +- .../dropdown/DropdownOrderListAccounts.svelte | 14 +++++ ...t.ts => DropdownOrderListAccounts.test.ts} | 36 ++++++------- .../DropdownOrderListWatchlist.svelte | 14 ----- .../components/tables/OrdersListTable.svelte | 6 +-- .../components/tables/VaultListTable.svelte | 6 +-- tauri-app/src/lib/mocks/settings.ts | 2 +- tauri-app/src/lib/stores/settings.ts | 18 +++---- tauri-app/src/tests/pickConfig.test.ts | 4 +- 13 files changed, 93 insertions(+), 95 deletions(-) create mode 100644 tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.svelte rename tauri-app/src/lib/components/dropdown/{DropdownOrderListWatchlist.test.ts => DropdownOrderListAccounts.test.ts} (60%) delete mode 100644 tauri-app/src/lib/components/dropdown/DropdownOrderListWatchlist.svelte diff --git a/crates/settings/src/config.rs b/crates/settings/src/config.rs index bbe724303..7636881ed 100644 --- a/crates/settings/src/config.rs +++ b/crates/settings/src/config.rs @@ -35,7 +35,7 @@ pub struct Config { pub sentry: Option, pub raindex_version: Option, #[typeshare(typescript(type = "Record"))] - pub watchlist: Option>>, + pub accounts: Option>>, } pub type Subgraph = Url; @@ -171,7 +171,7 @@ impl TryFrom for Config { }) .collect::>, ParseConfigSourceError>>()?; - let watchlist = item.watchlist.map(|wl| { + let accounts = item.accounts.map(|wl| { wl.into_iter() .map(|(name, address)| (name, Arc::new(address))) .collect::>>() @@ -190,7 +190,7 @@ impl TryFrom for Config { charts, deployments, sentry: item.sentry, - watchlist, + accounts, }; Ok(config) @@ -282,7 +282,7 @@ mod tests { let charts = HashMap::new(); let deployments = HashMap::new(); let sentry = Some(true); - let watchlist = Some(HashMap::from([( + let accounts = Some(HashMap::from([( "name-one".to_string(), "address-one".to_string(), )])); @@ -301,7 +301,7 @@ mod tests { charts, deployments, sentry, - watchlist, + accounts, }; let config_result = Config::try_from(config_string); @@ -361,11 +361,11 @@ mod tests { // Verify raindex_version assert_eq!(config.raindex_version, Some("0x123".to_string())); - // Verify watchlist - assert!(config.watchlist.is_some()); - let watchlist = config.watchlist.as_ref().unwrap(); - assert_eq!(watchlist.len(), 1); - let (name, address) = watchlist.iter().next().unwrap(); + // Verify accounts + assert!(config.accounts.is_some()); + let accounts = config.accounts.as_ref().unwrap(); + assert_eq!(accounts.len(), 1); + let (name, address) = accounts.iter().next().unwrap(); assert_eq!(name, "name-one"); assert_eq!(address.as_str(), "address-one"); } diff --git a/crates/settings/src/config_source.rs b/crates/settings/src/config_source.rs index 95e143d40..8d3a2eca0 100644 --- a/crates/settings/src/config_source.rs +++ b/crates/settings/src/config_source.rs @@ -39,7 +39,7 @@ pub struct ConfigSource { #[serde(skip_serializing_if = "Option::is_none")] pub raindex_version: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub watchlist: Option>, + pub accounts: Option>, } #[typeshare] @@ -375,7 +375,7 @@ deployments: sentry: true -watchlist: +accounts: name-one: address-one name-two: address-two"#, mocked_chain_id_server.url("/json") @@ -483,9 +483,9 @@ watchlist: assert_eq!(config.raindex_version, Some("123".to_string())); - let watchlist = config.watchlist.unwrap(); - assert_eq!(watchlist.get("name-one").unwrap(), "address-one"); - assert_eq!(watchlist.get("name-two").unwrap(), "address-two"); + let accounts = config.accounts.unwrap(); + assert_eq!(accounts.get("name-one").unwrap(), "address-one"); + assert_eq!(accounts.get("name-two").unwrap(), "address-two"); } #[tokio::test] diff --git a/crates/settings/src/merge.rs b/crates/settings/src/merge.rs index feb2f67b0..d2a4e3b0f 100644 --- a/crates/settings/src/merge.rs +++ b/crates/settings/src/merge.rs @@ -37,8 +37,8 @@ pub enum MergeError { #[error("There is already a remote networks definition called {0}")] RemoteNetworksCollision(String), - #[error("There is already a watchlist called {0}")] - WatchlistCollision(String), + #[error("There is already a accounts called {0}")] + AccountsCollision(String), } impl ConfigSource { @@ -150,18 +150,18 @@ impl ConfigSource { (Some(_), Some(_)) => Err(MergeError::DeploymentCollision("sentry".into())), }?; - // Watchlist - match (&mut self.watchlist, other.watchlist) { - (Some(watchlist), Some(other_watchlist)) => { - for (key, value) in other_watchlist { - if watchlist.contains_key(&key) { - return Err(MergeError::WatchlistCollision(key)); + // Accounts + match (&mut self.accounts, other.accounts) { + (Some(accounts), Some(other_accounts)) => { + for (key, value) in other_accounts { + if accounts.contains_key(&key) { + return Err(MergeError::AccountsCollision(key)); } - watchlist.insert(key, value); + accounts.insert(key, value); } } - (None, Some(other_watchlist)) => { - self.watchlist = Some(other_watchlist); + (None, Some(other_accounts)) => { + self.accounts = Some(other_accounts); } _ => {} } @@ -270,18 +270,18 @@ impl Config { (Some(_), Some(_)) => Err(MergeError::DeploymentCollision("sentry".into())), }?; - // Watchlist - match (&mut self.watchlist, other.watchlist) { - (Some(watchlist), Some(other_watchlist)) => { - for (key, value) in other_watchlist { - if watchlist.contains_key(&key) { - return Err(MergeError::WatchlistCollision(key)); + // Accounts + match (&mut self.accounts, other.accounts) { + (Some(accounts), Some(other_accounts)) => { + for (key, value) in other_accounts { + if accounts.contains_key(&key) { + return Err(MergeError::AccountsCollision(key)); } - watchlist.insert(key, value); + accounts.insert(key, value); } } - (None, Some(other_watchlist)) => { - self.watchlist = Some(other_watchlist); + (None, Some(other_accounts)) => { + self.accounts = Some(other_accounts); } _ => {} } @@ -312,7 +312,7 @@ mod tests { networks: HashMap::new(), deployments: HashMap::new(), sentry: None, - watchlist: None, + accounts: None, }; let other = ConfigSource { @@ -329,7 +329,7 @@ mod tests { networks: HashMap::new(), deployments: HashMap::new(), sentry: None, - watchlist: None, + accounts: None, }; assert_eq!(config.merge(other), Ok(())); @@ -351,7 +351,7 @@ mod tests { networks: HashMap::new(), deployments: HashMap::new(), sentry: None, - watchlist: None, + accounts: None, }; let mut other = ConfigSource { @@ -368,7 +368,7 @@ mod tests { networks: HashMap::new(), deployments: HashMap::new(), sentry: None, - watchlist: None, + accounts: None, }; // Add a collision to cause an unsuccessful merge @@ -404,7 +404,7 @@ mod tests { networks: HashMap::new(), deployments: HashMap::new(), sentry: None, - watchlist: None, + accounts: None, }; let mut other = ConfigSource { @@ -421,7 +421,7 @@ mod tests { networks: HashMap::new(), deployments: HashMap::new(), sentry: None, - watchlist: None, + accounts: None, }; other.metaboards.insert( diff --git a/crates/settings/src/scenario.rs b/crates/settings/src/scenario.rs index 6d457d6df..701307dd3 100644 --- a/crates/settings/src/scenario.rs +++ b/crates/settings/src/scenario.rs @@ -213,7 +213,7 @@ mod tests { charts: HashMap::new(), // Assuming no charts for simplification deployments: HashMap::new(), sentry: None, - watchlist: None, // Assuming no watchlist for simplification + accounts: None, // Assuming no accounts for simplification }; // Perform the conversion diff --git a/tauri-app/src/lib/components/ListViewOrderbookSelector.svelte b/tauri-app/src/lib/components/ListViewOrderbookSelector.svelte index 193f5b421..12fe98d38 100644 --- a/tauri-app/src/lib/components/ListViewOrderbookSelector.svelte +++ b/tauri-app/src/lib/components/ListViewOrderbookSelector.svelte @@ -2,7 +2,7 @@ import { isEmpty } from 'lodash'; import DropdownActiveNetwork from './DropdownActiveNetwork.svelte'; import DropdownActiveOrderbook from './DropdownActiveOrderbook.svelte'; - import DropdownOrderListWatchlist from './dropdown/DropdownOrderListWatchlist.svelte'; + import DropdownOrderListAccounts from './dropdown/DropdownOrderListAccounts.svelte'; import DropdownOrderStatus from './dropdown/DropdownOrderStatus.svelte'; import { settings } from '$lib/stores/settings'; import { Alert } from 'flowbite-svelte'; @@ -15,7 +15,7 @@ > {:else} - + {/if} diff --git a/tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.svelte b/tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.svelte new file mode 100644 index 000000000..90050e9a8 --- /dev/null +++ b/tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.svelte @@ -0,0 +1,14 @@ + + + diff --git a/tauri-app/src/lib/components/dropdown/DropdownOrderListWatchlist.test.ts b/tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.test.ts similarity index 60% rename from tauri-app/src/lib/components/dropdown/DropdownOrderListWatchlist.test.ts rename to tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.test.ts index 53d71c4d0..1e0a6b93a 100644 --- a/tauri-app/src/lib/components/dropdown/DropdownOrderListWatchlist.test.ts +++ b/tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.test.ts @@ -1,7 +1,7 @@ import { render, fireEvent, screen, waitFor } from '@testing-library/svelte'; import { get, writable } from 'svelte/store'; -import DropdownOrderListWatchlist from './DropdownOrderListWatchlist.svelte'; -import { activeWatchlistItems } from '$lib/stores/settings'; +import DropdownOrderListAccounts from './DropdownOrderListAccounts.svelte'; +import { activeAccountsItems } from '$lib/stores/settings'; import { expect, test, vi } from 'vitest'; vi.mock('$lib/stores/settings', async (importOriginal) => { @@ -9,23 +9,23 @@ vi.mock('$lib/stores/settings', async (importOriginal) => { return { ...((await importOriginal()) as object), settings: mockSettingsStore, - watchlist: writable({ + accounts: writable({ address1: 'Label 1', address2: 'Label 2', address3: 'Label 3', }), - activeWatchlist: writable({}), - activeWatchlistItems: writable({}), + activeAccounts: writable({}), + activeAccountItems: writable({}), }; }); test('renders correctly', () => { - render(DropdownOrderListWatchlist); - expect(screen.getByText('Watchlist')).toBeInTheDocument(); + render(DropdownOrderListAccounts); + expect(screen.getByText('Accounts')).toBeInTheDocument(); }); test('displays the correct number of options', async () => { - render(DropdownOrderListWatchlist); + render(DropdownOrderListAccounts); await fireEvent.click(screen.getByTestId('dropdown-checkbox-button')); @@ -35,25 +35,25 @@ test('displays the correct number of options', async () => { }); }); -test('updates active watchlist when an option is selected', async () => { - render(DropdownOrderListWatchlist); +test('updates active accounts when an option is selected', async () => { + render(DropdownOrderListAccounts); await fireEvent.click(screen.getByTestId('dropdown-checkbox-button')); await fireEvent.click(screen.getByText('Label 1')); await waitFor(() => { - expect(get(activeWatchlistItems)).toEqual({ address1: 'Label 1' }); + expect(get(activeAccountsItems)).toEqual({ address1: 'Label 1' }); }); }); test('selects all items when "All addresses" is clicked', async () => { - render(DropdownOrderListWatchlist); + render(DropdownOrderListAccounts); await fireEvent.click(screen.getByTestId('dropdown-checkbox-button')); await fireEvent.click(screen.getByText('All addresses')); await waitFor(() => { - expect(get(activeWatchlistItems)).toEqual({ + expect(get(activeAccountsItems)).toEqual({ address1: 'Label 1', address2: 'Label 2', address3: 'Label 3', @@ -61,19 +61,17 @@ test('selects all items when "All addresses" is clicked', async () => { }); }); -test('displays "No watchlist added" when watchlist is empty', async () => { +test('displays "No accounts added" when accounts list is empty', async () => { vi.doUnmock('$lib/stores/settings'); vi.resetModules(); - const { default: DropdownOrderListWatchlist } = await import( - './DropdownOrderListWatchlist.svelte' - ); + const { default: DropdownOrderListAccounts } = await import('./DropdownOrderListAccounts.svelte'); - render(DropdownOrderListWatchlist); + render(DropdownOrderListAccounts); await fireEvent.click(screen.getByTestId('dropdown-checkbox-button')); await waitFor(() => { - expect(screen.getByText('No watchlist added')).toBeInTheDocument(); + expect(screen.getByText('No accounts added')).toBeInTheDocument(); }); }); diff --git a/tauri-app/src/lib/components/dropdown/DropdownOrderListWatchlist.svelte b/tauri-app/src/lib/components/dropdown/DropdownOrderListWatchlist.svelte deleted file mode 100644 index db9b7317f..000000000 --- a/tauri-app/src/lib/components/dropdown/DropdownOrderListWatchlist.svelte +++ /dev/null @@ -1,14 +0,0 @@ - - - diff --git a/tauri-app/src/lib/components/tables/OrdersListTable.svelte b/tauri-app/src/lib/components/tables/OrdersListTable.svelte index da6e7f180..d1b412f6c 100644 --- a/tauri-app/src/lib/components/tables/OrdersListTable.svelte +++ b/tauri-app/src/lib/components/tables/OrdersListTable.svelte @@ -21,15 +21,15 @@ import { subgraphUrl } from '$lib/stores/settings'; import { formatTimestampSecondsAsLocal } from '$lib/utils/time'; import { handleOrderRemoveModal } from '$lib/services/modal'; - import { activeWatchlist, activeOrderStatus } from '$lib/stores/settings'; + import { activeAccounts, activeOrderStatus } from '$lib/stores/settings'; import { get } from 'svelte/store'; $: query = createInfiniteQuery({ - queryKey: [QKEY_ORDERS, $activeWatchlist, $activeOrderStatus], + queryKey: [QKEY_ORDERS, $activeAccounts, $activeOrderStatus], queryFn: ({ pageParam }) => { return ordersList( $subgraphUrl, - Object.values(get(activeWatchlist)), + Object.values(get(activeAccounts)), $activeOrderStatus, pageParam, ); diff --git a/tauri-app/src/lib/components/tables/VaultListTable.svelte b/tauri-app/src/lib/components/tables/VaultListTable.svelte index ec3dac891..86955b2b2 100644 --- a/tauri-app/src/lib/components/tables/VaultListTable.svelte +++ b/tauri-app/src/lib/components/tables/VaultListTable.svelte @@ -19,13 +19,13 @@ handleDepositModal, handleWithdrawModal, } from '$lib/services/modal'; - import { activeWatchlist } from '$lib/stores/settings'; + import { activeAccounts } from '$lib/stores/settings'; import { get } from 'svelte/store'; $: query = createInfiniteQuery({ - queryKey: [QKEY_VAULTS, $activeWatchlist], + queryKey: [QKEY_VAULTS, $activeAccounts], queryFn: ({ pageParam }) => { - return vaultList($subgraphUrl, Object.values(get(activeWatchlist)), pageParam); + return vaultList($subgraphUrl, Object.values(get(activeAccounts)), pageParam); }, initialPageParam: 0, getNextPageParam(lastPage, _allPages, lastPageParam) { diff --git a/tauri-app/src/lib/mocks/settings.ts b/tauri-app/src/lib/mocks/settings.ts index beab1514c..d90d7ec41 100644 --- a/tauri-app/src/lib/mocks/settings.ts +++ b/tauri-app/src/lib/mocks/settings.ts @@ -31,7 +31,7 @@ const mockConfigSource: ConfigSource = { metaboards: { metaboard1: 'https://example.com/metaboard1', }, - watchlist: { + accounts: { name_one: 'address_one', name_two: 'address_two', }, diff --git a/tauri-app/src/lib/stores/settings.ts b/tauri-app/src/lib/stores/settings.ts index 162ab532f..a83a145a5 100644 --- a/tauri-app/src/lib/stores/settings.ts +++ b/tauri-app/src/lib/stores/settings.ts @@ -103,11 +103,11 @@ export const hasRequiredSettings = derived( $activeNetworkRef !== undefined && $activeOrderbookRef !== undefined, ); -// watchlist -export const watchlist = derived(settings, ($settings) => $settings?.watchlist ?? {}); +// accounts +export const accounts = derived(settings, ($settings) => $settings?.accounts ?? {}); -export const activeWatchlistItems = cachedWritableStore>( - 'settings.activeWatchlistItems', +export const activeAccountsItems = cachedWritableStore>( + 'settings.activeAccountsItems', {}, JSON.stringify, (s) => { @@ -119,13 +119,13 @@ export const activeWatchlistItems = cachedWritableStore>( }, ); -export const activeWatchlist = derived( - [watchlist, activeWatchlistItems], - ([$watchlist, $activeWatchlistItems]) => - Object.keys($activeWatchlistItems).length === 0 +export const activeAccounts = derived( + [accounts, activeAccountsItems], + ([$accounts, $activeAccountsItems]) => + Object.keys($activeAccountsItems).length === 0 ? {} : Object.fromEntries( - Object.entries($watchlist).filter(([key]) => key in $activeWatchlistItems), + Object.entries($accounts).filter(([key]) => key in $activeAccountsItems), ), ); diff --git a/tauri-app/src/tests/pickConfig.test.ts b/tauri-app/src/tests/pickConfig.test.ts index 9185fafa3..ffcb4d473 100644 --- a/tauri-app/src/tests/pickConfig.test.ts +++ b/tauri-app/src/tests/pickConfig.test.ts @@ -151,7 +151,7 @@ export const config: Config = { }, }, }, - watchlist: { + accounts: { name_one: 'address_one', name_two: 'address_two', }, @@ -218,7 +218,7 @@ export const configSource: ConfigSource = { order: 'sell', }, }, - watchlist: { + accounts: { name_one: 'address_one', name_two: 'address_two', }, From 02245bf5e3ab654f7c8a556422f897b63709ff01 Mon Sep 17 00:00:00 2001 From: findolor Date: Mon, 9 Sep 2024 13:35:27 +0300 Subject: [PATCH 2/2] test: update test --- .../lib/components/dropdown/DropdownOrderListAccounts.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.test.ts b/tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.test.ts index 1e0a6b93a..3940b2332 100644 --- a/tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.test.ts +++ b/tauri-app/src/lib/components/dropdown/DropdownOrderListAccounts.test.ts @@ -46,11 +46,11 @@ test('updates active accounts when an option is selected', async () => { }); }); -test('selects all items when "All addresses" is clicked', async () => { +test('selects all items when "All accounts" is clicked', async () => { render(DropdownOrderListAccounts); await fireEvent.click(screen.getByTestId('dropdown-checkbox-button')); - await fireEvent.click(screen.getByText('All addresses')); + await fireEvent.click(screen.getByText('All accounts')); await waitFor(() => { expect(get(activeAccountsItems)).toEqual({