Skip to content

Commit

Permalink
Add interrupt method to state trait
Browse files Browse the repository at this point in the history
Before changing panel, the previous state
may need to release a harware connection
for example.
In order to achieve this we introduce an interrupt method
that is used to drop action state.

close #1162
  • Loading branch information
edouardparis committed Jul 1, 2024
1 parent 1eb46b6 commit c4e2814
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gui/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ impl App {
}

fn set_current_panel(&mut self, menu: Menu) -> Command<Message> {
self.panels.current_mut().interrupt();

match &menu {
menu::Menu::TransactionPreSelected(txid) => {
if let Ok(Some(tx)) = Handle::current().block_on(async {
Expand Down
1 change: 1 addition & 0 deletions gui/src/app/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub trait State {
fn subscription(&self) -> Subscription<Message> {
Subscription::none()
}
fn interrupt(&mut self) {}
fn reload(
&mut self,
_daemon: Arc<dyn Daemon + Sync + Send>,
Expand Down
4 changes: 4 additions & 0 deletions gui/src/app/state/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ impl PsbtState {
}
}

pub fn interrupt(&mut self) {
self.action = None;
}

pub fn subscription(&self) -> Subscription<Message> {
if let Some(action) = &self.action {
action.as_ref().subscription()
Expand Down
4 changes: 4 additions & 0 deletions gui/src/app/state/psbts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ impl State for PsbtsPanel {
}
}

fn interrupt(&mut self) {
self.selected_tx = None;
}

fn update(
&mut self,
daemon: Arc<dyn Daemon + Sync + Send>,
Expand Down
4 changes: 4 additions & 0 deletions gui/src/app/state/spend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl State for CreateSpendPanel {
self.steps.get(self.current).unwrap().subscription()
}

fn interrupt(&mut self) {
self.steps.get_mut(self.current).unwrap().interrupt();
}

fn update(
&mut self,
daemon: Arc<dyn Daemon + Sync + Send>,
Expand Down
7 changes: 7 additions & 0 deletions gui/src/app/state/spend/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub trait Step {
message: Message,
) -> Command<Message>;
fn apply(&self, _draft: &mut TransactionDraft) {}
fn interrupt(&mut self) {}
fn load(&mut self, _draft: &TransactionDraft) {}
fn subscription(&self) -> Subscription<Message> {
Subscription::none()
Expand Down Expand Up @@ -776,6 +777,12 @@ impl Step for SaveSpend {
));
}

fn interrupt(&mut self) {
if let Some((psbt_state, _)) = &mut self.spend {
psbt_state.interrupt()
}
}

fn subscription(&self) -> Subscription<Message> {
if let Some((psbt_state, _)) = &self.spend {
psbt_state.subscription()
Expand Down

0 comments on commit c4e2814

Please sign in to comment.