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

Update transaction workflow to display pasted slates #59

Merged
merged 1 commit into from
Feb 3, 2023
Merged
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
5 changes: 4 additions & 1 deletion locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
"tx-create-submit": "Create",
"tx-confirmed": "Confirmed",
"tx-create-success-title": "Transaction Created",
"tx-paste-success-title": "Transaction Data",
"tx-create-success-desc": "Send this encrypted slate to the recipient via a channel of your choosing",
"tx-unconfirmed": "Not Confirmed",
"tx-list": "Transactions",
Expand All @@ -240,8 +241,10 @@
"tx-details": "Details",
"tx-details-title": "Transaction Details",
"tx-slatepack-paste-transaction-here": "Paste Transaction from Clipboard",
"tx-slatepack-read-result-default": "Ensure the clipboard contains the encrypted slatepack contents and press 'Continue'",
"tx-slatepack-read-result-default": "Ensure the clipboard contains the encrypted slatepack contents and press 'Paste'",
"tx-slatepack-read-failure": "Clipboard does not contain a slatepack that can be decrypted by this wallet",
"tx-slatepack-read-success": "Clipboard contains the above slatepack - Press 'Continue' to progress this transaction",
"tx-paste": "Paste",
"tx-continue": "Continue",
"apply-tx-confirm": "Confirm Transaction Details",
"tx-sender-name": "Sender",
Expand Down
5 changes: 4 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"create-tx": "Start Transaction",
"create-tx-amount-error": "Invalid amount provided",
"create-tx-address-error": "Invalid slatepack address",
"tx-paste-success-title": "Transaction Data",
"slatepack-address-name": "This Wallet's Slatepack Address",
"address-instruction": "Provide this address to others to allow them to send you funds",
"recipient-address-instruction": "Input the address of the recipient's wallet here",
Expand All @@ -251,8 +252,10 @@
"tx-create-success-title": "Encrypted Transaction",
"tx-create-success-desc": "Copy/Paste this encrypted transaction to the recipient via a channel of your choosing",
"tx-slatepack-paste-transaction-here": "Paste Transaction from Clipboard",
"tx-slatepack-read-result-default": "Ensure the clipboard contains the encrypted slatepack contents and press 'Continue'",
"tx-slatepack-read-result-default": "Ensure the clipboard contains the encrypted slatepack contents and press 'Paste'",
"tx-slatepack-read-failure": "Clipboard does not contain a slatepack that can be decrypted by this wallet",
"tx-slatepack-read-success": "Clipboard contains the above slatepack - Press 'Continue' to progress this transaction",
"tx-paste": "Paste",
"tx-continue": "Continue",
"apply-tx-confirm": "Confirm Transaction Details",
"tx-sender-name": "Sender",
Expand Down
99 changes: 87 additions & 12 deletions src/gui/element/wallet/operation/apply_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub struct StateContainer {
pub address_value: String,
// Slatepack read result
pub slatepack_read_result: String,
// Slatepack data itself as read
pub slatepack_read_data: String,
// whether we can continue
pub can_continue: bool,
}

