From f118ad7d072a7158e129997dec11b5cf3ed1244d Mon Sep 17 00:00:00 2001 From: ardocrat Date: Fri, 17 May 2024 19:15:25 +0300 Subject: [PATCH] txs: pull to refresh --- Cargo.lock | 10 +++++++ Cargo.toml | 1 + src/gui/views/wallets/wallet/txs.rs | 43 +++++++++++++++++------------ 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d1e87d3..46f4c0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2691,6 +2691,15 @@ dependencies = [ "winit", ] +[[package]] +name = "egui_pull_to_refresh" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c649d50513fc760df6d6ad74b739189f2768e81df3ec734f1f280bcf68e33c75" +dependencies = [ + "egui", +] + [[package]] name = "either" version = "1.11.0" @@ -3769,6 +3778,7 @@ dependencies = [ "eframe", "egui", "egui_extras", + "egui_pull_to_refresh", "env_logger 0.10.2", "eye", "fs-mistrust", diff --git a/Cargo.toml b/Cargo.toml index f0e0410..1aa7f5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ grin_wallet_controller = "5.3.0" egui = { version = "0.27.2", default-features = false } egui_extras = { version = "0.27.2", features = ["image", "svg"] } rust-i18n = "2.3.1" +egui_pull_to_refresh = "0.4.0" ## other thiserror = "1.0.58" diff --git a/src/gui/views/wallets/wallet/txs.rs b/src/gui/views/wallets/wallet/txs.rs index 1e04790..c2812f1 100644 --- a/src/gui/views/wallets/wallet/txs.rs +++ b/src/gui/views/wallets/wallet/txs.rs @@ -14,6 +14,7 @@ use egui::{Align, Id, Layout, Margin, RichText, Rounding, ScrollArea}; use egui::scroll_area::ScrollBarVisibility; +use egui_pull_to_refresh::PullToRefresh; use grin_core::core::amount_to_hr_string; use grin_util::ToHex; use grin_wallet_libwallet::{Slate, SlateState, TxLogEntryType}; @@ -178,23 +179,31 @@ impl WalletTransactions { // Show list of transactions. ui.add_space(4.0); - ScrollArea::vertical() - .scroll_bar_visibility(ScrollBarVisibility::AlwaysVisible) - .id_source(Id::from("txs_content").with(wallet.get_config().id)) - .auto_shrink([false; 2]) - .show_rows(ui, TX_ITEM_HEIGHT, data.txs.len(), |ui, row_range| { - ui.add_space(3.0); - View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| { - let extra_padding = amount_awaiting_conf != 0 || amount_awaiting_fin != 0 || - amount_locked != 0; - for index in row_range { - // Show transaction item. - let tx = data.txs.get(index).unwrap(); - let rounding = View::item_rounding(index, data.txs.len(), false); - self.tx_item_ui(ui, tx, rounding, extra_padding, true, &data, wallet, cb); - } - }); - }); + + let refresh_resp = PullToRefresh::new(wallet.syncing()).scroll_area_ui(ui, |ui| { + ScrollArea::vertical() + .scroll_bar_visibility(ScrollBarVisibility::AlwaysVisible) + .id_source(Id::from("txs_content").with(wallet.get_config().id)) + .auto_shrink([false; 2]) + .show_rows(ui, TX_ITEM_HEIGHT, data.txs.len(), |ui, row_range| { + ui.add_space(3.0); + View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| { + let extra_padding = amount_awaiting_conf != 0 || amount_awaiting_fin != 0 || + amount_locked != 0; + for index in row_range { + // Show transaction item. + let tx = data.txs.get(index).unwrap(); + let rounding = View::item_rounding(index, data.txs.len(), false); + self.tx_item_ui(ui, tx, rounding, extra_padding, true, &data, wallet, cb); + } + }); + }) + }); + + // Sync wallet on refresh. + if refresh_resp.should_refresh() { + wallet.sync(); + } } /// Draw [`Modal`] content for this ui container.