Merge #1165: Add interrupt method to state trait

5c59c4f5deb5576b7935191d4ed11a8916c974de Add interrupt method to state trait (edouardparis)

Pull request description:

  Before changing panel, the previous state may need to release a hardware connection for example.
  In order to achieve this we introduce an interrupt method that is used to drop action state.

  close #1162

ACKs for top commit:
  pythcoiner:
    tACK 5c59c4f5deb5576b7935191d4ed11a8916c974de
  jp1ac4:
    ACK 5c59c4f5deb5576b7935191d4ed11a8916c974de.

Tree-SHA512: 6405a928f0303b25ff863e76dcc7a36e703471cf726c10e755b4145d301d4e01b0ca241160b49216cb456fc7d934c83fcbecf976dcee56473163cce01507f7b0
This commit is contained in:
edouardparis 2024-07-01 15:32:43 +02:00
commit 1f86504bdc
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F
6 changed files with 22 additions and 0 deletions

View File

@ -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 {

View File

@ -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>,

View File

@ -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()

View File

@ -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>,

View File

@ -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>,

View File

@ -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()
@ -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()