Skip to content

Commit

Permalink
Merge pull request #61 from yeastplume/tx_reworking
Browse files Browse the repository at this point in the history
Standard TX Workflow Finalization
  • Loading branch information
yeastplume committed Feb 17, 2023
2 parents 3d8a478 + c06cf5b commit dfdc879
Show file tree
Hide file tree
Showing 12 changed files with 484 additions and 111 deletions.
41 changes: 37 additions & 4 deletions crates/core/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use grin_core::{self};
use grin_keychain as keychain;
use grin_util::{file, Mutex, ZeroingString};

use super::node::amount_to_hr_string;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};

Expand Down Expand Up @@ -104,6 +105,29 @@ where
node_client: C,
}

// Amount / Fee
pub fn parse_abs_tx_amount_fee(tx: &TxLogEntry, subtract_fee_from_amt: bool) -> (String, String) {
let mut amt = if tx.amount_credited >= tx.amount_debited {
tx.amount_credited - tx.amount_debited
} else {
tx.amount_debited - tx.amount_credited
};

let fee = match tx.fee {
Some(f) => f.fee(),
None => 0,
};

if subtract_fee_from_amt {
amt = amt - fee;
}

(
amount_to_hr_string(amt, true),
amount_to_hr_string(fee, true),
)
}

impl<L, C> WalletInterface<L, C>
where
L: WalletLCProvider<'static, C, keychain::ExtKeychain>,
Expand Down Expand Up @@ -373,16 +397,22 @@ where
Ok(api.create_slatepack_message(None, &unenc_slate, Some(0), recipients)?)
}

