txs: pull to refresh

This commit is contained in:
ardocrat 2024-05-17 19:15:25 +03:00
parent 8ff6fd1c20
commit f118ad7d07
3 changed files with 37 additions and 17 deletions

10
Cargo.lock generated
View file

@ -2691,6 +2691,15 @@ dependencies = [
"winit", "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]] [[package]]
name = "either" name = "either"
version = "1.11.0" version = "1.11.0"
@ -3769,6 +3778,7 @@ dependencies = [
"eframe", "eframe",
"egui", "egui",
"egui_extras", "egui_extras",
"egui_pull_to_refresh",
"env_logger 0.10.2", "env_logger 0.10.2",
"eye", "eye",
"fs-mistrust", "fs-mistrust",

View file

@ -36,6 +36,7 @@ grin_wallet_controller = "5.3.0"
egui = { version = "0.27.2", default-features = false } egui = { version = "0.27.2", default-features = false }
egui_extras = { version = "0.27.2", features = ["image", "svg"] } egui_extras = { version = "0.27.2", features = ["image", "svg"] }
rust-i18n = "2.3.1" rust-i18n = "2.3.1"
egui_pull_to_refresh = "0.4.0"
## other ## other
thiserror = "1.0.58" thiserror = "1.0.58"

View file

@ -14,6 +14,7 @@
use egui::{Align, Id, Layout, Margin, RichText, Rounding, ScrollArea}; use egui::{Align, Id, Layout, Margin, RichText, Rounding, ScrollArea};
use egui::scroll_area::ScrollBarVisibility; use egui::scroll_area::ScrollBarVisibility;
use egui_pull_to_refresh::PullToRefresh;
use grin_core::core::amount_to_hr_string; use grin_core::core::amount_to_hr_string;
use grin_util::ToHex; use grin_util::ToHex;
use grin_wallet_libwallet::{Slate, SlateState, TxLogEntryType}; use grin_wallet_libwallet::{Slate, SlateState, TxLogEntryType};
@ -178,23 +179,31 @@ impl WalletTransactions {
// Show list of transactions. // Show list of transactions.
ui.add_space(4.0); ui.add_space(4.0);
ScrollArea::vertical()
.scroll_bar_visibility(ScrollBarVisibility::AlwaysVisible) let refresh_resp = PullToRefresh::new(wallet.syncing()).scroll_area_ui(ui, |ui| {
.id_source(Id::from("txs_content").with(wallet.get_config().id)) ScrollArea::vertical()
.auto_shrink([false; 2]) .scroll_bar_visibility(ScrollBarVisibility::AlwaysVisible)
.show_rows(ui, TX_ITEM_HEIGHT, data.txs.len(), |ui, row_range| { .id_source(Id::from("txs_content").with(wallet.get_config().id))
ui.add_space(3.0); .auto_shrink([false; 2])
View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| { .show_rows(ui, TX_ITEM_HEIGHT, data.txs.len(), |ui, row_range| {
let extra_padding = amount_awaiting_conf != 0 || amount_awaiting_fin != 0 || ui.add_space(3.0);
amount_locked != 0; View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| {
for index in row_range { let extra_padding = amount_awaiting_conf != 0 || amount_awaiting_fin != 0 ||
// Show transaction item. amount_locked != 0;
let tx = data.txs.get(index).unwrap(); for index in row_range {
let rounding = View::item_rounding(index, data.txs.len(), false); // Show transaction item.
self.tx_item_ui(ui, tx, rounding, extra_padding, true, &data, wallet, cb); 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. /// Draw [`Modal`] content for this ui container.