Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portfolio deployer #190

Merged
merged 5 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/book.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
lint:
runs-on: ubuntu-latest
name: Lints
needs: Install
needs: install
steps:
- uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
with:
check_hidden: true
check_filenames: true
skip: .git,Cargo.lock,target
skip: .git,Cargo.lock,target,position_renderer.rs,portfolio.rs
ignore_words_list: crate,Crate,functio


Expand Down
13 changes: 5 additions & 8 deletions crates/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl From<Execution> for WindowsMessage {

impl From<Execution> for Message {
fn from(msg: Execution) -> Self {
Message::WindowsMessage(msg.into()).into()
Message::WindowsMessage(msg.into())
}
}

Expand Down Expand Up @@ -189,7 +189,7 @@ impl App {

// All view updates are forwarded to the Screen's update function.
pub fn update(&mut self, message: Message) -> Command<Message> {
let msg = app_span().in_scope(|| match message {
app_span().in_scope(|| match message {
Message::StorageMessage(msg) => self.storage_update(msg),
Message::CacheMessage(msg) => self.cache_update(msg),
Message::StreamsMessage(msg) => self.streams_update(msg),
Expand All @@ -202,9 +202,7 @@ impl App {
}
Message::Empty => Command::none(),
_ => self.windows.screen.update(message),
});

msg
})
}

pub fn view(&self) -> Element<Message> {
Expand Down Expand Up @@ -324,9 +322,8 @@ impl App {
}

fn chains_update(&mut self, _message: ChainMessage) -> Command<Message> {
let cmd = Command::none();
// todo: implement
cmd
Command::none()
}

// Forwards window messages to the screen.
Expand All @@ -352,7 +349,7 @@ impl App {
self.windows.screen = match navigate_to {
view::sidebar::Route::Page(page) => {
// Update the current page.
self.cache.current_page = page.clone();
self.cache.current_page = *page;

match page {
view::sidebar::Page::Execute => Screen::new(Box::new(
Expand Down
8 changes: 4 additions & 4 deletions crates/app/src/components/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl StyleSheet for SidebarContainer {
fn appearance(&self, _: &<Self as StyleSheet>::Style) -> Appearance {
Appearance {
background: Some(iced::Background::Color(SIDEBAR_BG_COLOR)),
border_width: 1.0.into(),
border_width: 1.0,
border_color: Color::BLACK,
..Default::default()
}
Expand All @@ -54,7 +54,7 @@ impl StyleSheet for ScreenWindowContainer {
Appearance {
background: Some(iced::Background::Color(PANEL)),
border_radius: 9.0.into(),
border_width: 1.0.into(),
border_width: 1.0,
border_color: Color::BLACK,
..Default::default()
}
Expand Down Expand Up @@ -96,7 +96,7 @@ impl StyleSheet for WindowHeader {
Appearance {
background: Some(iced::Background::Color(WINDOW_HEADER_COLOR)),
border_radius: [9.0, 9.0, 0.0, 0.0].into(),
border_width: 1.0.into(),
border_width: 1.0,
border_color: Color::BLACK,
..Default::default()
}
Expand Down Expand Up @@ -274,7 +274,7 @@ impl StyleSheet for CustomContainer {

fn appearance(&self, _: &<Self as StyleSheet>::Style) -> Appearance {
Appearance {
background: self.background.clone(),
background: self.background,
border_radius: self.border_radius,
border_width: self.border_width,
border_color: self.border_color,
Expand Down
26 changes: 15 additions & 11 deletions crates/app/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,12 @@ where
pub column_2_alignment: Option<alignment::Alignment>,
}

impl<'a, Message> Default for DualColumn<'a, Message> {
fn default() -> Self {
Self::new()
}
}

impl<'a, Message> DualColumn<'a, Message> {
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -637,18 +643,16 @@ impl<'a, Message> DualColumn<'a, Message> {
pub fn build(self) -> Row<'a, Message> {
let mut row = Row::new();

let mut first_column =
Column::with_children(self.column_1.into_iter().map(|e| e.into()).collect())
.width(Length::FillPortion(2))
.align_items(
self.column_1_alignment
.unwrap_or(alignment::Alignment::Start),
);
let mut first_column = Column::with_children(self.column_1.into_iter().collect())
.width(Length::FillPortion(2))
.align_items(
self.column_1_alignment
.unwrap_or(alignment::Alignment::Start),
);

let mut second_column =
Column::with_children(self.column_2.into_iter().map(|e| e.into()).collect())
.width(Length::FillPortion(2))
.align_items(self.column_2_alignment.unwrap_or(alignment::Alignment::End));
let mut second_column = Column::with_children(self.column_2.into_iter().collect())
.width(Length::FillPortion(2))
.align_items(self.column_2_alignment.unwrap_or(alignment::Alignment::End));

if let Some(spacing) = self.spacing {
first_column = first_column.spacing(spacing);
Expand Down
14 changes: 10 additions & 4 deletions crates/app/src/components/tables/cells/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ where
containerize: Box<dyn Fn(Element<'static, Message>) -> Container<'static, Message>>,
}

impl<Message> Default for CellBuilder<Message>
where
Message: 'static + Default,
{
fn default() -> Self {
Self::new()
}
}

impl<Message> CellBuilder<Message>
where
Message: 'static + Default,
Expand Down Expand Up @@ -165,10 +174,7 @@ where
where
Message: 'a + Default,
{
let value = match self.value.as_ref() {
Some(val) => Some(val.clone()),
None => None,
};
let value = self.value.as_ref().cloned();

// If on_checkbox is Some, then we need to render a checkbox.
if self.on_checkbox.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/components/tables/cells/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ pub fn cell_select<'a, Message>(
where
Message: 'static + Default,
{
let mut select = custom_pick_list(options, selected, on_selected, placeholder);
let select = custom_pick_list(options, selected, on_selected, placeholder);
select
}
9 changes: 9 additions & 0 deletions crates/app/src/components/tables/columns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ where
padding_cell_internal: Option<Sizes>,
}

impl<Message> Default for ColumnBuilder<Message>
where
Message: 'static + Default,
{
fn default() -> Self {
Self::new()
}
}

impl<Message> ColumnBuilder<Message>
where
Message: 'static + Default,
Expand Down
9 changes: 9 additions & 0 deletions crates/app/src/components/tables/rows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ where
containerize: Box<dyn Fn(Row<'static, Message>) -> Row<'static, Message>>,
}

impl<Message> Default for RowBuilder<Message>
where
Message: Default,
{
fn default() -> Self {
Self::new()
}
}

impl<Message> RowBuilder<Message>
where
Message: Default,
Expand Down
8 changes: 3 additions & 5 deletions crates/app/src/screens/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,17 @@ impl State for Execution {
match message {
Message::Empty => Command::none(),
Message::View(msg) => {
match msg {
view::Message::Execution(e) => match e {
if let view::Message::Execution(e) = msg {
match e {
view::Execution::Form(form_message) => {
return self.form.update(form_message)
}
view::Execution::Simulate => return self.handle_simulate(),
view::Execution::Execute => return self.handle_execute(),
view::Execution::Results => {}
view::Execution::Reset => return self.handle_restart(),
},
_ => {}
}
}

Command::none()
}
Message::WindowsMessage(app::WindowsMessage::Execution(msg)) => match msg {
Expand Down
4 changes: 2 additions & 2 deletions crates/app/src/screens/portfolio/create/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl State for Form {
self.assets[index].price = price
}
Message::AssetBalanceChanged(index, balance) => self.assets[index].balance = balance,
Message::Submit => return self.submit().map(|x| x.into()),
Message::Submit => return self.submit().map(|x| x),
}

Command::none()
Expand All @@ -230,7 +230,7 @@ impl State for Form {
.cell(
CellBuilder::new()
.checked(Some(asset.selected))
.on_checkbox(move |x| form::Message::AssetSelected(i)),
.on_checkbox(move |_x| form::Message::AssetSelected(i)),
)
})
.collect(),
Expand Down
10 changes: 5 additions & 5 deletions crates/app/src/screens/portfolio/dashboard/stages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl Stages {
DashboardState::Empty => {
self.current = DashboardState::Review(review::ReviewAdjustment::default());
}
DashboardState::Review(state) => {
DashboardState::Review(_state) => {
// Construct the MiniWorldBuilder from the review form data and portfolio.
self.construct();
// Prepare the simulate screen with the MiniWorldBuilder.
Expand All @@ -199,7 +199,7 @@ impl Stages {
)
.map(|x| x.into());
}
DashboardState::Simulate(state) => {
DashboardState::Simulate(_state) => {
self.current = DashboardState::Execute;
}
DashboardState::Execute => {
Expand All @@ -218,8 +218,8 @@ impl State for Stages {
fn load(&self) -> Command<Self::AppMessage> {
match &self.current {
DashboardState::Empty => {}
DashboardState::Review(state) => {}
DashboardState::Simulate(state) => {}
DashboardState::Review(_state) => {}
DashboardState::Simulate(_state) => {}
DashboardState::Execute => {}
_ => {}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ impl State for Stages {
let mut commands = vec![];

// todo: figure out proper order of operations here...
// batch executes simultaneously, so whats the effect here?
// batch executes simultaneously, so what's the effect here?
if let DashboardState::Review(state) = &mut self.current {
commands.push(state.update(message.clone()).map(|x| x.into()));
}
Expand Down
31 changes: 16 additions & 15 deletions crates/app/src/screens/portfolio/dashboard/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,20 @@ impl PortfolioTable {
.enumerate()
.map(|(pos_index, position)| {
let balance = self.form.balance.get(&pos_index).cloned();
let targets =
position
.clone()
.targets
.unwrap_or_default()
.into_iter()
.filter(|target| matches!(target, Targetable::Weight(_)))
.map(|target| {
self.form.weight.get(&pos_index).cloned().and_then(|x| {
Some(Targetable::from_string(Targetable::Weight(0.0), x))
})
})
.collect::<Vec<Option<Targetable>>>();
let targets = position
.clone()
.targets
.unwrap_or_default()
.into_iter()
.filter(|target| matches!(target, Targetable::Weight(_)))
.map(|_target| {
self.form
.weight
.get(&pos_index)
.cloned()
.map(|x| Targetable::from_string(Targetable::Weight(0.0), x))
})
.collect::<Vec<Option<Targetable>>>();

PositionDelta { balance, targets }
})
Expand All @@ -124,14 +125,14 @@ impl PortfolioTable {
) -> Vec<CellBuilder<Self::AppMessage>> {
// todo: support more targets
let (value, on_change_msg) = match target {
Targetable::Weight(x) => (
Targetable::Weight(_x) => (
self.form.weight.get(&pos_index).cloned(),
Box::new(move |x| form::DeltaFormMessage::Weight(pos_index, x).into())
as Self::FormEvent,
),
_ => (
None,
Box::new(|x| form::DeltaFormMessage::Empty.into()) as Self::FormEvent,
Box::new(|_x| form::DeltaFormMessage::Empty.into()) as Self::FormEvent,
),
};

Expand Down
4 changes: 2 additions & 2 deletions crates/app/src/screens/portfolio/dashboard/table/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl DeltaSummary {
data.push(("Balance".to_string(), balance));
}

for (i, target) in position.targets.iter().enumerate() {
for target in position.targets.iter() {
if let Some(target) = target.clone() {
data.push((format!("{:?}", target), target.to_string()));
}
Expand Down Expand Up @@ -101,7 +101,7 @@ impl State for DeltaSummary {

let mut rows: Vec<Element<'a, Self::ViewMessage>> = vec![];

for (i, pos) in self.deltas.iter().enumerate() {
for (i, _pos) in self.deltas.iter().enumerate() {
rows.push(
Column::new()
.spacing(Sizes::Sm)
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/view/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn agent_card<'a>(agent_data: Vec<(String, String)>, actions: bool) -> Eleme
_ => c.to_string(),
})
.collect::<String>()
.replace("_", " ");
.replace('_', " ");

content = content
.push(agent_header(agent_name.clone()))
Expand Down
8 changes: 1 addition & 7 deletions crates/clients/src/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ use ethers::{
types::{transaction::eip2718::TypedTransaction, Address},
utils::parse_ether,
};
use simulation::bindings::coin::{Coin, TransferCall};

use super::{forking::forking::*, *};

// todo: proper abi management?
abigen!(Coin, "crates/abi/Coin.sol/coin.json",
methods {
transfer(address,uint) as transfer_call;
},
);

#[derive(Default, Debug, Clone)]
pub struct Stages {
pub before: Option<CacheDB<EmptyDB>>,
Expand Down
Loading
Loading