/// Attempt to decode and decrypt a given slatepack
/// Attempt to decode and decrypt a given slatepack, also return associated transaction (if we can find it)
pub fn decrypt_slatepack(
wallet_interface: Arc<RwLock<WalletInterface<L, C>>>,
slatepack: String,
) -> Result<(Slatepack, Slate), GrinWalletInterfaceError> {
) -> Result<(Slatepack, Slate, Option<TxLogEntry>), GrinWalletInterfaceError> {
let w = wallet_interface.read().unwrap();
if let Some(o) = &w.owner_api {
let sp = o.decode_slatepack_message(None, slatepack.clone(), vec![0])?;
let slate = o.slate_from_slatepack_message(None, slatepack, vec![0])?;
return Ok((sp, slate));
let txs = o.retrieve_txs(None, false, None, Some(slate.id), None)?;
let ret_tx = if txs.1.len() > 0 {
Some(txs.1[0].clone())
} else {
None
};
return Ok((sp, slate, ret_tx));
} else {
return Err(GrinWalletInterfaceError::OwnerAPINotInstantiated);
}
Expand Down Expand Up @@ -450,7 +480,10 @@ where
if let Some(o) = &w.owner_api {
let slate = { o.init_send_tx(None, init_args)? };
o.tx_lock_outputs(None, &slate)?;
return Ok((slate.clone(), WalletInterface::encrypt_slatepack(o, &dest_slatepack_address, &slate)?));
return Ok((
slate.clone(),
WalletInterface::encrypt_slatepack(o, &dest_slatepack_address, &slate)?,
));
} else {
return Err(GrinWalletInterfaceError::OwnerAPINotInstantiated);
}
Expand Down
27 changes: 21 additions & 6 deletions locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@
"info-awaiting-finalization": "Awaiting Finalization",
"info-locked": "Locked",
"wallet-default-name": "Default",
"wallet-create-tx": "Send",
"wallet-apply-tx": "Receive",
"wallet-create-tx": "Start",
"wallet-apply-tx": "Continue",
"wallet-home": "Wallet - Set Name Here TBD",
"apply-tx": "Apply Transaction",
"apply-tx": "Continue Transaction",
"create-tx": "Start Transaction",
"create-tx-amount-error": "Invalid amount provided",
"create-tx-address-error": "Invalid slatepack address",
Expand All @@ -233,9 +233,13 @@
"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-create-success-desc": "To continue this transaction, copy/paste the encrypted transaction data below to the recipient",
"tx-continue-success-title": "Transaction Ready to Finalize",
"tx-continue-success-desc": "To continue this transaction, copy/paste the encrypted transaction data below back to the original sender",
"tx-view-desc": "To continue this transaction, copy/paste the encrypted transaction data below to the other party",
"tx-unconfirmed": "Not Confirmed",
"tx-list": "Transactions",
"tx-transact": "Transaction",
"tx-outstanding": "Outstanding",
"tx-recent": "Most Recent",
"tx-details": "Details",
Expand All @@ -245,9 +249,12 @@
"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-paste-again": "Paste Again",
"tx-continue": "Sign",
"tx-done": "Transaction Complete",
"apply-tx-confirm": "Confirm Transaction Details",
"tx-sender-name": "Sender",
"tx-sender-name": "From the wallet",
"tx-recipient-name": "To the wallet",
"apply-tx-amount": "Incoming amount",
"tx-state": "Transaction Stage (this will be presented better)",
"tx-reload-slate": "Show Slatepack",
Expand All @@ -263,5 +270,13 @@
"tx-show-full-slatepack": "Show Full",
"this-wallet-receive-addr": "Receive address",
"pasted-slatepack": "Clipboard Contents",
"pasted-slatepack-details": "Transaction Details"
"pasted-slatepack-details": "Transaction Details",
"tx-reception": "You are agreeing to receive [AMOUNT] Grin",
"tx-reception-instruction": "If you agree to this transaction, press 'Sign' below, then return the resulting transaction to the sender for completion.",
"tx-reception-instruction-2": "This transaction will not be completed until the sender has finalized it and posted it to the chain",
"tx-s1-finalization-1": "You are finalizing an agreement to pay [AMOUNT] Grin",
"tx-s1-finalization-2": "Along with a mining fee of [AMOUNT]",
"tx-s1-finalization-3": "This will complete the transaction and post it to the chain, at which point it becomes irreversible.",
"tx-done-instruction": "The transaction has been completed and posted to the chain. Please wait a few blocks for validation.",
"signing-tx": "Signing..."
}
29 changes: 22 additions & 7 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@
"info-locked": "Locked",
"name": "Name",
"directory": "Directory",
"wallet-create-tx": "Send",
"wallet-apply-tx": "Receive",
"wallet-create-tx": "Start",
"wallet-apply-tx": "Continue",
"wallet-home": "Wallet - Set Name Here TBD",
"apply-tx": "Apply Transaction",
"apply-tx": "Continue Transaction",
"create-tx": "Start Transaction",
"create-tx-amount-error": "Invalid amount provided",
"create-tx-address-error": "Invalid slatepack address",
Expand All @@ -246,19 +246,26 @@
"tx-unconfirmed": "Not Confirmed",
"tx-outstanding": "Outstanding",
"tx-list": "Transactions",
"tx-transact": "Transaction",
"tx-recent": "Most Recent",
"tx-details": "Details",
"tx-details-title": "Transaction Details",
"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-create-success-title": "Transaction Created",
"tx-create-success-desc": "To continue this transaction, copy/paste the encrypted transaction data below to the recipient",
"tx-continue-success-desc": "To continue this transaction, copy/paste the encrypted transaction data below back to the original sender",
"tx-continue-success-title": "Transaction Ready to Finalize",
"tx-view-desc": "To continue this transaction, copy/paste the encrypted transaction data below to the other party",
"tx-slatepack-paste-transaction-here": "Paste Transaction from Clipboard",
"tx-slatepack-read-result-default": "Ensure the clipboard contains a valid encrypted slatepack 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-paste-again": "Paste Again",
"tx-continue": "Sign",
"tx-done": "Transaction Complete",
"apply-tx-confirm": "Confirm Transaction Details",
"tx-sender-name": "Sender",
"tx-sender-name": "From the wallet",
"tx-recipient-name": "To the wallet",
"apply-tx-amount": "Incoming amount",
"tx-state": "Transaction Stage (this will be presented better)",
"tx-reload-slate": "Show Slatepack",
Expand All @@ -272,5 +279,13 @@
"tx-fee": "Fee",
"this-wallet-receive-addr": "Receive address",
"pasted-slatepack": "Clipboard Contents",
"pasted-slatepack-details": "Transaction Details"
"pasted-slatepack-details": "Transaction Details",
"tx-reception": "You are agreeing to receive [AMOUNT] Grin",
"tx-reception-instruction": "If you agree to this transaction, press 'Sign' below, then return the resulting transaction to the sender for completion.",
"tx-reception-instruction-2": "This transaction will not be completed until the sender has finalized it and posted it to the chain",
"tx-s1-finalization-1": "You are finalizing an agreement to pay [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-done-instruction": "The transaction has been completed and posted to the chain. Please wait a few blocks for validation.",
"signing-tx": "Signing..."
}
64 changes: 40 additions & 24 deletions src/gui/element/wallet/operation/action_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ use {
crate::localization::localized_string,
crate::Result,
anyhow::Context,
grin_gui_core::theme::{
Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text,
TextInput,
},
grin_gui_core::wallet::{StatusMessage, WalletInfo, WalletInterface},
grin_gui_core::{node::amount_to_hr_string, theme::ColorPalette},
grin_gui_core::theme::{Container, Button, Element, Column, PickList, Row, Scrollable, Text, TextInput, Header, TableRow},
iced::widget::{button, pick_list, scrollable, text_input, Checkbox, Space},
iced::{Alignment, Command, Length},
iced::widget::{
button, pick_list, scrollable, text_input, Checkbox, Space,
},
serde::{Deserialize, Serialize},
std::sync::{Arc, RwLock},
};
Expand Down Expand Up @@ -86,42 +87,49 @@ pub fn handle_message<'a>(
Ok(Command::none())
}

