2023-07-21 04:17:57 +03:00
|
|
|
// 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.
|
|
|
|
|
2024-04-18 22:07:21 +03:00
|
|
|
use std::time::Duration;
|
2024-05-15 20:51:14 +03:00
|
|
|
use egui::{Align, Id, Layout, Margin, RichText, Rounding, ScrollArea};
|
2024-05-17 21:37:29 +03:00
|
|
|
use egui::scroll_area::ScrollBarVisibility;
|
2023-07-21 04:17:57 +03:00
|
|
|
|
2023-08-03 00:00:23 +03:00
|
|
|
use crate::AppConfig;
|
2023-07-21 04:17:57 +03:00
|
|
|
use crate::gui::Colors;
|
2024-05-01 05:04:55 +03:00
|
|
|
use crate::gui::icons::{ARROW_LEFT, CARET_RIGHT, COMPUTER_TOWER, FOLDER_LOCK, FOLDER_OPEN, GEAR, GLOBE, GLOBE_SIMPLE, LOCK_KEY, PLUS, SIDEBAR_SIMPLE, SPINNER, SUITCASE, WARNING_CIRCLE};
|
2023-07-21 04:17:57 +03:00
|
|
|
use crate::gui::platform::PlatformCallbacks;
|
2024-05-01 05:04:55 +03:00
|
|
|
use crate::gui::views::{Modal, Root, TitlePanel, View};
|
2023-11-08 01:00:56 +03:00
|
|
|
use crate::gui::views::types::{ModalContainer, ModalPosition, TextEditOptions, TitleContentType, TitleType};
|
2023-08-03 04:11:25 +03:00
|
|
|
use crate::gui::views::wallets::creation::WalletCreation;
|
2023-08-12 23:41:34 +03:00
|
|
|
use crate::gui::views::wallets::types::WalletTabType;
|
2023-08-03 00:00:23 +03:00
|
|
|
use crate::gui::views::wallets::WalletContent;
|
2024-05-24 13:35:59 +03:00
|
|
|
use crate::wallet::{Wallet, WalletList};
|
2023-07-21 04:17:57 +03:00
|
|
|
|
|
|
|
/// Wallets content.
|
2023-07-25 03:42:52 +03:00
|
|
|
pub struct WalletsContent {
|
2023-08-13 21:09:04 +03:00
|
|
|
/// List of wallets.
|
2023-08-11 01:20:41 +03:00
|
|
|
wallets: WalletList,
|
2023-08-03 00:00:23 +03:00
|
|
|
|
2023-07-29 00:17:54 +03:00
|
|
|
/// Password to open wallet for [`Modal`].
|
|
|
|
pass_edit: String,
|
|
|
|
/// Flag to check if wrong password was entered.
|
|
|
|
wrong_pass: bool,
|
|
|
|
|
|
|
|
/// Selected [`Wallet`] content.
|
|
|
|
wallet_content: WalletContent,
|
2023-07-21 04:17:57 +03:00
|
|
|
/// Wallet creation content.
|
|
|
|
creation_content: WalletCreation,
|
|
|
|
|
2023-08-01 05:16:28 +03:00
|
|
|
/// Flag to show [`Wallet`] list at dual panel mode.
|
2023-08-04 01:10:23 +03:00
|
|
|
show_wallets_at_dual_panel: bool,
|
2023-08-01 05:16:28 +03:00
|
|
|
|
2023-08-03 04:11:25 +03:00
|
|
|
/// [`Modal`] identifiers allowed at this ui container.
|
2023-07-21 04:17:57 +03:00
|
|
|
modal_ids: Vec<&'static str>
|
|
|
|
}
|
|
|
|
|
2023-08-03 04:11:25 +03:00
|
|
|
/// Identifier for wallet opening [`Modal`].
|
|
|
|
const OPEN_WALLET_MODAL: &'static str = "open_wallet_modal";
|
|
|
|
|
2023-07-25 03:42:52 +03:00
|
|
|
impl Default for WalletsContent {
|
2023-07-21 04:17:57 +03:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2023-08-11 01:20:41 +03:00
|
|
|
wallets: WalletList::default(),
|
2023-07-29 00:17:54 +03:00
|
|
|
pass_edit: "".to_string(),
|
|
|
|
wrong_pass: false,
|
|
|
|
wallet_content: WalletContent::default(),
|
2023-07-21 04:17:57 +03:00
|
|
|
creation_content: WalletCreation::default(),
|
2023-08-04 01:10:23 +03:00
|
|
|
show_wallets_at_dual_panel: AppConfig::show_wallets_at_dual_panel(),
|
2023-07-21 04:17:57 +03:00
|
|
|
modal_ids: vec![
|
2023-08-03 04:11:25 +03:00
|
|
|
OPEN_WALLET_MODAL,
|
|
|
|
WalletCreation::NAME_PASS_MODAL
|
2023-07-21 04:17:57 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-25 03:42:52 +03:00
|
|
|
impl ModalContainer for WalletsContent {
|
2023-07-21 04:17:57 +03:00
|
|
|
fn modal_ids(&self) -> &Vec<&'static str> {
|
|
|
|
&self.modal_ids
|
|
|
|
}
|
2023-08-03 04:11:25 +03:00
|
|
|
|
|
|
|
fn modal_ui(&mut self,
|
|
|
|
ui: &mut egui::Ui,
|
|
|
|
_: &mut eframe::Frame,
|
|
|
|
modal: &Modal,
|
|
|
|
cb: &dyn PlatformCallbacks) {
|
|
|
|
match modal.id {
|
|
|
|
OPEN_WALLET_MODAL => self.open_wallet_modal_ui(ui, modal, cb),
|
|
|
|
WalletCreation::NAME_PASS_MODAL => {
|
|
|
|
self.creation_content.name_pass_modal_ui(ui, modal, cb)
|
|
|
|
},
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2023-07-21 04:17:57 +03:00
|
|
|
}
|
|
|
|
|
2023-07-25 03:42:52 +03:00
|
|
|
impl WalletsContent {
|
2023-07-21 04:17:57 +03:00
|
|
|
pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
2023-08-03 04:11:25 +03:00
|
|
|
// Draw modal content for current ui container.
|
|
|
|
self.current_modal_ui(ui, frame, cb);
|
2023-07-21 04:17:57 +03:00
|
|
|
|
2023-07-29 00:17:54 +03:00
|
|
|
// Setup wallet content flags.
|
2023-08-11 17:29:25 +03:00
|
|
|
let empty_list = self.wallets.is_current_list_empty();
|
2023-07-30 18:57:12 +03:00
|
|
|
let create_wallet = self.creation_content.can_go_back();
|
2023-08-03 00:00:23 +03:00
|
|
|
let show_wallet = self.wallets.is_selected_open();
|
2023-07-28 00:00:57 +03:00
|
|
|
|
2023-07-29 00:17:54 +03:00
|
|
|
// Setup panels parameters.
|
2024-04-16 15:24:22 +03:00
|
|
|
let dual_panel = is_dual_panel_mode(ui);
|
2023-07-30 18:57:12 +03:00
|
|
|
let open_wallet_panel = dual_panel || show_wallet || create_wallet || empty_list;
|
|
|
|
let wallet_panel_width = self.wallet_panel_width(ui, empty_list, dual_panel, show_wallet);
|
2023-08-03 23:49:11 +03:00
|
|
|
let content_width = ui.available_width();
|
2023-07-30 18:57:12 +03:00
|
|
|
|
|
|
|
// Show title panel.
|
2023-08-01 17:23:09 +03:00
|
|
|
self.title_ui(ui, frame, dual_panel, create_wallet, show_wallet);
|
2023-07-29 00:17:54 +03:00
|
|
|
|
|
|
|
// Show wallet panel content.
|
2023-07-21 04:17:57 +03:00
|
|
|
egui::SidePanel::right("wallet_panel")
|
|
|
|
.resizable(false)
|
2023-08-11 01:20:41 +03:00
|
|
|
.exact_width(wallet_panel_width)
|
2023-07-21 04:17:57 +03:00
|
|
|
.frame(egui::Frame {
|
2023-08-01 17:23:09 +03:00
|
|
|
fill: if empty_list && !create_wallet
|
2023-08-04 01:10:23 +03:00
|
|
|
|| (dual_panel && show_wallet && !self.show_wallets_at_dual_panel) {
|
2024-05-29 22:47:17 +03:00
|
|
|
Colors::fill_deep()
|
2023-07-29 00:17:54 +03:00
|
|
|
} else {
|
2023-08-09 22:14:01 +03:00
|
|
|
if create_wallet {
|
2024-05-29 22:47:17 +03:00
|
|
|
Colors::white_or_black(true)
|
2023-08-09 22:14:01 +03:00
|
|
|
} else {
|
2024-05-29 22:47:17 +03:00
|
|
|
Colors::button()
|
2023-08-09 22:14:01 +03:00
|
|
|
}
|
2023-07-28 00:00:57 +03:00
|
|
|
},
|
2023-07-21 04:17:57 +03:00
|
|
|
..Default::default()
|
|
|
|
})
|
2023-07-30 18:57:12 +03:00
|
|
|
.show_animated_inside(ui, open_wallet_panel, |ui| {
|
2023-08-01 05:16:28 +03:00
|
|
|
// Do not draw content on zero width.
|
2023-08-03 23:49:11 +03:00
|
|
|
if content_width == 0.0 {
|
2023-08-01 02:10:45 +03:00
|
|
|
return;
|
|
|
|
}
|
2023-07-30 18:57:12 +03:00
|
|
|
if create_wallet || !show_wallet {
|
2023-08-03 00:00:23 +03:00
|
|
|
// Show wallet creation content.
|
2023-08-09 02:22:16 +03:00
|
|
|
self.creation_content.ui(ui, frame, cb, |wallet| {
|
2023-08-03 00:00:23 +03:00
|
|
|
// Add created wallet to list.
|
|
|
|
self.wallets.add(wallet);
|
2024-04-16 15:24:22 +03:00
|
|
|
// Reset wallet content.
|
|
|
|
self.wallet_content = WalletContent::default();
|
2023-08-03 00:00:23 +03:00
|
|
|
});
|
2023-07-30 18:57:12 +03:00
|
|
|
} else {
|
2023-08-14 03:17:54 +03:00
|
|
|
let selected_id = self.wallets.selected_id.clone();
|
|
|
|
let list = self.wallets.mut_list();
|
|
|
|
for wallet in list {
|
2023-07-30 18:57:12 +03:00
|
|
|
// Show content for selected wallet.
|
2023-10-18 02:26:22 +03:00
|
|
|
if selected_id == Some(wallet.get_config().id) {
|
2023-08-03 23:49:11 +03:00
|
|
|
// Setup wallet content width.
|
|
|
|
let mut rect = ui.available_rect_before_wrap();
|
|
|
|
let mut width = ui.available_width();
|
2023-08-04 01:10:23 +03:00
|
|
|
if dual_panel && self.show_wallets_at_dual_panel {
|
2023-08-03 23:49:11 +03:00
|
|
|
width = content_width - Root::SIDE_PANEL_WIDTH;
|
|
|
|
}
|
|
|
|
rect.set_width(width);
|
|
|
|
// Show wallet content.
|
|
|
|
ui.allocate_ui_at_rect(rect, |ui| {
|
2023-08-11 17:29:25 +03:00
|
|
|
self.wallet_content.ui(ui, frame, wallet, cb);
|
2023-08-03 23:49:11 +03:00
|
|
|
});
|
2023-07-30 18:57:12 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-07-29 00:17:54 +03:00
|
|
|
}
|
2023-07-21 04:17:57 +03:00
|
|
|
});
|
|
|
|
|
2024-04-17 01:30:28 +03:00
|
|
|
// Flag to check if wallet list is hidden on the screen.
|
2024-04-18 05:20:49 +03:00
|
|
|
let list_hidden = content_width == 0.0 || empty_list || create_wallet
|
2024-04-17 01:30:28 +03:00
|
|
|
|| (dual_panel && show_wallet && !self.show_wallets_at_dual_panel)
|
|
|
|
|| (!dual_panel && show_wallet);
|
|
|
|
|
|
|
|
// Setup flag to show wallets bottom panel if wallet is not showing
|
|
|
|
// at non-dual panel mode and network is no open or showing at dual panel mode.
|
2024-04-18 05:20:49 +03:00
|
|
|
let show_bottom_panel = !list_hidden &&
|
|
|
|
((!show_wallet && !dual_panel && !Root::is_network_panel_open()) ||
|
|
|
|
(dual_panel && show_wallet));
|
2024-04-17 01:30:28 +03:00
|
|
|
|
|
|
|
// Show wallets bottom panel.
|
|
|
|
egui::TopBottomPanel::bottom("wallets_bottom_panel")
|
|
|
|
.frame(egui::Frame {
|
2024-05-29 22:47:17 +03:00
|
|
|
stroke: View::item_stroke(),
|
|
|
|
fill: Colors::fill(),
|
2024-04-17 01:30:28 +03:00
|
|
|
inner_margin: Margin {
|
|
|
|
left: View::get_left_inset() + 4.0,
|
|
|
|
right: View::far_right_inset_margin(ui) + 4.0,
|
|
|
|
top: 4.0,
|
|
|
|
bottom: View::get_bottom_inset() + 4.0,
|
|
|
|
},
|
|
|
|
..Default::default()
|
|
|
|
})
|
2024-04-18 05:20:49 +03:00
|
|
|
.show_animated_inside(ui, show_bottom_panel, |ui| {
|
2024-04-17 01:30:28 +03:00
|
|
|
// Setup vertical padding inside buttons.
|
|
|
|
ui.style_mut().spacing.button_padding = egui::vec2(10.0, 4.0);
|
|
|
|
|
|
|
|
ui.vertical_centered(|ui| {
|
2024-04-17 03:51:01 +03:00
|
|
|
let pressed = Modal::opened() == Some(WalletCreation::NAME_PASS_MODAL);
|
|
|
|
View::tab_button(ui, PLUS, pressed, || {
|
2024-04-17 01:30:28 +03:00
|
|
|
self.creation_content.show_name_pass_modal(cb);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-04-18 05:20:49 +03:00
|
|
|
// Show non-empty list if wallet is not creating and list not hidden.
|
|
|
|
if !list_hidden {
|
2023-08-01 05:16:28 +03:00
|
|
|
// Show wallet list panel.
|
2023-07-21 04:17:57 +03:00
|
|
|
egui::CentralPanel::default()
|
|
|
|
.frame(egui::Frame {
|
2024-05-29 22:47:17 +03:00
|
|
|
stroke: View::default_stroke(),
|
|
|
|
fill: Colors::fill_deep(),
|
2023-07-21 04:17:57 +03:00
|
|
|
inner_margin: Margin {
|
2023-08-01 05:16:28 +03:00
|
|
|
left: if list_hidden {
|
2023-08-01 02:10:45 +03:00
|
|
|
0.0
|
|
|
|
} else {
|
|
|
|
View::far_left_inset_margin(ui) + 4.0
|
|
|
|
},
|
2023-08-01 05:16:28 +03:00
|
|
|
right: if list_hidden {
|
2023-08-01 02:10:45 +03:00
|
|
|
0.0
|
|
|
|
} else {
|
2024-04-16 15:24:22 +03:00
|
|
|
View::far_right_inset_margin(ui) + 4.0
|
2023-08-01 02:10:45 +03:00
|
|
|
},
|
2023-07-30 21:08:16 +03:00
|
|
|
top: 4.0,
|
|
|
|
bottom: View::get_bottom_inset() + 4.0,
|
2023-07-21 04:17:57 +03:00
|
|
|
},
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.show_inside(ui, |ui| {
|
2024-04-18 22:07:21 +03:00
|
|
|
// Update ui after 1 sec at single panel mode.
|
|
|
|
if !dual_panel {
|
|
|
|
ui.ctx().request_repaint_after(Duration::from_millis(1000));
|
|
|
|
}
|
2023-07-30 21:08:16 +03:00
|
|
|
// Show list of wallets.
|
2024-04-17 01:30:28 +03:00
|
|
|
self.wallet_list_ui(ui, dual_panel, cb);
|
2023-07-21 04:17:57 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-29 00:17:54 +03:00
|
|
|
/// Draw [`TitlePanel`] content.
|
2023-08-01 17:23:09 +03:00
|
|
|
fn title_ui(&mut self,
|
|
|
|
ui: &mut egui::Ui,
|
|
|
|
frame: &mut eframe::Frame,
|
|
|
|
dual_panel: bool,
|
|
|
|
create_wallet: bool,
|
|
|
|
show_wallet: bool) {
|
2023-08-09 22:58:07 +03:00
|
|
|
let show_list = self.show_wallets_at_dual_panel;
|
|
|
|
|
|
|
|
// Setup title.
|
|
|
|
let title_content = if self.wallets.is_selected_open() && (!dual_panel
|
2023-08-15 21:20:20 +03:00
|
|
|
|| (dual_panel && !show_list)) && !create_wallet {
|
2023-08-12 23:41:34 +03:00
|
|
|
let title_text = self.wallet_content.current_tab.get_type().name().to_uppercase();
|
|
|
|
if self.wallet_content.current_tab.get_type() == WalletTabType::Settings {
|
|
|
|
TitleType::Single(TitleContentType::Title(title_text))
|
|
|
|
} else {
|
|
|
|
let subtitle_text = self.wallets.selected_name();
|
|
|
|
TitleType::Single(TitleContentType::WithSubTitle(title_text, subtitle_text, false))
|
|
|
|
}
|
2023-08-09 22:58:07 +03:00
|
|
|
} else {
|
2023-08-12 23:41:34 +03:00
|
|
|
let title_text = if create_wallet {
|
|
|
|
t!("wallets.add")
|
|
|
|
} else {
|
|
|
|
t!("wallets.title")
|
|
|
|
}.to_uppercase();
|
|
|
|
let dual_title = !create_wallet && show_wallet && dual_panel;
|
|
|
|
if dual_title {
|
|
|
|
let wallet_tab_type = self.wallet_content.current_tab.get_type();
|
|
|
|
let wallet_tab_name = wallet_tab_type.name().to_uppercase();
|
|
|
|
let title_content = if wallet_tab_type == WalletTabType::Settings {
|
|
|
|
TitleContentType::Title(wallet_tab_name)
|
|
|
|
} else {
|
|
|
|
let subtitle_text = self.wallets.selected_name();
|
|
|
|
TitleContentType::WithSubTitle(wallet_tab_name, subtitle_text, false)
|
|
|
|
};
|
|
|
|
TitleType::Dual(TitleContentType::Title(title_text), title_content)
|
|
|
|
} else {
|
|
|
|
TitleType::Single(TitleContentType::Title(title_text))
|
|
|
|
}
|
2023-08-09 22:58:07 +03:00
|
|
|
};
|
2023-07-21 04:17:57 +03:00
|
|
|
|
|
|
|
// Draw title panel.
|
2024-05-15 20:51:14 +03:00
|
|
|
TitlePanel::ui(title_content, |ui, _| {
|
2023-08-01 17:23:09 +03:00
|
|
|
if show_wallet && !dual_panel {
|
2023-07-30 18:57:12 +03:00
|
|
|
View::title_button(ui, ARROW_LEFT, || {
|
2023-08-03 00:00:23 +03:00
|
|
|
self.wallets.select(None);
|
2023-07-30 18:57:12 +03:00
|
|
|
});
|
2023-08-01 17:23:09 +03:00
|
|
|
} else if create_wallet {
|
2023-07-22 01:59:19 +03:00
|
|
|
View::title_button(ui, ARROW_LEFT, || {
|
|
|
|
self.creation_content.back();
|
|
|
|
});
|
2023-08-01 17:23:09 +03:00
|
|
|
} else if show_wallet && dual_panel {
|
2023-08-01 05:16:28 +03:00
|
|
|
let list_icon = if show_list {
|
|
|
|
SIDEBAR_SIMPLE
|
|
|
|
} else {
|
|
|
|
SUITCASE
|
|
|
|
};
|
|
|
|
View::title_button(ui, list_icon, || {
|
2023-08-04 01:10:23 +03:00
|
|
|
self.show_wallets_at_dual_panel = !show_list;
|
|
|
|
AppConfig::toggle_show_wallets_at_dual_panel();
|
2023-08-01 05:16:28 +03:00
|
|
|
});
|
2024-04-16 15:24:22 +03:00
|
|
|
} else if !Root::is_dual_panel_mode(ui) {
|
2023-07-21 04:17:57 +03:00
|
|
|
View::title_button(ui, GLOBE, || {
|
|
|
|
Root::toggle_network_panel();
|
|
|
|
});
|
|
|
|
};
|
2024-05-15 20:51:14 +03:00
|
|
|
}, |ui, _| {
|
2023-07-21 04:17:57 +03:00
|
|
|
View::title_button(ui, GEAR, || {
|
2024-04-24 11:29:38 +03:00
|
|
|
// Show settings modal.
|
2024-05-01 05:04:55 +03:00
|
|
|
Modal::new(Root::SETTINGS_MODAL)
|
2024-04-24 11:29:38 +03:00
|
|
|
.position(ModalPosition::CenterTop)
|
|
|
|
.title(t!("settings"))
|
|
|
|
.show();
|
2023-07-21 04:17:57 +03:00
|
|
|
});
|
|
|
|
}, ui, frame);
|
|
|
|
}
|
|
|
|
|
2023-08-01 05:16:28 +03:00
|
|
|
/// Calculate [`WalletContent`] panel width.
|
|
|
|
fn wallet_panel_width(
|
|
|
|
&self,
|
|
|
|
ui:&mut egui::Ui,
|
|
|
|
list_empty: bool,
|
|
|
|
dual_panel: bool,
|
|
|
|
show_wallet: bool
|
|
|
|
) -> f32 {
|
|
|
|
let create_wallet = self.creation_content.can_go_back();
|
|
|
|
let available_width = if list_empty || create_wallet || (show_wallet && !dual_panel)
|
2023-08-04 01:10:23 +03:00
|
|
|
|| (show_wallet && !self.show_wallets_at_dual_panel) {
|
2023-08-01 05:16:28 +03:00
|
|
|
ui.available_width()
|
|
|
|
} else {
|
|
|
|
ui.available_width() - Root::SIDE_PANEL_WIDTH
|
|
|
|
};
|
2023-08-04 01:10:23 +03:00
|
|
|
if dual_panel && show_wallet && self.show_wallets_at_dual_panel {
|
2023-08-01 05:16:28 +03:00
|
|
|
let min_width = Root::SIDE_PANEL_WIDTH + View::get_right_inset();
|
|
|
|
f32::max(min_width, available_width)
|
|
|
|
} else {
|
|
|
|
available_width
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-17 01:30:28 +03:00
|
|
|
/// Draw list of wallets.
|
2023-08-03 23:49:11 +03:00
|
|
|
fn wallet_list_ui(&mut self,
|
|
|
|
ui: &mut egui::Ui,
|
|
|
|
dual_panel: bool,
|
2024-04-17 01:30:28 +03:00
|
|
|
cb: &dyn PlatformCallbacks) {
|
2023-07-30 21:08:16 +03:00
|
|
|
ui.scope(|ui| {
|
2024-04-18 05:20:49 +03:00
|
|
|
ScrollArea::vertical()
|
2023-07-30 21:08:16 +03:00
|
|
|
.id_source("wallet_list")
|
2024-05-17 21:37:29 +03:00
|
|
|
.scroll_bar_visibility(ScrollBarVisibility::AlwaysHidden)
|
2023-07-30 21:08:16 +03:00
|
|
|
.auto_shrink([false; 2])
|
|
|
|
.show(ui, |ui| {
|
|
|
|
ui.vertical_centered(|ui| {
|
2023-07-31 01:04:41 +03:00
|
|
|
// Setup wallet list width.
|
2023-08-15 21:20:20 +03:00
|
|
|
let max_width = if !dual_panel {
|
|
|
|
Root::SIDE_PANEL_WIDTH * 1.3
|
|
|
|
} else {
|
|
|
|
ui.available_width()
|
|
|
|
};
|
|
|
|
View::max_width_ui(ui, max_width, |ui| {
|
2023-08-14 03:17:54 +03:00
|
|
|
let mut list = self.wallets.list().clone();
|
|
|
|
// Remove deleted wallet from the list.
|
|
|
|
list.retain(|w| !w.is_deleted());
|
2023-08-11 17:29:25 +03:00
|
|
|
for wallet in &list {
|
2023-08-12 04:24:23 +03:00
|
|
|
// Check if wallet reopen is needed.
|
|
|
|
if !wallet.is_open() && wallet.reopen_needed() {
|
|
|
|
wallet.set_reopen(false);
|
2023-10-18 02:26:22 +03:00
|
|
|
self.wallets.select(Some(wallet.get_config().id));
|
2023-08-12 04:24:23 +03:00
|
|
|
self.show_open_wallet_modal(cb);
|
|
|
|
}
|
2023-07-30 21:08:16 +03:00
|
|
|
// Draw wallet list item.
|
2023-08-11 17:29:25 +03:00
|
|
|
self.wallet_item_ui(ui, wallet, cb);
|
2023-08-03 00:00:23 +03:00
|
|
|
ui.add_space(5.0);
|
|
|
|
}
|
2023-07-30 21:08:16 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-07-30 18:57:12 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Draw wallet list item.
|
2023-08-03 00:00:23 +03:00
|
|
|
fn wallet_item_ui(&mut self,
|
|
|
|
ui: &mut egui::Ui,
|
2023-08-11 17:29:25 +03:00
|
|
|
wallet: &Wallet,
|
2023-08-03 00:00:23 +03:00
|
|
|
cb: &dyn PlatformCallbacks) {
|
2023-10-18 02:26:22 +03:00
|
|
|
let config = wallet.get_config();
|
|
|
|
let id = config.id;
|
2023-08-11 17:29:25 +03:00
|
|
|
let is_selected = self.wallets.selected_id == Some(id);
|
2024-04-19 04:09:23 +03:00
|
|
|
let current = is_selected && wallet.is_open();
|
2023-07-30 18:57:12 +03:00
|
|
|
// Draw round background.
|
|
|
|
let mut rect = ui.available_rect_before_wrap();
|
2023-07-31 01:04:41 +03:00
|
|
|
rect.set_height(78.0);
|
2023-08-05 22:39:42 +03:00
|
|
|
let rounding = View::item_rounding(0, 1, false);
|
2024-04-19 04:09:23 +03:00
|
|
|
let bg = if current {
|
2024-05-29 22:47:17 +03:00
|
|
|
if AppConfig::dark_theme().unwrap_or(false) {
|
|
|
|
egui::Color32::from_gray(32)
|
|
|
|
} else {
|
|
|
|
egui::Color32::from_gray(233)
|
|
|
|
}
|
2024-04-19 04:09:23 +03:00
|
|
|
} else {
|
2024-05-29 22:47:17 +03:00
|
|
|
Colors::fill()
|
2024-04-19 04:09:23 +03:00
|
|
|
};
|
2024-05-29 22:47:17 +03:00
|
|
|
ui.painter().rect(rect, rounding, bg, View::hover_stroke());
|
2023-07-30 18:57:12 +03:00
|
|
|
|
|
|
|
ui.allocate_ui_with_layout(rect.size(), Layout::right_to_left(Align::Center), |ui| {
|
|
|
|
// Setup padding for item buttons.
|
|
|
|
ui.style_mut().spacing.button_padding = egui::vec2(14.0, 0.0);
|
|
|
|
|
2023-08-03 00:00:23 +03:00
|
|
|
if !wallet.is_open() {
|
2023-07-30 18:57:12 +03:00
|
|
|
// Show button to open closed wallet.
|
2023-08-09 02:22:16 +03:00
|
|
|
View::item_button(ui, View::item_rounding(0, 1, true), FOLDER_OPEN, None, || {
|
2023-08-03 00:00:23 +03:00
|
|
|
self.wallets.select(Some(id));
|
2023-07-29 00:17:54 +03:00
|
|
|
self.show_open_wallet_modal(cb);
|
|
|
|
});
|
2023-08-09 02:22:16 +03:00
|
|
|
} else {
|
|
|
|
if !is_selected {
|
|
|
|
// Show button to select opened wallet.
|
|
|
|
View::item_button(ui, View::item_rounding(0, 1, true), CARET_RIGHT, None, || {
|
2023-08-11 23:43:25 +03:00
|
|
|
// Reset wallet content.
|
|
|
|
self.wallet_content = WalletContent::default();
|
|
|
|
// Select wallet.
|
2023-08-09 02:22:16 +03:00
|
|
|
self.wallets.select(Some(id));
|
|
|
|
});
|
|
|
|
}
|
2023-08-11 01:20:41 +03:00
|
|
|
|
2023-08-13 21:09:04 +03:00
|
|
|
// Show button to close opened wallet.
|
|
|
|
if !wallet.is_closing() {
|
2023-08-11 01:20:41 +03:00
|
|
|
View::item_button(ui, if !is_selected {
|
2023-11-08 01:00:56 +03:00
|
|
|
Rounding::default()
|
2023-08-11 01:20:41 +03:00
|
|
|
} else {
|
|
|
|
View::item_rounding(0, 1, true)
|
|
|
|
}, LOCK_KEY, None, || {
|
|
|
|
wallet.close();
|
|
|
|
});
|
|
|
|
}
|
2023-07-29 00:17:54 +03:00
|
|
|
}
|
2023-07-30 18:57:12 +03:00
|
|
|
|
|
|
|
let layout_size = ui.available_size();
|
|
|
|
ui.allocate_ui_with_layout(layout_size, Layout::left_to_right(Align::Center), |ui| {
|
|
|
|
ui.add_space(7.0);
|
|
|
|
ui.vertical(|ui| {
|
2023-07-31 01:04:41 +03:00
|
|
|
ui.add_space(3.0);
|
2023-07-30 18:57:12 +03:00
|
|
|
// Setup wallet name text.
|
2024-05-29 22:47:17 +03:00
|
|
|
let name_color = if is_selected {
|
|
|
|
Colors::white_or_black(true)
|
|
|
|
} else {
|
|
|
|
Colors::title(false)
|
|
|
|
};
|
2023-10-18 02:26:22 +03:00
|
|
|
View::ellipsize_text(ui, config.name, 18.0, name_color);
|
2023-07-30 18:57:12 +03:00
|
|
|
|
|
|
|
// Setup wallet connection text.
|
2024-05-24 13:35:59 +03:00
|
|
|
let conn_text = if let Some(conn) = wallet.get_current_ext_conn() {
|
|
|
|
format!("{} {}", GLOBE_SIMPLE, conn.url)
|
2023-07-30 18:57:12 +03:00
|
|
|
} else {
|
|
|
|
format!("{} {}", COMPUTER_TOWER, t!("network.node"))
|
|
|
|
};
|
2024-05-29 22:47:17 +03:00
|
|
|
View::ellipsize_text(ui, conn_text, 15.0, Colors::text(false));
|
2023-07-31 01:04:41 +03:00
|
|
|
ui.add_space(1.0);
|
2023-07-30 18:57:12 +03:00
|
|
|
|
|
|
|
// Setup wallet status text.
|
2023-08-03 00:00:23 +03:00
|
|
|
let status_text = if wallet.is_open() {
|
2023-08-13 21:09:04 +03:00
|
|
|
if wallet.sync_error() {
|
2023-08-16 05:15:35 +03:00
|
|
|
format!("{} {}", WARNING_CIRCLE, t!("error"))
|
2023-08-13 21:09:04 +03:00
|
|
|
} 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!("wallets.checking"),
|
|
|
|
repair_progress)
|
|
|
|
}
|
2023-08-11 01:20:41 +03:00
|
|
|
} else if wallet.get_data().is_none() {
|
2023-08-13 21:09:04 +03:00
|
|
|
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)
|
|
|
|
}
|
2023-08-09 20:11:44 +03:00
|
|
|
} else {
|
2023-08-13 21:09:04 +03:00
|
|
|
let tx_progress = wallet.txs_sync_progress();
|
|
|
|
if tx_progress == 0 {
|
2023-08-14 03:17:54 +03:00
|
|
|
format!("{} {}", SPINNER, t!("wallets.tx_loading"))
|
2023-08-13 21:09:04 +03:00
|
|
|
} else {
|
|
|
|
format!("{} {}: {}%",
|
|
|
|
SPINNER,
|
|
|
|
t!("wallets.tx_loading"),
|
|
|
|
tx_progress)
|
|
|
|
}
|
2023-08-09 20:11:44 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
format!("{} {}", FOLDER_OPEN, t!("wallets.unlocked"))
|
|
|
|
}
|
2023-07-30 18:57:12 +03:00
|
|
|
} else {
|
|
|
|
format!("{} {}", FOLDER_LOCK, t!("wallets.locked"))
|
|
|
|
};
|
2024-05-29 22:47:17 +03:00
|
|
|
ui.label(RichText::new(status_text).size(15.0).color(Colors::gray()));
|
2023-07-30 21:08:16 +03:00
|
|
|
ui.add_space(4.0);
|
2023-07-30 18:57:12 +03:00
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
2023-07-21 04:17:57 +03:00
|
|
|
}
|
|
|
|
|
2023-07-29 00:17:54 +03:00
|
|
|
/// Show [`Modal`] to open selected wallet.
|
|
|
|
pub fn show_open_wallet_modal(&mut self, cb: &dyn PlatformCallbacks) {
|
|
|
|
// Reset modal values.
|
|
|
|
self.pass_edit = String::from("");
|
|
|
|
self.wrong_pass = false;
|
|
|
|
// Show modal.
|
2023-08-03 04:11:25 +03:00
|
|
|
Modal::new(OPEN_WALLET_MODAL)
|
2023-07-29 00:17:54 +03:00
|
|
|
.position(ModalPosition::CenterTop)
|
|
|
|
.title(t!("wallets.open"))
|
|
|
|
.show();
|
|
|
|
cb.show_keyboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Draw wallet opening [`Modal`] content.
|
|
|
|
fn open_wallet_modal_ui(&mut self,
|
|
|
|
ui: &mut egui::Ui,
|
|
|
|
modal: &Modal,
|
|
|
|
cb: &dyn PlatformCallbacks) {
|
|
|
|
ui.add_space(6.0);
|
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
ui.label(RichText::new(t!("wallets.pass"))
|
|
|
|
.size(17.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::gray()));
|
2023-11-08 01:00:56 +03:00
|
|
|
ui.add_space(8.0);
|
|
|
|
|
|
|
|
// Show password input.
|
2024-05-21 13:31:46 +03:00
|
|
|
let mut pass_edit_opts = TextEditOptions::new(Id::from(modal.id)).password();
|
|
|
|
View::text_edit(ui, cb, &mut self.pass_edit, &mut pass_edit_opts);
|
2023-07-29 00:17:54 +03:00
|
|
|
|
|
|
|
// Show information when password is empty.
|
|
|
|
if self.pass_edit.is_empty() {
|
2024-04-19 01:55:09 +03:00
|
|
|
self.wrong_pass = false;
|
2023-07-29 00:17:54 +03:00
|
|
|
ui.add_space(10.0);
|
|
|
|
ui.label(RichText::new(t!("wallets.pass_empty"))
|
|
|
|
.size(17.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::inactive_text()));
|
2023-07-29 00:17:54 +03:00
|
|
|
} else if self.wrong_pass {
|
|
|
|
ui.add_space(10.0);
|
|
|
|
ui.label(RichText::new(t!("wallets.wrong_pass"))
|
|
|
|
.size(17.0)
|
2024-05-29 22:47:17 +03:00
|
|
|
.color(Colors::red()));
|
2023-07-29 00:17:54 +03:00
|
|
|
}
|
|
|
|
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| {
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, t!("modal.cancel"), Colors::white_or_black(false), || {
|
2023-07-29 00:17:54 +03:00
|
|
|
// Close modal.
|
|
|
|
cb.hide_keyboard();
|
|
|
|
modal.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
columns[1].vertical_centered_justified(|ui| {
|
2023-08-03 00:00:23 +03:00
|
|
|
// Callback for button to continue.
|
2023-07-29 00:17:54 +03:00
|
|
|
let mut on_continue = || {
|
|
|
|
if self.pass_edit.is_empty() {
|
|
|
|
return;
|
|
|
|
}
|
2023-08-09 20:11:44 +03:00
|
|
|
match self.wallets.open_selected(self.pass_edit.clone()) {
|
2023-07-29 00:17:54 +03:00
|
|
|
Ok(_) => {
|
|
|
|
// Clear values.
|
|
|
|
self.pass_edit = "".to_string();
|
|
|
|
self.wrong_pass = false;
|
|
|
|
// Close modal.
|
|
|
|
cb.hide_keyboard();
|
|
|
|
modal.close();
|
2023-08-11 23:43:25 +03:00
|
|
|
// Reset wallet content.
|
|
|
|
self.wallet_content = WalletContent::default();
|
2023-07-29 00:17:54 +03:00
|
|
|
}
|
|
|
|
Err(_) => self.wrong_pass = true
|
|
|
|
}
|
|
|
|
};
|
2023-08-03 00:00:23 +03:00
|
|
|
|
2023-07-29 00:17:54 +03:00
|
|
|
// Continue on Enter key press.
|
|
|
|
View::on_enter_key(ui, || {
|
|
|
|
(on_continue)();
|
|
|
|
});
|
|
|
|
|
2024-05-29 22:47:17 +03:00
|
|
|
View::button(ui, t!("continue"), Colors::white_or_black(false), on_continue);
|
2023-07-29 00:17:54 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
ui.add_space(6.0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-21 04:17:57 +03:00
|
|
|
/// Handle Back key event.
|
|
|
|
/// Return `false` when event was handled.
|
|
|
|
pub fn on_back(&mut self) -> bool {
|
|
|
|
let can_go_back = self.creation_content.can_go_back();
|
|
|
|
if can_go_back {
|
2023-07-22 01:59:19 +03:00
|
|
|
self.creation_content.back();
|
2024-04-17 01:30:28 +03:00
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
if self.wallets.is_selected_open() {
|
|
|
|
self.wallets.select(None);
|
|
|
|
return false
|
|
|
|
}
|
2023-07-21 04:17:57 +03:00
|
|
|
}
|
2024-04-17 01:30:28 +03:00
|
|
|
true
|
2023-07-21 04:17:57 +03:00
|
|
|
}
|
2023-08-01 05:16:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Check if it's possible to show [`WalletsContent`] and [`WalletContent`] panels at same time.
|
2024-04-16 15:24:22 +03:00
|
|
|
fn is_dual_panel_mode(ui: &mut egui::Ui) -> bool {
|
|
|
|
let dual_panel_root = Root::is_dual_panel_mode(ui);
|
2023-08-01 05:16:28 +03:00
|
|
|
let max_width = ui.available_width();
|
|
|
|
dual_panel_root && max_width >= (Root::SIDE_PANEL_WIDTH * 2.0) + View::get_right_inset()
|
2023-07-21 04:17:57 +03:00
|
|
|
}
|