impl Default for StateContainer {
Expand All @@ -50,6 +54,8 @@ impl Default for StateContainer {
// address_state: Default::default(),
address_value: Default::default(),
slatepack_read_result: localized_string("tx-slatepack-read-result-default"),
slatepack_read_data: Default::default(),
can_continue: false,
}
}
}
Expand All @@ -60,6 +66,7 @@ pub enum Action {}
#[derive(Debug, Clone)]
pub enum LocalViewInteraction {
Back,
Continue,
Address(String),
ApplyTransaction(String),
ReadFromClipboardSuccess(String),
Expand All @@ -74,25 +81,53 @@ pub fn handle_message<'a>(
match message {
LocalViewInteraction::Back => {
log::debug!("Interaction::WalletOperationApplyTxViewInteraction(Back)");
state.slatepack_read_result = localized_string("tx-slatepack-read-result-default");
state.slatepack_read_data = "".to_string();
grin_gui.wallet_state.operation_state.mode =
crate::gui::element::wallet::operation::Mode::Home;
grin_gui
.wallet_state
.operation_state
.apply_tx_confirm_state
.slatepack_parsed = None;
state.can_continue = false;
}
LocalViewInteraction::ReadFromClipboardSuccess(value) => {
debug!("Read from clipboard: {}", value);
let w = grin_gui.wallet_interface.clone();
let decode_res = WalletInterface::decrypt_slatepack(w, value);
let decode_res = WalletInterface::decrypt_slatepack(w, value.clone());
match decode_res {
Err(e) => {
state.slatepack_read_result = localized_string("tx-slatepack-read-failure")
state.slatepack_read_result = localized_string("tx-slatepack-read-failure");
state.slatepack_read_data = "".to_string();
grin_gui
.wallet_state
.operation_state
.apply_tx_confirm_state
.slatepack_parsed = None;

state.can_continue = false;
}
Ok(s) => {
debug!("{}", s.0);
grin_gui.wallet_state.operation_state.apply_tx_confirm_state.slatepack_parsed = Some(s);
grin_gui.wallet_state.operation_state.mode =
crate::gui::element::wallet::operation::Mode::ApplyTxConfirm;
state.slatepack_read_result = localized_string("tx-slatepack-read-success");
state.slatepack_read_data = value;
grin_gui
.wallet_state
.operation_state
.apply_tx_confirm_state
.slatepack_parsed = Some(s);
state.can_continue = true;
}
}
}
LocalViewInteraction::Continue => {
state.slatepack_read_result = localized_string("tx-slatepack-read-result-default");
state.slatepack_read_data = "".to_string();
state.can_continue = false;
grin_gui.wallet_state.operation_state.mode =
crate::gui::element::wallet::operation::Mode::ApplyTxConfirm;
}
LocalViewInteraction::ReadFromClipboardFailure => {
error!("Failed to read from clipboard");
}
Expand Down Expand Up @@ -182,6 +217,20 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
.size(DEFAULT_FONT_SIZE)
.width(Length::Units(400));

let encrypted_slate_card = Card::new(
Text::new(localized_string("tx-paste-success-title")).size(DEFAULT_HEADER_FONT_SIZE),
Text::new(&state.slatepack_read_data).size(DEFAULT_FONT_SIZE),
)
.foot(
Column::new()
.spacing(10)
.padding(5)
.width(Length::Fill)
.align_items(Alignment::Center),
)
.max_width(400)
.style(grin_gui_core::theme::CardStyle::Normal);

/*let paste_slatepack_button = Button::new(
// &mut state.copy_address_button_state,
Text::new(localized_string("tx-slatepack-paste-from-clipboard"))
Expand All @@ -201,6 +250,8 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
let slatepack_area = Column::new()
.push(slatepack_paste_name_container)
.push(Space::new(Length::Units(0), Length::Units(unit_spacing)))
.push(encrypted_slate_card)
.push(Space::new(Length::Units(0), Length::Units(unit_spacing)))
.push(paste_slatepack_row);

let slatepack_area_container = Container::new(slatepack_area);
Expand All @@ -209,7 +260,7 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
let button_width = Length::Units(BUTTON_WIDTH);

let submit_button_label_container =
Container::new(Text::new(localized_string("tx-continue")).size(DEFAULT_FONT_SIZE))
Container::new(Text::new(localized_string("tx-paste")).size(DEFAULT_FONT_SIZE))
.width(button_width)
.height(button_height)
.center_x()
Expand All @@ -219,12 +270,24 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
let mut submit_button = Button::new(submit_button_label_container)
.style(grin_gui_core::theme::ButtonStyle::Primary)
.on_press(Interaction::ReadSlatepackFromClipboard);
/*let submit_button = submit_button.on_press(Interaction::WalletOperationApplyTxViewInteraction(
LocalViewInteraction::ApplyTransaction("_".into()),
));*/

let submit_button: Element<Interaction> = submit_button.into();

let continue_button_label_container =
Container::new(Text::new(localized_string("tx-continue")).size(DEFAULT_FONT_SIZE))
.width(button_width)
.height(button_height)
.center_x()
.center_y()
.align_x(alignment::Horizontal::Center);

let continue_button: Element<Interaction> = Button::new(continue_button_label_container)
.style(grin_gui_core::theme::ButtonStyle::Primary)
.on_press(Interaction::WalletOperationApplyTxViewInteraction(
LocalViewInteraction::Continue,
))
.into();

let cancel_button_label_container =
Container::new(Text::new(localized_string("cancel")).size(DEFAULT_FONT_SIZE))
.width(button_width)
Expand All @@ -245,15 +308,27 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
.style(grin_gui_core::theme::ContainerStyle::Segmented)
.padding(1);

let continue_container = Container::new(continue_button.map(Message::Interaction)).padding(1);
let continue_container = Container::new(continue_container)
.style(grin_gui_core::theme::ContainerStyle::Segmented)
.padding(1);

let cancel_container = Container::new(cancel_button.map(Message::Interaction)).padding(1);
let cancel_container = Container::new(cancel_container)
.style(grin_gui_core::theme::ContainerStyle::Segmented)
.padding(1);

let button_row = Row::new()
let mut button_row = Row::new()
.push(submit_container)
.push(Space::new(Length::Units(unit_spacing), Length::Units(0)))
.push(cancel_container);
.push(Space::new(Length::Units(unit_spacing), Length::Units(0)));

if state.can_continue {
button_row = button_row
.push(continue_container)
.push(Space::new(Length::Units(unit_spacing), Length::Units(0)))
}

button_row = button_row.push(cancel_container);

let column = Column::new()
.push(address_name_container)
Expand Down