pub fn data_container<'a>(
config: &'a Config,
state: &'a StateContainer,
) -> Container<'a, Message> {
pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Container<'a, Message> {
let button_width = Length::Units(70);

let description = Text::new(localized_string("tx-transact"))
.size(DEFAULT_FONT_SIZE)
.horizontal_alignment(alignment::Horizontal::Center)
.vertical_alignment(alignment::Vertical::Center);
let description_container = Container::new(description)
.padding(iced::Padding::from([
7, // top
5, // right
5, // bottom
5, // left
]));

// Buttons to perform wallet operations
let create_tx_container =
Container::new(Text::new(localized_string("wallet-create-tx")).size(DEFAULT_FONT_SIZE))
.width(button_width)
.align_y(alignment::Vertical::Center)
.align_x(alignment::Horizontal::Center);

let create_tx_button: Element<Interaction> =
Button::new(create_tx_container)
.width(button_width)
.style(grin_gui_core::theme::ButtonStyle::Primary)
.on_press(Interaction::WalletOperationHomeActionMenuViewInteraction(
LocalViewInteraction::SelectAction(Action::CreateTx),
))
.into();
let create_tx_button: Element<Interaction> = Button::new(create_tx_container)
.width(button_width)
.style(grin_gui_core::theme::ButtonStyle::Primary)
.on_press(Interaction::WalletOperationHomeActionMenuViewInteraction(
LocalViewInteraction::SelectAction(Action::CreateTx),
))
.into();

let apply_tx_container =
Container::new(Text::new(localized_string("wallet-apply-tx")).size(DEFAULT_FONT_SIZE))
.width(button_width)
.align_y(alignment::Vertical::Center)
.align_x(alignment::Horizontal::Center);

let apply_tx_button: Element<Interaction> =
Button::new( apply_tx_container)
.width(button_width)
.style(grin_gui_core::theme::ButtonStyle::Primary)
.on_press(Interaction::WalletOperationHomeActionMenuViewInteraction(
LocalViewInteraction::SelectAction(Action::ApplyTx),
))
.into();
let apply_tx_button: Element<Interaction> = Button::new(apply_tx_container)
.width(button_width)
.style(grin_gui_core::theme::ButtonStyle::Primary)
.on_press(Interaction::WalletOperationHomeActionMenuViewInteraction(
LocalViewInteraction::SelectAction(Action::ApplyTx),
))
.into();

// add a nice double border around our buttons
// TODO refactor since many of the buttons around the UI repeat this theme
Expand All @@ -136,9 +144,17 @@ pub fn data_container<'a>(
.padding(1);

let menu_column = Row::new()
.push(description_container)
.push(Space::with_width(Length::Units(DEFAULT_PADDING)))
.push(create_container)
.push(Space::with_width(Length::Units(DEFAULT_PADDING)))
.push(apply_container);

Container::new(menu_column)
.padding(iced::Padding::from([
5, // top
5, // right
5, // bottom
5, // left
]))
}
Loading

0 comments on commit dfdc879

Please sign in to comment.