wallet + ui: optimize wallet synchronization, add wallet repairing, fix wallet loading content, and wallet status, fix wallet settings panel width update translations

This commit is contained in:
ardocrat
2023-08-13 21:09:04 +03:00
parent a0930d4bf3
commit 09d3835082
14 changed files with 1056 additions and 269 deletions
+38 -10
View File
@@ -29,7 +29,7 @@ use crate::wallet::{ConnectionsConfig, ExternalConnection, Wallet, WalletList};
/// Wallets content.
pub struct WalletsContent {
/// Loaded list of wallets.
/// List of wallets.
wallets: WalletList,
/// Password to open wallet for [`Modal`].
@@ -415,8 +415,8 @@ impl WalletsContent {
});
}
// Show button to close opened wallet if wallet is not loading.
if !wallet.is_closing() {
// Show button to close opened wallet.
if !wallet.is_closing() {
View::item_button(ui, if !is_selected {
Rounding::none()
} else {
@@ -437,7 +437,7 @@ impl WalletsContent {
View::ellipsize_text(ui, wallet.config.name.to_owned(), 18.0, name_color);
// Setup wallet connection text.
let conn_text = if let Some(id) = wallet.config.ext_conn_id {
let conn_text = if let Some(id) = wallet.get_current_ext_conn_id() {
let ext_conn_url = match ConnectionsConfig::ext_conn(id) {
None => ExternalConnection::DEFAULT_MAIN_URL.to_string(),
Some(ext_conn) => ext_conn.url
@@ -451,13 +451,41 @@ impl WalletsContent {
// Setup wallet status text.
let status_text = if wallet.is_open() {
if wallet.is_closing() {
format!("{} {}", SPINNER, t!("wallets.wallet_closing"))
} else if wallet.get_data().is_none() {
if wallet.load_error() {
format!("{} {}", WARNING_CIRCLE, t!("loading_error"))
if wallet.sync_error() {
format!("{} {}", WARNING_CIRCLE, t!("loading_error"))
} else if wallet.is_closing() {
format!("{} {}", SPINNER, t!("wallets.closing"))
} else if wallet.is_repairing() {
let repair_progress = wallet.repairing_progress();
if repair_progress == 0 {
format!("{} {}", SPINNER, t!("wallets.checking"))
} else {
format!("{} {}", SPINNER, t!("loading"))
format!("{} {}: {}%",
SPINNER,
t!("wallets.checking"),
repair_progress)
}
} else if wallet.get_data().is_none() {
let info_progress = wallet.info_sync_progress();
if info_progress != 100 {
if info_progress == 0 {
format!("{} {}", SPINNER, t!("wallets.loading"))
} else {
format!("{} {}: {}%",
SPINNER,
t!("wallets.loading"),
info_progress)
}
} else {
let tx_progress = wallet.txs_sync_progress();
if tx_progress == 0 {
t!("wallets.tx_loading")
} else {
format!("{} {}: {}%",
SPINNER,
t!("wallets.tx_loading"),
tx_progress)
}
}
} else {
format!("{} {}", FOLDER_OPEN, t!("wallets.unlocked"))
+445
View File
@@ -0,0 +1,445 @@
// Copyright 2023 The Grim Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use egui::{Align, Id, Layout, RichText, TextStyle, Widget};
use crate::gui::Colors;
use crate::gui::icons::{CLOCK_COUNTDOWN, EYE, EYE_SLASH, PASSWORD, PENCIL};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, View};
use crate::gui::views::types::ModalPosition;
use crate::wallet::Wallet;
/// Common wallet setup content.
pub struct CommonSetup {
/// Wallet name [`Modal`] value.
name_edit: String,
/// Flag to check if password change [`Modal`] was opened at first time to focus input field.
first_edit_pass_opening: bool,
/// Flag to check if wrong password was entered.
wrong_pass: bool,
/// Current wallet password [`Modal`] value.
current_pass_edit: String,
/// Flag to show/hide old password at [`egui::TextEdit`] field.
hide_current_pass: bool,
/// New wallet password [`Modal`] value.
new_pass_edit: String,
/// Flag to show/hide new password at [`egui::TextEdit`] field.
hide_new_pass: bool,
/// Minimum confirmations number value.
min_confirmations_edit: String
}
/// Identifier for wallet name [`Modal`].
const NAME_EDIT_MODAL: &'static str = "wallet_name_edit_modal";
/// Identifier for wallet password [`Modal`].
const PASS_EDIT_MODAL: &'static str = "wallet_pass_edit_modal";
/// Identifier for minimum confirmations [`Modal`].
const MIN_CONFIRMATIONS_EDIT_MODAL: &'static str = "wallet_min_conf_edit_modal";
impl Default for CommonSetup {
fn default() -> Self {
Self {
name_edit: "".to_string(),
first_edit_pass_opening: true,
wrong_pass: false,
current_pass_edit: "".to_string(),
hide_current_pass: true,
new_pass_edit: "".to_string(),
hide_new_pass: true,
min_confirmations_edit: "".to_string()
}
}
}
impl CommonSetup {
pub fn ui(&mut self,
ui: &mut egui::Ui,
_: &mut eframe::Frame,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
// Draw modal content for this ui container.
self.modal_content_ui(ui, wallet, cb);
ui.vertical_centered(|ui| {
// Show wallet name.
ui.add_space(2.0);
ui.label(RichText::new(t!("wallets.name")).size(16.0).color(Colors::GRAY));
ui.add_space(2.0);
ui.label(RichText::new(wallet.config.name.clone()).size(16.0).color(Colors::BLACK));
ui.add_space(8.0);
// Show wallet name setup.
let name_text = format!("{} {}", PENCIL, t!("change"));
View::button(ui, name_text, Colors::BUTTON, || {
self.name_edit = wallet.config.name.clone();
// Show wallet name modal.
Modal::new(NAME_EDIT_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.wallet"))
.show();
cb.show_keyboard();
});
ui.add_space(12.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(6.0);
ui.label(RichText::new(t!("wallets.pass")).size(16.0).color(Colors::GRAY));
ui.add_space(6.0);
// Show wallet password setup.
let pass_text = format!("{} {}", PASSWORD, t!("change"));
View::button(ui, pass_text, Colors::BUTTON, || {
// Setup modal values.
self.first_edit_pass_opening = true;
self.current_pass_edit = "".to_string();
self.new_pass_edit = "".to_string();
self.hide_current_pass = true;
self.hide_new_pass = true;
self.wrong_pass = false;
// Show wallet password modal.
Modal::new(PASS_EDIT_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.wallet"))
.show();
cb.show_keyboard();
});
ui.add_space(12.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(6.0);
ui.label(RichText::new(t!("wallets.min_tx_conf_count")).size(16.0).color(Colors::GRAY));
ui.add_space(6.0);
// Show minimum amount of confirmations value setup.
let min_conf_text = format!("{} {}", CLOCK_COUNTDOWN, wallet.config.min_confirmations);
View::button(ui, min_conf_text, Colors::BUTTON, || {
self.min_confirmations_edit = wallet.config.min_confirmations.to_string();
// Show minimum amount of confirmations value modal.
Modal::new(MIN_CONFIRMATIONS_EDIT_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("network_settings.change_value"))
.show();
cb.show_keyboard();
});
ui.add_space(12.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(4.0);
});
}
/// Draw modal content for current ui container.
fn modal_content_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
match Modal::opened() {
None => {}
Some(id) => {
match id {
NAME_EDIT_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
self.name_modal_ui(ui, wallet, modal, cb);
});
}
PASS_EDIT_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
self.pass_modal_ui(ui, wallet, modal, cb);
});
}
MIN_CONFIRMATIONS_EDIT_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
self.min_conf_modal_ui(ui, wallet, modal, cb);
});
}
_ => {}
}
}
}
}
/// Draw wallet name [`Modal`] content.
fn name_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
ui.add_space(6.0);
ui.vertical_centered(|ui| {
ui.label(RichText::new(t!("wallets.name"))
.size(17.0)
.color(Colors::GRAY));
ui.add_space(8.0);
// Draw wallet name edit.
let text_edit_resp = egui::TextEdit::singleline(&mut self.name_edit)
.id(Id::from(modal.id).with(wallet.config.id))
.font(TextStyle::Heading)
.desired_width(ui.available_width())
.cursor_at_end(true)
.ui(ui);
text_edit_resp.request_focus();
if text_edit_resp.clicked() {
cb.show_keyboard();
}
ui.add_space(12.0);
});
// Show modal buttons.
ui.scope(|ui| {
// Setup spacing between buttons.
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
ui.columns(2, |columns| {
columns[0].vertical_centered_justified(|ui| {
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
// Close modal.
cb.hide_keyboard();
modal.close();
});
});
columns[1].vertical_centered_justified(|ui| {
// Save button callback.
let mut on_save = || {
if !self.name_edit.is_empty() {
wallet.config.name = self.name_edit.clone();
wallet.config.save();
cb.hide_keyboard();
modal.close();
}
};
View::on_enter_key(ui, || {
(on_save)();
});
View::button(ui, t!("modal.save"), Colors::WHITE, on_save);
});
});
ui.add_space(6.0);
});
}
/// Draw wallet pass [`Modal`] content.
fn pass_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
ui.add_space(6.0);
ui.vertical_centered(|ui| {
ui.label(RichText::new(t!("wallets.current_pass"))
.size(17.0)
.color(Colors::GRAY));
ui.add_space(6.0);
let mut rect = ui.available_rect_before_wrap();
rect.set_height(34.0);
ui.allocate_ui_with_layout(rect.size(), Layout::right_to_left(Align::Center), |ui| {
// Draw button to show/hide current password.
let eye_icon = if self.hide_current_pass { EYE } else { EYE_SLASH };
View::button(ui, eye_icon.to_string(), Colors::WHITE, || {
self.hide_current_pass = !self.hide_current_pass;
});
let layout_size = ui.available_size();
ui.allocate_ui_with_layout(layout_size, Layout::left_to_right(Align::Center), |ui| {
// Draw current wallet password text edit.
let old_pass_resp = egui::TextEdit::singleline(&mut self.current_pass_edit)
.id(Id::from(modal.id).with(wallet.config.id).with("old_pass"))
.font(TextStyle::Heading)
.desired_width(ui.available_width())
.cursor_at_end(true)
.password(self.hide_current_pass)
.ui(ui);
if old_pass_resp.clicked() {
cb.show_keyboard();
}
// Setup focus on input field on first modal opening.
if self.first_edit_pass_opening {
self.first_edit_pass_opening = false;
old_pass_resp.request_focus();
}
});
});
ui.add_space(6.0);
ui.label(RichText::new(t!("wallets.new_pass"))
.size(17.0)
.color(Colors::GRAY));
ui.add_space(6.0);
let mut new_rect = ui.available_rect_before_wrap();
new_rect.set_height(34.0);
ui.allocate_ui_with_layout(new_rect.size(), Layout::right_to_left(Align::Center), |ui| {
// Draw button to show/hide new password.
let eye_icon = if self.hide_new_pass { EYE } else { EYE_SLASH };
View::button(ui, eye_icon.to_string(), Colors::WHITE, || {
self.hide_new_pass = !self.hide_new_pass;
});
let layout_size = ui.available_size();
ui.allocate_ui_with_layout(layout_size, Layout::left_to_right(Align::Center), |ui| {
// Draw new wallet password text edit.
let new_pass_resp = egui::TextEdit::singleline(&mut self.new_pass_edit)
.id(Id::from(modal.id).with(wallet.config.id).with("new_pass"))
.font(TextStyle::Heading)
.desired_width(ui.available_width())
.cursor_at_end(true)
.password(self.hide_new_pass)
.ui(ui);
if new_pass_resp.clicked() {
cb.show_keyboard();
}
});
});
// Show information when password is empty.
if self.current_pass_edit.is_empty() || self.new_pass_edit.is_empty() {
ui.add_space(8.0);
ui.label(RichText::new(t!("wallets.pass_empty"))
.size(17.0)
.color(Colors::INACTIVE_TEXT));
} else if self.wrong_pass {
ui.add_space(8.0);
ui.label(RichText::new(t!("wallets.wrong_pass"))
.size(17.0)
.color(Colors::RED));
}
ui.add_space(10.0);
});
// Show modal buttons.
ui.scope(|ui| {
// Setup spacing between buttons.
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
ui.columns(2, |columns| {
columns[0].vertical_centered_justified(|ui| {
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
// Close modal.
cb.hide_keyboard();
modal.close();
});
});
columns[1].vertical_centered_justified(|ui| {
// Callback for button to continue.
let mut on_continue = || {
if self.new_pass_edit.is_empty() {
return;
}
let old_pass = self.current_pass_edit.clone();
let new_pass = self.new_pass_edit.clone();
match wallet.change_password(old_pass, new_pass) {
Ok(_) => {
// Clear values.
self.first_edit_pass_opening = true;
self.current_pass_edit = "".to_string();
self.new_pass_edit = "".to_string();
self.hide_current_pass = true;
self.hide_new_pass = true;
self.wrong_pass = false;
// Close modal.
cb.hide_keyboard();
modal.close();
}
Err(_) => self.wrong_pass = true
}
};
// Continue on Enter key press.
View::on_enter_key(ui, || {
(on_continue)();
});
View::button(ui, t!("change"), Colors::WHITE, on_continue);
});
});
ui.add_space(6.0);
});
}
/// Draw wallet name [`Modal`] content.
fn min_conf_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
ui.add_space(6.0);
ui.vertical_centered(|ui| {
ui.label(RichText::new(t!("wallets.min_tx_conf_count"))
.size(17.0)
.color(Colors::GRAY));
ui.add_space(8.0);
// Minimum amount of confirmations text edit.
let text_edit_resp = egui::TextEdit::singleline(&mut self.min_confirmations_edit)
.id(Id::from(modal.id))
.font(TextStyle::Heading)
.desired_width(48.0)
.cursor_at_end(true)
.ui(ui);
text_edit_resp.request_focus();
if text_edit_resp.clicked() {
cb.show_keyboard();
}
// Show error when specified value is not valid or reminder to restart enabled node.
if self.min_confirmations_edit.parse::<u64>().is_err() {
ui.add_space(12.0);
ui.label(RichText::new(t!("network_settings.not_valid_value"))
.size(17.0)
.color(Colors::RED));
}
ui.add_space(12.0);
});
// Show modal buttons.
ui.scope(|ui| {
// Setup spacing between buttons.
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
ui.columns(2, |columns| {
columns[0].vertical_centered_justified(|ui| {
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
// Close modal.
cb.hide_keyboard();
modal.close();
});
});
columns[1].vertical_centered_justified(|ui| {
// Save button callback.
let mut on_save = || {
if let Ok(min_conf) = self.min_confirmations_edit.parse::<u64>() {
wallet.config.min_confirmations = min_conf;
cb.hide_keyboard();
modal.close();
}
};
View::on_enter_key(ui, || {
(on_save)();
});
View::button(ui, t!("modal.save"), Colors::WHITE, on_save);
});
});
ui.add_space(6.0);
});
}
}
+8 -10
View File
@@ -16,7 +16,7 @@ use egui::{Align, Id, Layout, RichText, Rounding, TextStyle, Widget};
use url::Url;
use crate::gui::Colors;
use crate::gui::icons::{CHECK, CHECK_CIRCLE, CHECK_FAT, COMPUTER_TOWER, DOTS_THREE_CIRCLE, GLOBE, GLOBE_SIMPLE, POWER, X_CIRCLE};
use crate::gui::icons::{CHECK, CHECK_CIRCLE, CHECK_FAT, COMPUTER_TOWER, DOTS_THREE_CIRCLE, GLOBE, PLUS_CIRCLE, POWER, X_CIRCLE};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, View};
use crate::gui::views::types::{ModalContainer, ModalPosition};
@@ -164,7 +164,7 @@ impl ConnectionSetup {
ui.add_space(6.0);
// Show button to add new external node connection.
let add_node_text = format!("{} {}", GLOBE_SIMPLE, t!("wallets.add_node"));
let add_node_text = format!("{} {}", PLUS_CIRCLE, t!("wallets.add_node"));
View::button(ui, add_node_text, Colors::GOLD, || {
self.show_add_ext_conn_modal(cb);
});
@@ -203,16 +203,15 @@ impl ConnectionSetup {
View::item_button(ui, View::item_rounding(0, 1, true), CHECK, None, || {
self.method = ConnectionMethod::Integrated;
});
} else {
ui.add_space(14.0);
ui.label(RichText::new(CHECK_FAT).size(20.0).color(Colors::GREEN));
ui.add_space(14.0);
}
if !Node::is_running() {
// Draw button to start integrated node.
let rounding = if is_current_method {
View::item_rounding(0, 1, true)
} else {
Rounding::none()
};
View::item_button(ui, rounding, POWER, Some(Colors::GREEN), || {
View::item_button(ui, Rounding::none(), POWER, Some(Colors::GREEN), || {
Node::start();
});
}
@@ -273,7 +272,7 @@ impl ConnectionSetup {
});
} else {
ui.add_space(12.0);
ui.label(RichText::new(CHECK_FAT).size(20.0).color(Colors::TITLE));
ui.label(RichText::new(CHECK_FAT).size(20.0).color(Colors::GREEN));
}
let layout_size = ui.available_size();
@@ -285,7 +284,6 @@ impl ConnectionSetup {
let conn_text = format!("{} {}", COMPUTER_TOWER, conn.url);
View::ellipsize_text(ui, conn_text, 15.0, Colors::TITLE);
ui.add_space(1.0);
// Setup connection status text.
let status_text = if let Some(available) = conn.available {
if available {
-18
View File
@@ -1,18 +0,0 @@
// Copyright 2023 The Grim Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/// Main wallet setup content.
pub struct MainSetup {
}
+2 -2
View File
@@ -15,8 +15,8 @@
mod connection;
pub use connection::ConnectionSetup;
mod main;
pub use main::MainSetup;
mod common;
pub use common::CommonSetup;
mod recovery;
pub use recovery::RecoverySetup;
+163
View File
@@ -12,7 +12,170 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use egui::RichText;
use grin_chain::SyncStatus;
use crate::gui::Colors;
use crate::gui::icons::{EYE, STETHOSCOPE, TRASH, WRENCH};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, View};
use crate::gui::views::types::ModalPosition;
use crate::node::Node;
use crate::wallet::Wallet;
/// Wallet recovery setup content.
pub struct RecoverySetup {
/// Wallet password [`Modal`] value.
pass_edit: String,
/// Flag to check if wrong password was entered.
wrong_pass: bool,
/// Flag to show recovery phrase when password check was passed.
show_recovery_phrase: bool,
}
/// Identifier for recovery phrase [`Modal`].
const RECOVERY_PHRASE_MODAL: &'static str = "recovery_phrase_modal";
/// Identifier to confirm wallet deletion [`Modal`].
const DELETE_CONFIRMATION_MODAL: &'static str = "delete_wallet_confirmation_modal";
impl Default for RecoverySetup {
fn default() -> Self {
Self {
wrong_pass: false,
pass_edit: "".to_string(),
show_recovery_phrase: false,
}
}
}
impl RecoverySetup {
pub fn ui(&mut self,
ui: &mut egui::Ui,
_: &mut eframe::Frame,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
// Draw modal content for this ui container.
self.modal_content_ui(ui, wallet, cb);
ui.add_space(10.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(6.0);
View::sub_title(ui, format!("{} {}", WRENCH, t!("wallets.recovery")));
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(4.0);
ui.vertical_centered(|ui| {
let integrated_node = wallet.get_current_ext_conn_id().is_none();
let integrated_node_ready = Node::get_sync_status() == Some(SyncStatus::NoSync);
if wallet.sync_error() || (integrated_node && !integrated_node_ready) {
ui.add_space(8.0);
ui.label(RichText::new(t!("wallets.repair_unavailable"))
.size(16.0)
.color(Colors::RED));
} else if wallet.is_repairing() {
ui.add_space(8.0);
View::small_loading_spinner(ui);
ui.add_space(1.0);
} else {
ui.add_space(6.0);
// Draw button to repair the wallet.
let repair_text = format!("{} {}", STETHOSCOPE, t!("wallets.repair_wallet"));
View::button(ui, repair_text, Colors::GOLD, || {
wallet.repair();
});
}
ui.add_space(6.0);
ui.label(RichText::new(t!("wallets.repair_desc"))
.size(16.0)
.color(Colors::INACTIVE_TEXT));
ui.add_space(6.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(6.0);
let recovery_phrase_text = format!("{}:", t!("wallets.recovery_phrase"));
ui.label(RichText::new(recovery_phrase_text).size(16.0).color(Colors::GRAY));
ui.add_space(6.0);
// Draw button to show recovery phrase.
let repair_text = format!("{} {}", EYE, t!("show"));
View::button(ui, repair_text, Colors::BUTTON, || {
// Setup modal values.
self.pass_edit = "".to_string();
self.wrong_pass = false;
self.show_recovery_phrase = false;
// Show recovery phrase modal.
Modal::new(RECOVERY_PHRASE_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.recovery_phrase"))
.show();
cb.show_keyboard();
});
ui.add_space(12.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(6.0);
ui.label(RichText::new(t!("wallets.delete_desc")).size(16.0).color(Colors::GRAY));
ui.add_space(6.0);
// Draw button to delete the wallet.
let delete_text = format!("{} {}", TRASH, t!("wallets.delete"));
View::button(ui, delete_text, Colors::GOLD, || {
// Setup modal values.
self.pass_edit = "".to_string();
self.wrong_pass = false;
// Show wallet deletion confirmation modal.
Modal::new(DELETE_CONFIRMATION_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("modal.confirmation"))
.show();
cb.show_keyboard();
});
ui.add_space(8.0);
});
}
/// Draw modal content for current ui container.
fn modal_content_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
match Modal::opened() {
None => {}
Some(id) => {
match id {
RECOVERY_PHRASE_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
self.recovery_phrase_modal_ui(ui, wallet, modal, cb);
});
}
DELETE_CONFIRMATION_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
self.delete_confirmation_modal_ui(ui, wallet, modal, cb);
});
}
_ => {}
}
}
}
}
/// Draw recovery phrase [`Modal`] content.
fn recovery_phrase_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
}
/// Draw recovery phrase [`Modal`] content.
fn delete_confirmation_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
}
}
+52 -51
View File
@@ -14,7 +14,7 @@
use std::time::Duration;
use egui::{Margin, RichText, ScrollArea};
use egui::{Margin, RichText};
use grin_chain::SyncStatus;
use crate::AppConfig;
@@ -30,7 +30,7 @@ use crate::wallet::Wallet;
/// Selected and opened wallet content.
pub struct WalletContent {
/// Current tab content to show.
current_tab: Box<dyn WalletTab>,
pub current_tab: Box<dyn WalletTab>,
}
impl Default for WalletContent {
@@ -46,8 +46,6 @@ impl WalletContent {
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
// Show wallet tabs panel.
let not_show_tabs =
wallet.is_closing() || (wallet.get_data().is_none() && !wallet.load_error());
egui::TopBottomPanel::bottom("wallet_tabs")
.frame(egui::Frame {
fill: Colors::FILL,
@@ -59,7 +57,7 @@ impl WalletContent {
},
..Default::default()
})
.show_animated_inside(ui, !not_show_tabs, |ui| {
.show_animated_inside(ui, !Self::block_navigation_on_sync(wallet), |ui| {
ui.vertical_centered(|ui| {
// Setup tabs width.
let available_width = ui.available_width();
@@ -85,38 +83,16 @@ impl WalletContent {
inner_margin: Margin {
left: View::far_left_inset_margin(ui) + 4.0,
right: View::get_right_inset() + 4.0,
top: 4.0,
top: 3.0,
bottom: 4.0,
},
..Default::default()
})
.show_inside(ui, |ui| {
let scroll_id = format!("wallet_tab_{}_{}",
wallet.config.id,
self.current_tab.get_type().id());
ScrollArea::vertical()
.id_source(scroll_id)
.auto_shrink([false; 2])
.show(ui, |ui| {
ui.vertical_centered(|ui| {
// Setup tab content width.
let available_width = ui.available_width();
if available_width == 0.0 {
return;
}
let mut rect = ui.available_rect_before_wrap();
let width = f32::min(available_width, Root::SIDE_PANEL_WIDTH * 1.3);
rect.set_width(width);
// Draw current tab content.
ui.allocate_ui(rect.size(), |ui| {
self.current_tab.ui(ui, frame, wallet, cb);
});
});
});
self.current_tab.ui(ui, frame, wallet, cb);
});
// Refresh content after 1 second for loaded wallet.
// Refresh content after 1 second for synced wallet.
if wallet.get_data().is_some() {
ui.ctx().request_repaint_after(Duration::from_millis(1000));
} else {
@@ -159,12 +135,15 @@ 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.is_closing() {
Self::loading_progress_ui(ui, wallet);
/// Draw content when wallet is syncing and not ready to use, returns `true` at this case.
pub fn sync_ui(ui: &mut egui::Ui, frame: &mut eframe::Frame, wallet: &Wallet) -> bool {
if wallet.is_repairing() && !wallet.sync_error() {
Self::sync_progress_ui(ui, wallet);
return true;
} else if wallet.config.ext_conn_id.is_none() {
} else if wallet.is_closing() {
Self::sync_progress_ui(ui, wallet);
return true;
} else if wallet.get_current_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, 108.0, |ui| {
@@ -182,48 +161,70 @@ impl WalletContent {
}
});
return true
} else if wallet.load_error()
} else if wallet.sync_error()
&& Node::get_sync_status() == Some(SyncStatus::NoSync) {
Self::loading_error_ui(ui, wallet);
Self::sync_error_ui(ui, wallet);
return true;
} else if wallet.get_data().is_none() {
Self::loading_progress_ui(ui, wallet);
Self::sync_progress_ui(ui, wallet);
return true;
}
} else if wallet.sync_error() {
Self::sync_error_ui(ui, wallet);
return true;
} else if wallet.get_data().is_none() {
if wallet.load_error() {
Self::loading_error_ui(ui, wallet);
} else {
Self::loading_progress_ui(ui, wallet);
}
Self::sync_progress_ui(ui, wallet);
return true;
}
false
}
/// Draw wallet loading error content.
fn loading_error_ui(ui: &mut egui::Ui, wallet: &Wallet) {
/// Draw wallet sync error content.
fn sync_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_load_error(false);
wallet.retry_sync();
});
});
}
/// Draw wallet loading progress content.
pub fn loading_progress_ui(ui: &mut egui::Ui, wallet: &Wallet) {
/// Check when to block tabs navigation on sync progress.
pub fn block_navigation_on_sync(wallet: &Wallet) -> bool {
let sync_error = wallet.sync_error();
let integrated_node = wallet.get_current_ext_conn_id().is_none();
let integrated_node_ready = Node::get_sync_status() == Some(SyncStatus::NoSync);
let sync_after_opening = wallet.get_data().is_none() && !wallet.sync_error();
// Block navigation if wallet is repairing and integrated node is not launching,
// or wallet is closing or syncing after opening when there is no data to show.
(wallet.is_repairing() && (integrated_node_ready || !integrated_node) && !sync_error)
|| wallet.is_closing() || (sync_after_opening && !integrated_node)
}
/// Draw wallet sync progress content.
pub fn sync_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.
// Setup sync progress text.
let text = {
let info_progress = wallet.info_load_progress();
let integrated_node = wallet.get_current_ext_conn_id().is_none();
let integrated_node_ready = Node::get_sync_status() == Some(SyncStatus::NoSync);
let info_progress = wallet.info_sync_progress();
if wallet.is_closing() {
t!("wallets.wallet_closing")
} else if integrated_node && !integrated_node_ready {
t!("wallets.node_loading", "settings" => GEAR_FINE)
} else if wallet.is_repairing() {
let repair_progress = wallet.repairing_progress();
if repair_progress == 0 {
t!("wallets.wallet_checking")
} else {
format!("{}: {}%", t!("wallets.wallet_checking"), repair_progress)
}
} else if info_progress != 100 {
if info_progress == 0 {
t!("wallets.wallet_loading")
@@ -231,7 +232,7 @@ impl WalletContent {
format!("{}: {}%", t!("wallets.wallet_loading"), info_progress)
}
} else {
let tx_progress = wallet.txs_load_progress();
let tx_progress = wallet.txs_sync_progress();
if tx_progress == 0 {
t!("wallets.tx_loading")
} else {
+1 -1
View File
@@ -32,7 +32,7 @@ impl WalletTab for WalletInfo {
frame: &mut eframe::Frame,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
if WalletContent::loading_ui(ui, frame, wallet) {
if WalletContent::sync_ui(ui, frame, wallet) {
return;
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ impl WalletTab for WalletReceive {
frame: &mut eframe::Frame,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
if WalletContent::loading_ui(ui, frame, wallet) {
if WalletContent::sync_ui(ui, frame, wallet) {
return;
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ impl WalletTab for WalletSend {
frame: &mut eframe::Frame,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
if WalletContent::loading_ui(ui, frame, wallet) {
if WalletContent::sync_ui(ui, frame, wallet) {
return;
}
}
+40 -7
View File
@@ -12,24 +12,33 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use egui::{Id, ScrollArea};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::wallets::setup::ConnectionSetup;
use crate::gui::views::Root;
use crate::gui::views::wallets::setup::{CommonSetup, ConnectionSetup, RecoverySetup};
use crate::gui::views::wallets::wallet::types::{WalletTab, WalletTabType};
use crate::gui::views::wallets::wallet::WalletContent;
use crate::wallet::{ExternalConnection, Wallet};
/// Wallet settings tab content.
pub struct WalletSettings {
/// Common setup content.
common_setup: CommonSetup,
/// Connection setup content.
conn_setup: ConnectionSetup
conn_setup: ConnectionSetup,
/// Recovery setup content.
recovery_setup: RecoverySetup
}
impl Default for WalletSettings {
fn default() -> Self {
// Check external connections availability on first tab opening.
// Check external connections availability on opening.
ExternalConnection::start_ext_conn_availability_check();
Self {
common_setup: CommonSetup::default(),
conn_setup: ConnectionSetup::default(),
recovery_setup: RecoverySetup::default()
}
}
}
@@ -44,12 +53,36 @@ impl WalletTab for WalletSettings {
frame: &mut eframe::Frame,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
// Show progress if wallet is loading after opening without an error.
if wallet.is_closing() || (wallet.get_data().is_none() && !wallet.load_error()) {
WalletContent::loading_progress_ui(ui, wallet);
// Show loading progress if navigation is blocked.
if WalletContent::block_navigation_on_sync(wallet) {
WalletContent::sync_progress_ui(ui, wallet);
return;
}
self.conn_setup.wallet_ui(ui, frame, wallet, cb);
ScrollArea::vertical()
.id_source(Id::from("wallet_settings_scroll").with(wallet.config.id))
.auto_shrink([false; 2])
.show(ui, |ui| {
ui.vertical_centered(|ui| {
// Setup tab content width.
let available_width = ui.available_width();
if available_width == 0.0 {
return;
}
let mut rect = ui.available_rect_before_wrap();
let width = f32::min(available_width, Root::SIDE_PANEL_WIDTH * 1.3);
rect.set_width(width);
// Draw current tab content.
ui.allocate_ui(rect.size(), |ui| {
// Show common wallet setup.
self.common_setup.ui(ui, frame, wallet, cb);
// Show wallet connections setup.
self.conn_setup.wallet_ui(ui, frame, wallet, cb);
// Show wallet recovery setup.
self.recovery_setup.ui(ui, frame, wallet, cb);
});
});
});
}
}