Skip to content

Commit a54c19c

Browse files
committed
feat: expose settlement_invoice_status in billing summary API
Queries the settlement invoice status when a billing cycle has a linked settlement_invoice_id, so the dashboard can show intermediate states (detected/confirmed) instead of always showing "SETTLE NOW".
1 parent f308161 commit a54c19c

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ async fn billing_summary(
10841084
"auto_collected_zec": summary.auto_collected_zec,
10851085
"outstanding_zec": summary.outstanding_zec,
10861086
"min_settlement_zec": 0.05,
1087+
"settlement_invoice_status": summary.settlement_invoice_status,
10871088
})),
10881089
Err(e) => {
10891090
tracing::error!(error = %e, "Failed to get billing summary");

src/billing/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub struct BillingSummary {
5555
pub total_fees_zatoshis: i64,
5656
pub auto_collected_zatoshis: i64,
5757
pub outstanding_zatoshis: i64,
58+
pub settlement_invoice_status: Option<String>,
5859
}
5960

6061
pub async fn create_fee_entry(
@@ -189,6 +190,16 @@ pub async fn get_billing_summary(
189190
None => (0, 0, 0),
190191
};
191192

193+
let settlement_invoice_status: Option<String> = match &current_cycle {
194+
Some(c) if c.settlement_invoice_id.is_some() => {
195+
sqlx::query_scalar("SELECT status FROM invoices WHERE id = ?")
196+
.bind(c.settlement_invoice_id.as_ref().unwrap())
197+
.fetch_optional(pool)
198+
.await?
199+
}
200+
_ => None,
201+
};
202+
192203
Ok(BillingSummary {
193204
fee_rate: config.fee_rate,
194205
trust_tier,
@@ -200,6 +211,7 @@ pub async fn get_billing_summary(
200211
total_fees_zatoshis,
201212
auto_collected_zatoshis,
202213
outstanding_zatoshis,
214+
settlement_invoice_status,
203215
})
204216
}
205217

0 commit comments

Comments
 (0)