Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tx flowchart #329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bitcoin = { version = "0.27", features = ["base64", "use-serde"] }
revaultd = { git = "https://github.com/revault/revaultd", default-features = false}
backtrace = "0.3"

iced = { version = "0.4", default-features= false, features = ["tokio", "wgpu", "svg", "qr_code"] }
iced = { version = "0.4", default-features= false, features = ["tokio", "wgpu", "svg", "qr_code", "canvas"] }
iced_native = "0.5"
revault_ui = { path = "./ui" }
revault_hwi = { path = "./hwi" }
Expand Down
5 changes: 4 additions & 1 deletion src/app/message.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use bitcoin::{util::psbt::PartiallySignedTransaction as Psbt, OutPoint};
use std::sync::Arc;

use bitcoin::{util::psbt::PartiallySignedTransaction as Psbt, OutPoint};
use tokio::sync::Mutex;

use revault_hwi::{app::revault::RevaultHWI, HWIError};
use revault_ui::chart::FlowChartMessage;
use revaultd::config::Config as DaemonConfig;

use crate::{
Expand Down Expand Up @@ -104,6 +105,8 @@ pub enum SpendTxMessage {
#[derive(Debug, Clone)]
pub enum HistoryEventMessage {
OnChainTransactions(Result<Vec<VaultTransactions>, RevaultDError>),
ToggleFlowChart(bool),
FlowChart(FlowChartMessage),
}

#[derive(Debug, Clone)]
Expand Down
105 changes: 95 additions & 10 deletions src/app/state/history.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::convert::TryInto;
use std::time::{SystemTime, UNIX_EPOCH};

use bitcoin::Txid;
use iced::{Command, Element};

use super::State;

use revault_ui::chart::{FlowChart, FlowChartMessage};

use crate::{
app::{
context::Context,
Expand All @@ -13,7 +16,10 @@ use crate::{
view::LoadingDashboard,
view::{HistoryEventListItemView, HistoryEventView, HistoryView},
},
daemon::model::{HistoryEvent, HistoryEventKind, VaultTransactions, ALL_HISTORY_EVENTS},
daemon::model::{
HistoryEvent, HistoryEventKind, HistoryEventTransaction, TransactionKind,
ALL_HISTORY_EVENTS,
},
};

pub const HISTORY_EVENT_PAGE_SIZE: u64 = 20;
Expand Down Expand Up @@ -93,7 +99,7 @@ impl State for HistoryState {
}
Message::HistoryEvent(msg) => {
if let Some(event) = selected_event {
event.update(msg)
event.update(ctx, msg)
}
}
Message::Close => {
Expand Down Expand Up @@ -283,7 +289,9 @@ impl HistoryEventListItemState {
#[derive(Debug)]
pub struct HistoryEventState {
event: HistoryEvent,
txs: Vec<VaultTransactions>,
txs: Vec<HistoryEventTransaction>,
selected_tx: Option<Txid>,
flowchart: Option<FlowChart>,
loading_fail: Option<Error>,
view: HistoryEventView,
}
Expand All @@ -293,22 +301,99 @@ impl HistoryEventState {
Self {
event,
txs: Vec::new(),
flowchart: None,
selected_tx: None,
loading_fail: None,
view: HistoryEventView::new(),
}
}

pub fn update(&mut self, message: HistoryEventMessage) {
let HistoryEventMessage::OnChainTransactions(res) = message;
match res {
Ok(txs) => self.txs = txs,
Err(e) => self.loading_fail = Some(e.into()),
pub fn update(&mut self, ctx: &Context, message: HistoryEventMessage) {
match message {
HistoryEventMessage::ToggleFlowChart(toggle) => {
if toggle {
self.flowchart = Some(FlowChart::new(
ctx.network(),
self.txs
.iter()
.map(|event_tx| event_tx.tx.clone())
.collect(),
));
} else {
self.flowchart = None;
}
}
HistoryEventMessage::FlowChart(FlowChartMessage::TxSelected(txid)) => {
if self.selected_tx.is_none() {
self.selected_tx = txid;
} else {
self.selected_tx = None;
}
}
HistoryEventMessage::OnChainTransactions(res) => match res {
Ok(vault_txs) => {
let mut list: Vec<HistoryEventTransaction> = Vec::new();
for txs in vault_txs {
list.push(HistoryEventTransaction::new(
&txs.deposit,
TransactionKind::Deposit,
));

if let Some(unvault) = txs.unvault {
list.push(HistoryEventTransaction::new(
&unvault,
TransactionKind::Unvault,
));
}
if let Some(cancel) = txs.cancel {
list.push(HistoryEventTransaction::new(
&cancel,
TransactionKind::Cancel,
));
}
if let Some(spend) = txs.spend {
list.push(HistoryEventTransaction::new(&spend, TransactionKind::Spend));
}
if let Some(unvault_emergency) = txs.unvault_emergency {
list.push(HistoryEventTransaction::new(
&unvault_emergency,
TransactionKind::UnvaultEmergency,
));
}
if let Some(emergency) = txs.emergency {
list.push(HistoryEventTransaction::new(
&emergency,
TransactionKind::Emergency,
));
}
}

list.sort_by(|a, b| a.blockheight.cmp(&b.blockheight));
self.txs = list;
}
Err(e) => self.loading_fail = Some(e.into()),
},
}
}

pub fn view(&mut self, ctx: &Context) -> Element<Message> {
self.view
.view(ctx, &self.event, &self.txs, self.loading_fail.as_ref())
let selected = if let Some(txid) = self.selected_tx {
self.txs.iter().find(|vault_tx| vault_tx.tx.txid() == txid)
} else {
None
};
self.view.view(
ctx,
&self.event,
&self.txs,
selected,
self.flowchart.as_mut().map(|chart| {
chart
.view()
.map(|msg| Message::HistoryEvent(HistoryEventMessage::FlowChart(msg)))
}),
self.loading_fail.as_ref(),
)
}

pub fn load(&self, ctx: &Context) -> Command<Message> {
Expand Down
2 changes: 1 addition & 1 deletion src/app/state/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl State for ManagerHomeState {
}
Message::HistoryEvent(msg) => {
if let Some(event) = selected_event {
event.update(msg)
event.update(ctx, msg)
}
}
Message::Close => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/state/stakeholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl State for StakeholderHomeState {
}
Message::HistoryEvent(msg) => {
if let Some(event) = selected_event {
event.update(msg)
event.update(ctx, msg)
}
}
Message::Close => {
Expand Down
Loading