ui: add processing hw notification to components
This commit is contained in:
parent
1ea292f058
commit
7d97f466ef
@ -504,7 +504,7 @@ impl Action for SignAction {
|
||||
fn view<'a>(&'a self, content: Element<'a, view::Message>) -> Element<'a, view::Message> {
|
||||
let content = toast::Manager::new(
|
||||
content,
|
||||
view::psbt::sign_action_toasts(&self.hws.list, &self.signing),
|
||||
view::psbt::sign_action_toasts(self.error.as_ref(), &self.hws.list, &self.signing),
|
||||
)
|
||||
.into();
|
||||
if self.display_modal {
|
||||
|
||||
@ -993,10 +993,12 @@ pub fn sign_action<'a>(
|
||||
}
|
||||
|
||||
pub fn sign_action_toasts<'a>(
|
||||
error: Option<&Error>,
|
||||
hws: &'a [HardwareWallet],
|
||||
signing: &HashSet<Fingerprint>,
|
||||
) -> Vec<Element<'a, Message>> {
|
||||
hws.iter()
|
||||
let mut vec: Vec<Element<'a, Message>> = hws
|
||||
.iter()
|
||||
.filter_map(|hw| {
|
||||
if let HardwareWallet::Supported {
|
||||
kind,
|
||||
@ -1008,13 +1010,13 @@ pub fn sign_action_toasts<'a>(
|
||||
{
|
||||
if signing.contains(fingerprint) {
|
||||
Some(
|
||||
card::simple(liana_ui::component::hw::processing_hardware_wallet(
|
||||
liana_ui::component::notification::processing_hardware_wallet(
|
||||
kind,
|
||||
version.as_ref(),
|
||||
fingerprint,
|
||||
alias.as_ref(),
|
||||
))
|
||||
.width(Length::Fixed(500.0))
|
||||
)
|
||||
.max_width(400.0)
|
||||
.into(),
|
||||
)
|
||||
} else {
|
||||
@ -1024,7 +1026,19 @@ pub fn sign_action_toasts<'a>(
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
.collect();
|
||||
if let Some(e) = error {
|
||||
vec.push(
|
||||
liana_ui::component::notification::processing_hardware_wallet_error(
|
||||
"Device failed to sign".to_string(),
|
||||
e.to_string(),
|
||||
)
|
||||
.max_width(400.0)
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
vec
|
||||
}
|
||||
|
||||
pub fn update_spend_view<'a>(
|
||||
|
||||
@ -1,10 +1,17 @@
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::{
|
||||
color,
|
||||
component::{collapse, text},
|
||||
icon, theme,
|
||||
util::*,
|
||||
widget::*,
|
||||
};
|
||||
use iced::{Alignment, Length};
|
||||
use iced::{
|
||||
widget::{column, container, row},
|
||||
Alignment, Length,
|
||||
};
|
||||
|
||||
pub fn warning<'a, T: 'a + Clone>(message: String, error: String) -> Container<'a, T> {
|
||||
let message_clone = message.clone();
|
||||
@ -14,7 +21,7 @@ pub fn warning<'a, T: 'a + Clone>(message: String, error: String) -> Container<'
|
||||
Row::new()
|
||||
.push(
|
||||
Container::new(
|
||||
text::p1_bold(message_clone.to_string()).style(color::WHITE),
|
||||
text::p1_bold(message_clone.to_string()).style(color::LIGHT_BLACK),
|
||||
)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
@ -22,8 +29,8 @@ pub fn warning<'a, T: 'a + Clone>(message: String, error: String) -> Container<'
|
||||
Row::new()
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(10)
|
||||
.push(text::p1_bold("Learn more").style(color::WHITE))
|
||||
.push(icon::collapse_icon()),
|
||||
.push(text::p1_bold("Learn more").style(color::LIGHT_BLACK))
|
||||
.push(icon::collapse_icon().style(color::LIGHT_BLACK)),
|
||||
),
|
||||
)
|
||||
.style(theme::Button::Transparent)
|
||||
@ -32,15 +39,15 @@ pub fn warning<'a, T: 'a + Clone>(message: String, error: String) -> Container<'
|
||||
Button::new(
|
||||
Row::new()
|
||||
.push(
|
||||
Container::new(text::p1_bold(message.to_owned()).style(color::WHITE))
|
||||
Container::new(text::p1_bold(message.to_owned()).style(color::LIGHT_BLACK))
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.push(
|
||||
Row::new()
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(10)
|
||||
.push(text::p1_bold("Learn more").style(color::WHITE))
|
||||
.push(icon::collapsed_icon()),
|
||||
.push(text::p1_bold("Learn more").style(color::LIGHT_BLACK))
|
||||
.push(icon::collapsed_icon().style(color::LIGHT_BLACK)),
|
||||
),
|
||||
)
|
||||
.style(theme::Button::Transparent)
|
||||
@ -51,3 +58,86 @@ pub fn warning<'a, T: 'a + Clone>(message: String, error: String) -> Container<'
|
||||
.style(theme::Container::Card(theme::Card::Warning))
|
||||
.width(Length::Fill)
|
||||
}
|
||||
|
||||
pub fn processing_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Display>(
|
||||
kind: K,
|
||||
version: Option<V>,
|
||||
fingerprint: F,
|
||||
alias: Option<impl Into<Cow<'a, str>>>,
|
||||
) -> Container<'a, T> {
|
||||
container(
|
||||
row(vec![
|
||||
column(vec![
|
||||
Row::new()
|
||||
.spacing(5)
|
||||
.push_maybe(alias.map(|a| text::p1_bold(a)))
|
||||
.push(text::p1_regular(format!("#{}", fingerprint)))
|
||||
.into(),
|
||||
Row::new()
|
||||
.spacing(5)
|
||||
.push(text::caption(kind.to_string()))
|
||||
.push_maybe(version.map(|v| text::caption(v.to_string())))
|
||||
.into(),
|
||||
])
|
||||
.width(Length::Fill)
|
||||
.into(),
|
||||
column(vec![
|
||||
text::p2_regular("Processing...").into(),
|
||||
text::p2_regular("Please check your device").into(),
|
||||
])
|
||||
.into(),
|
||||
])
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.style(theme::Container::Notification(theme::Notification::Pending))
|
||||
.padding(10)
|
||||
}
|
||||
|
||||
pub fn processing_hardware_wallet_error<'a, T: 'a + Clone>(
|
||||
message: String,
|
||||
error: String,
|
||||
) -> Container<'a, T> {
|
||||
let message_clone = message.clone();
|
||||
Container::new(Container::new(collapse::Collapse::new(
|
||||
move || {
|
||||
Button::new(
|
||||
Row::new()
|
||||
.push(
|
||||
Container::new(
|
||||
text::p1_bold(message_clone.to_string()).style(color::LIGHT_BLACK),
|
||||
)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.push(
|
||||
Row::new()
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(10)
|
||||
.push(text::p1_bold("Learn more").style(color::LIGHT_BLACK))
|
||||
.push(icon::collapse_icon().style(color::LIGHT_BLACK)),
|
||||
),
|
||||
)
|
||||
.style(theme::Button::Transparent)
|
||||
},
|
||||
move || {
|
||||
Button::new(
|
||||
Row::new()
|
||||
.push(
|
||||
Container::new(text::p1_bold(message.to_owned()).style(color::LIGHT_BLACK))
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.push(
|
||||
Row::new()
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(10)
|
||||
.push(text::p1_bold("Learn more").style(color::LIGHT_BLACK))
|
||||
.push(icon::collapsed_icon().style(color::LIGHT_BLACK)),
|
||||
),
|
||||
)
|
||||
.style(theme::Button::Transparent)
|
||||
},
|
||||
move || Element::<'a, T>::from(text::p2_regular(error.to_owned())),
|
||||
)))
|
||||
.padding(10)
|
||||
.style(theme::Container::Notification(theme::Notification::Error))
|
||||
.width(Length::Fill)
|
||||
}
|
||||
|
||||
@ -1,14 +1,10 @@
|
||||
use std::fmt;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Instant;
|
||||
|
||||
use super::card;
|
||||
use super::text::h1;
|
||||
use super::theme::Theme;
|
||||
use crate::widget::*;
|
||||
|
||||
use iced::{Alignment, Element, Length, Point, Rectangle, Size, Vector};
|
||||
use iced_native::widget::{Operation, Tree};
|
||||
use iced_native::{event, layout, mouse, overlay, renderer, window};
|
||||
use iced_native::{event, layout, mouse, overlay, renderer};
|
||||
use iced_native::{Clipboard, Event, Layout, Shell, Widget};
|
||||
|
||||
pub trait Toast {
|
||||
|
||||
@ -93,6 +93,7 @@ pub enum Container {
|
||||
Badge(Badge),
|
||||
Pill(Pill),
|
||||
Custom(iced::Color),
|
||||
Notification(Notification),
|
||||
QrCode,
|
||||
}
|
||||
|
||||
@ -122,6 +123,7 @@ impl container::StyleSheet for Theme {
|
||||
Container::Card(c) => c.appearance(self),
|
||||
Container::Badge(c) => c.appearance(self),
|
||||
Container::Pill(c) => c.appearance(self),
|
||||
Container::Notification(c) => c.appearance(self),
|
||||
Container::Custom(c) => container::Appearance {
|
||||
background: (*c).into(),
|
||||
..container::Appearance::default()
|
||||
@ -154,6 +156,7 @@ impl container::StyleSheet for Theme {
|
||||
Container::Card(c) => c.appearance(self),
|
||||
Container::Badge(c) => c.appearance(self),
|
||||
Container::Pill(c) => c.appearance(self),
|
||||
Container::Notification(c) => c.appearance(self),
|
||||
Container::Custom(c) => container::Appearance {
|
||||
background: (*c).into(),
|
||||
..container::Appearance::default()
|
||||
@ -186,6 +189,52 @@ impl From<Pill> for Container {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Default)]
|
||||
pub enum Notification {
|
||||
#[default]
|
||||
Pending,
|
||||
Error,
|
||||
}
|
||||
|
||||
impl Notification {
|
||||
fn appearance(&self, theme: &Theme) -> iced::widget::container::Appearance {
|
||||
match theme {
|
||||
Theme::Light => match self {
|
||||
Self::Pending => container::Appearance {
|
||||
background: color::GREEN.into(),
|
||||
text_color: color::LIGHT_BLACK.into(),
|
||||
border_width: 1.0,
|
||||
border_color: color::GREEN,
|
||||
border_radius: 25.0,
|
||||
},
|
||||
Self::Error => container::Appearance {
|
||||
background: color::ORANGE.into(),
|
||||
text_color: color::LIGHT_BLACK.into(),
|
||||
border_width: 1.0,
|
||||
border_color: color::ORANGE,
|
||||
border_radius: 25.0,
|
||||
},
|
||||
},
|
||||
Theme::Dark => match self {
|
||||
Self::Pending => container::Appearance {
|
||||
background: color::GREEN.into(),
|
||||
text_color: color::LIGHT_BLACK.into(),
|
||||
border_width: 1.0,
|
||||
border_color: color::GREEN,
|
||||
border_radius: 25.0,
|
||||
},
|
||||
Self::Error => container::Appearance {
|
||||
background: color::ORANGE.into(),
|
||||
text_color: color::LIGHT_BLACK.into(),
|
||||
border_width: 1.0,
|
||||
border_color: color::ORANGE,
|
||||
border_radius: 25.0,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Default)]
|
||||
pub enum Card {
|
||||
#[default]
|
||||
@ -260,7 +309,7 @@ impl Card {
|
||||
},
|
||||
Card::Warning => container::Appearance {
|
||||
background: color::ORANGE.into(),
|
||||
text_color: color::WHITE.into(),
|
||||
text_color: color::LIGHT_BLACK.into(),
|
||||
..container::Appearance::default()
|
||||
},
|
||||
},
|
||||
@ -574,7 +623,7 @@ impl button::StyleSheet for Theme {
|
||||
},
|
||||
Button::Transparent => button::Appearance {
|
||||
shadow_offset: iced::Vector::default(),
|
||||
background: color::GREY_7.into(),
|
||||
background: iced::Color::TRANSPARENT.into(),
|
||||
border_radius: 25.0,
|
||||
border_width: 0.0,
|
||||
border_color: iced::Color::TRANSPARENT,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user