Skip to content

Commit

Permalink
Merge pull request #840 from rainlanguage/2024-09-09-watchlist-renaming
Browse files Browse the repository at this point in the history
Renaming watchlist to accounts
  • Loading branch information
findolor authored Sep 9, 2024
2 parents 29161eb + 26c6dd4 commit 6c46137
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 97 deletions.
20 changes: 10 additions & 10 deletions crates/settings/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct Config {
pub sentry: Option<bool>,
pub raindex_version: Option<String>,
#[typeshare(typescript(type = "Record<string, string>"))]
pub watchlist: Option<HashMap<String, Arc<String>>>,
pub accounts: Option<HashMap<String, Arc<String>>>,
}

pub type Subgraph = Url;
Expand Down Expand Up @@ -171,7 +171,7 @@ impl TryFrom<ConfigSource> for Config {
})
.collect::<Result<HashMap<String, Arc<Chart>>, ParseConfigSourceError>>()?;

let watchlist = item.watchlist.map(|wl| {
let accounts = item.accounts.map(|wl| {
wl.into_iter()
.map(|(name, address)| (name, Arc::new(address)))
.collect::<HashMap<String, Arc<String>>>()
Expand All @@ -190,7 +190,7 @@ impl TryFrom<ConfigSource> for Config {
charts,
deployments,
sentry: item.sentry,
watchlist,
accounts,
};

Ok(config)
Expand Down Expand Up @@ -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(),
)]));
Expand All @@ -301,7 +301,7 @@ mod tests {
charts,
deployments,
sentry,
watchlist,
accounts,
};

let config_result = Config::try_from(config_string);
Expand Down Expand Up @@ -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");
}
Expand Down
10 changes: 5 additions & 5 deletions crates/settings/src/config_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct ConfigSource {
#[serde(skip_serializing_if = "Option::is_none")]
pub raindex_version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub watchlist: Option<HashMap<String, String>>,
pub accounts: Option<HashMap<String, String>>,
}

#[typeshare]
Expand Down Expand Up @@ -375,7 +375,7 @@ deployments:
sentry: true
watchlist:
accounts:
name-one: address-one
name-two: address-two"#,
mocked_chain_id_server.url("/json")
Expand Down Expand Up @@ -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]
Expand Down
52 changes: 26 additions & 26 deletions crates/settings/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
_ => {}
}
Expand Down Expand Up @@ -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);
}
_ => {}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ mod tests {
networks: HashMap::new(),
deployments: HashMap::new(),
sentry: None,
watchlist: None,
accounts: None,
};

let other = ConfigSource {
Expand All @@ -329,7 +329,7 @@ mod tests {
networks: HashMap::new(),
deployments: HashMap::new(),
sentry: None,
watchlist: None,
accounts: None,
};

assert_eq!(config.merge(other), Ok(()));
Expand All @@ -351,7 +351,7 @@ mod tests {
networks: HashMap::new(),
deployments: HashMap::new(),
sentry: None,
watchlist: None,
accounts: None,
};

let mut other = ConfigSource {
Expand All @@ -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
Expand Down Expand Up @@ -404,7 +404,7 @@ mod tests {
networks: HashMap::new(),
deployments: HashMap::new(),
sentry: None,
watchlist: None,
accounts: None,
};

let mut other = ConfigSource {
Expand All @@ -421,7 +421,7 @@ mod tests {
networks: HashMap::new(),
deployments: HashMap::new(),
sentry: None,
watchlist: None,
accounts: None,
};

other.metaboards.insert(
Expand Down
2 changes: 1 addition & 1 deletion crates/settings/src/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tauri-app/src/lib/components/ListViewOrderbookSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,7 +15,7 @@
>
{:else}
<DropdownOrderStatus />
<DropdownOrderListWatchlist />
<DropdownOrderListAccounts />
<DropdownActiveNetwork />
<DropdownActiveOrderbook />
{/if}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script lang="ts">
import { accounts, activeAccountsItems } from '$lib/stores/settings';
import DropdownCheckbox from './DropdownCheckbox.svelte';
$: options = $accounts;
</script>

<DropdownCheckbox
{options}
bind:value={$activeAccountsItems}
label="Accounts"
allLabel="All accounts"
emptyMessage="No accounts added"
/>
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
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) => {
const { mockSettingsStore } = await import('$lib/mocks/settings');
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'));

Expand All @@ -35,45 +35,43 @@ 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);
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(activeWatchlistItems)).toEqual({
expect(get(activeAccountsItems)).toEqual({
address1: 'Label 1',
address2: 'Label 2',
address3: 'Label 3',
});
});
});

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();
});
});

This file was deleted.

6 changes: 3 additions & 3 deletions tauri-app/src/lib/components/tables/OrdersListTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
Loading

0 comments on commit 6c46137

Please sign in to comment.