Skip to content

Commit

Permalink
wip: show warnings outside of overview w/o clicking
Browse files Browse the repository at this point in the history
  • Loading branch information
jp1ac4 committed Jan 29, 2024
1 parent 0af4fe3 commit 2466b93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 82 deletions.
78 changes: 2 additions & 76 deletions gui/src/app/view/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn psbt_view<'a>(
}),
)
.push(spend_header(tx, labels_editing))
.push(spend_overview_view(tx, desc_info, key_aliases, None))
.push(spend_overview_view(tx, desc_info, key_aliases))
.push(
Column::new()
.spacing(20)
Expand Down Expand Up @@ -255,7 +255,6 @@ pub fn spend_overview_view<'a>(
tx: &'a SpendTx,
desc_info: &'a LianaPolicy,
key_aliases: &'a HashMap<Fingerprint, String>,
warnings: Option<&'a Vec<String>>,
) -> Element<'a, Message> {
Column::new()
.spacing(20)
Expand Down Expand Up @@ -307,8 +306,7 @@ pub fn spend_overview_view<'a>(
.align_items(Alignment::Center),
),
)
.push(signatures(tx, desc_info, key_aliases))
.push_maybe(warnings.map(|w| spend_warnings_view(w))),
.push(signatures(tx, desc_info, key_aliases)),
)
.style(theme::Container::Card(theme::Card::Simple)),
)
Expand Down Expand Up @@ -338,78 +336,6 @@ pub fn spend_overview_view<'a>(
.into()
}

fn spend_warnings_button<'a>(
num_warnings: usize,
is_collapsed: bool,
) -> impl Fn() -> Button<'a, liana_ui::component::collapse::Event<Message>> {
let color = if num_warnings >= 1 {
color::ORANGE
} else {
color::GREEN
};
move || {
Button::new(
Row::new()
.align_items(Alignment::Center)
.spacing(20)
.push(p1_bold("Warnings"))
.push(
Row::new()
.spacing(5)
.align_items(Alignment::Center)
.push(if num_warnings >= 1 {
icon::warning_icon().style(color)
} else {
icon::circle_check_icon().style(color)
})
.push(
text(format!(
"{} warning{}",
num_warnings,
if num_warnings == 1 { "" } else { "s" }
))
.style(color),
)
.width(Length::Fill),
)
.push(if is_collapsed {
icon::collapsed_icon()
} else {
icon::collapse_icon()
}),
)
.padding(15)
.width(Length::Fill)
.style(theme::Button::TransparentBorder)
}
}

fn spend_warnings_view(warnings: &Vec<String>) -> Element<Message> {
Container::new(Collapse::new(
spend_warnings_button(warnings.len(), false),
spend_warnings_button(warnings.len(), true),
move || {
Into::<Element<Message>>::into(
warnings.iter().fold(
Column::new()
.padding(15)
.spacing(10)
.push(text(if warnings.is_empty() {
"No warnings were generated.".to_string()
} else {
format!(
"The following warning{} generated:",
if warnings.len() > 1 { "s were" } else { " was" }
)
})),
|col, warning| col.push(text(warning).style(color::GREY_3)),
),
)
},
))
.into()
}

pub fn signatures<'a>(
tx: &'a SpendTx,
desc_info: &'a LianaPolicy,
Expand Down
22 changes: 16 additions & 6 deletions gui/src/app/view/spend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@ pub fn spend_view<'a>(
.spacing(20)
.push(Container::new(h3("Send")).width(Length::Fill))
.push(psbt::spend_header(tx, labels_editing))
.push(psbt::spend_overview_view(
tx,
desc_info,
key_aliases,
if saved { None } else { Some(spend_warnings) },
))
.push_maybe(if spend_warnings.is_empty() || saved {
None
} else {
Some(spend_warnings.iter().fold(
Column::new().padding(15).spacing(5),
|col, warning| {
col.push(
Row::new()
.spacing(5)
.push(icon::warning_icon().style(color::ORANGE))
.push(text(warning).style(color::ORANGE)),
)
},
))
})
.push(psbt::spend_overview_view(tx, desc_info, key_aliases))
.push(
Column::new()
.spacing(20)
Expand Down

0 comments on commit 2466b93

Please sign in to comment.