Skip to content

Commit

Permalink
Merge pull request #26 from yeastplume/tx_create_again
Browse files Browse the repository at this point in the history
[WIP] Home / Transaction Screen Updates
  • Loading branch information
yeastplume committed Dec 8, 2022
2 parents 6734cae + 1e0a209 commit 4830273
Show file tree
Hide file tree
Showing 10 changed files with 737 additions and 392 deletions.
400 changes: 203 additions & 197 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions crates/core/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use dirs;
pub use global::ChainTypes;
pub use grin_wallet_impls::HTTPNodeClient;
pub use grin_wallet_libwallet::{
InitTxArgs, Slate, StatusMessage, TxLogEntry, TxLogEntryType, WalletInfo,
InitTxArgs, Slate, StatusMessage, TxLogEntry, TxLogEntryType, WalletInfo, RetrieveTxQueryArgs
};

use crate::error::GrinWalletInterfaceError;
Expand Down Expand Up @@ -363,10 +363,11 @@ where

pub async fn get_txs(
wallet_interface: Arc<RwLock<WalletInterface<L, C>>>,
query_args: Option<RetrieveTxQueryArgs>,
) -> Result<(bool, Vec<TxLogEntry>), GrinWalletInterfaceError> {
let w = wallet_interface.read().unwrap();
if let Some(o) = &w.owner_api {
let res = o.retrieve_txs(None, false, None, None)?;
let res = o.retrieve_txs(None, true, None, None, query_args)?;
/*for tx in &mut res.1 {
if tx.amount_credited == 0 && tx.amount_debited == 0 {
let saved_tx = o.get_stored_tx(None, Some(tx.id), None);
Expand Down
9 changes: 8 additions & 1 deletion locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,12 @@
"recipient-address-instruction": "Paste the address of the recipient's wallet here",
"recipient-address": "Recipient's Slatepack Address",
"create-tx-amount": "Amount",
"cancel-tx": "Cancel Transaction"
"cancel-tx": "Cancel",
"tx-confirmed": "Confirmed",
"tx-unconfirmed": "Not Confirmed",
"tx-list": "Transactions",
"tx-outstanding": "Outstanding",
"tx-recent": "Most Recent",
"tx-details": "Details"

}
8 changes: 7 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,11 @@
"recipient-address-instruction": "Input the address of the recipient's wallet here",
"recipient-address": "Recipient's Slatepack Address",
"create-tx-amount": "Amount",
"cancel-tx": "Cancel Transaction"
"cancel-tx": "Cancel",
"tx-confirmed": "Confirmed",
"tx-unconfirmed": "Not Confirmed",
"tx-outstanding": "Outstanding",
"tx-list": "Transactions",
"tx-recent": "Most Recent",
"tx-details": "Details"
}
136 changes: 29 additions & 107 deletions src/gui/element/wallet/operation/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use super::tx_list::{self, ExpandType};
use async_std::prelude::FutureExt;
use grin_gui_core::{
config::Config,
wallet::{TxLogEntry, TxLogEntryType},
wallet::{TxLogEntry, TxLogEntryType, RetrieveTxQueryArgs},
};
use iced_aw::Card;
use iced_native::Widget;
use std::path::PathBuf;

use super::action_menu;
use super::{action_menu, tx_list_display};
use super::tx_list::{HeaderState, TxList, TxLogEntryWrap};
use grin_gui_widgets::widget::header;

Expand All @@ -35,7 +35,7 @@ use {

pub struct StateContainer {
pub action_menu_state: action_menu::StateContainer,
pub expanded_type: ExpandType,
pub tx_list_display_state: tx_list_display::StateContainer,

wallet_info: Option<WalletInfo>,
wallet_txs: TxList,
Expand All @@ -49,8 +49,8 @@ impl Default for StateContainer {
fn default() -> Self {
Self {
action_menu_state: Default::default(),
tx_list_display_state: Default::default(),
// back_button_state: Default::default(),
expanded_type: ExpandType::None,
wallet_info: Default::default(),
wallet_txs: Default::default(),
wallet_status: Default::default(),
Expand All @@ -72,6 +72,7 @@ pub enum LocalViewInteraction {
WalletCloseError(Arc<RwLock<Option<anyhow::Error>>>),
WalletCloseSuccess,
CancelTx(u32),
TxDetails(TxLogEntryWrap),
TxCancelledOk(u32),
TxCancelError(Arc<RwLock<Option<anyhow::Error>>>)
}
Expand Down Expand Up @@ -105,12 +106,18 @@ pub fn handle_tick<'a>(
{
state.last_summary_update = chrono::Local::now();

let mut query_args = RetrieveTxQueryArgs::default();

query_args.exclude_cancelled = Some(true);
query_args.include_outstanding_only = Some(true);

let w = grin_gui.wallet_interface.clone();

let fut =
move || WalletInterface::get_wallet_info(w.clone()).join(WalletInterface::get_txs(w));
move || WalletInterface::get_wallet_info(w.clone());//.join(WalletInterface::get_txs(w, Some(query_args)));

return Ok(Command::perform(fut(), |(wallet_info_res, txs_res)| {
//return Ok(Command::perform(fut(), |(wallet_info_res, txs_res)| {
return Ok(Command::perform(fut(), |(wallet_info_res)| {
if wallet_info_res.is_err() {
let e = wallet_info_res
.context("Failed to retrieve wallet info status")
Expand All @@ -119,18 +126,19 @@ pub fn handle_tick<'a>(
LocalViewInteraction::WalletInfoUpdateFailure(Arc::new(RwLock::new(Some(e)))),
));
}
if txs_res.is_err() {
/*if txs_res.is_err() {
let e = txs_res
.context("Failed to retrieve wallet tx status")
.unwrap_err();
return Message::Interaction(Interaction::WalletOperationHomeViewInteraction(
LocalViewInteraction::WalletInfoUpdateFailure(Arc::new(RwLock::new(Some(e)))),
));
}
}*/
let (node_success, wallet_info) = wallet_info_res.unwrap();
let (_, txs) = txs_res.unwrap();
//let (_, txs) = txs_res.unwrap();
Message::Interaction(Interaction::WalletOperationHomeViewInteraction(
LocalViewInteraction::WalletInfoUpdateSuccess(node_success, wallet_info, txs),
//LocalViewInteraction::WalletInfoUpdateSuccess(node_success, wallet_info, txs),
LocalViewInteraction::WalletInfoUpdateSuccess(node_success, wallet_info, vec![]),
))
}));
}
Expand Down Expand Up @@ -221,6 +229,10 @@ pub fn handle_message<'a>(
.apply_tx_state
.address_value = address;
}
LocalViewInteraction::TxDetails(tx_log_entry_wrap) => {
log::debug!("Interaction::WalletOperationHomeViewInteraction::TxDetails");
log::debug!("TBD {}", tx_log_entry_wrap.tx.id);
}
LocalViewInteraction::CancelTx(id) => {
debug!("Cancel Tx: {}", id);
grin_gui.error.take();
Expand Down Expand Up @@ -491,110 +503,20 @@ pub fn data_container<'a>(

let status_row = Row::new()
.push(status_container)
.height(Length::Units(25))
//.height(Length::Units(25))
.align_items(Alignment::Center)
.spacing(25);

// Temp Test Data
use grin_gui_core::node::Identifier;
/*let tx_list = TxList {
txs: vec![
TxLogEntry::new(Identifier::zero(), TxLogEntryType::ConfirmedCoinbase, 0),
TxLogEntry::new(Identifier::zero(), TxLogEntryType::ConfirmedCoinbase, 1),
TxLogEntry::new(Identifier::zero(), TxLogEntryType::ConfirmedCoinbase, 2),
TxLogEntry::new(Identifier::zero(), TxLogEntryType::ConfirmedCoinbase, 3),
TxLogEntry::new(Identifier::zero(), TxLogEntryType::ConfirmedCoinbase, 4),
TxLogEntry::new(Identifier::zero(), TxLogEntryType::ConfirmedCoinbase, 5),
TxLogEntry::new(Identifier::zero(), TxLogEntryType::ConfirmedCoinbase, 6),
],
};*/

let column_config = state.tx_header_state.column_config();

// Tx row titles is a row of titles above the tx scrollable.
// This is to add titles above each section of the tx row, to let
// the user easily identify what the value is.
let tx_row_titles = super::tx_list::titles_row_header(
&state.wallet_txs,
&state.tx_header_state.state,
&state.tx_header_state.columns,
state.tx_header_state.previous_column_key,
state.tx_header_state.previous_sort_direction,
);

// A scrollable list containing rows.
// Each row holds data about a single tx.
let mut content = Column::new().spacing(1);
//.height(Length::Fill)
//.style(grin_gui_core::theme::ScrollableStyles::Primary);

let mut has_txs = false;

// Loops though the txs.
for (idx, tx_wrap) in state.wallet_txs.txs.iter().enumerate() {
has_txs = true;
// If hiding ignored addons, we will skip it.
/*if addon.state == AddonState::Ignored && self.config.hide_ignored_addons {
continue;
}*/

// Skip addon if we are filter from query and addon doesn't have fuzzy score
/*if query.is_some() && addon.fuzzy_score.is_none() {
continue;
}*/

// Checks if the current tx is expanded.
let is_tx_expanded = match &state.expanded_type {
ExpandType::Details(a) => a.tx.id == tx_wrap.tx.id,
ExpandType::None => false,
};

let is_odd = if config.alternating_row_colors {
Some(idx % 2 != 0)
} else {
None
};

// A container cell which has all data about the current tx.
// If the tx is expanded, then this is also included in this container.
let tx_data_cell = tx_list::data_row_container(
tx_wrap,
is_tx_expanded,
&state.expanded_type,
config,
&column_config,
is_odd,
&None,
);

// Adds the addon data cell to the scrollable.
content = content.push(tx_data_cell);
}

let mut tx_list_scrollable = Scrollable::new(content).style(
grin_gui_core::theme::ScrollableStyle::Primary,
);

// Bottom space below the scrollable.
let bottom_space = Space::new(Length::FillPortion(1), Length::Units(DEFAULT_PADDING));

// This column gathers all the tx list elements together.
let mut tx_list_content = Column::new();

// Adds the rest of the elements to the content column.
if has_txs {
//TODO: Header widget is crashing specatularly on windows after iced-rs 0.5.0 update
// disable header column until we figure out why and how to fix
tx_list_content = tx_list_content.push(tx_row_titles).push(tx_list_scrollable);
//tx_list_content = tx_list_content.push(tx_list_scrollable);
}
// Buttons to perform operations go here, but empty container for now
let tx_list_display =
tx_list_display::data_container(config, &state.tx_list_display_state);

// Overall Home screen layout column
// Overall Home screen layout column
let column = Column::new()
.push(header_container)
.push(first_row_container)
.push(tx_list_content)
.push(Space::new(Length::Units(0), Length::Fill))
.push(Space::new(Length::Units(0), Length::Units(10)))
.push(tx_list_display)
.push(status_row)
.padding(10);
//.align_items(Alignment::Center);
Expand Down
1 change: 1 addition & 0 deletions src/gui/element/wallet/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod home;
pub mod tx_list;
pub mod create_tx;
pub mod apply_tx;
pub mod tx_list_display;

use {
crate::gui::{GrinGui, Message},
Expand Down
Loading

0 comments on commit 4830273

Please sign in to comment.