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",
]
[[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",

View file

@ -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"

View file

@ -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.