ui: add history events to design-system

This commit is contained in:
edouard committed 2023-04-20 12:20:48 +02:00
1 parent 196b8cc3e9
commit e7e8028d8a
17 files changed
+173 -34

No files matched your search

+2 -5
View File
@@ -2,17 +2,14 @@ use iced::{Alignment, Length};
use liana_ui::{
color,
component::{badge, separation, text::*},
component::{amount::*, badge, separation, text::*},
icon, theme,
util::Collection,
widget::*,
};
use crate::{
app::{
cache::Cache,
view::{message::Message, util::*},
},
app::{cache::Cache, view::message::Message},
daemon::model::{remaining_sequence, Coin},
};
+2 -5
View File
@@ -5,16 +5,13 @@ use iced::{alignment, Alignment, Length};
use liana::miniscript::bitcoin;
use liana_ui::{
color,
component::{badge, text::*},
component::{amount::*, badge, text::*},
icon, theme,
util::Collection,
widget::*,
};
use crate::{
app::view::{message::Message, util::*},
daemon::model::HistoryTransaction,
};
use crate::{app::view::message::Message, daemon::model::HistoryTransaction};
pub const HISTORY_EVENT_PAGE_SIZE: u64 = 20;
-1
View File
@@ -1,5 +1,4 @@
mod message;
mod util;
mod warning;
pub mod coins;
+2 -2
View File
@@ -2,14 +2,14 @@ use iced::{widget::Space, Alignment, Length};
use liana_ui::{
color,
component::{badge, button, card, form, text::*},
component::{amount::*, badge, button, card, form, text::*},
icon, theme,
util::Collection,
widget::*,
};
use crate::{
app::{error::Error, menu::Menu, view::util::*},
app::{error::Error, menu::Menu},
daemon::model::{SpendStatus, SpendTx},
};
+2 -5
View File
@@ -11,15 +11,12 @@ use liana::miniscript::bitcoin::{
};
use liana_ui::{
component::{button, form, text::*},
component::{amount::*, button, form, text::*},
icon, theme,
widget::*,
};
use crate::app::view::{
message::{CreateSpendMessage, Message},
util::amount,
};
use crate::app::view::message::{CreateSpendMessage, Message};
#[allow(clippy::too_many_arguments)]
pub fn recovery<'a>(
+2 -1
View File
@@ -16,6 +16,7 @@ use liana::{
use liana_ui::{
color,
component::{
amount::*,
badge, button, card,
collapse::Collapse,
form, hw, separation,
@@ -29,7 +30,7 @@ use liana_ui::{
use crate::{
app::{
error::Error,
view::{hw::hw_list_view, message::*, util::*, warning::warn},
view::{hw::hw_list_view, message::*, warning::warn},
},
daemon::model::{Coin, SpendStatus, SpendTx},
hw::HardwareWallet,
+2 -1
View File
@@ -5,6 +5,7 @@ use liana::miniscript::bitcoin::Amount;
use liana_ui::{
color,
component::{
amount::*,
badge, button, form,
text::{text, Text},
},
@@ -17,7 +18,7 @@ use crate::{
app::{
cache::Cache,
error::Error,
view::{message::*, modal, util::amount},
view::{message::*, modal},
},
daemon::model::{remaining_sequence, Coin},
};
+2 -5
View File
@@ -3,17 +3,14 @@ use chrono::NaiveDateTime;
use iced::{alignment, Alignment, Length};
use liana_ui::{
component::{badge, card, text::*},
component::{amount::*, badge, card, text::*},
icon, theme,
util::Collection,
widget::*,
};
use crate::{
app::{
cache::Cache,
view::{message::Message, util::*},
},
app::{cache::Cache, view::message::Message},
daemon::model::HistoryTransaction,
};
-59
View File
@@ -1,59 +0,0 @@
use liana::miniscript::bitcoin::Amount;
use liana_ui::{color, component::text::*, util::Collection, widget::*};
pub fn amount<'a, T: 'a>(a: &Amount) -> impl Into<Element<'a, T>> {
amount_with_size(a, P1_SIZE)
}
pub fn amount_with_size<'a, T: 'a>(a: &Amount, size: u16) -> impl Into<Element<'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))
}
+4
View File
@@ -180,4 +180,8 @@ impl HistoryTransaction {
pub fn is_external(&self) -> bool {
self.coins.is_empty()
}
pub fn is_self_send(&self) -> bool {
!self.coins.is_empty() && self.outgoing_amount == Amount::from_sat(0)
}
}