scan: show result text
This commit is contained in:
parent
a2e45bd8ba
commit
8e434505ae
3 changed files with 74 additions and 15 deletions
|
@ -19,6 +19,7 @@ scan: Scan
|
||||||
qr_code: QR code
|
qr_code: QR code
|
||||||
scan_qr: Scan QR code
|
scan_qr: Scan QR code
|
||||||
repeat: Repeat
|
repeat: Repeat
|
||||||
|
scan_result: Scan result
|
||||||
wallets:
|
wallets:
|
||||||
await_conf_amount: Awaiting confirmation
|
await_conf_amount: Awaiting confirmation
|
||||||
await_fin_amount: Awaiting finalization
|
await_fin_amount: Awaiting finalization
|
||||||
|
|
|
@ -17,8 +17,9 @@ settings: Настройки
|
||||||
language: Язык
|
language: Язык
|
||||||
scan: Сканировать
|
scan: Сканировать
|
||||||
qr_code: QR-код
|
qr_code: QR-код
|
||||||
scan_qr: Сканировать QR-код
|
scan_qr: Сканирование QR-кода
|
||||||
repeat: Повторить
|
repeat: Повторить
|
||||||
|
scan_result: Результат сканирования
|
||||||
wallets:
|
wallets:
|
||||||
await_conf_amount: Ожидает подтверждения
|
await_conf_amount: Ожидает подтверждения
|
||||||
await_fin_amount: Ожидает завершения
|
await_fin_amount: Ожидает завершения
|
||||||
|
|
|
@ -19,7 +19,7 @@ use grin_core::core::amount_to_hr_string;
|
||||||
|
|
||||||
use crate::AppConfig;
|
use crate::AppConfig;
|
||||||
use crate::gui::Colors;
|
use crate::gui::Colors;
|
||||||
use crate::gui::icons::{BRIDGE, CHAT_CIRCLE_TEXT, CHECK, CHECK_FAT, FOLDER_USER, GEAR_FINE, GRAPH, PACKAGE, PATH, POWER, REPEAT, SCAN, USERS_THREE};
|
use crate::gui::icons::{BRIDGE, CHAT_CIRCLE_TEXT, CHECK, CHECK_FAT, COPY, FOLDER_USER, GEAR_FINE, GRAPH, PACKAGE, PATH, POWER, REPEAT, SCAN, USERS_THREE};
|
||||||
use crate::gui::platform::PlatformCallbacks;
|
use crate::gui::platform::PlatformCallbacks;
|
||||||
use crate::gui::views::{CameraContent, Modal, Root, View};
|
use crate::gui::views::{CameraContent, Modal, Root, View};
|
||||||
use crate::gui::views::types::{ModalPosition, QrScanResult, TextEditOptions};
|
use crate::gui::views::types::{ModalPosition, QrScanResult, TextEditOptions};
|
||||||
|
@ -366,48 +366,105 @@ impl WalletContent {
|
||||||
modal: &Modal,
|
modal: &Modal,
|
||||||
cb: &dyn PlatformCallbacks) {
|
cb: &dyn PlatformCallbacks) {
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
|
// Show scan result if exists or show camera content while scanning.
|
||||||
if let Some(result) = &self.qr_scan_result {
|
if let Some(result) = &self.qr_scan_result {
|
||||||
let result_text = match result {
|
let mut result_text = match result {
|
||||||
QrScanResult::Slatepack(t) => t,
|
QrScanResult::Slatepack(t) => t,
|
||||||
QrScanResult::Address(t) => t,
|
QrScanResult::Address(t) => t,
|
||||||
QrScanResult::Text(t) => t
|
QrScanResult::Text(t) => t
|
||||||
};
|
}.clone();
|
||||||
ui.vertical_centered(|ui| {
|
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||||
ui.label(RichText::new(result_text).size(16.0).color(Colors::INACTIVE_TEXT));
|
ui.add_space(3.0);
|
||||||
|
ScrollArea::vertical()
|
||||||
|
.max_height(128.0)
|
||||||
|
.id_source(Id::from("qr_scan_result_input").with(wallet.get_config().id))
|
||||||
|
.auto_shrink([false; 2])
|
||||||
|
.show(ui, |ui| {
|
||||||
|
ui.add_space(7.0);
|
||||||
|
egui::TextEdit::multiline(&mut result_text)
|
||||||
|
.font(egui::TextStyle::Small)
|
||||||
|
.desired_rows(5)
|
||||||
|
.interactive(false)
|
||||||
|
.desired_width(f32::INFINITY)
|
||||||
|
.show(ui);
|
||||||
|
ui.add_space(6.0);
|
||||||
});
|
});
|
||||||
|
ui.add_space(2.0);
|
||||||
|
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||||
|
ui.add_space(10.0);
|
||||||
|
|
||||||
|
// Show copy button.
|
||||||
|
ui.vertical_centered(|ui| {
|
||||||
|
let copy_text = format!("{} {}", COPY, t!("copy"));
|
||||||
|
View::button(ui, copy_text, Colors::BUTTON, || {
|
||||||
|
cb.copy_string_to_buffer(result_text);
|
||||||
|
self.qr_scan_result = None;
|
||||||
|
modal.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ui.add_space(6.0);
|
||||||
} else if let Some(result) = self.camera_content.qr_scan_result() {
|
} else if let Some(result) = self.camera_content.qr_scan_result() {
|
||||||
cb.stop_camera();
|
cb.stop_camera();
|
||||||
self.camera_content.clear_state();
|
self.camera_content.clear_state();
|
||||||
match &result {
|
match &result {
|
||||||
QrScanResult::Slatepack(message) => {
|
QrScanResult::Slatepack(message) => {
|
||||||
|
// Redirect to messages to handle parsed message.
|
||||||
let mut messages =
|
let mut messages =
|
||||||
WalletMessages::new(wallet.can_use_dandelion(), Some(message.clone()));
|
WalletMessages::new(wallet.can_use_dandelion(), Some(message.clone()));
|
||||||
messages.parse_message(wallet);
|
messages.parse_message(wallet);
|
||||||
self.current_tab = Box::new(messages);
|
|
||||||
modal.close();
|
modal.close();
|
||||||
|
self.current_tab = Box::new(messages);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
QrScanResult::Address(receiver) => {
|
QrScanResult::Address(receiver) => {
|
||||||
if wallet.get_data().unwrap().info.amount_currently_spendable > 0 {
|
if wallet.get_data().unwrap().info.amount_currently_spendable > 0 {
|
||||||
|
// Redirect to send amount with Tor.
|
||||||
let addr = wallet.slatepack_address().unwrap();
|
let addr = wallet.slatepack_address().unwrap();
|
||||||
let mut transport = WalletTransport::new(addr.clone());
|
let mut transport = WalletTransport::new(addr.clone());
|
||||||
transport.show_send_tor_modal(cb, Some(receiver.clone()));
|
transport.show_send_tor_modal(cb, Some(receiver.clone()));
|
||||||
|
modal.close();
|
||||||
self.current_tab = Box::new(transport);
|
self.current_tab = Box::new(transport);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QrScanResult::Text(_) => {
|
QrScanResult::Text(_) => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set result and rename modal title.
|
||||||
self.qr_scan_result = Some(result);
|
self.qr_scan_result = Some(result);
|
||||||
}
|
Modal::set_title(t!("scan_result"));
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
self.camera_content.ui(ui, cb);
|
self.camera_content.ui(ui, cb);
|
||||||
}
|
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.qr_scan_result.is_some() {
|
||||||
|
// Setup spacing between buttons.
|
||||||
|
ui.spacing_mut().item_spacing = egui::Vec2::new(6.0, 0.0);
|
||||||
|
|
||||||
|
ui.columns(2, |columns| {
|
||||||
|
columns[0].vertical_centered_justified(|ui| {
|
||||||
|
View::button(ui, t!("close"), Colors::WHITE, || {
|
||||||
|
self.qr_scan_result = None;
|
||||||
|
modal.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
columns[1].vertical_centered_justified(|ui| {
|
||||||
|
View::button(ui, t!("repeat"), Colors::WHITE, || {
|
||||||
|
Modal::set_title(t!("scan_qr"));
|
||||||
|
cb.start_camera();
|
||||||
|
self.qr_scan_result = None;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
ui.vertical_centered_justified(|ui| {
|
ui.vertical_centered_justified(|ui| {
|
||||||
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
|
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
|
||||||
cb.stop_camera();
|
cb.stop_camera();
|
||||||
modal.close();
|
modal.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue