Skip to content

Commit

Permalink
Merge pull request #57 from yeastplume/fixes_4
Browse files Browse the repository at this point in the history
Transaction list clean up
  • Loading branch information
yeastplume committed Jan 25, 2023
2 parents f95a28b + 29f227a commit 5f5930d
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 67 deletions.
4 changes: 3 additions & 1 deletion locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,7 @@
"tx-sender-name": "Sender",
"apply-tx-amount": "Incoming amount",
"tx-state": "Transaction Stage (this will be presented better)",
"tx-reload-slate": "Show Slatepack"
"tx-reload-slate": "Show Slatepack",
"txs-list-loading": "Transactions not loaded",
"no-txs-list": "No transactions matching the current filter have been found."
}
4 changes: 3 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,7 @@
"tx-sender-name": "Sender",
"apply-tx-amount": "Incoming amount",
"tx-state": "Transaction Stage (this will be presented better)",
"tx-reload-slate": "Show Slatepack"
"tx-reload-slate": "Show Slatepack",
"no-txs-list": "No transactions matching the current filter have been found.",
"txs-list-loading": "Transactions not loaded"
}
44 changes: 41 additions & 3 deletions src/gui/element/wallet/operation/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,45 @@ pub fn handle_message<'a>(
"Update Wallet Info Summary: {}, {:?}",
node_success, wallet_info
);
state.wallet_info = Some(wallet_info);
// check if different from last update, if so refresh the current transaction listing
if state.wallet_info.as_ref() != Some(&wallet_info) {
// If transaction list hasn't been init yet, refresh the list with latest
debug!(
"Updating transactions based on new wallet info data: {:?} (old) vs {:?} (new)",
state.wallet_info.as_ref(),
wallet_info
);
state.wallet_info = Some(wallet_info);
if grin_gui
.wallet_state
.operation_state
.home_state
.tx_list_display_state
.mode
== crate::gui::element::wallet::operation::tx_list_display::Mode::NotInit
{
let fut = move || async {};
return Ok(Command::perform(fut(), |_| {
return Message::Interaction(
Interaction::WalletOperationHomeTxListDisplayInteraction(
crate::gui::element::wallet::operation::tx_list_display::LocalViewInteraction::SelectMode(
crate::gui::element::wallet::operation::tx_list_display::Mode::Recent
),
),
);
}));
} else {
let fut = move || async {};
return Ok(Command::perform(fut(), |_| {
return Message::Interaction(
Interaction::WalletOperationHomeTxListDisplayInteraction(
crate::gui::element::wallet::operation::tx_list_display::LocalViewInteraction::RefreshList
,
),
);
}));
}
}
}
LocalViewInteraction::WalletInfoUpdateFailure(err) => {
grin_gui.error = err.write().unwrap().take();
Expand Down Expand Up @@ -286,7 +324,7 @@ pub fn handle_message<'a>(
debug!("Cancel Tx: {}", id);
grin_gui.error.take();

log::debug!("Interaction::WalletOperationHomeViewInteraction::CancelTx");
log::debug!("Interaction::WalletOperationHomeViewInteraction::CancelTx");

let w = grin_gui.wallet_interface.clone();

Expand Down Expand Up @@ -314,7 +352,7 @@ pub fn handle_message<'a>(
let _ = fs::remove_file(out_file_name);
}

