wallet: qr scan modal, connections content and default list, wallet creation and list refactoring, tx height

This commit is contained in:
ardocrat
2024-09-19 15:56:53 +03:00
parent 3bc8c407b4
commit c155deedb5
34 changed files with 1254 additions and 1168 deletions
+70 -58
View File
@@ -21,23 +21,25 @@ use crate::AppConfig;
use crate::gui::Colors;
use crate::gui::icons::{ARROWS_CLOCKWISE, BRIDGE, 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};
use crate::gui::views::{Modal, Content, View, CameraScanModal};
use crate::gui::views::types::{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, WalletScanModal};
use crate::gui::views::wallets::wallet::modals::WalletAccountsModal;
use crate::gui::views::wallets::wallet::WalletSettings;
use crate::node::Node;
use crate::wallet::{Wallet, WalletConfig};
use crate::wallet::types::WalletData;
use crate::wallet::types::{ConnectionMethod, WalletData};
/// Selected and opened wallet content.
/// Wallet content.
pub struct WalletContent {
/// Selected and opened wallet.
pub wallet: Wallet,
/// Wallet accounts [`Modal`] content.
accounts_modal_content: Option<WalletAccountsModal>,
/// QR code scan [`Modal`] content.
scan_modal_content: Option<WalletScanModal>,
scan_modal_content: Option<CameraScanModal>,
/// Current tab content to show.
pub current_tab: Box<dyn WalletTab>,
@@ -51,37 +53,41 @@ const QR_CODE_SCAN_MODAL: &'static str = "qr_code_scan_modal";
impl WalletContent {
/// Create new instance with optional data.
pub fn new(data: Option<String>) -> Self {
pub fn new(wallet: Wallet, data: Option<String>) -> Self {
let mut content = Self {
wallet,
accounts_modal_content: None,
scan_modal_content: None,
current_tab: Box::new(WalletTransactions::default()),
};
// Provide data to messages.
if data.is_some() {
content.current_tab = Box::new(WalletMessages::new(data));
content.on_data(data);
}
content
}
/// Handle data from deeplink or opened file.
pub fn on_data(&mut self, data: Option<String>) {
// Provide data to messages.
self.current_tab = Box::new(WalletMessages::new(data));
}
/// Draw wallet content.
pub fn ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
// Show modal content for this ui container.
self.modal_content_ui(ui, wallet, cb);
pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
self.modal_content_ui(ui, cb);
let dual_panel = Content::is_dual_panel_mode(ui);
let wallet = &self.wallet;
let data = wallet.get_data();
let data_empty = data.is_none();
let hide_tabs = Self::block_navigation_on_sync(wallet);
// Show wallet balance panel not on Settings tab with selected non-repairing
// wallet, when there is no error and data is not empty.
let mut show_balance = self.current_tab.get_type() != WalletTabType::Settings && !data_empty
&& !wallet.sync_error() && !wallet.is_repairing() && !wallet.is_closing();
if wallet.get_current_ext_conn().is_none() && !Node::is_running() {
if wallet.get_current_connection() == ConnectionMethod::Integrated && !Node::is_running() {
show_balance = false;
}
egui::TopBottomPanel::top(Id::from("wallet_balance").with(wallet.identifier()))
@@ -117,13 +123,12 @@ impl WalletContent {
}
// Draw account info.
View::max_width_ui(ui, Content::SIDE_PANEL_WIDTH * 1.3, |ui| {
self.account_ui(ui, wallet, data.unwrap(), cb);
self.account_ui(ui, data.unwrap(), cb);
});
});
});
// Show wallet tabs panel.
let show_tabs = !Self::block_navigation_on_sync(wallet);
egui::TopBottomPanel::bottom("wallet_tabs_content")
.frame(egui::Frame {
fill: Colors::fill(),
@@ -135,7 +140,7 @@ impl WalletContent {
},
..Default::default()
})
.show_animated_inside(ui, show_tabs, |ui| {
.show_animated_inside(ui, !hide_tabs, |ui| {
ui.vertical_centered(|ui| {
// Draw wallet tabs.
View::max_width_ui(ui, Content::SIDE_PANEL_WIDTH * 1.3, |ui| {
@@ -162,7 +167,7 @@ impl WalletContent {
..Default::default()
})
.show_inside(ui, |ui| {
self.current_tab.ui(ui, wallet, cb);
self.current_tab.ui(ui, &self.wallet, cb);
});
// Refresh content after 1 second for synced wallet.
@@ -173,11 +178,21 @@ impl WalletContent {
}
}
/// 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_connection() == ConnectionMethod::Integrated;
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
// and if 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 || integrated_node_ready))
}
/// Draw [`Modal`] content for this ui container.
fn modal_content_ui(&mut self,
ui: &mut egui::Ui,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
fn modal_content_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
match Modal::opened() {
None => {}
Some(id) => {
@@ -185,29 +200,30 @@ impl WalletContent {
ACCOUNT_LIST_MODAL => {
if let Some(content) = self.accounts_modal_content.as_mut() {
Modal::ui(ui.ctx(), |ui, modal| {
content.ui(ui, wallet, modal, cb);
content.ui(ui, &self.wallet, modal, cb);
});
}
}
QR_CODE_SCAN_MODAL => {
let mut success = false;
if let Some(content) = self.scan_modal_content.as_mut() {
Modal::ui(ui.ctx(), |ui, modal| {
content.ui(ui, wallet, modal, cb, |result| {
content.ui(ui, modal, cb, |result| {
match result {
QrScanResult::Slatepack(message) => {
modal.close();
success = true;
let msg = Some(message.to_string());
let messages = WalletMessages::new(msg);
self.current_tab = Box::new(messages);
return;
}
QrScanResult::Address(receiver) => {
let balance = wallet.get_data()
success = true;
let balance = self.wallet.get_data()
.unwrap()
.info
.amount_currently_spendable;
if balance > 0 {
modal.close();
let mut transport = WalletTransport::default();
let rec = Some(receiver.to_string());
transport.show_send_tor_modal(cb, rec);
@@ -217,9 +233,15 @@ impl WalletContent {
}
_ => {}
}
if success {
modal.close();
}
});
});
}
if success {
self.scan_modal_content = None;
}
}
_ => {}
}
@@ -230,7 +252,6 @@ impl WalletContent {
/// Draw wallet account content.
fn account_ui(&mut self,
ui: &mut egui::Ui,
wallet: &Wallet,
data: WalletData,
cb: &dyn PlatformCallbacks) {
let mut rect = ui.available_rect_before_wrap();
@@ -240,10 +261,9 @@ impl WalletContent {
ui.painter().rect(rect, rounding, Colors::button(), View::hover_stroke());
ui.allocate_ui_with_layout(rect.size(), Layout::right_to_left(Align::Center), |ui| {
// Draw button to scan QR code.
// Draw button to show QR code scanner.
View::item_button(ui, View::item_rounding(0, 2, true), SCAN, None, || {
self.scan_modal_content = Some(WalletScanModal::default());
// Show QR code scan modal.
self.scan_modal_content = Some(CameraScanModal::default());
Modal::new(QR_CODE_SCAN_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("scan_qr"))
@@ -254,8 +274,9 @@ 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(wallet.accounts()));
// Show account list modal.
self.accounts_modal_content = Some(
WalletAccountsModal::new(self.wallet.accounts())
);
Modal::new(ACCOUNT_LIST_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.accounts"))
@@ -279,7 +300,7 @@ impl WalletContent {
ui.add_space(-2.0);
// Show account label.
let account = wallet.get_config().account;
let account = self.wallet.get_config().account;
let default_acc_label = WalletConfig::DEFAULT_ACCOUNT_LABEL.to_string();
let acc_label = if account == default_acc_label {
t!("wallets.default_account")
@@ -290,15 +311,15 @@ impl WalletContent {
View::ellipsize_text(ui, acc_text, 15.0, Colors::text(false));
// Show confirmed height or sync progress.
let status_text = if !wallet.syncing() {
let status_text = if !self.wallet.syncing() {
format!("{} {}", PACKAGE, data.info.last_confirmed_height)
} else {
let info_progress = wallet.info_sync_progress();
let info_progress = self.wallet.info_sync_progress();
if info_progress == 100 || info_progress == 0 {
format!("{} {}", SPINNER, t!("wallets.wallet_loading"))
} else {
if wallet.is_repairing() {
let rep_progress = wallet.repairing_progress();
if self.wallet.is_repairing() {
let rep_progress = self.wallet.repairing_progress();
if rep_progress == 0 {
format!("{} {}", SPINNER, t!("wallets.wallet_checking"))
} else {
@@ -315,7 +336,11 @@ impl WalletContent {
}
}
};
View::animate_text(ui, status_text, 15.0, Colors::gray(), wallet.syncing());
View::animate_text(ui,
status_text,
15.0,
Colors::gray(),
self.wallet.syncing());
})
});
});
@@ -367,7 +392,7 @@ impl WalletContent {
} else if wallet.is_closing() {
Self::sync_progress_ui(ui, wallet);
return true;
} else if wallet.get_current_ext_conn().is_none() {
} else if wallet.get_current_connection() == ConnectionMethod::Integrated {
if !Node::is_running() || Node::is_stopping() {
View::center_content(ui, 108.0, |ui| {
View::max_width_ui(ui, Content::SIDE_PANEL_WIDTH * 1.5, |ui| {
@@ -418,19 +443,6 @@ impl WalletContent {
});
}
/// 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().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
// and if 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 || integrated_node_ready))
}
/// Draw wallet sync progress content.
pub fn sync_progress_ui(ui: &mut egui::Ui, wallet: &Wallet) {
View::center_content(ui, 162.0, |ui| {
@@ -439,13 +451,13 @@ impl WalletContent {
ui.add_space(18.0);
// Setup sync progress text.
let text = {
let integrated_node = wallet.get_current_ext_conn().is_none();
let integrated_node_ready = Node::get_sync_status() == Some(SyncStatus::NoSync);
let int_node = wallet.get_current_connection() == ConnectionMethod::Integrated;
let int_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 {
} else if int_node && !int_ready {
t!("wallets.node_loading", "settings" => GEAR_FINE)
} else if wallet.is_repairing() {
let repair_progress = wallet.repairing_progress();
@@ -74,7 +74,7 @@ impl WalletTab for WalletMessages {
WalletTabType::Messages
}
fn ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) {
fn ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
if WalletContent::sync_ui(ui, wallet) {
return;
}
@@ -130,7 +130,7 @@ impl WalletMessages {
/// Draw manual wallet transaction interaction content.
pub fn ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
if self.first_draw {
// Parse provided message on first draw.
@@ -158,7 +158,7 @@ impl WalletMessages {
/// Draw [`Modal`] content for this ui container.
fn modal_content_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
match Modal::opened() {
None => {}
@@ -244,7 +244,7 @@ impl WalletMessages {
/// Draw Slatepack message input content.
fn input_slatepack_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
// Setup description text.
if !self.message_error.is_empty() {
@@ -524,7 +524,6 @@ impl WalletMessages {
return;
} else if let Some(result) = self.message_camera_content.qr_scan_result() {
cb.stop_camera();
self.message_camera_content.clear_state();
match &result {
QrScanResult::Slatepack(text) => {
self.message_edit = text.to_string();
@@ -62,7 +62,7 @@ impl MessageRequestModal {
/// Draw [`Modal`] content.
pub fn ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
// Draw transaction information on request result.
@@ -147,7 +147,7 @@ impl MessageRequestModal {
/// Draw amount input content.
fn amount_input_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
ui.vertical_centered(|ui| {
@@ -211,7 +211,7 @@ impl MessageRequestModal {
}
/// Draw loading request content.
fn loading_request_ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, modal: &Modal) {
fn loading_request_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, modal: &Modal) {
ui.add_space(34.0);
ui.vertical_centered(|ui| {
View::big_loading_spinner(ui);
+1 -4
View File
@@ -13,7 +13,4 @@
// limitations under the License.
mod accounts;
pub use accounts::*;
mod scan;
pub use scan::*;
pub use accounts::*;
@@ -61,7 +61,7 @@ impl Default for CommonSettings {
impl CommonSettings {
/// Draw common wallet settings content.
pub fn ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) {
pub fn ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
// Show modal content for this ui container.
self.modal_content_ui(ui, wallet, cb);
@@ -146,7 +146,7 @@ impl CommonSettings {
/// Draw [`Modal`] content for this ui container.
fn modal_content_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
match Modal::opened() {
None => {}
@@ -176,7 +176,7 @@ impl CommonSettings {
/// Draw wallet name [`Modal`] content.
fn name_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
ui.add_space(6.0);
@@ -230,7 +230,7 @@ impl CommonSettings {
/// Draw wallet pass [`Modal`] content.
fn pass_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
let wallet_id = wallet.get_config().id;
@@ -328,7 +328,7 @@ impl CommonSettings {
/// Draw wallet name [`Modal`] content.
fn min_conf_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
ui.add_space(6.0);
@@ -29,9 +29,6 @@ pub struct ConnectionSettings {
/// Selected connection method.
pub method: ConnectionMethod,
/// Current wallet external connection.
curr_ext_conn: Option<ExternalConnection>,
/// External connection [`Modal`] content.
ext_conn_modal: ExternalConnectionModal,
@@ -44,7 +41,6 @@ impl Default for ConnectionSettings {
ExternalConnection::check_ext_conn_availability(None);
Self {
method: ConnectionMethod::Integrated,
curr_ext_conn: None,
ext_conn_modal: ExternalConnectionModal::new(None),
modal_ids: vec![
ExternalConnectionModal::WALLET_ID
@@ -74,52 +70,29 @@ impl ModalContainer for ConnectionSettings {
impl ConnectionSettings {
/// Draw wallet creation setup content.
pub fn create_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
self.ui(ui, None, cb);
self.ui(ui, cb);
}
/// Draw existing wallet connection setup content.
pub fn wallet_ui(&mut self, ui: &mut egui::Ui, w: &mut Wallet, cb: &dyn PlatformCallbacks) {
// Setup connection value from provided wallet.
match w.get_config().ext_conn_id {
None => self.method = ConnectionMethod::Integrated,
Some(id) => self.method = ConnectionMethod::External(id)
}
pub fn wallet_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
self.method = wallet.get_current_connection();
// Draw setup content.
self.ui(ui, Some(w), cb);
let changed = self.ui(ui, cb);
// Setup wallet connection value after change.
let changed = match self.method {
ConnectionMethod::Integrated => {
let changed = w.get_current_ext_conn().is_some();
if changed {
w.update_ext_conn_id(None);
}
changed
}
ConnectionMethod::External(id) => {
let changed = w.get_config().ext_conn_id != Some(id);
if changed {
w.update_ext_conn_id(Some(id));
}
changed
}
};
// Reopen wallet if connection changed.
if changed {
if !w.reopen_needed() {
w.set_reopen(true);
w.close();
wallet.update_connection(&self.method);
// Reopen wallet if connection changed.
if !wallet.reopen_needed() {
wallet.set_reopen(true);
wallet.close();
}
}
}
/// Draw connection setup content.
fn ui(&mut self,
ui: &mut egui::Ui,
wallet: Option<&Wallet>,
cb: &dyn PlatformCallbacks) {
/// Draw connection setup content, returning `true` if connection was changed.
fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) -> bool {
let mut changed = false;
// Draw modal content for current ui container.
self.current_modal_ui(ui, cb);
@@ -129,14 +102,14 @@ impl ConnectionSettings {
ui.add_space(6.0);
ui.vertical_centered(|ui| {
// Show integrated node selection.
ui.add_space(6.0);
// Show integrated node selection.
ConnectionsContent::integrated_node_item_ui(ui, |ui| {
// Draw button to select integrated node if it was not selected.
let is_current_method = self.method == ConnectionMethod::Integrated;
if !is_current_method {
View::item_button(ui, View::item_rounding(0, 1, true), CHECK, None, || {
self.method = ConnectionMethod::Integrated;
changed = true;
});
} else {
ui.add_space(14.0);
@@ -145,7 +118,6 @@ impl ConnectionSettings {
}
});
// Show external connections.
ui.add_space(8.0);
ui.label(RichText::new(t!("wallets.ext_conn")).size(16.0).color(Colors::gray()));
ui.add_space(6.0);
@@ -153,45 +125,58 @@ impl ConnectionSettings {
// Show button to add new external node connection.
let add_node_text = format!("{} {}", PLUS_CIRCLE, t!("wallets.add_node"));
View::button(ui, add_node_text, Colors::button(), || {
self.show_add_ext_conn_modal(cb);
self.ext_conn_modal = ExternalConnectionModal::new(None);
Modal::new(ExternalConnectionModal::WALLET_ID)
.position(ModalPosition::CenterTop)
.title(t!("wallets.add_node"))
.show();
cb.show_keyboard();
});
ui.add_space(4.0);
let mut ext_conn_list = ConnectionsConfig::ext_conn_list();
// Check if current external connection was deleted to show at 1st place.
if let Some(wallet) = wallet {
if let Some(conn) = wallet.get_current_ext_conn() {
if ext_conn_list.iter()
.filter(|c| c.id == conn.id)
.collect::<Vec<&ExternalConnection>>().is_empty() {
if self.curr_ext_conn.is_none() {
self.curr_ext_conn = Some(conn);
}
ext_conn_list.insert(0, self.curr_ext_conn.as_ref().unwrap().clone());
}
// Check if it's current method.
let is_current = |m: &ConnectionMethod, c: &ExternalConnection| -> Option<bool> {
match m {
ConnectionMethod::External(id, _) => if c.deleted && *id == c.id {
None
} else {
Some(*id == c.id)
},
_ => Some(false)
}
}
};
if !ext_conn_list.is_empty() {
let method = &self.method.clone();
let ext_conn_list = ConnectionsConfig::ext_conn_list();
let ext_list = ext_conn_list.iter().filter(|c| {
!c.deleted || is_current(method, c).unwrap_or(true)
}).collect::<Vec<&ExternalConnection>>();
let ext_size = ext_list.len();
if ext_size != 0 {
ui.add_space(8.0);
for (index, conn) in ext_conn_list.iter().enumerate() {
for (i, c) in ext_list.iter().enumerate() {
ui.horizontal_wrapped(|ui| {
// Draw external connection item.
self.ext_conn_item_ui(ui, wallet, conn, index, ext_conn_list.len());
let is_current = is_current(method, c);
Self::ext_conn_item_ui(ui, c, is_current, i, ext_size, || {
self.method = ConnectionMethod::External(c.id, c.url.clone());
changed = true;
});
});
}
}
});
changed
}
/// Draw external connection item content.
fn ext_conn_item_ui(&mut self,
ui: &mut egui::Ui,
wallet: Option<&Wallet>,
fn ext_conn_item_ui(ui: &mut egui::Ui,
conn: &ExternalConnection,
is_current: Option<bool>,
index: usize,
len: usize) {
len: usize,
mut on_select: impl FnMut()) {
// Setup layout size.
let mut rect = ui.available_rect_before_wrap();
rect.set_height(52.0);
@@ -203,24 +188,15 @@ impl ConnectionSettings {
ui.vertical(|ui| {
ui.allocate_ui_with_layout(rect.size(), Layout::right_to_left(Align::Center), |ui| {
// Draw button to select connection.
let is_current_method = if let Some(wallet) = wallet {
if let Some(cur) = wallet.get_config().ext_conn_id {
cur == conn.id
} else {
false
}
} else {
self.method == ConnectionMethod::External(conn.id)
};
if !is_current_method {
let button_rounding = View::item_rounding(index, len, true);
View::item_button(ui, button_rounding, CHECK, None, || {
self.method = ConnectionMethod::External(conn.id);
});
} else {
if is_current.unwrap_or(true) {
ui.add_space(12.0);
ui.label(RichText::new(CHECK_FAT).size(20.0).color(Colors::green()));
} else {
// Draw button to select connection.
let button_rounding = View::item_rounding(index, len, true);
View::item_button(ui, button_rounding, CHECK, None, || {
on_select();
});
}
let layout_size = ui.available_size();
@@ -235,7 +211,11 @@ impl ConnectionSettings {
// Setup connection status text.
let status_text = if let Some(available) = conn.available {
if available {
format!("{} {}", CHECK_CIRCLE, t!("network.available"))
format!("{} {}", CHECK_CIRCLE, if is_current.is_none() {
t!("transport.connected")
} else {
t!("network.available")
})
} else {
format!("{} {}", X_CIRCLE, t!("network.not_available"))
}
@@ -249,15 +229,4 @@ impl ConnectionSettings {
});
});
}
/// Show external connection adding [`Modal`].
fn show_add_ext_conn_modal(&mut self, cb: &dyn PlatformCallbacks) {
self.ext_conn_modal = ExternalConnectionModal::new(None);
// Show modal.
Modal::new(ExternalConnectionModal::WALLET_ID)
.position(ModalPosition::CenterTop)
.title(t!("wallets.add_node"))
.show();
cb.show_keyboard();
}
}
@@ -50,7 +50,7 @@ impl WalletTab for WalletSettings {
fn ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
// Show loading progress if navigation is blocked.
if WalletContent::block_navigation_on_sync(wallet) {
@@ -22,6 +22,7 @@ use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, View};
use crate::gui::views::types::{ModalPosition, TextEditOptions};
use crate::node::Node;
use crate::wallet::types::ConnectionMethod;
use crate::wallet::Wallet;
/// Wallet recovery settings content.
@@ -51,7 +52,7 @@ impl Default for RecoverySettings {
}
impl RecoverySettings {
pub fn ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) {
pub fn ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
// Show modal content for this ui container.
self.modal_content_ui(ui, wallet, cb);
@@ -63,7 +64,7 @@ impl RecoverySettings {
ui.add_space(4.0);
ui.vertical_centered(|ui| {
let integrated_node = wallet.get_current_ext_conn().is_none();
let integrated_node = wallet.get_current_connection() == ConnectionMethod::Integrated;
let integrated_node_ready = Node::get_sync_status() == Some(SyncStatus::NoSync);
if wallet.sync_error() || (integrated_node && !integrated_node_ready) {
ui.add_space(2.0);
@@ -136,7 +137,7 @@ impl RecoverySettings {
/// Draw [`Modal`] content for this ui container.
fn modal_content_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
match Modal::opened() {
None => {}
@@ -175,7 +176,7 @@ impl RecoverySettings {
/// Draw recovery phrase [`Modal`] content.
fn recovery_phrase_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
ui.add_space(6.0);
@@ -260,7 +261,7 @@ impl RecoverySettings {
/// Draw wallet deletion [`Modal`] content.
fn deletion_modal_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
modal: &Modal) {
ui.add_space(8.0);
ui.vertical_centered(|ui| {
@@ -47,7 +47,7 @@ impl WalletTab for WalletTransport {
fn ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
if WalletContent::sync_ui(ui, wallet) {
return;
@@ -106,7 +106,7 @@ impl Default for WalletTransport {
impl WalletTransport {
/// Draw wallet transport content.
pub fn ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) {
pub fn ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
ui.add_space(3.0);
ui.label(RichText::new(t!("transport.desc"))
.size(16.0)
@@ -120,7 +120,7 @@ impl WalletTransport {
/// Draw [`Modal`] content for this ui container.
fn modal_content_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
match Modal::opened() {
None => {}
@@ -152,7 +152,7 @@ impl WalletTransport {
}
/// Draw Tor transport content.
fn tor_ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) {
fn tor_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
let data = wallet.get_data().unwrap();
// Draw header content.
@@ -74,7 +74,7 @@ impl TransportSendModal {
/// Draw [`Modal`] content.
pub fn ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
// Draw transaction information on request result.
+7 -7
View File
@@ -56,7 +56,7 @@ impl WalletTab for WalletTransactions {
WalletTabType::Txs
}
fn ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) {
fn ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
if WalletContent::sync_ui(ui, wallet) {
return;
}
@@ -100,7 +100,7 @@ impl WalletTransactions {
/// Draw transactions content.
fn txs_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
data: &WalletData,
cb: &dyn PlatformCallbacks) {
let amount_conf = data.info.amount_awaiting_confirmation;
@@ -245,7 +245,7 @@ impl WalletTransactions {
/// Draw [`Modal`] content for this ui container.
fn modal_content_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
match Modal::opened() {
None => {}
@@ -360,8 +360,8 @@ impl WalletTransactions {
TxLogEntryType::TxSent | TxLogEntryType::TxReceived => {
let height = data.info.last_confirmed_height;
let min_conf = data.info.minimum_confirmations;
if tx.conf_height.is_none() || (tx.conf_height.unwrap() != 0 &&
height - tx.conf_height.unwrap() > min_conf - 1) {
if tx.height.is_none() || (tx.height.unwrap() != 0 &&
height - tx.height.unwrap() > min_conf - 1) {
let (i, t) = if tx.data.tx_type == TxLogEntryType::TxSent {
(ARROW_CIRCLE_UP, t!("wallets.tx_sent"))
} else {
@@ -369,7 +369,7 @@ impl WalletTransactions {
};
format!("{} {}", i, t)
} else {
let tx_height = tx.conf_height.unwrap() - 1;
let tx_height = tx.height.unwrap() - 1;
let left_conf = height - tx_height;
let conf_info = if tx_height != 0 && height >= tx_height &&
left_conf < min_conf {
@@ -428,7 +428,7 @@ impl WalletTransactions {
}
/// Confirmation [`Modal`] to cancel transaction.
fn cancel_confirmation_modal(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, modal: &Modal) {
fn cancel_confirmation_modal(&mut self, ui: &mut egui::Ui, wallet: &Wallet, modal: &Modal) {
ui.add_space(6.0);
ui.vertical_centered(|ui| {
// Setup confirmation text.
+11 -5
View File
@@ -21,7 +21,7 @@ use grin_util::ToHex;
use grin_wallet_libwallet::{Error, Slate, SlateState, TxLogEntryType};
use parking_lot::RwLock;
use crate::gui::Colors;
use crate::gui::icons::{BROOM, CHECK, CLIPBOARD_TEXT, COPY, FILE_ARCHIVE, FILE_TEXT, HASH_STRAIGHT, PROHIBIT, QR_CODE, SCAN};
use crate::gui::icons::{BROOM, CHECK, CLIPBOARD_TEXT, COPY, CUBE, FILE_ARCHIVE, FILE_TEXT, HASH_STRAIGHT, PROHIBIT, QR_CODE, SCAN};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{CameraContent, FilePickButton, Modal, QrCodeContent, View};
@@ -106,7 +106,7 @@ impl WalletTransactionModal {
/// Draw [`Modal`] content.
pub fn ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
// Check values and setup transaction data.
@@ -171,16 +171,23 @@ impl WalletTransactionModal {
}
});
// Show transaction ID info.
// Show identifier.
if let Some(id) = tx.data.tx_slate_id {
let label = format!("{} {}", HASH_STRAIGHT, t!("id"));
Self::info_item_ui(ui, id.to_string(), label, true, cb);
}
// Show transaction kernel info.
// Show kernel.
if let Some(kernel) = tx.data.kernel_excess {
let label = format!("{} {}", FILE_ARCHIVE, t!("kernel"));
Self::info_item_ui(ui, kernel.0.to_hex(), label, true, cb);
}
// Show block height.
if let Some(height) = tx.height {
if height != 0 {
let label = format!("{} {}", CUBE, t!("network_node.block"));
Self::info_item_ui(ui, height.to_string(), label, true, cb);
}
}
}
// Show Slatepack message or reset QR code state if not available.
@@ -335,7 +342,6 @@ impl WalletTransactionModal {
if let Some(qr_scan_content) = self.qr_scan_content.as_mut() {
if let Some(result) = qr_scan_content.qr_scan_result() {
cb.stop_camera();
qr_scan_content.clear_state();
// Setup value to finalization input field.
self.finalize_edit = result.text();
+2 -2
View File
@@ -26,7 +26,7 @@ pub trait WalletTab {
fn get_type(&self) -> WalletTabType;
fn ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
wallet: &Wallet,
cb: &dyn PlatformCallbacks);
}
@@ -52,7 +52,7 @@ impl WalletTabType {
}
/// Get wallet status text.
pub fn status_text(wallet: &Wallet) -> String {
pub fn wallet_status_text(wallet: &Wallet) -> String {
if wallet.is_open() {
if wallet.sync_error() {
format!("{} {}", WARNING_CIRCLE, t!("error"))