invoice.rs (2625B)
1 use crate::event::LoadingState; 2 use crate::ui; 3 use lightning_invoice::Bolt11Invoice; 4 use notedeck::AppContext; 5 use serde::{Deserialize, Serialize}; 6 use std::collections::HashMap; 7 8 #[derive(Debug, Deserialize, Serialize)] 9 pub struct Invoice { 10 pub lastpay_index: Option<u64>, 11 pub label: String, 12 pub bolt11: Bolt11Invoice, 13 pub payment_hash: String, 14 pub amount_msat: u64, 15 pub status: String, 16 pub description: String, 17 pub expires_at: u64, 18 pub created_index: u64, 19 pub updated_index: u64, 20 } 21 22 pub fn invoices_ui( 23 ui: &mut egui::Ui, 24 invoice_notes: &HashMap<String, [u8; 32]>, 25 ctx: &mut AppContext, 26 invoices: &LoadingState<Vec<Invoice>, lnsocket::Error>, 27 ) { 28 match invoices { 29 LoadingState::Loading => { 30 ui.label("loading invoices..."); 31 } 32 33 LoadingState::Failed(err) => { 34 ui.label(format!("failed to load invoices: {err}")); 35 } 36 37 LoadingState::Loaded(invoices) => { 38 use egui_extras::{Column, TableBuilder}; 39 40 TableBuilder::new(ui) 41 .column(Column::auto().resizable(true)) 42 .column(Column::remainder()) 43 .vscroll(false) 44 .header(20.0, |mut header| { 45 header.col(|ui| { 46 ui.strong("description"); 47 }); 48 header.col(|ui| { 49 ui.strong("amount"); 50 }); 51 }) 52 .body(|mut body| { 53 for invoice in invoices { 54 body.row(20.0, |mut row| { 55 row.col(|ui| { 56 if invoice.description.starts_with("{") { 57 ui.label("Zap!").on_hover_ui_at_pointer(|ui| { 58 ui::note_hover_ui(ui, &invoice.label, ctx, invoice_notes); 59 }); 60 } else { 61 ui.label(&invoice.description); 62 } 63 }); 64 row.col(|ui| match invoice.bolt11.amount_milli_satoshis() { 65 None => { 66 ui.label("any"); 67 } 68 Some(amt) => { 69 ui.label(ui::human_verbose_sat(amt as i64)); 70 } 71 }); 72 }); 73 } 74 }); 75 } 76 } 77 }