mirror of
https://github.com/jwinterm/grim.git
synced 2026-10-20 23:28:31 +02:00
wallets: optimize loading, list refactoring, add wallet closing state, wallet data state and tx loading progress
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
|
||||
use egui::{Align, Align2, Layout, Margin, RichText, Rounding, ScrollArea, TextStyle, Widget};
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
use grin_core::global::ChainTypes;
|
||||
|
||||
use crate::AppConfig;
|
||||
use crate::gui::Colors;
|
||||
@@ -24,14 +23,12 @@ use crate::gui::views::{Modal, Root, TitlePanel, View};
|
||||
use crate::gui::views::types::{ModalContainer, ModalPosition, TitleType};
|
||||
use crate::gui::views::wallets::creation::WalletCreation;
|
||||
use crate::gui::views::wallets::WalletContent;
|
||||
use crate::wallet::{ConnectionsConfig, ExternalConnection, Wallet, Wallets};
|
||||
use crate::wallet::{ConnectionsConfig, ExternalConnection, Wallet, WalletList};
|
||||
|
||||
/// Wallets content.
|
||||
pub struct WalletsContent {
|
||||
/// Chain type for loaded wallets.
|
||||
chain_type: ChainTypes,
|
||||
/// Loaded list of wallets.
|
||||
wallets: Wallets,
|
||||
wallets: WalletList,
|
||||
|
||||
/// Password to open wallet for [`Modal`].
|
||||
pass_edit: String,
|
||||
@@ -58,8 +55,7 @@ const OPEN_WALLET_MODAL: &'static str = "open_wallet_modal";
|
||||
impl Default for WalletsContent {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
chain_type: AppConfig::chain_type(),
|
||||
wallets: Wallets::default(),
|
||||
wallets: WalletList::default(),
|
||||
pass_edit: "".to_string(),
|
||||
hide_pass: true,
|
||||
wrong_pass: false,
|
||||
@@ -99,13 +95,8 @@ impl WalletsContent {
|
||||
// Draw modal content for current ui container.
|
||||
self.current_modal_ui(ui, frame, cb);
|
||||
|
||||
// Setup list of wallets if chain type was changed.
|
||||
let chain_type = AppConfig::chain_type();
|
||||
if self.chain_type != chain_type {
|
||||
self.wallets.reinit(chain_type);
|
||||
self.chain_type = chain_type;
|
||||
}
|
||||
let empty_list = self.wallets.list.is_empty();
|
||||
let wallets = self.wallets.list();
|
||||
let empty_list = wallets.is_empty();
|
||||
|
||||
// Setup wallet content flags.
|
||||
let create_wallet = self.creation_content.can_go_back();
|
||||
@@ -123,7 +114,7 @@ impl WalletsContent {
|
||||
// Show wallet panel content.
|
||||
egui::SidePanel::right("wallet_panel")
|
||||
.resizable(false)
|
||||
.min_width(wallet_panel_width)
|
||||
.exact_width(wallet_panel_width)
|
||||
.frame(egui::Frame {
|
||||
fill: if empty_list && !create_wallet
|
||||
|| (dual_panel && show_wallet && !self.show_wallets_at_dual_panel) {
|
||||
@@ -149,7 +140,7 @@ impl WalletsContent {
|
||||
self.wallets.add(wallet);
|
||||
});
|
||||
} else {
|
||||
for mut wallet in self.wallets.list.clone() {
|
||||
for mut wallet in wallets.clone() {
|
||||
// Show content for selected wallet.
|
||||
if self.wallets.is_selected(wallet.config.id) {
|
||||
// Setup wallet content width.
|
||||
@@ -205,13 +196,14 @@ impl WalletsContent {
|
||||
|
||||
// Setup flag to show wallet creation button if wallet is not showing
|
||||
// at non-dual panel mode or showing at dual panel mode.
|
||||
let show_creation_btn
|
||||
let show_creation_button
|
||||
= (!show_wallet && !dual_panel) || (dual_panel && show_wallet);
|
||||
|
||||
// Show list of wallets.
|
||||
let scroll = self.wallet_list_ui(ui, dual_panel, show_creation_btn, cb);
|
||||
let scroll =
|
||||
self.wallet_list_ui(ui, wallets, dual_panel, show_creation_button, cb);
|
||||
|
||||
if show_creation_btn {
|
||||
if show_creation_button {
|
||||
// Setup right margin for button.
|
||||
let mut right_margin = if dual_panel { wallet_panel_width } else { 0.0 };
|
||||
if scroll { right_margin += 6.0 }
|
||||
@@ -304,6 +296,7 @@ impl WalletsContent {
|
||||
/// Draw list of wallets. Returns `true` if scroller is showing.
|
||||
fn wallet_list_ui(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
wallets: Vec<Wallet>,
|
||||
dual_panel: bool,
|
||||
show_creation_btn: bool,
|
||||
cb: &dyn PlatformCallbacks) -> bool {
|
||||
@@ -331,7 +324,7 @@ impl WalletsContent {
|
||||
rect.set_width(width);
|
||||
|
||||
ui.allocate_ui(rect.size(), |ui| {
|
||||
for mut wallet in self.wallets.list.clone() {
|
||||
for mut wallet in wallets {
|
||||
// Draw wallet list item.
|
||||
self.wallet_item_ui(ui, &mut wallet, cb);
|
||||
ui.add_space(5.0);
|
||||
@@ -386,14 +379,17 @@ impl WalletsContent {
|
||||
self.wallets.select(Some(id));
|
||||
});
|
||||
}
|
||||
// Show button to close opened wallet.
|
||||
View::item_button(ui, if !is_selected {
|
||||
Rounding::none()
|
||||
} else {
|
||||
View::item_rounding(0, 1, true)
|
||||
}, LOCK_KEY, None, || {
|
||||
let _ = wallet.close();
|
||||
});
|
||||
|
||||
// Show button to close opened wallet if wallet is not loading.
|
||||
if !wallet.is_closing() {
|
||||
View::item_button(ui, if !is_selected {
|
||||
Rounding::none()
|
||||
} else {
|
||||
View::item_rounding(0, 1, true)
|
||||
}, LOCK_KEY, None, || {
|
||||
wallet.close();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let layout_size = ui.available_size();
|
||||
@@ -420,7 +416,9 @@ impl WalletsContent {
|
||||
|
||||
// Setup wallet status text.
|
||||
let status_text = if wallet.is_open() {
|
||||
if wallet.get_info().is_none() {
|
||||
if wallet.is_closing() {
|
||||
format!("{} {}", SPINNER, t!("wallets.wallet_closing"))
|
||||
} else if wallet.get_data().is_none() {
|
||||
if wallet.loading_error() {
|
||||
format!("{} {}", WARNING_CIRCLE, t!("loading_error"))
|
||||
} else {
|
||||
|
||||
@@ -79,7 +79,7 @@ impl WalletContent {
|
||||
});
|
||||
|
||||
// Refresh content after 1 second for loaded wallet.
|
||||
if wallet.get_info().is_some() {
|
||||
if wallet.get_data().is_some() {
|
||||
ui.ctx().request_repaint_after(Duration::from_millis(1000));
|
||||
} else {
|
||||
ui.ctx().request_repaint();
|
||||
@@ -123,10 +123,13 @@ impl WalletContent {
|
||||
|
||||
/// Content to draw when wallet is loading, returns `true` if wallet is not ready.
|
||||
pub fn loading_ui(ui: &mut egui::Ui, frame: &mut eframe::Frame, wallet: &Wallet) -> bool {
|
||||
if wallet.config.ext_conn_id.is_none() {
|
||||
if wallet.is_closing() {
|
||||
Self::loading_progress_ui(ui, wallet);
|
||||
return true;
|
||||
} else if wallet.config.ext_conn_id.is_none() {
|
||||
if !Node::is_running() || Node::is_stopping() {
|
||||
let dual_panel_root = Root::is_dual_panel_mode(frame);
|
||||
View::center_content(ui, if !dual_panel_root { 162.0 } else { 96.0 }, |ui| {
|
||||
View::center_content(ui, 108.0, |ui| {
|
||||
let text = t!("wallets.enable_node", "settings" => GEAR_FINE);
|
||||
ui.label(RichText::new(text).size(16.0).color(Colors::INACTIVE_TEXT));
|
||||
ui.add_space(8.0);
|
||||
@@ -141,41 +144,62 @@ impl WalletContent {
|
||||
}
|
||||
});
|
||||
return true
|
||||
} else if wallet.get_info().is_none() {
|
||||
Self::progress_ui(ui, wallet);
|
||||
} else if wallet.loading_error()
|
||||
&& Node::get_sync_status() == Some(SyncStatus::NoSync) {
|
||||
Self::loading_error_ui(ui, wallet);
|
||||
return true;
|
||||
} else if wallet.get_data().is_none() {
|
||||
Self::loading_progress_ui(ui, wallet);
|
||||
return true;
|
||||
}
|
||||
} else if wallet.get_info().is_none() {
|
||||
// Show error message with button to retry on wallet loading error or loading progress.
|
||||
} else if wallet.get_data().is_none() {
|
||||
if wallet.loading_error() {
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
let text = t!("wallets.wallet_loading_err", "settings" => GEAR_FINE);
|
||||
ui.label(RichText::new(text).size(16.0).color(Colors::INACTIVE_TEXT));
|
||||
ui.add_space(8.0);
|
||||
let retry_text = format!("{} {}", REPEAT, t!("retry"));
|
||||
View::button(ui, retry_text, Colors::GOLD, || {
|
||||
wallet.set_loading_error(false);
|
||||
});
|
||||
});
|
||||
Self::loading_error_ui(ui, wallet);
|
||||
} else {
|
||||
Self::progress_ui(ui, wallet);
|
||||
Self::loading_progress_ui(ui, wallet);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Draw wallet loading progress.
|
||||
fn progress_ui(ui: &mut egui::Ui, wallet: &Wallet) {
|
||||
/// Draw wallet loading error content.
|
||||
fn loading_error_ui(ui: &mut egui::Ui, wallet: &Wallet) {
|
||||
View::center_content(ui, 108.0, |ui| {
|
||||
let text = t!("wallets.wallet_loading_err", "settings" => GEAR_FINE);
|
||||
ui.label(RichText::new(text).size(16.0).color(Colors::INACTIVE_TEXT));
|
||||
ui.add_space(8.0);
|
||||
let retry_text = format!("{} {}", REPEAT, t!("retry"));
|
||||
View::button(ui, retry_text, Colors::GOLD, || {
|
||||
wallet.set_loading_error(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Draw wallet loading progress content.
|
||||
fn loading_progress_ui(ui: &mut egui::Ui, wallet: &Wallet) {
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
ui.add_space(18.0);
|
||||
// Setup loading progress text.
|
||||
let progress = wallet.loading_progress();
|
||||
let text = if progress == 0 {
|
||||
t!("wallets.wallet_loading")
|
||||
} else {
|
||||
format!("{}: {}%", t!("wallets.wallet_loading"), progress)
|
||||
let text = {
|
||||
let info_progress = wallet.info_loading_progress();
|
||||
if wallet.is_closing() {
|
||||
t!("wallets.wallet_closing")
|
||||
} else if info_progress != 100 {
|
||||
if info_progress == 0 {
|
||||
t!("wallets.wallet_loading")
|
||||
} else {
|
||||
format!("{}: {}%", t!("wallets.wallet_loading"), info_progress)
|
||||
}
|
||||
} else {
|
||||
let tx_progress = wallet.txs_loading_progress();
|
||||
if tx_progress == 0 {
|
||||
t!("wallets.tx_loading")
|
||||
} else {
|
||||
format!("{}: {}%", t!("wallets.tx_loading"), tx_progress)
|
||||
}
|
||||
}
|
||||
};
|
||||
ui.label(RichText::new(text).size(16.0).color(Colors::INACTIVE_TEXT));
|
||||
});
|
||||
|
||||
@@ -25,6 +25,10 @@ impl WalletTab for WalletSettings {
|
||||
WalletTabType::Settings
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
|
||||
fn ui(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
frame: &mut eframe::Frame,
|
||||
wallet: &Wallet,
|
||||
cb: &dyn PlatformCallbacks) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user