fix: parse result from scan on top panel

This commit is contained in:
ardocrat
2025-03-31 20:46:23 +03:00
parent bb7e00b0eb
commit 85ce58f69c
2 changed files with 37 additions and 20 deletions
+28 -12
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};
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()));
});
});
}
}
@@ -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<String>, 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<String>) {
fn show_send_tor_modal(&mut self, cb: &dyn PlatformCallbacks, address: Option<String>) {
self.send_modal_content = Some(TransportSendModal::new(address));
// Show modal.
Modal::new(SEND_TOR_MODAL)