From 85ce58f69c747c90e91e829b16bf462dba67bc6d Mon Sep 17 00:00:00 2001 From: ardocrat Date: Mon, 31 Mar 2025 20:46:23 +0300 Subject: [PATCH] fix: parse result from scan on top panel --- src/gui/views/wallets/wallet/content.rs | 40 +++++++++++++------ .../views/wallets/wallet/transport/content.rs | 17 ++++---- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/gui/views/wallets/wallet/content.rs b/src/gui/views/wallets/wallet/content.rs index 5c84f8d1..6a82087c 100644 --- a/src/gui/views/wallets/wallet/content.rs +++ b/src/gui/views/wallets/wallet/content.rs @@ -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}; +use crate::gui::views::types::{LinePosition, ModalContainer, 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; @@ -134,17 +134,33 @@ impl WalletContent { .show_animated_inside(ui, show_account, |ui| { let rect = ui.available_rect_before_wrap(); if show_qr_scan { - View::max_width_ui(ui, Content::SIDE_PANEL_WIDTH, |ui| { - self.qr_scan_content.as_mut().unwrap().ui(ui, cb); - ui.add_space(6.0); - ui.vertical_centered_justified(|ui| { - View::button(ui, t!("close"), Colors::white_or_black(false), || { - cb.stop_camera(); - self.qr_scan_content = None; + if let Some(result) = self.qr_scan_content.as_ref().unwrap().qr_scan_result() { + match result { + QrScanResult::Address(address) => { + self.current_tab = + Box::new(WalletTransport::new(Some(address.to_string()), cb)); + } + _ => { + self.current_tab = + Box::new(WalletMessages::new(Some(result.text()))) + } + } + // Stop camera and close scanning. + cb.stop_camera(); + self.qr_scan_content = None; + } else { + View::max_width_ui(ui, Content::SIDE_PANEL_WIDTH, |ui| { + self.qr_scan_content.as_mut().unwrap().ui(ui, cb); + ui.add_space(6.0); + ui.vertical_centered_justified(|ui| { + View::button(ui, t!("close"), Colors::white_or_black(false), || { + cb.stop_camera(); + self.qr_scan_content = None; + }); }); + ui.add_space(6.0); }); - ui.add_space(6.0); - }); + } } else { View::max_width_ui(ui, Content::SIDE_PANEL_WIDTH * 1.3, |ui| { self.account_ui(ui, data.unwrap(), cb); @@ -393,7 +409,7 @@ impl WalletContent { }); columns[2].vertical_centered_justified(|ui| { View::tab_button(ui, BRIDGE, current_type == WalletTabType::Transport, |_| { - self.current_tab = Box::new(WalletTransport::default()); + self.current_tab = Box::new(WalletTransport::new(None, cb)); }); }); columns[3].vertical_centered_justified(|ui| { @@ -502,4 +518,4 @@ fn sync_progress_ui(ui: &mut egui::Ui, wallet: &Wallet) { ui.label(RichText::new(text).size(16.0).color(Colors::inactive_text())); }); }); -} \ No newline at end of file +} diff --git a/src/gui/views/wallets/wallet/transport/content.rs b/src/gui/views/wallets/wallet/transport/content.rs index 0db7b090..62178037 100644 --- a/src/gui/views/wallets/wallet/transport/content.rs +++ b/src/gui/views/wallets/wallet/transport/content.rs @@ -54,24 +54,25 @@ impl WalletTab for WalletTransport { /// Identifier for [`Modal`] to send amount over Tor. const SEND_TOR_MODAL: &'static str = "send_tor_modal"; - /// Identifier for [`Modal`] to setup Tor service. const TOR_SETTINGS_MODAL: &'static str = "tor_settings_modal"; - /// Identifier for [`Modal`] to show QR code address image. const QR_ADDRESS_MODAL: &'static str = "qr_address_modal"; -impl Default for WalletTransport { - fn default() -> Self { - Self { +impl WalletTransport { + /// Create new transport content instance, opening sending `Modal` if address was provided. + pub fn new(address: Option, cb: &dyn PlatformCallbacks) -> Self { + let mut content = Self { send_modal_content: None, qr_address_content: None, settings_modal_content: None, + }; + if address.is_some() { + content.show_send_tor_modal(cb, address) } + content } -} -impl WalletTransport { /// Draw wallet transport content. fn transport_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) { ui.add_space(3.0); @@ -352,7 +353,7 @@ impl WalletTransport { } /// Show [`Modal`] to send over Tor. - pub fn show_send_tor_modal(&mut self, cb: &dyn PlatformCallbacks, address: Option) { + fn show_send_tor_modal(&mut self, cb: &dyn PlatformCallbacks, address: Option) { self.send_modal_content = Some(TransportSendModal::new(address)); // Show modal. Modal::new(SEND_TOR_MODAL)