Skip to content

Commit

Permalink
add explicit self-spend cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Feb 14, 2024
1 parent 8741a90 commit 496aaea
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
6 changes: 3 additions & 3 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@
"wallet-home": "Wallet - Set Name Here TBD",
"wallet-create-contract": "Create Contract",
"wallet-create-contract-other-address": "Other Party's Slatepack Address",
"wallet-self-send": "Self-send",
"wallet-self-send-instruction": "This is a self-send",
"wallet-self-send": "Self-spend",
"wallet-self-send-instruction": "This is a self-spend",
"tx-contract-debit": "I will agree to PAY",
"tx-contract-credit": "I will agree to RECEIVE",
"apply-tx": "Continue Transaction",
Expand Down Expand Up @@ -304,7 +304,7 @@
"tx-i1-finalization-1": "You are finalizing an agreement to receive [AMOUNT] Grin",
"tx-s1-finalization-2": "Along with a mining fee of [AMOUNT] Grin",
"tx-s1-finalization-3": "This will complete the transaction and post it to the chain, at which point it becomes irreversible.",
"tx-s1-finalization-self-send": "You are self-sending [AMOUNT] Grin",
"tx-s1-finalization-self-send": "You are self-spending [AMOUNT] Grin",
"tx-done-instruction": "The transaction has been completed and posted to the chain. Please wait a few blocks for validation.",
"signing-tx": "Signing...",
"mw-mixnet-addresses": "MWMixnet Server Keys",
Expand Down
43 changes: 39 additions & 4 deletions src/gui/element/wallet/operation/apply_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use grin_gui_core::{
use grin_gui_widgets::widget::header;
use iced_aw::Card;
use iced_core::Widget;
use serde::de;
use std::path::PathBuf;

use super::tx_list::{HeaderState, TxList};
Expand Down Expand Up @@ -77,6 +78,7 @@ pub enum LocalViewInteraction {
ReadFromClipboardSuccess(String),
ReadFromClipboardFailure,
ShowSlate,
CancelSelfSpend,
}

pub fn handle_message<'a>(
Expand Down Expand Up @@ -189,6 +191,33 @@ pub fn handle_message<'a>(
grin_gui.wallet_state.operation_state.mode =
crate::gui::element::wallet::operation::Mode::ShowSlatepack;
}
LocalViewInteraction::CancelSelfSpend => {
// If this was a self-send, cancel the transaction and remove from log
if state.confirm_state.is_self_send {
// Unwrap tx id
let tx_id = match state.confirm_state.slatepack_parsed.as_ref() {
Some(p) => {
if let Some(t) = p.2.as_ref() {
Some(t.id)
} else {
None
}
}
None => None,
};
let w = grin_gui.wallet_interface.clone();
let fut = move || WalletInterface::cancel_tx(w, tx_id.unwrap());
debug!("Cancelling self-spend tx: {:?}", tx_id);

return Ok(Command::perform(fut(), |_| {
return Message::Interaction(
Interaction::WalletOperationApplyTxViewInteraction(
crate::gui::element::wallet::operation::apply_tx::LocalViewInteraction::BackCleanup,
),
);
}));
}
}
LocalViewInteraction::Address(_) => {}
LocalViewInteraction::ApplyTransaction(_) => {}
}
Expand Down Expand Up @@ -386,12 +415,18 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
.center_y()
.align_x(alignment::Horizontal::Center);

let cancel_button: Element<Interaction> = Button::new(cancel_button_label_container)
.style(grin_gui_core::theme::ButtonStyle::Primary)
.on_press(Interaction::WalletOperationApplyTxViewInteraction(
let cancel_button = Button::new(cancel_button_label_container)
.style(grin_gui_core::theme::ButtonStyle::Primary);
let cancel_button: Element<Interaction> = if state.confirm_state.is_self_send {
cancel_button.on_press(Interaction::WalletOperationApplyTxViewInteraction(
LocalViewInteraction::CancelSelfSpend,
))
} else {
cancel_button.on_press(Interaction::WalletOperationApplyTxViewInteraction(
LocalViewInteraction::Back,
))
.into();
}
.into();

let submit_container = Container::new(submit_button.map(Message::Interaction)).padding(1);
let submit_container = Container::new(submit_container)
Expand Down

0 comments on commit 496aaea

Please sign in to comment.