ui: content container

This commit is contained in:
ardocrat
2025-05-30 12:33:13 +03:00
parent 5dd8de7950
commit b84f6480e7
34 changed files with 493 additions and 564 deletions
+112 -126
View File
@@ -12,24 +12,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::time::Duration;
use egui::{Align, CornerRadius, Id, Layout, Margin, RichText, ScrollArea, StrokeKind};
use egui::scroll_area::ScrollBarVisibility;
use egui::{Align, CornerRadius, Id, Layout, Margin, RichText, ScrollArea, StrokeKind};
use std::time::Duration;
use crate::AppConfig;
use crate::gui::Colors;
use crate::gui::icons::{ARROW_LEFT, CARET_RIGHT, COMPUTER_TOWER, FOLDER_OPEN, FOLDER_PLUS, GEAR, GLOBE, GLOBE_SIMPLE, LOCK_KEY, PLUS, SIDEBAR_SIMPLE, SUITCASE};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, Content, TitlePanel, View};
use crate::gui::views::settings::SettingsContent;
use crate::gui::views::types::{ModalContainer, ModalPosition, LinePosition, TitleContentType, TitleType};
use crate::gui::views::wallets::creation::WalletCreation;
use crate::gui::views::types::{ContentContainer, LinePosition, ModalPosition, TitleContentType, TitleType};
use crate::gui::views::wallets::creation::WalletCreationContent;
use crate::gui::views::wallets::modals::{AddWalletModal, OpenWalletModal, WalletConnectionModal, WalletsModal};
use crate::gui::views::wallets::types::WalletTabType;
use crate::gui::views::wallets::wallet::types::wallet_status_text;
use crate::gui::views::wallets::WalletContent;
use crate::wallet::{ExternalConnection, Wallet, WalletList};
use crate::gui::views::{Content, Modal, TitlePanel, View};
use crate::gui::Colors;
use crate::wallet::types::ConnectionMethod;
use crate::wallet::{ExternalConnection, Wallet, WalletList};
use crate::AppConfig;
/// Wallets content.
pub struct WalletsContent {
@@ -37,27 +37,21 @@ pub struct WalletsContent {
wallets: WalletList,
/// Initial wallet creation [`Modal`] content.
add_wallet_modal_content: Option<AddWalletModal>,
add_wallet_modal_content: AddWalletModal,
/// Wallet opening [`Modal`] content.
open_wallet_content: Option<OpenWalletModal>,
/// Wallet connection selection content.
conn_selection_content: Option<WalletConnectionModal>,
open_wallet_content: OpenWalletModal,
/// Wallet connection selection [`Modal`] content.
conn_selection_content: WalletConnectionModal,
/// Wallet selection [`Modal`] content.
wallet_selection_content: Option<WalletsModal>,
wallet_selection_content: WalletsModal,
/// Selected [`Wallet`] content.
wallet_content: Option<WalletContent>,
/// Wallet creation content.
creation_content: Option<WalletCreation>,
creation_content: Option<WalletCreationContent>,
/// Settings content.
settings_content: Option<SettingsContent>,
/// Flag to show [`Wallet`] list at dual panel mode.
show_wallets_at_dual_panel: bool,
/// [`Modal`] identifiers allowed at this ui container.
modal_ids: Vec<&'static str>
}
const ADD_WALLET_MODAL: &'static str = "wallets_add_modal";
@@ -69,97 +63,121 @@ impl Default for WalletsContent {
fn default() -> Self {
Self {
wallets: WalletList::default(),
wallet_selection_content: None,
open_wallet_content: None,
conn_selection_content: None,
wallet_selection_content: WalletsModal::new(None, None, true),
open_wallet_content: OpenWalletModal::new(None),
add_wallet_modal_content: AddWalletModal::default(),
conn_selection_content: WalletConnectionModal::new(ConnectionMethod::Integrated),
wallet_content: None,
creation_content: None,
settings_content: None,
show_wallets_at_dual_panel: AppConfig::show_wallets_at_dual_panel(),
modal_ids: vec![
ADD_WALLET_MODAL,
OPEN_WALLET_MODAL,
SELECT_CONNECTION_MODAL,
SELECT_WALLET_MODAL,
],
add_wallet_modal_content: None,
}
}
}
impl ModalContainer for WalletsContent {
fn modal_ids(&self) -> &Vec<&'static str> {
&self.modal_ids
impl ContentContainer for WalletsContent {
fn modal_ids(&self) -> Vec<&'static str> {
vec![
ADD_WALLET_MODAL,
OPEN_WALLET_MODAL,
SELECT_CONNECTION_MODAL,
SELECT_WALLET_MODAL,
]
}
fn modal_ui(&mut self,
ui: &mut egui::Ui,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
fn modal_ui(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) {
match modal.id {
ADD_WALLET_MODAL => {
if let Some(content) = self.add_wallet_modal_content.as_mut() {
content.ui(ui, modal, cb, |name, pass| {
self.creation_content = Some(
WalletCreation::new(name.clone(), pass.clone())
);
});
}
if self.creating_wallet() {
self.add_wallet_modal_content = None;
}
self.add_wallet_modal_content.ui(ui, modal, cb, |name, pass| {
self.creation_content = Some(
WalletCreationContent::new(name.clone(), pass.clone())
);
});
},
OPEN_WALLET_MODAL => {
let mut open = false;
if let Some(open_content) = self.open_wallet_content.as_mut() {
open_content.ui(ui, modal, cb, |wallet, data| {
self.wallet_content = Some(WalletContent::new(wallet, data));
open = true;
});
}
if open {
self.open_wallet_content = None;
}
self.open_wallet_content.ui(ui, modal, cb, |pass, _| {
if let Some(content) = &self.wallet_content {
return match content.wallet.open(pass) {
Ok(_) => true,
Err(_) => false
};
}
true
});
},
SELECT_CONNECTION_MODAL => {
if let Some(content) = self.conn_selection_content.as_mut() {
content.ui(ui, modal, cb, |conn| {
if let Some(wallet_content) = &self.wallet_content {
wallet_content.wallet.update_connection(&conn);
}
});
}
self.conn_selection_content.ui(ui, modal, cb, |conn| {
if let Some(wallet_content) = &self.wallet_content {
wallet_content.wallet.update_connection(&conn);
}
});
}
SELECT_WALLET_MODAL => {
let mut select = false;
if let Some(content) = self.wallet_selection_content.as_mut() {
content.ui(ui, modal, &mut self.wallets, cb, |wallet, data| {
self.wallet_content = Some(WalletContent::new(wallet, data));
select = true;
});
}
if select {
self.wallet_selection_content = None;
}
self.wallet_selection_content.ui(ui, &mut self.wallets, |wallet, data| {
if !wallet.is_open() {
self.open_wallet_content = OpenWalletModal::new(data.clone());
Modal::new(OPEN_WALLET_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.open"))
.show();
}
self.wallet_content = Some(WalletContent::new(wallet, data));
});
}
_ => {}
}
}
fn on_back(&mut self, cb: &dyn PlatformCallbacks) -> bool {
if self.showing_settings() {
// Close settings.
self.settings_content = None;
return false;
} else if self.creating_wallet() {
// Close wallet creation.
let creation = self.creation_content.as_mut().unwrap();
if creation.on_back() {
self.creation_content = None;
}
return false;
} else {
if self.showing_wallet() {
let content = self.wallet_content.as_mut().unwrap();
// Close opened QR code scanner.
if content.qr_scan_content.is_some() {
cb.stop_camera();
content.qr_scan_content = None;
return false;
}
// Close opened wallet.
self.wallet_content = None;
return false;
}
}
true
}
fn container_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
self.content_ui(ui, cb);
}
}
impl WalletsContent {
/// Draw wallets content.
pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
self.current_modal_ui(ui, cb);
fn content_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
if let Some(data) = crate::consume_incoming_data() {
if !data.is_empty() {
self.on_data(ui, Some(data));
}
}
let showing_settings = self.showing_settings();
let creating_wallet = self.creating_wallet();
let showing_wallet = self.showing_wallet() && !creating_wallet && !showing_settings;
let dual_panel = Self::is_dual_panel_mode(ui);
let dual_panel = is_dual_panel_mode(ui);
let content_width = ui.available_width();
let list_hidden = showing_settings || creating_wallet || self.wallets.list().is_empty()
|| (showing_wallet && self.wallet_content.as_ref().unwrap().qr_scan_content.is_some())
|| (dual_panel && showing_wallet && !self.show_wallets_at_dual_panel)
|| (dual_panel && showing_wallet && !AppConfig::show_wallets_at_dual_panel())
|| (!dual_panel && showing_wallet);
// Show title panel.
@@ -262,7 +280,7 @@ impl WalletsContent {
if self.showing_settings() {
if let Some(c) = &mut self.settings_content {
View::max_width_ui(ui, Content::SIDE_PANEL_WIDTH * 1.3, |ui| {
c.ui(ui);
c.ui(ui, cb);
});
}
} else if self.creating_wallet() {
@@ -270,7 +288,7 @@ impl WalletsContent {
let pass = creation.pass.clone();
let mut created = false;
// Show wallet creation content.
creation.ui(ui, cb, |wallet| {
creation.content_ui(ui, cb, |wallet| {
self.wallets.add(wallet.clone());
if let Ok(_) = wallet.open(pass.clone()) {
self.wallet_content = Some(WalletContent::new(wallet, None));
@@ -324,7 +342,7 @@ impl WalletsContent {
}
/// Handle data from deeplink or opened file.
pub fn on_data(&mut self, ui: &mut egui::Ui, data: Option<String>) {
fn on_data(&mut self, ui: &mut egui::Ui, data: Option<String>) {
let wallets_size = self.wallets.list().len();
if wallets_size == 0 {
return;
@@ -348,7 +366,7 @@ impl WalletsContent {
/// Show initial wallet creation [`Modal`].
pub fn show_add_wallet_modal(&mut self) {
self.add_wallet_modal_content = Some(AddWalletModal::default());
self.add_wallet_modal_content = AddWalletModal::default();
Modal::new(ADD_WALLET_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.add"))
@@ -357,50 +375,20 @@ impl WalletsContent {
/// Show wallet selection with provided optional data.
fn show_wallet_selection_modal(&mut self, data: Option<String>) {
self.wallet_selection_content = Some(WalletsModal::new(None, data, true));
self.wallet_selection_content = WalletsModal::new(None, data, true);
Modal::new(SELECT_WALLET_MODAL)
.position(ModalPosition::Center)
.title(t!("network_settings.choose_wallet"))
.show();
}
/// Handle Back key event returning `false` when event was handled.
pub fn on_back(&mut self, cb: &dyn PlatformCallbacks) -> bool {
if self.showing_settings() {
// Close settings.
self.settings_content = None;
return false;
} else if self.creating_wallet() {
// Close wallet creation.
let creation = self.creation_content.as_mut().unwrap();
if creation.on_back() {
self.creation_content = None;
}
return false;
} else {
if self.showing_wallet() {
let content = self.wallet_content.as_mut().unwrap();
// Close opened QR code scanner.
if content.qr_scan_content.is_some() {
cb.stop_camera();
content.qr_scan_content = None;
return false;
}
// Close opened wallet.
self.wallet_content = None;
return false;
}
}
true
}
/// Draw [`TitlePanel`] content.
fn title_ui(&mut self,
ui: &mut egui::Ui,
dual_panel: bool,
show_wallet: bool,
cb: &dyn PlatformCallbacks) {
let show_list = self.show_wallets_at_dual_panel;
let show_list = AppConfig::show_wallets_at_dual_panel();
let showing_settings = self.showing_settings();
let creating_wallet = self.creating_wallet();
let qr_scan = {
@@ -501,7 +489,6 @@ impl WalletsContent {
SUITCASE
};
View::title_button_big(ui, list_icon, |_| {
self.show_wallets_at_dual_panel = !show_list;
AppConfig::toggle_show_wallets_at_dual_panel();
});
}
@@ -586,9 +573,8 @@ impl WalletsContent {
let mut show_selection = false;
View::item_button(ui, CornerRadius::default(), GLOBE, None, || {
self.wallet_content = Some(WalletContent::new(wallet.clone(), None));
self.conn_selection_content = Some(
WalletConnectionModal::new(wallet.get_current_connection())
);
self.conn_selection_content =
WalletConnectionModal::new(wallet.get_current_connection());
// Show connection selection modal.
Modal::new(SELECT_CONNECTION_MODAL)
.position(ModalPosition::CenterTop)
@@ -657,17 +643,17 @@ impl WalletsContent {
/// Show [`Modal`] to select and open wallet.
fn show_opening_modal(&mut self, wallet: Wallet, data: Option<String>) {
self.wallet_content = Some(WalletContent::new(wallet.clone(), None));
self.open_wallet_content = Some(OpenWalletModal::new(wallet, data));
self.open_wallet_content = OpenWalletModal::new(data);
Modal::new(OPEN_WALLET_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.open"))
.show();
}
}
/// Check if it's possible to show [`WalletsContent`] and [`WalletContent`] panels at same time.
fn is_dual_panel_mode(ui: &mut egui::Ui) -> bool {
let dual_panel_root = Content::is_dual_panel_mode(ui.ctx());
let max_width = ui.available_width();
dual_panel_root && max_width >= (Content::SIDE_PANEL_WIDTH * 2.0) + View::get_right_inset()
}
/// Check if it's possible to show [`WalletsContent`] and [`WalletContent`] panels at same time.
fn is_dual_panel_mode(ui: &mut egui::Ui) -> bool {
let dual_panel_root = Content::is_dual_panel_mode(ui.ctx());
let max_width = ui.available_width();
dual_panel_root && max_width >= (Content::SIDE_PANEL_WIDTH * 2.0) + View::get_right_inset()
}
@@ -20,7 +20,7 @@ use crate::gui::Colors;
use crate::gui::icons::{CHECK, CLIPBOARD_TEXT, COPY, SCAN};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, Content, View, CameraScanModal};
use crate::gui::views::types::{LinePosition, ModalContainer, ModalPosition, QrScanResult};
use crate::gui::views::types::{LinePosition, ContentContainer, ModalPosition, QrScanResult};
use crate::gui::views::wallets::creation::MnemonicSetup;
use crate::gui::views::wallets::creation::types::Step;
use crate::gui::views::wallets::ConnectionSettings;
@@ -29,7 +29,7 @@ use crate::wallet::{ExternalConnection, Wallet};
use crate::wallet::types::PhraseMode;
/// Wallet creation content.
pub struct WalletCreation {
pub struct WalletCreationContent {
/// Wallet name.
pub name: String,
/// Wallet password.
@@ -48,16 +48,15 @@ pub struct WalletCreation {
/// Flag to check if an error occurred during wallet creation.
creation_error: Option<String>,
/// [`Modal`] identifiers allowed at this ui container.
modal_ids: Vec<&'static str>
}
const QR_CODE_PHRASE_SCAN_MODAL: &'static str = "qr_code_rec_phrase_scan_modal";
impl ModalContainer for WalletCreation {
fn modal_ids(&self) -> &Vec<&'static str> {
&self.modal_ids
impl ContentContainer for WalletCreationContent {
fn modal_ids(&self) -> Vec<&'static str> {
vec![
QR_CODE_PHRASE_SCAN_MODAL
]
}
fn modal_ui(&mut self,
@@ -86,10 +85,16 @@ impl ModalContainer for WalletCreation {
_ => {}
}
}
fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool {
true
}
fn container_ui(&mut self, _: &mut egui::Ui, _: &dyn PlatformCallbacks) {}
}
impl WalletCreation {
/// Create new wallet creation instance from name and password.
impl WalletCreationContent {
/// Create new wallet creation content from name and password.
pub fn new(name: String, pass: ZeroingString) -> Self {
Self {
name,
@@ -99,19 +104,15 @@ impl WalletCreation {
mnemonic_setup: MnemonicSetup::default(),
network_setup: ConnectionSettings::default(),
creation_error: None,
modal_ids: vec![
QR_CODE_PHRASE_SCAN_MODAL
],
}
}
/// Draw wallet creation content.
pub fn ui(&mut self,
ui: &mut egui::Ui,
cb: &dyn PlatformCallbacks,
on_create: impl FnMut(Wallet)) {
self.current_modal_ui(ui, cb);
pub fn content_ui(&mut self,
ui: &mut egui::Ui,
cb: &dyn PlatformCallbacks,
on_create: impl FnMut(Wallet)) {
self.ui(ui, cb);
egui::TopBottomPanel::bottom("wallet_creation_step_panel")
.frame(egui::Frame {
inner_margin: Margin {
@@ -350,14 +351,14 @@ impl WalletCreation {
/// Draw wallet creation [`Step`] content.
fn step_content_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
match &self.step {
Step::EnterMnemonic => self.mnemonic_setup.ui(ui, cb),
Step::EnterMnemonic => self.mnemonic_setup.import_ui(ui, cb),
Step::ConfirmMnemonic => self.mnemonic_setup.confirm_ui(ui, cb),
Step::SetupConnection => {
// Redraw if node is running.
if Node::is_running() && !Content::is_dual_panel_mode(ui.ctx()) {
ui.ctx().request_repaint_after(Node::STATS_UPDATE_DELAY);
}
self.network_setup.create_ui(ui, cb)
self.network_setup.content_ui(ui, cb);
}
}
}
+16 -19
View File
@@ -18,7 +18,7 @@ use crate::gui::Colors;
use crate::gui::icons::PENCIL;
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, Content, View, TextEdit};
use crate::gui::views::types::{ModalContainer, ModalPosition};
use crate::gui::views::types::{ContentContainer, ModalPosition};
use crate::wallet::Mnemonic;
use crate::wallet::types::{PhraseMode, PhraseSize, PhraseWord};
@@ -33,9 +33,6 @@ pub struct MnemonicSetup {
word_edit: String,
/// Flag to check if entered word is valid at [`Modal`].
valid_word_edit: bool,
/// [`Modal`] identifiers allowed at this ui container.
modal_ids: Vec<&'static str>
}
/// Identifier for word input [`Modal`].
@@ -48,16 +45,15 @@ impl Default for MnemonicSetup {
word_index_edit: 0,
word_edit: String::from(""),
valid_word_edit: true,
modal_ids: vec![
WORD_INPUT_MODAL
]
}
}
}
impl ModalContainer for MnemonicSetup {
fn modal_ids(&self) -> &Vec<&'static str> {
&self.modal_ids
impl ContentContainer for MnemonicSetup {
fn modal_ids(&self) -> Vec<&'static str> {
vec![
WORD_INPUT_MODAL
]
}
fn modal_ui(&mut self,
@@ -69,14 +65,19 @@ impl ModalContainer for MnemonicSetup {
_ => {}
}
}
fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool {
true
}
fn container_ui(&mut self, ui: &mut egui::Ui, _: &dyn PlatformCallbacks) {
}
}
impl MnemonicSetup {
/// Draw content for phrase input step.
pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
// Draw modal content for current ui container.
self.current_modal_ui(ui, cb);
/// Draw content for phrase import step.
pub fn import_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
ui.add_space(10.0);
// Show mode and type setup.
@@ -89,12 +90,8 @@ impl MnemonicSetup {
// Show words setup.
self.word_list_ui(ui, self.mnemonic.mode() == PhraseMode::Import);
}
/// Draw content for phrase confirmation step.
pub fn confirm_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
// Draw modal content for current ui container.
self.current_modal_ui(ui, cb);
ui.add_space(4.0);
ui.vertical_centered(|ui| {
let text = format!("{}:", t!("wallets.recovery_phrase"));
+2 -2
View File
@@ -15,7 +15,7 @@
mod mnemonic;
pub use mnemonic::MnemonicSetup;
mod creation;
pub use creation::WalletCreation;
mod content;
pub use content::WalletCreationContent;
pub mod types;
+6 -14
View File
@@ -18,13 +18,9 @@ use grin_util::ZeroingString;
use crate::gui::Colors;
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, TextEdit, View};
use crate::wallet::Wallet;
/// Wallet opening [`Modal`] content.
pub struct OpenWalletModal {
/// Wallet to open.
wallet: Wallet,
/// Password to open wallet.
pass_edit: String,
/// Flag to check if wrong password was entered.
@@ -36,9 +32,8 @@ pub struct OpenWalletModal {
impl OpenWalletModal {
/// Create new content instance.
pub fn new(wallet: Wallet, data: Option<String>) -> Self {
pub fn new(data: Option<String>) -> Self {
Self {
wallet,
pass_edit: "".to_string(),
wrong_pass: false,
data,
@@ -49,20 +44,17 @@ impl OpenWalletModal {
ui: &mut egui::Ui,
modal: &Modal,
cb: &dyn PlatformCallbacks,
mut on_continue: impl FnMut(Wallet, Option<String>)) {
mut on_continue: impl FnMut(ZeroingString, &Option<String>) -> bool) {
// Callback for button to continue.
let mut on_continue = |m: &mut OpenWalletModal| {
let pass = m.pass_edit.clone();
if pass.is_empty() {
return;
}
match m.wallet.open(ZeroingString::from(pass)) {
Ok(_) => {
m.pass_edit = "".to_string();
Modal::close();
on_continue(m.wallet.clone(), m.data.clone());
}
Err(_) => m.wrong_pass = true
m.wrong_pass = !on_continue(ZeroingString::from(pass), &m.data);
if !m.wrong_pass {
m.pass_edit = "".to_string();
Modal::close();
}
};
+5 -28
View File
@@ -15,15 +15,12 @@
use egui::scroll_area::ScrollBarVisibility;
use egui::{Align, Layout, RichText, ScrollArea, StrokeKind};
use crate::gui::Colors;
use crate::gui::icons::{CHECK, CHECK_FAT, COMPUTER_TOWER, FOLDER_OPEN, GLOBE_SIMPLE, PLUGS_CONNECTED};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, View};
use crate::gui::views::types::ModalPosition;
use crate::gui::views::wallets::modals::OpenWalletModal;
use crate::gui::views::wallets::wallet::types::wallet_status_text;
use crate::wallet::{Wallet, WalletList};
use crate::gui::views::{Modal, View};
use crate::gui::Colors;
use crate::wallet::types::ConnectionMethod;
use crate::wallet::{Wallet, WalletList};
/// Wallet list [`Modal`] content
pub struct WalletsModal {
@@ -35,32 +32,19 @@ pub struct WalletsModal {
/// Flag to check if wallet can be opened from the list.
can_open: bool,
/// Wallet opening content.
open_wallet_content: Option<OpenWalletModal>,
}
impl WalletsModal {
/// Create new content instance.
pub fn new(selected_id: Option<i64>, data: Option<String>, can_open: bool) -> Self {
Self { selected_id, data, can_open, open_wallet_content: None }
Self { selected_id, data, can_open }
}
/// Draw content.
pub fn ui(&mut self,
ui: &mut egui::Ui,
modal: &Modal,
wallets: &WalletList,
cb: &dyn PlatformCallbacks,
mut on_select: impl FnMut(Wallet, Option<String>)) {
// Draw wallet opening modal content.
if let Some(open_content) = self.open_wallet_content.as_mut() {
open_content.ui(ui, modal, cb, |wallet, data| {
on_select(wallet, data);
self.data = None;
});
return;
}
ui.add_space(4.0);
ScrollArea::vertical()
.max_height(373.0)
@@ -123,14 +107,7 @@ impl WalletsModal {
FOLDER_OPEN
};
View::item_button(ui, View::item_rounding(0, 1, true), icon, None, || {
if wallet.is_open() {
on_select();
} else {
Modal::change_position(ModalPosition::CenterTop);
self.open_wallet_content = Some(
OpenWalletModal::new(wallet.clone(), self.data.clone())
);
}
on_select();
});
} else {
// Draw button to select wallet.
+17 -21
View File
@@ -23,7 +23,7 @@ use crate::gui::Colors;
use crate::gui::icons::{ARROWS_CLOCKWISE, BRIDGE, CAMERA_ROTATE, CHAT_CIRCLE_TEXT, FOLDER_USER, GEAR_FINE, GRAPH, PACKAGE, POWER, SCAN, SPINNER, USERS_THREE};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, Content, View, CameraContent};
use crate::gui::views::types::{LinePosition, ModalContainer, ModalPosition, QrScanResult};
use crate::gui::views::types::{LinePosition, ContentContainer, ModalPosition, QrScanResult};
use crate::gui::views::wallets::{WalletTransactions, WalletMessages, WalletTransport};
use crate::gui::views::wallets::types::{GRIN, WalletTab, WalletTabType};
use crate::gui::views::wallets::wallet::modals::WalletAccountsModal;
@@ -40,48 +40,47 @@ pub struct WalletContent {
pub current_tab: Box<dyn WalletTab>,
/// Wallet accounts [`Modal`] content.
accounts_modal_content: Option<WalletAccountsModal>,
accounts_modal_content: WalletAccountsModal,
/// QR code scan content.
pub qr_scan_content: Option<CameraContent>,
/// List of allowed [`Modal`] ids for this [`ModalContainer`].
allowed_modal_ids: Vec<&'static str>
}
/// Identifier for account list [`Modal`].
const ACCOUNT_LIST_MODAL: &'static str = "account_list_modal";
impl ModalContainer for WalletContent {
fn modal_ids(&self) -> &Vec<&'static str> {
&self.allowed_modal_ids
impl ContentContainer for WalletContent {
fn modal_ids(&self) -> Vec<&'static str> {
vec![
ACCOUNT_LIST_MODAL,
]
}
fn modal_ui(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) {
match modal.id {
ACCOUNT_LIST_MODAL => {
if let Some(content) = self.accounts_modal_content.as_mut() {
Modal::ui(ui.ctx(), |ui, modal| {
content.ui(ui, &self.wallet, modal, cb);
});
}
self.accounts_modal_content.ui(ui, &self.wallet, modal, cb);
}
_ => {}
}
}
fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool {
true
}
fn container_ui(&mut self, _: &mut egui::Ui, _: &dyn PlatformCallbacks) {}
}
impl WalletContent {
/// Create new instance with optional data.
pub fn new(wallet: Wallet, data: Option<String>) -> Self {
let accounts_modal = WalletAccountsModal::new(wallet.accounts());
let mut content = Self {
wallet,
accounts_modal_content: None,
accounts_modal_content: accounts_modal,
qr_scan_content: None,
current_tab: Box::new(WalletTransactions::default()),
allowed_modal_ids: vec![
ACCOUNT_LIST_MODAL,
],
};
if data.is_some() {
content.on_data(data);
@@ -97,7 +96,6 @@ impl WalletContent {
/// Draw wallet content.
pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
ui.ctx().request_repaint_after(Duration::from_millis(1000));
self.current_modal_ui(ui, cb);
let dual_panel = Content::is_dual_panel_mode(ui.ctx());
let show_wallets_dual = AppConfig::show_wallets_at_dual_panel();
@@ -302,9 +300,7 @@ impl WalletContent {
// Draw button to show list of accounts.
View::item_button(ui, View::item_rounding(1, 3, true), USERS_THREE, None, || {
self.accounts_modal_content = Some(
WalletAccountsModal::new(self.wallet.accounts())
);
self.accounts_modal_content = WalletAccountsModal::new(self.wallet.accounts());
Modal::new(ACCOUNT_LIST_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.accounts"))
@@ -37,10 +37,10 @@ pub struct WalletMessages {
first_draw: bool,
/// Invoice or sending request creation [`Modal`] content.
request_modal_content: Option<MessageRequestModal>,
request_modal_content: MessageRequestModal,
/// Wallet transaction [`Modal`] content.
tx_info_content: Option<WalletTransactionModal>,
tx_info_content: WalletTransactionModal,
/// Slatepacks message input text.
message_edit: String,
@@ -85,8 +85,8 @@ impl WalletMessages {
message_loading: false,
message_error: "".to_string(),
message_result: Arc::new(Default::default()),
tx_info_content: None,
request_modal_content: None,
tx_info_content: WalletTransactionModal::new(None, false),
request_modal_content: MessageRequestModal::new(false),
file_pick_button: FilePickButton::default(),
scan_modal_content: None,
}
@@ -129,23 +129,19 @@ impl WalletMessages {
Some(id) => {
match id {
REQUEST_MODAL => {
if let Some(content) = self.request_modal_content.as_mut() {
Modal::ui(ui.ctx(), |ui, modal| {
content.ui(ui, wallet, modal, cb);
});
}
Modal::ui(ui.ctx(), cb, |ui, modal, cb| {
self.request_modal_content.ui(ui, wallet, modal, cb);
});
}
TX_INFO_MODAL => {
if let Some(content) = self.tx_info_content.as_mut() {
Modal::ui(ui.ctx(), |ui, modal| {
content.ui(ui, wallet, modal, cb);
});
}
Modal::ui(ui.ctx(), cb, |ui, modal, cb| {
self.tx_info_content.ui(ui, wallet, modal, cb);
});
}
SCAN_QR_MODAL => {
let mut result = None;
if let Some(content) = self.scan_modal_content.as_mut() {
Modal::ui(ui.ctx(), |ui, _| {
Modal::ui(ui.ctx(), cb, |ui, _, cb| {
content.ui(ui, cb, |res| {
result = Some(res.clone());
Modal::close();
@@ -217,7 +213,7 @@ impl WalletMessages {
/// Show [`Modal`] to create invoice or sending request.
fn show_request_modal(&mut self, invoice: bool) {
self.request_modal_content = Some(MessageRequestModal::new(invoice));
self.request_modal_content = MessageRequestModal::new(invoice);
let title = if invoice {
t!("wallets.receive")
} else {
@@ -299,7 +295,7 @@ impl WalletMessages {
Ok(tx) => {
self.message_edit.clear();
// Show transaction modal on success.
self.tx_info_content = Some(WalletTransactionModal::new(wallet, tx, false));
self.tx_info_content = WalletTransactionModal::new(Some(tx.data.id), false);
Modal::new(TX_INFO_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.tx"))
@@ -322,9 +318,8 @@ impl WalletMessages {
// Show tx modal or show default error message.
if let Some(tx) = wallet.tx_by_slate(&slate).as_ref() {
self.message_edit.clear();
self.tx_info_content = Some(
WalletTransactionModal::new(wallet, tx, false)
);
self.tx_info_content =
WalletTransactionModal::new(Some(tx.data.id), false);
Modal::new(TX_INFO_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.tx"))
@@ -427,7 +422,7 @@ impl WalletMessages {
if exists {
if let Some(tx) = wallet.tx_by_slate(&slate).as_ref() {
self.message_edit.clear();
self.tx_info_content = Some(WalletTransactionModal::new(wallet, tx, false));
self.tx_info_content = WalletTransactionModal::new(Some(tx.data.id), false);
Modal::new(TX_INFO_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.tx"))
@@ -229,7 +229,8 @@ impl MessageRequestModal {
let result = r_request.as_ref().unwrap();
match result {
Ok(tx) => {
self.result_tx_content = Some(WalletTransactionModal::new(wallet, tx, false));
self.result_tx_content =
Some(WalletTransactionModal::new(Some(tx.data.id), false));
}
Err(err) => {
match err {
@@ -146,17 +146,17 @@ impl CommonSettings {
Some(id) => {
match id {
NAME_EDIT_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
Modal::ui(ui.ctx(), cb, |ui, modal, cb| {
self.name_modal_ui(ui, wallet, modal, cb);
});
}
PASS_EDIT_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
Modal::ui(ui.ctx(), cb, |ui, modal, cb| {
self.pass_modal_ui(ui, wallet, modal, cb);
});
}
MIN_CONFIRMATIONS_EDIT_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
Modal::ui(ui.ctx(), cb, |ui, modal, cb| {
self.min_conf_modal_ui(ui, wallet, modal, cb);
});
}
@@ -20,7 +20,7 @@ use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, View};
use crate::gui::views::network::ConnectionsContent;
use crate::gui::views::network::modals::ExternalConnectionModal;
use crate::gui::views::types::{ModalContainer, ModalPosition};
use crate::gui::views::types::{ContentContainer, ModalPosition};
use crate::wallet::{ConnectionsConfig, ExternalConnection, Wallet};
use crate::wallet::types::ConnectionMethod;
@@ -31,9 +31,6 @@ pub struct ConnectionSettings {
/// External connection [`Modal`] content.
ext_conn_modal: ExternalConnectionModal,
/// [`Modal`] identifiers allowed at this ui container.
modal_ids: Vec<&'static str>
}
impl Default for ConnectionSettings {
@@ -41,16 +38,15 @@ impl Default for ConnectionSettings {
Self {
method: ConnectionMethod::Integrated,
ext_conn_modal: ExternalConnectionModal::new(None),
modal_ids: vec![
ExternalConnectionModal::WALLET_ID
]
}
}
}
impl ModalContainer for ConnectionSettings {
fn modal_ids(&self) -> &Vec<&'static str> {
&self.modal_ids
impl ContentContainer for ConnectionSettings {
fn modal_ids(&self) -> Vec<&'static str> {
vec![
ExternalConnectionModal::WALLET_ID
]
}
fn modal_ui(&mut self,
@@ -64,20 +60,21 @@ impl ModalContainer for ConnectionSettings {
_ => {}
}
}
fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool {
true
}
fn container_ui(&mut self, _: &mut egui::Ui, _: &dyn PlatformCallbacks) {}
}
impl ConnectionSettings {
/// Draw wallet creation setup content.
pub fn create_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
self.ui(ui, cb);
}
/// Draw existing wallet connection setup content.
pub fn wallet_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
self.method = wallet.get_current_connection();
// Draw setup content.
let changed = self.ui(ui, cb);
let changed = self.content_ui(ui, cb);
if changed {
wallet.update_connection(&self.method);
@@ -90,10 +87,9 @@ impl ConnectionSettings {
}
/// Draw connection setup content, returning `true` if connection was changed.
fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) -> bool {
pub fn content_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) -> bool {
self.ui(ui, cb);
let mut changed = false;
// Draw modal content for current ui container.
self.current_modal_ui(ui, cb);
ui.add_space(2.0);
View::sub_title(ui, format!("{} {}", GLOBE, t!("wallets.conn_method")));
@@ -148,12 +148,12 @@ impl RecoverySettings {
Some(id) => {
match id {
RECOVERY_PHRASE_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
Modal::ui(ui.ctx(), cb, |ui, modal, cb| {
self.recovery_phrase_modal_ui(ui, wallet, modal, cb);
});
}
DELETE_CONFIRMATION_MODAL => {
Modal::ui(ui.ctx(), |ui, _| {
Modal::ui(ui.ctx(), cb, |ui, _, _| {
self.deletion_modal_ui(ui, wallet);
});
}
@@ -96,20 +96,20 @@ impl WalletTransport {
match id {
SEND_TOR_MODAL => {
if let Some(content) = self.send_modal_content.as_mut() {
Modal::ui(ui.ctx(), |ui, modal| {
Modal::ui(ui.ctx(), cb, |ui, modal, cb| {
content.ui(ui, wallet, modal, cb);
});
}
}
TOR_SETTINGS_MODAL => {
if let Some(content) = self.settings_modal_content.as_mut() {
Modal::ui(ui.ctx(), |ui, modal| {
Modal::ui(ui.ctx(), cb, |ui, modal, cb| {
content.ui(ui, wallet, modal, cb);
});
}
}
QR_ADDRESS_MODAL => {
Modal::ui(ui.ctx(), |ui, _| {
Modal::ui(ui.ctx(), cb, |ui, _, cb| {
self.qr_address_modal_ui(ui, cb);
});
}
@@ -342,7 +342,7 @@ impl TransportSendModal {
match res {
Ok(tx) => {
self.tx_info_content =
Some(WalletTransactionModal::new(wallet, &tx, false));
Some(WalletTransactionModal::new(Some(tx.data.id), false));
}
Err(_) => {
self.error = true;
+6 -6
View File
@@ -165,7 +165,7 @@ impl WalletTransactions {
r.nw = 0.0 as u8;
r.sw = 0.0 as u8;
View::item_button(ui, r, FILE_TEXT, None, || {
self.show_tx_info_modal(wallet, tx, false);
self.show_tx_info_modal(tx, false);
});
}
@@ -175,7 +175,7 @@ impl WalletTransactions {
if wallet_loaded && tx.can_finalize {
let (icon, color) = (CHECK, Some(Colors::green()));
View::item_button(ui, CornerRadius::default(), icon, color, || {
self.show_tx_info_modal(wallet, tx, true);
self.show_tx_info_modal(tx, true);
});
}
@@ -246,14 +246,14 @@ impl WalletTransactions {
Some(id) => {
match id {
TX_INFO_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
Modal::ui(ui.ctx(), cb, |ui, modal, cb| {
if let Some(content) = self.tx_info_content.as_mut() {
content.ui(ui, wallet, modal, cb);
}
});
}
CANCEL_TX_CONFIRMATION_MODAL => {
Modal::ui(ui.ctx(), |ui, _| {
Modal::ui(ui.ctx(), cb, |ui, _, cb| {
self.cancel_confirmation_modal(ui, wallet);
});
}
@@ -453,8 +453,8 @@ impl WalletTransactions {
}
/// Show transaction information [`Modal`].
fn show_tx_info_modal(&mut self, wallet: &Wallet, tx: &WalletTransaction, finalize: bool) {
let modal = WalletTransactionModal::new(wallet, tx, finalize);
fn show_tx_info_modal(&mut self, tx: &WalletTransaction, finalize: bool) {
let modal = WalletTransactionModal::new(Some(tx.data.id), finalize);
self.tx_info_content = Some(modal);
Modal::new(TX_INFO_MODAL)
.position(ModalPosition::CenterTop)
+39 -32
View File
@@ -36,7 +36,7 @@ pub struct WalletTransactionModal {
tx_id: u32,
/// Response Slatepack message input value.
response_edit: String,
response_edit: Option<String>,
/// Flag to show transaction finalization input.
show_finalization: bool,
@@ -61,32 +61,10 @@ pub struct WalletTransactionModal {
impl WalletTransactionModal {
/// Create new content instance with [`Wallet`] from provided [`WalletTransaction`].
pub fn new(wallet: &Wallet, tx: &WalletTransaction, show_finalization: bool) -> Self {
pub fn new(tx_id: Option<u32>, show_finalization: bool) -> Self {
Self {
tx_id: tx.data.id,
response_edit: if !tx.cancelling && !tx.finalizing && !tx.data.confirmed &&
tx.data.tx_slate_id.is_some() &&
(tx.data.tx_type == TxLogEntryType::TxSent ||
tx.data.tx_type == TxLogEntryType::TxReceived) {
let mut slate = Slate::blank(1, false);
slate.state = if tx.can_finalize {
if tx.data.tx_type == TxLogEntryType::TxSent {
SlateState::Standard1
} else {
SlateState::Invoice1
}
} else {
if tx.data.tx_type == TxLogEntryType::TxReceived {
SlateState::Standard2
} else {
SlateState::Invoice2
}
};
slate.id = tx.data.tx_slate_id.unwrap();
wallet.read_slatepack(&slate).unwrap_or("".to_string())
} else {
"".to_string()
},
tx_id: tx_id.unwrap(),
response_edit: None,
finalize_edit: "".to_string(),
finalize_error: false,
show_finalization,
@@ -121,13 +99,42 @@ impl WalletTransactionModal {
}
let tx = txs.get(0).unwrap();
// Check if response was loaded.
if self.response_edit.is_none() {
self.response_edit = Some(
if !tx.cancelling && !tx.finalizing && !tx.data.confirmed &&
tx.data.tx_slate_id.is_some() &&
(tx.data.tx_type == TxLogEntryType::TxSent ||
tx.data.tx_type == TxLogEntryType::TxReceived) {
let mut slate = Slate::blank(1, false);
slate.state = if tx.can_finalize {
if tx.data.tx_type == TxLogEntryType::TxSent {
SlateState::Standard1
} else {
SlateState::Invoice1
}
} else {
if tx.data.tx_type == TxLogEntryType::TxReceived {
SlateState::Standard2
} else {
SlateState::Invoice2
}
};
slate.id = tx.data.tx_slate_id.unwrap();
wallet.read_slatepack(&slate).unwrap_or("".to_string())
} else {
"".to_string()
}
);
}
// Show transaction information.
if self.qr_code_content.is_none() && self.scan_qr_content.is_none() {
self.info_ui(ui, tx, wallet, cb);
}
// Show Slatepack message interaction.
if !self.response_edit.is_empty() {
if !self.response_edit.as_ref().unwrap().is_empty() {
self.message_ui(ui, tx, wallet, modal, cb);
}
@@ -201,7 +208,7 @@ impl WalletTransactionModal {
if let Ok(_) = res {
self.show_finalization = false;
self.finalize_edit = "".to_string();
self.response_edit = "".to_string();
self.response_edit = Some("".to_string());
} else {
self.finalize_error = true;
}
@@ -370,7 +377,7 @@ impl WalletTransactionModal {
let message_edit = if self.show_finalization {
&mut self.finalize_edit
} else {
&mut self.response_edit
&mut self.response_edit.as_mut().unwrap()
};
let message_before = message_edit.clone();
@@ -471,14 +478,14 @@ impl WalletTransactionModal {
let qr_text = format!("{} {}", QR_CODE, t!("qr_code"));
View::button(ui, qr_text.clone(), Colors::white_or_black(false), || {
let text = self.response_edit.clone();
self.qr_code_content = Some(QrCodeContent::new(text, true));
self.qr_code_content = Some(QrCodeContent::new(text.unwrap(), true));
});
});
columns[1].vertical_centered_justified(|ui| {
// Draw copy button.
let copy_text = format!("{} {}", COPY, t!("copy"));
View::button(ui, copy_text, Colors::white_or_black(false), || {
cb.copy_string_to_buffer(self.response_edit.clone());
cb.copy_string_to_buffer(self.response_edit.clone().unwrap());
self.finalize_edit = "".to_string();
if tx.can_finalize {
self.show_finalization = true;
@@ -499,7 +506,7 @@ impl WalletTransactionModal {
Colors::white_or_black(false), || {
if let Some((s, _)) = wallet.read_slate_by_tx(tx) {
let name = format!("{}.{}.slatepack", s.id, s.state);
let data = self.response_edit.as_bytes().to_vec();
let data = self.response_edit.as_ref().unwrap().as_bytes().to_vec();
cb.share_data(name, data).unwrap_or_default();
}
});