Skip to content

Commit bdff4b5

Browse files
committed
Add tx flowchart for visual entertainment
1 parent b785fe8 commit bdff4b5

File tree

13 files changed

+825
-38
lines changed

13 files changed

+825
-38
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bitcoin = { version = "0.27", features = ["base64", "use-serde"] }
2323
revaultd = { git = "https://github.com/revault/revaultd", branch = "master", default-features = false}
2424
backtrace = "0.3"
2525

26-
iced = { version = "0.3", default-features= false, features = ["tokio", "wgpu", "svg", "qr_code"] }
26+
iced = { version = "0.3", default-features= false, features = ["tokio", "wgpu", "svg", "qr_code", "canvas"] }
2727
revault_ui = { path = "./ui" }
2828
revault_hwi = { path = "./hwi" }
2929
iced_native = "0.4"

src/app/message.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use bitcoin::{util::psbt::PartiallySignedTransaction as Psbt, OutPoint};
2-
use revault_hwi::{app::revault::RevaultHWI, HWIError};
32
use std::sync::Arc;
43
use tokio::sync::Mutex;
54

5+
use revault_hwi::{app::revault::RevaultHWI, HWIError};
6+
use revault_ui::chart::FlowChartMessage;
7+
68
use crate::{
79
app::{error::Error, menu::Menu},
810
daemon::{
@@ -77,6 +79,8 @@ pub enum SpendTxMessage {
7779
#[derive(Debug, Clone)]
7880
pub enum HistoryEventMessage {
7981
OnChainTransactions(Result<Vec<VaultTransactions>, RevaultDError>),
82+
ToggleFlowChart(bool),
83+
FlowChart(FlowChartMessage),
8084
}
8185

8286
#[derive(Debug, Clone)]

src/app/state/history.rs

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use std::convert::TryInto;
22
use std::time::{SystemTime, UNIX_EPOCH};
33

4+
use bitcoin::Txid;
45
use iced::{Command, Element};
56

67
use super::State;
78

9+
use revault_ui::chart::{FlowChart, FlowChartMessage};
10+
811
use crate::{
912
app::{
1013
context::Context,
@@ -13,7 +16,10 @@ use crate::{
1316
view::LoadingDashboard,
1417
view::{HistoryEventListItemView, HistoryEventView, HistoryView},
1518
},
16-
daemon::model::{HistoryEvent, HistoryEventKind, VaultTransactions, ALL_HISTORY_EVENTS},
19+
daemon::model::{
20+
HistoryEvent, HistoryEventKind, HistoryEventTransaction, TransactionKind,
21+
ALL_HISTORY_EVENTS,
22+
},
1723
};
1824

1925
pub const HISTORY_EVENT_PAGE_SIZE: u64 = 20;
@@ -93,7 +99,7 @@ impl State for HistoryState {
9399
}
94100
Message::HistoryEvent(msg) => {
95101
if let Some(event) = selected_event {
96-
event.update(msg)
102+
event.update(ctx, msg)
97103
}
98104
}
99105
Message::Close => {
@@ -283,7 +289,9 @@ impl HistoryEventListItemState {
283289
#[derive(Debug)]
284290
pub struct HistoryEventState {
285291
event: HistoryEvent,
286-
txs: Vec<VaultTransactions>,
292+
txs: Vec<HistoryEventTransaction>,
293+
selected_tx: Option<Txid>,
294+
flowchart: Option<FlowChart>,
287295
loading_fail: Option<Error>,
288296
view: HistoryEventView,
289297
}
@@ -293,22 +301,99 @@ impl HistoryEventState {
293301
Self {
294302
event,
295303
txs: Vec::new(),
304+
flowchart: None,
305+
selected_tx: None,
296306
loading_fail: None,
297307
view: HistoryEventView::new(),
298308
}
299309
}
300310

301-
pub fn update(&mut self, message: HistoryEventMessage) {
302-
let HistoryEventMessage::OnChainTransactions(res) = message;
303-
match res {
304-
Ok(txs) => self.txs = txs,
305-
Err(e) => self.loading_fail = Some(e.into()),
311+
pub fn update(&mut self, ctx: &Context, message: HistoryEventMessage) {
312+
match message {
313+
HistoryEventMessage::ToggleFlowChart(toggle) => {
314+
if toggle {
315+
self.flowchart = Some(FlowChart::new(
316+
ctx.network(),
317+
self.txs
318+
.iter()
319+
.map(|event_tx| event_tx.tx.clone())
320+
.collect(),
321+
));
322+
} else {
323+
self.flowchart = None;
324+
}
325+
}
326+
HistoryEventMessage::FlowChart(FlowChartMessage::TxSelected(txid)) => {
327+
if self.selected_tx.is_none() {
328+
self.selected_tx = txid;
329+
} else {
330+
self.selected_tx = None;
331+
}
332+
}
333+
HistoryEventMessage::OnChainTransactions(res) => match res {
334+
Ok(vault_txs) => {
335+
let mut list: Vec<HistoryEventTransaction> = Vec::new();
336+
for txs in vault_txs {
337+
list.push(HistoryEventTransaction::new(
338+
&txs.deposit,
339+
TransactionKind::Deposit,
340+
));
341+
342+
if let Some(unvault) = txs.unvault {
343+
list.push(HistoryEventTransaction::new(
344+
&unvault,
345+
TransactionKind::Unvault,
346+
));
347+
}
348+
if let Some(cancel) = txs.cancel {
349+
list.push(HistoryEventTransaction::new(
350+
&cancel,
351+
TransactionKind::Cancel,
352+
));
353+
}
354+
if let Some(spend) = txs.spend {
355+
list.push(HistoryEventTransaction::new(&spend, TransactionKind::Spend));
356+
}
357+
if let Some(unvault_emergency) = txs.unvault_emergency {
358+
list.push(HistoryEventTransaction::new(
359+
&unvault_emergency,
360+
TransactionKind::UnvaultEmergency,
361+
));
362+
}
363+
if let Some(emergency) = txs.emergency {
364+
list.push(HistoryEventTransaction::new(
365+
&emergency,
366+
TransactionKind::Emergency,
367+
));
368+
}
369+
}
370+
371+
list.sort_by(|a, b| a.blockheight.cmp(&b.blockheight));
372+
self.txs = list;
373+
}
374+
Err(e) => self.loading_fail = Some(e.into()),
375+
},
306376
}
307377
}
308378

309379
pub fn view(&mut self, ctx: &Context) -> Element<Message> {
310-
self.view
311-
.view(ctx, &self.event, &self.txs, self.loading_fail.as_ref())
380+
let selected = if let Some(txid) = self.selected_tx {
381+
self.txs.iter().find(|vault_tx| vault_tx.tx.txid() == txid)
382+
} else {
383+
None
384+
};
385+
self.view.view(
386+
ctx,
387+
&self.event,
388+
&self.txs,
389+
selected,
390+
self.flowchart.as_mut().map(|chart| {
391+
chart
392+
.view()
393+
.map(|msg| Message::HistoryEvent(HistoryEventMessage::FlowChart(msg)))
394+
}),
395+
self.loading_fail.as_ref(),
396+
)
312397
}
313398

314399
pub fn load(&self, ctx: &Context) -> Command<Message> {

src/app/state/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl State for ManagerHomeState {
344344
}
345345
Message::HistoryEvent(msg) => {
346346
if let Some(event) = selected_event {
347-
event.update(msg)
347+
event.update(ctx, msg)
348348
}
349349
}
350350
Message::Close => {

src/app/state/stakeholder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl State for StakeholderHomeState {
204204
}
205205
Message::HistoryEvent(msg) => {
206206
if let Some(event) = selected_event {
207-
event.update(msg)
207+
event.update(ctx, msg)
208208
}
209209
}
210210
Message::Close => {

0 commit comments

Comments
 (0)