ui: add history events to design-system
This commit is contained in:
1 parent
196b8cc3e9
commit
e7e8028d8a
17 files changed
+173
-34
No files matched your search
@@ -0,0 +1,59 @@
|
||||
pub use bitcoin::Amount;
|
||||
|
||||
use crate::{color, component::text::*, util::Collection, widget::*};
|
||||
|
||||
pub fn amount<'a, T: 'a>(a: &Amount) -> Row<'a, T> {
|
||||
amount_with_size(a, P1_SIZE)
|
||||
}
|
||||
|
||||
pub fn amount_with_size<'a, T: 'a>(a: &Amount, size: u16) -> Row<'a, T> {
|
||||
let spacing = if size > P1_SIZE { 10 } else { 5 };
|
||||
let sats = format!("{:.8}", a.to_btc());
|
||||
assert!(sats.len() >= 9);
|
||||
let row = Row::new()
|
||||
.spacing(spacing)
|
||||
.push(split_digits(sats[0..sats.len() - 6].to_string(), size).into())
|
||||
.push(if a.to_sat() < 1_000_000 {
|
||||
split_digits(sats[sats.len() - 6..sats.len() - 3].to_string(), size).into()
|
||||
} else {
|
||||
Row::new()
|
||||
.push(
|
||||
text(sats[sats.len() - 6..sats.len() - 3].to_string())
|
||||
.bold()
|
||||
.size(size),
|
||||
)
|
||||
.into()
|
||||
})
|
||||
.push(if a.to_sat() < 1000 {
|
||||
split_digits(sats[sats.len() - 3..sats.len()].to_string(), size).into()
|
||||
} else {
|
||||
Row::new()
|
||||
.push(
|
||||
text(sats[sats.len() - 3..sats.len()].to_string())
|
||||
.bold()
|
||||
.size(size),
|
||||
)
|
||||
.into()
|
||||
});
|
||||
|
||||
Row::with_children(vec![row.into(), text("BTC").size(size).into()])
|
||||
.spacing(spacing)
|
||||
.align_items(iced::Alignment::Center)
|
||||
}
|
||||
|
||||
fn split_digits<'a, T: 'a>(mut s: String, size: u16) -> impl Into<Element<'a, T>> {
|
||||
let prefixes = vec!["0.00", "0.0", "0.", "000", "00", "0"];
|
||||
for prefix in prefixes {
|
||||
if s.starts_with(prefix) {
|
||||
let right = s.split_off(prefix.len());
|
||||
return Row::new()
|
||||
.push(text(s).size(size).style(color::GREY_2))
|
||||
.push_maybe(if right.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(text(right).bold().size(size))
|
||||
});
|
||||
}
|
||||
}
|
||||
Row::new().push(text(s).bold().size(size))
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
use crate::{
|
||||
component::{amount, badge, text},
|
||||
theme,
|
||||
widget::*,
|
||||
};
|
||||
use bitcoin::Amount;
|
||||
use iced::{
|
||||
widget::{button, row},
|
||||
Alignment, Length,
|
||||
};
|
||||
|
||||
pub fn unconfirmed_outgoing_event<'a, T: Clone + 'a>(amount: &Amount, msg: T) -> Container<'a, T> {
|
||||
Container::new(
|
||||
button(
|
||||
row!(
|
||||
row!(badge::spend(), badge::unconfirmed())
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
.width(Length::Fill),
|
||||
row!(text::p1_regular("-"), amount::amount(amount))
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.padding(10)
|
||||
.spacing(20),
|
||||
)
|
||||
.on_press(msg)
|
||||
.style(theme::Button::TransparentBorder),
|
||||
)
|
||||
.style(theme::Container::Card(theme::Card::Simple))
|
||||
}
|
||||
|
||||
pub fn confirmed_outgoing_event<'a, T: Clone + 'a>(
|
||||
date: chrono::NaiveDate,
|
||||
amount: &Amount,
|
||||
msg: T,
|
||||
) -> Container<'a, T> {
|
||||
Container::new(
|
||||
button(
|
||||
row!(
|
||||
row!(badge::spend(), text::p2_regular(date.to_string()))
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
.width(Length::Fill),
|
||||
row!(text::p1_regular("-"), amount::amount(amount))
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.padding(10)
|
||||
.spacing(20),
|
||||
)
|
||||
.on_press(msg)
|
||||
.style(theme::Button::TransparentBorder),
|
||||
)
|
||||
.style(theme::Container::Card(theme::Card::Simple))
|
||||
}
|
||||
|
||||
pub fn unconfirmed_incoming_event<'a, T: Clone + 'a>(amount: &Amount, msg: T) -> Container<'a, T> {
|
||||
Container::new(
|
||||
button(
|
||||
row!(
|
||||
row!(badge::receive(), badge::unconfirmed())
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
.width(Length::Fill),
|
||||
row!(text::p1_regular("+"), amount::amount(amount))
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.padding(10)
|
||||
.spacing(20),
|
||||
)
|
||||
.on_press(msg)
|
||||
.style(theme::Button::TransparentBorder),
|
||||
)
|
||||
.style(theme::Container::Card(theme::Card::Simple))
|
||||
}
|
||||
|
||||
pub fn confirmed_incoming_event<'a, T: Clone + 'a>(
|
||||
date: chrono::NaiveDate,
|
||||
amount: &Amount,
|
||||
msg: T,
|
||||
) -> Container<'a, T> {
|
||||
Container::new(
|
||||
button(
|
||||
row!(
|
||||
row!(badge::receive(), text::p2_regular(date.to_string()))
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
.width(Length::Fill),
|
||||
row!(text::p1_regular("+"), amount::amount(amount))
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.padding(10)
|
||||
.spacing(20),
|
||||
)
|
||||
.on_press(msg)
|
||||
.style(theme::Button::TransparentBorder),
|
||||
)
|
||||
.style(theme::Container::Card(theme::Card::Simple))
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
pub mod amount;
|
||||
pub mod badge;
|
||||
pub mod button;
|
||||
pub mod card;
|
||||
pub mod collapse;
|
||||
pub mod event;
|
||||
pub mod form;
|
||||
pub mod hw;
|
||||
pub mod modal;
|
||||
|
||||
Reference in new issue
Block a user