wallets: fix wallet mutability, wallet connection change, optimize wallet lists for different chain types

This commit is contained in:
ardocrat
2023-08-11 17:29:25 +03:00
parent 3635b7abe6
commit d466cb1d9c
10 changed files with 133 additions and 60 deletions
+17 -12
View File
@@ -14,6 +14,7 @@
use egui::{Align, Align2, Layout, Margin, RichText, Rounding, ScrollArea, TextStyle, Widget};
use egui_extras::{Size, StripBuilder};
use grin_core::global::ChainTypes;
use crate::AppConfig;
use crate::gui::Colors;
@@ -95,10 +96,8 @@ impl WalletsContent {
// Draw modal content for current ui container.
self.current_modal_ui(ui, frame, cb);
let wallets = self.wallets.list();
let empty_list = wallets.is_empty();
// Setup wallet content flags.
let empty_list = self.wallets.is_current_list_empty();
let create_wallet = self.creation_content.can_go_back();
let show_wallet = self.wallets.is_selected_open();
@@ -140,9 +139,15 @@ impl WalletsContent {
self.wallets.add(wallet);
});
} else {
for mut wallet in wallets.clone() {
let chain_type = AppConfig::chain_type();
let list = if chain_type == ChainTypes::Mainnet {
&mut self.wallets.main_list
} else {
&mut self.wallets.test_list
};
for wallet in list.iter_mut() {
// Show content for selected wallet.
if self.wallets.is_selected(wallet.config.id) {
if self.wallets.selected_id == Some(wallet.config.id) {
// Setup wallet content width.
let mut rect = ui.available_rect_before_wrap();
let mut width = ui.available_width();
@@ -152,7 +157,7 @@ impl WalletsContent {
rect.set_width(width);
// Show wallet content.
ui.allocate_ui_at_rect(rect, |ui| {
self.wallet_content.ui(ui, frame, &mut wallet, cb);
self.wallet_content.ui(ui, frame, wallet, cb);
});
break;
}
@@ -201,7 +206,7 @@ impl WalletsContent {
// Show list of wallets.
let scroll =
self.wallet_list_ui(ui, wallets, dual_panel, show_creation_button, cb);
self.wallet_list_ui(ui, dual_panel, show_creation_button, cb);
if show_creation_button {
// Setup right margin for button.
@@ -296,7 +301,6 @@ impl WalletsContent {
/// Draw list of wallets. Returns `true` if scroller is showing.
fn wallet_list_ui(&mut self,
ui: &mut egui::Ui,
wallets: Vec<Wallet>,
dual_panel: bool,
show_creation_btn: bool,
cb: &dyn PlatformCallbacks) -> bool {
@@ -324,9 +328,10 @@ impl WalletsContent {
rect.set_width(width);
ui.allocate_ui(rect.size(), |ui| {
for mut wallet in wallets {
let list = self.wallets.list().clone();
for wallet in &list {
// Draw wallet list item.
self.wallet_item_ui(ui, &mut wallet, cb);
self.wallet_item_ui(ui, wallet, cb);
ui.add_space(5.0);
}
// Add space for wallet creation button.
@@ -345,10 +350,10 @@ impl WalletsContent {
/// Draw wallet list item.
fn wallet_item_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
let id = wallet.config.id;
let is_selected = self.wallets.is_selected(id);
let is_selected = self.wallets.selected_id == Some(id);
let is_current = wallet.is_open() && is_selected;
// Draw round background.
+45 -6
View File
@@ -20,7 +20,7 @@ use crate::gui::icons::{GLOBE, GLOBE_SIMPLE};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, View};
use crate::gui::views::types::{ModalContainer, ModalPosition};
use crate::wallet::{ConnectionsConfig, ExternalConnection};
use crate::wallet::{ConnectionsConfig, ExternalConnection, Wallet};
use crate::wallet::types::ConnectionMethod;
/// Wallet node connection method setup content.
@@ -77,12 +77,51 @@ impl ModalContainer for ConnectionSetup {
}
impl ConnectionSetup {
//TODO: Setup for provided wallet
// pub fn new() -> Self {
// Self { method: ConnectionMethod::Integrated }
// }
/// Draw wallet creation setup content.
pub fn create_ui(&mut self,
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
cb: &dyn PlatformCallbacks) {
self.ui(ui, frame, cb);
}
pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
/// Draw existing wallet connection setup content.
pub fn wallet_ui(&mut self,
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
// Setup connection value from provided wallet.
match wallet.config.ext_conn_id {
None => self.method = ConnectionMethod::Integrated,
Some(id) => self.method = ConnectionMethod::External(id)
}
// Draw setup content.
self.ui(ui, frame, cb);
// Setup wallet connection value after change.
match self.method {
ConnectionMethod::Integrated => {
if wallet.config.ext_conn_id.is_some() {
wallet.config.ext_conn_id = None;
wallet.config.save();
}
}
ConnectionMethod::External(id) => {
if wallet.config.ext_conn_id != Some(id) {
wallet.config.ext_conn_id = Some(id);
wallet.config.save();
}
}
}
}
/// Draw connection setup content.
fn ui(&mut self,
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
cb: &dyn PlatformCallbacks) {
// Draw modal content for current ui container.
self.current_modal_ui(ui, frame, cb);
+8 -6
View File
@@ -60,11 +60,12 @@ impl WalletContent {
.show_inside(ui, |ui| {
ui.vertical_centered(|ui| {
// Setup tabs width.
let mut rect = ui.available_rect_before_wrap();
let mut width = f32::min(ui.available_width(), Root::SIDE_PANEL_WIDTH * 2.0);
if width == 0.0 {
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 * 2.0);
rect.set_width(width);
// Draw wallet tabs.
@@ -90,11 +91,12 @@ impl WalletContent {
.show_inside(ui, |ui| {
ui.vertical_centered(|ui| {
// Setup tab content width.
let mut rect = ui.available_rect_before_wrap();
let mut width = f32::min(ui.available_width(), Root::SIDE_PANEL_WIDTH * 2.0);
if width == 0.0 {
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 * 2.0);
rect.set_width(width);
// Draw current tab content.
+1 -1
View File
@@ -30,7 +30,7 @@ impl WalletTab for WalletInfo {
fn ui(&mut self,
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
wallet: &Wallet,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
WalletContent::loading_ui(ui, frame, wallet);
}
+5 -1
View File
@@ -25,6 +25,10 @@ impl WalletTab for WalletReceive {
WalletTabType::Receive
}
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
fn ui(&mut self,
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
}
}
+5 -1
View File
@@ -25,6 +25,10 @@ impl WalletTab for WalletSend {
WalletTabType::Send
}
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
fn ui(&mut self,
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
}
}
+7 -2
View File
@@ -13,12 +13,16 @@
// limitations under the License.
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::wallets::setup::ConnectionSetup;
use crate::gui::views::wallets::wallet::types::{WalletTab, WalletTabType};
use crate::wallet::Wallet;
/// Wallet settings tab content.
#[derive(Default)]
pub struct WalletSettings;
pub struct WalletSettings {
/// Connection setup content.
conn_setup: ConnectionSetup
}
impl WalletTab for WalletSettings {
fn get_type(&self) -> WalletTabType {
@@ -28,7 +32,8 @@ impl WalletTab for WalletSettings {
fn ui(&mut self,
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
wallet: &Wallet,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
self.conn_setup.wallet_ui(ui, frame, wallet, cb);
}
}
+1 -1
View File
@@ -21,7 +21,7 @@ pub trait WalletTab {
fn ui(&mut self,
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
wallet: &Wallet,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks);
}