-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 2024-11-01-sidebar-scroll
- Loading branch information
Showing
18 changed files
with
459 additions
and
124 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use futures::future::join_all; | ||
use reqwest::Url; | ||
use serde::Deserialize; | ||
|
||
use crate::{ | ||
types::common::{OrderWithSubgraphName, OrdersListFilterArgs}, | ||
OrderbookSubgraphClient, OrderbookSubgraphClientError, PaginationArgs, | ||
}; | ||
|
||
#[derive(Debug, Clone, Deserialize)] | ||
pub struct MultiSubgraphArgs { | ||
url: Url, | ||
name: String, | ||
} | ||
|
||
pub struct MultiOrderbookSubgraphClient { | ||
subgraphs: Vec<MultiSubgraphArgs>, | ||
} | ||
impl MultiOrderbookSubgraphClient { | ||
pub fn new(subgraphs: Vec<MultiSubgraphArgs>) -> Self { | ||
Self { subgraphs } | ||
} | ||
|
||
fn get_orderbook_subgraph_client(&self, url: Url) -> OrderbookSubgraphClient { | ||
OrderbookSubgraphClient::new(url) | ||
} | ||
|
||
pub async fn orders_list( | ||
&self, | ||
filter_args: OrdersListFilterArgs, | ||
pagination_args: PaginationArgs, | ||
) -> Result<Vec<OrderWithSubgraphName>, OrderbookSubgraphClientError> { | ||
let futures = self.subgraphs.iter().map(|subgraph| { | ||
let url = subgraph.url.clone(); | ||
let filter_args = filter_args.clone(); | ||
let pagination_args = pagination_args.clone(); | ||
async move { | ||
let client = self.get_orderbook_subgraph_client(url); | ||
let orders = client.orders_list(filter_args, pagination_args).await?; | ||
let wrapped_orders: Vec<OrderWithSubgraphName> = orders | ||
.into_iter() | ||
.map(|order| OrderWithSubgraphName { | ||
order, | ||
subgraph_name: subgraph.name.clone(), | ||
}) | ||
.collect(); | ||
Ok::<_, OrderbookSubgraphClientError>(wrapped_orders) | ||
} | ||
}); | ||
|
||
let results = join_all(futures).await; | ||
|
||
let mut all_orders: Vec<OrderWithSubgraphName> = results | ||
.into_iter() | ||
.filter_map(Result::ok) | ||
.flatten() | ||
.collect(); | ||
|
||
all_orders.sort_by(|a, b| { | ||
let a_timestamp = a.order.timestamp_added.0.parse::<i64>().unwrap_or(0); | ||
let b_timestamp = b.order.timestamp_added.0.parse::<i64>().unwrap_or(0); | ||
b_timestamp.cmp(&a_timestamp) | ||
}); | ||
|
||
Ok(all_orders) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tauri-app/src/lib/components/dropdown/DropdownActiveSubgraphs.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script lang="ts"> | ||
import DropdownCheckbox from './DropdownCheckbox.svelte'; | ||
import { settings, activeSubgraphs } from '$lib/stores/settings'; | ||
$: dropdownOptions = Object.keys($settings?.subgraphs ?? {}).reduce( | ||
(acc, key) => ({ | ||
...acc, | ||
[key]: key, | ||
}), | ||
{}, | ||
); | ||
function handleStatusChange(event: CustomEvent<Record<string, string>>) { | ||
let items = Object.keys(event.detail); | ||
activeSubgraphs.set( | ||
Object.values(items).reduce( | ||
(acc, key) => ({ ...acc, [key]: ($settings?.subgraphs ?? {})[key] }), | ||
{} as Record<string, string>, | ||
), | ||
); | ||
} | ||
$: value = | ||
Object.keys($activeSubgraphs).length === 0 | ||
? {} | ||
: Object.keys($activeSubgraphs).reduce( | ||
(acc, key) => ({ | ||
...acc, | ||
[key]: key, | ||
}), | ||
{}, | ||
); | ||
</script> | ||
|
||
<DropdownCheckbox | ||
options={dropdownOptions} | ||
on:change={handleStatusChange} | ||
label="Networks" | ||
showAllLabel={false} | ||
onlyTitle={true} | ||
{value} | ||
/> |
75 changes: 75 additions & 0 deletions
75
tauri-app/src/lib/components/dropdown/DropdownActiveSubgraphs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { render, fireEvent, screen, waitFor } from '@testing-library/svelte'; | ||
import { get, writable } from 'svelte/store'; | ||
import { activeSubgraphs, settings } from '$lib/stores/settings'; | ||
import { beforeEach, expect, test, vi, describe } from 'vitest'; | ||
import DropdownActiveSubgraphs from './DropdownActiveSubgraphs.svelte'; | ||
|
||
vi.mock('$lib/stores/settings', async (importOriginal) => { | ||
const { mockConfigSource } = await import('$lib/mocks/settings'); | ||
return { | ||
...((await importOriginal()) as object), | ||
settings: writable({ | ||
...mockConfigSource, | ||
subgraphs: { | ||
mainnet: 'mainnet', | ||
testnet: 'testnet', | ||
local: 'local', | ||
}, | ||
}), | ||
activeSubgraphs: writable({}), | ||
}; | ||
}); | ||
|
||
describe('DropdownActiveSubgraphs', () => { | ||
beforeEach(() => { | ||
settings.set({ | ||
...get(settings), | ||
subgraphs: { | ||
mainnet: 'mainnet', | ||
testnet: 'testnet', | ||
local: 'local', | ||
}, | ||
}); | ||
activeSubgraphs.set({}); | ||
}); | ||
|
||
test('renders correctly', () => { | ||
render(DropdownActiveSubgraphs); | ||
expect(screen.getByText('Networks')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays the correct number of options', async () => { | ||
render(DropdownActiveSubgraphs); | ||
|
||
await fireEvent.click(screen.getByTestId('dropdown-checkbox-button')); | ||
|
||
await waitFor(() => { | ||
const options = screen.getAllByTestId('dropdown-checkbox-option'); | ||
expect(options).toHaveLength(3); | ||
}); | ||
}); | ||
|
||
test('updates active subgraphs when an option is selected', async () => { | ||
render(DropdownActiveSubgraphs); | ||
|
||
await fireEvent.click(screen.getByTestId('dropdown-checkbox-button')); | ||
await fireEvent.click(screen.getByText('mainnet')); | ||
await waitFor(() => { | ||
expect(get(activeSubgraphs)).toEqual({ mainnet: 'mainnet' }); | ||
}); | ||
|
||
await fireEvent.click(screen.getByText('testnet')); | ||
await waitFor(() => { | ||
expect(get(activeSubgraphs)).toEqual({ mainnet: 'mainnet', testnet: 'testnet' }); | ||
}); | ||
|
||
await fireEvent.click(screen.getByText('local')); | ||
await waitFor(() => { | ||
expect(get(activeSubgraphs)).toEqual({ | ||
mainnet: 'mainnet', | ||
testnet: 'testnet', | ||
local: 'local', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.