// Trigger event to reload transaction list
// Trigger event to reload transaction list
let mode = grin_gui
.wallet_state
.operation_state
Expand Down
84 changes: 63 additions & 21 deletions src/gui/element/wallet/operation/tx_list_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use {
TextInput,
},
grin_gui_core::wallet::{
InitTxArgs, RetrieveTxQueryArgs, RetrieveTxQuerySortOrder, Slate, StatusMessage, WalletInfo, WalletInterface,
InitTxArgs, RetrieveTxQueryArgs, RetrieveTxQuerySortOrder, Slate, StatusMessage,
WalletInfo, WalletInterface,
},
grin_gui_core::{
node::amount_to_hr_string,
Expand All @@ -44,6 +45,7 @@ pub struct StateContainer {
confirmed_txns: Vec<TxLogEntry>,
wallet_txs: TxList,
tx_header_state: HeaderState,
query_args: RetrieveTxQueryArgs,
pub mode: Mode,

pub expanded_type: ExpandType,
Expand All @@ -58,6 +60,7 @@ impl Default for StateContainer {
wallet_txs: Default::default(),
tx_header_state: Default::default(),
expanded_type: ExpandType::None,
query_args: Default::default(),
mode: Mode::NotInit,
balance_data: vec![],
confirmed_txns: vec![],
Expand All @@ -78,6 +81,7 @@ pub enum Mode {
#[derive(Debug, Clone)]
pub enum LocalViewInteraction {
SelectMode(Mode),
RefreshList,
TxListUpdateSuccess(bool, Vec<TxLogEntry>),
TxListUpdateFailure(Arc<RwLock<Option<anyhow::Error>>>),
}
Expand All @@ -94,26 +98,37 @@ pub fn handle_message<'a>(

match message {
LocalViewInteraction::SelectMode(new_mode) => {
let mut query_args = RetrieveTxQueryArgs::default();
state.query_args = RetrieveTxQueryArgs::default();

query_args.sort_order = Some(RetrieveTxQuerySortOrder::Desc);
state.query_args.sort_order = Some(RetrieveTxQuerySortOrder::Desc);

match new_mode {
Mode::NotInit => {}
Mode::Recent => {
query_args.exclude_cancelled = Some(true);
state.query_args.exclude_cancelled = Some(true);
}
Mode::Outstanding => {
query_args.exclude_cancelled = Some(true);
query_args.include_outstanding_only = Some(true);
state.query_args.exclude_cancelled = Some(true);
state.query_args.include_outstanding_only = Some(true);
}
}

state.mode = new_mode;

let fut = move || async {};
return Ok(Command::perform(fut(), |_| {
return Message::Interaction(
Interaction::WalletOperationHomeTxListDisplayInteraction(
LocalViewInteraction::RefreshList,
),
);
}));
}

LocalViewInteraction::RefreshList => {
let w = grin_gui.wallet_interface.clone();

let fut = move || WalletInterface::get_txs(w, Some(query_args));
let fut = move || WalletInterface::get_txs(w, Some(state.query_args.clone()));
return Ok(Command::perform(fut(), |tx_list_res| {
if tx_list_res.is_err() {
let e = tx_list_res
Expand Down Expand Up @@ -240,13 +255,19 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
.align_y(alignment::Vertical::Center)
.align_x(alignment::Horizontal::Center);

let latest_button: Element<Interaction> = Button::new(latest_container)
.width(button_width)
.style(grin_gui_core::theme::ButtonStyle::Primary)
.on_press(Interaction::WalletOperationHomeTxListDisplayInteraction(
LocalViewInteraction::SelectMode(Mode::Recent),
))
.into();
let latest_button = Button::new(latest_container).width(button_width).on_press(
Interaction::WalletOperationHomeTxListDisplayInteraction(LocalViewInteraction::SelectMode(
Mode::Recent,
)),
);

let latest_button = if state.mode == Mode::Recent {
latest_button.style(grin_gui_core::theme::ButtonStyle::Selected)
} else {
latest_button.style(grin_gui_core::theme::ButtonStyle::Primary)
};

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

// add a nice double border around our buttons
// TODO refactor since many of the buttons around the UI repeat this theme
Expand All @@ -261,13 +282,19 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
.align_y(alignment::Vertical::Center)
.align_x(alignment::Horizontal::Center);

let outstanding_button: Element<Interaction> = Button::new(outstanding_container)
let outstanding_button = Button::new(outstanding_container)
.width(button_width)
.style(grin_gui_core::theme::ButtonStyle::Primary)
.on_press(Interaction::WalletOperationHomeTxListDisplayInteraction(
LocalViewInteraction::SelectMode(Mode::Outstanding),
))
.into();
));

let outstanding_button = if state.mode == Mode::Outstanding {
outstanding_button.style(grin_gui_core::theme::ButtonStyle::Selected)
} else {
outstanding_button.style(grin_gui_core::theme::ButtonStyle::Primary)
};

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

let outstanding_container_wrap =
Container::new(outstanding_button.map(Message::Interaction)).padding(1);
Expand Down Expand Up @@ -314,10 +341,10 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
);

let table_header_container = Container::new(table_header_row).padding(iced::Padding::from([
0, // top
0, // top
DEFAULT_PADDING * 3, // right - should roughly match width of content scroll bar to align table headers
0, // bottom
0, // left
0, // bottom
0, // left
]));
//.style(grin_gui_core::theme::ContainerStyle::PanelForeground);

Expand Down Expand Up @@ -379,6 +406,21 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
// Adds the rest of the elements to the content column.
if has_txs {
tx_list_content = tx_list_content.push(tx_list_scrollable);
} else {
let no_txs_label = if state.mode == Mode::NotInit {
Text::new(localized_string("txs-list-loading")).size(DEFAULT_FONT_SIZE)
} else {
Text::new(localized_string("no-txs-list")).size(DEFAULT_FONT_SIZE)
};
let no_txs_container = Container::new(no_txs_label)
.style(grin_gui_core::theme::ContainerStyle::BrightBackground)
.padding(iced::Padding::from([
0, // top
0, // right
0, // bottom
5, // left
]));
tx_list_content = tx_list_content.push(no_txs_container);
}

// TRANSACTION LISTING
Expand Down
Loading

0 comments on commit 5f5930d

Please sign in to comment.