gui: separate accounting events in the home panel
This commit is contained in:
parent
e7e8028d8a
commit
49be063ccd
@ -5,7 +5,7 @@ use iced::{alignment, Alignment, Length};
|
||||
use liana::miniscript::bitcoin;
|
||||
use liana_ui::{
|
||||
color,
|
||||
component::{amount::*, badge, text::*},
|
||||
component::{amount::*, event, text::*},
|
||||
icon, theme,
|
||||
util::Collection,
|
||||
widget::*,
|
||||
@ -23,7 +23,8 @@ pub fn home_view<'a>(
|
||||
events: &Vec<HistoryTransaction>,
|
||||
) -> Element<'a, Message> {
|
||||
Column::new()
|
||||
.push(amount_with_size(balance, 50))
|
||||
.push(h3("Balance"))
|
||||
.push(amount_with_size(balance, H1_SIZE))
|
||||
.push_maybe(recovery_warning.map(|(a, c)| {
|
||||
Row::new()
|
||||
.spacing(15)
|
||||
@ -60,6 +61,7 @@ pub fn home_view<'a>(
|
||||
.push(
|
||||
Column::new()
|
||||
.spacing(10)
|
||||
.push(h4_bold("Last payments"))
|
||||
.push(
|
||||
pending_events
|
||||
.iter()
|
||||
@ -71,6 +73,7 @@ pub fn home_view<'a>(
|
||||
.push(
|
||||
events
|
||||
.iter()
|
||||
.filter(|event| !event.is_self_send())
|
||||
.enumerate()
|
||||
.fold(Column::new().spacing(10), |col, (i, event)| {
|
||||
col.push(event_list_view(i + pending_events.len(), event))
|
||||
@ -98,57 +101,43 @@ pub fn home_view<'a>(
|
||||
},
|
||||
),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(20)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn event_list_view<'a>(i: usize, event: &HistoryTransaction) -> Element<'a, Message> {
|
||||
Container::new(
|
||||
Button::new(
|
||||
Row::new()
|
||||
.push(
|
||||
Row::new()
|
||||
.push(if event.is_external() {
|
||||
badge::receive()
|
||||
} else {
|
||||
badge::spend()
|
||||
})
|
||||
.push(if let Some(t) = event.time {
|
||||
Container::new(
|
||||
text(format!(
|
||||
"{}",
|
||||
NaiveDateTime::from_timestamp_opt(t as i64, 0).unwrap(),
|
||||
))
|
||||
.small(),
|
||||
)
|
||||
} else {
|
||||
badge::unconfirmed()
|
||||
})
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.push(if event.is_external() {
|
||||
Row::new()
|
||||
.spacing(5)
|
||||
.push(text("+"))
|
||||
.push(amount(&event.incoming_amount))
|
||||
.align_items(Alignment::Center)
|
||||
fn event_list_view<'a>(i: usize, event: &HistoryTransaction) -> Column<'a, Message> {
|
||||
event.tx.output.iter().enumerate().fold(
|
||||
Column::new().spacing(10),
|
||||
|col, (output_index, output)| {
|
||||
if event.is_external() {
|
||||
if !event.change_indexes.contains(&output_index) {
|
||||
col
|
||||
} else if let Some(t) = event.time {
|
||||
col.push(event::confirmed_incoming_event(
|
||||
NaiveDateTime::from_timestamp_opt(t as i64, 0).unwrap(),
|
||||
&Amount::from_sat(output.value),
|
||||
Message::Select(i),
|
||||
))
|
||||
} else {
|
||||
Row::new()
|
||||
.spacing(5)
|
||||
.push(text("-"))
|
||||
.push(amount(&event.outgoing_amount))
|
||||
.align_items(Alignment::Center)
|
||||
})
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(20),
|
||||
)
|
||||
.padding(10)
|
||||
.on_press(Message::Select(i))
|
||||
.style(theme::Button::TransparentBorder),
|
||||
col.push(event::unconfirmed_incoming_event(
|
||||
&Amount::from_sat(output.value),
|
||||
Message::Select(i),
|
||||
))
|
||||
}
|
||||
} else if event.change_indexes.contains(&output_index) {
|
||||
col
|
||||
} else if let Some(t) = event.time {
|
||||
col.push(event::confirmed_outgoing_event(
|
||||
NaiveDateTime::from_timestamp_opt(t as i64, 0).unwrap(),
|
||||
&Amount::from_sat(output.value),
|
||||
Message::Select(i),
|
||||
))
|
||||
} else {
|
||||
col.push(event::unconfirmed_outgoing_event(
|
||||
&Amount::from_sat(output.value),
|
||||
Message::Select(i),
|
||||
))
|
||||
}
|
||||
},
|
||||
)
|
||||
.style(theme::Container::Card(theme::Card::Simple))
|
||||
.into()
|
||||
}
|
||||
|
||||
@ -206,6 +206,8 @@ fn spend_header<'a>(tx: &SpendTx) -> Element<'a, Message> {
|
||||
.push(badge::Badge::new(icon::send_icon()).style(theme::Badge::Standard))
|
||||
.push(if !tx.sigs.recovery_paths().is_empty() {
|
||||
text("Recovery").bold()
|
||||
} else if tx.spend_amount == Amount::from_sat(0) {
|
||||
text("Self send").bold()
|
||||
} else {
|
||||
text("Spend").bold()
|
||||
})
|
||||
|
||||
@ -99,12 +99,14 @@ fn tx_list_view<'a>(i: usize, tx: &HistoryTransaction) -> Element<'a, Message> {
|
||||
.push(text("+"))
|
||||
.push(amount(&tx.incoming_amount))
|
||||
.align_items(Alignment::Center)
|
||||
} else {
|
||||
} else if tx.outgoing_amount != Amount::from_sat(0) {
|
||||
Row::new()
|
||||
.spacing(5)
|
||||
.push(text("-"))
|
||||
.push(amount(&tx.outgoing_amount))
|
||||
.align_items(Alignment::Center)
|
||||
} else {
|
||||
Row::new().push(text("Self send"))
|
||||
})
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(20),
|
||||
|
||||
@ -261,18 +261,20 @@ impl Section for Events {
|
||||
"Events "
|
||||
}
|
||||
fn view(&self) -> Element<Message> {
|
||||
let d = chrono::NaiveDate::from_ymd_opt(2015, 6, 3).unwrap();
|
||||
let t = chrono::NaiveTime::from_hms_milli_opt(12, 34, 56, 789).unwrap();
|
||||
column![
|
||||
h1(self.title()),
|
||||
column![
|
||||
event::unconfirmed_outgoing_event(&Amount::from_sat(32934234), Message::Ignore),
|
||||
event::confirmed_outgoing_event(
|
||||
chrono::NaiveDate::from_ymd_opt(2023, 04, 19).unwrap(),
|
||||
chrono::NaiveDateTime::new(d, t),
|
||||
&Amount::from_sat(32934234),
|
||||
Message::Ignore
|
||||
),
|
||||
event::unconfirmed_incoming_event(&Amount::from_sat(32934234), Message::Ignore),
|
||||
event::confirmed_incoming_event(
|
||||
chrono::NaiveDate::from_ymd_opt(2023, 04, 19).unwrap(),
|
||||
chrono::NaiveDateTime::new(d, t),
|
||||
&Amount::from_sat(32934234),
|
||||
Message::Ignore
|
||||
)
|
||||
|
||||
@ -36,9 +36,12 @@ pub fn amount_with_size<'a, T: 'a>(a: &Amount, size: u16) -> Row<'a, T> {
|
||||
.into()
|
||||
});
|
||||
|
||||
Row::with_children(vec![row.into(), text("BTC").size(size).into()])
|
||||
.spacing(spacing)
|
||||
.align_items(iced::Alignment::Center)
|
||||
Row::with_children(vec![
|
||||
row.into(),
|
||||
text("BTC").size(size).style(color::GREY_3).into(),
|
||||
])
|
||||
.spacing(spacing)
|
||||
.align_items(iced::Alignment::Center)
|
||||
}
|
||||
|
||||
fn split_digits<'a, T: 'a>(mut s: String, size: u16) -> impl Into<Element<'a, T>> {
|
||||
@ -47,7 +50,7 @@ fn split_digits<'a, T: 'a>(mut s: String, size: u16) -> impl Into<Element<'a, T>
|
||||
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(text(s).size(size).style(color::GREY_3))
|
||||
.push_maybe(if right.is_empty() {
|
||||
None
|
||||
} else {
|
||||
|
||||
@ -22,7 +22,7 @@ pub fn unconfirmed_outgoing_event<'a, T: Clone + 'a>(amount: &Amount, msg: T) ->
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.padding(10)
|
||||
.padding(5)
|
||||
.spacing(20),
|
||||
)
|
||||
.on_press(msg)
|
||||
@ -32,7 +32,7 @@ pub fn unconfirmed_outgoing_event<'a, T: Clone + 'a>(amount: &Amount, msg: T) ->
|
||||
}
|
||||
|
||||
pub fn confirmed_outgoing_event<'a, T: Clone + 'a>(
|
||||
date: chrono::NaiveDate,
|
||||
date: chrono::NaiveDateTime,
|
||||
amount: &Amount,
|
||||
msg: T,
|
||||
) -> Container<'a, T> {
|
||||
@ -48,7 +48,7 @@ pub fn confirmed_outgoing_event<'a, T: Clone + 'a>(
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.padding(10)
|
||||
.padding(5)
|
||||
.spacing(20),
|
||||
)
|
||||
.on_press(msg)
|
||||
@ -70,7 +70,7 @@ pub fn unconfirmed_incoming_event<'a, T: Clone + 'a>(amount: &Amount, msg: T) ->
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.padding(10)
|
||||
.padding(5)
|
||||
.spacing(20),
|
||||
)
|
||||
.on_press(msg)
|
||||
@ -80,7 +80,7 @@ pub fn unconfirmed_incoming_event<'a, T: Clone + 'a>(amount: &Amount, msg: T) ->
|
||||
}
|
||||
|
||||
pub fn confirmed_incoming_event<'a, T: Clone + 'a>(
|
||||
date: chrono::NaiveDate,
|
||||
date: chrono::NaiveDateTime,
|
||||
amount: &Amount,
|
||||
msg: T,
|
||||
) -> Container<'a, T> {
|
||||
@ -96,7 +96,7 @@ pub fn confirmed_incoming_event<'a, T: Clone + 'a>(
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.padding(10)
|
||||
.padding(5)
|
||||
.spacing(20),
|
||||
)
|
||||
.on_press(msg)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user