tor: settings modal, save slatepack message after finalization

This commit is contained in:
ardocrat 2024-04-30 23:28:49 +03:00
parent 12650c94fd
commit c3864cb229
4 changed files with 61 additions and 14 deletions

View file

@ -125,6 +125,7 @@ transport:
tor_send_error: An error occurred during sending over Tor, make sure receiver is online, transaction was canceled. tor_send_error: An error occurred during sending over Tor, make sure receiver is online, transaction was canceled.
tor_autorun_desc: Whether to launch Tor service on wallet opening to receive transactions synchronously. tor_autorun_desc: Whether to launch Tor service on wallet opening to receive transactions synchronously.
tor_sending: Sending over Tor tor_sending: Sending over Tor
tor_settings: Tor Settings
network: network:
self: Network self: Network
type: 'Network type:' type: 'Network type:'

View file

@ -125,6 +125,7 @@ transport:
tor_send_error: Во время отправки через Tor произошла ошибка, убедитесь, что получатель находится онлайн, транзакция была отменена. tor_send_error: Во время отправки через Tor произошла ошибка, убедитесь, что получатель находится онлайн, транзакция была отменена.
tor_autorun_desc: Запускать ли Tor сервис при открытии кошелька для синхронного получения транзакций. tor_autorun_desc: Запускать ли Tor сервис при открытии кошелька для синхронного получения транзакций.
tor_sending: Отправка через Tor tor_sending: Отправка через Tor
tor_settings: Настройки Tor
network: network:
self: Сеть self: Сеть
type: 'Тип сети:' type: 'Тип сети:'

View file

@ -20,7 +20,7 @@ use grin_core::core::{amount_from_hr_string, amount_to_hr_string};
use grin_wallet_libwallet::SlatepackAddress; use grin_wallet_libwallet::SlatepackAddress;
use crate::gui::Colors; use crate::gui::Colors;
use crate::gui::icons::{CHECK_CIRCLE, COMPUTER_TOWER, COPY, DOTS_THREE_CIRCLE, EXPORT, GEAR_SIX, GLOBE_SIMPLE, POWER, QR_CODE, UPLOAD, WARNING_CIRCLE, X_CIRCLE}; use crate::gui::icons::{CHECK_CIRCLE, COMPUTER_TOWER, COPY, DOTS_THREE_CIRCLE, EXPORT, GEAR_SIX, POWER, QR_CODE, WARNING_CIRCLE, X_CIRCLE};
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Modal, Root, View}; use crate::gui::views::{Modal, Root, View};
use crate::gui::views::types::{ModalPosition, TextEditOptions}; use crate::gui::views::types::{ModalPosition, TextEditOptions};
@ -110,6 +110,9 @@ impl WalletTab for WalletTransport {
/// Identifier for [`Modal`] to send amount over Tor. /// Identifier for [`Modal`] to send amount over Tor.
const SEND_TOR_MODAL: &'static str = "send_tor_modal"; 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";
impl WalletTransport { impl WalletTransport {
/// Draw wallet transport content. /// 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: &mut Wallet, cb: &dyn PlatformCallbacks) {
@ -137,6 +140,11 @@ impl WalletTransport {
self.send_tor_modal_ui(ui, wallet, modal, cb); self.send_tor_modal_ui(ui, wallet, modal, cb);
}); });
} }
TOR_SETTINGS_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| {
self.tor_settings_modal_ui(ui, wallet, modal);
});
}
_ => {} _ => {}
} }
} }
@ -146,7 +154,7 @@ impl WalletTransport {
/// Draw Tor transport content. /// 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: &mut Wallet, cb: &dyn PlatformCallbacks) {
// Draw header content. // Draw header content.
self.tor_header_ui(ui, wallet, cb); self.tor_header_ui(ui, wallet);
// Draw receive info content. // Draw receive info content.
if wallet.slatepack_address().is_some() { if wallet.slatepack_address().is_some() {
@ -154,11 +162,11 @@ impl WalletTransport {
} }
// Draw send content. // Draw send content.
self.tor_send_ui(ui, wallet, cb); self.tor_send_ui(ui, cb);
} }
/// Draw Tor transport header content. /// Draw Tor transport header content.
fn tor_header_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) { fn tor_header_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet) {
// Setup layout size. // Setup layout size.
let mut rect = ui.available_rect_before_wrap(); let mut rect = ui.available_rect_before_wrap();
rect.set_height(78.0); rect.set_height(78.0);
@ -173,7 +181,11 @@ impl WalletTransport {
// Draw button to setup Tor transport. // Draw button to setup Tor transport.
let button_rounding = View::item_rounding(0, 2, true); let button_rounding = View::item_rounding(0, 2, true);
View::item_button(ui, button_rounding, GEAR_SIX, None, || { View::item_button(ui, button_rounding, GEAR_SIX, None, || {
//TODO: tor settings // Show modal.
Modal::new(TOR_SETTINGS_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("transport.tor_settings"))
.show();
}); });
// Draw button to enable/disable Tor listener for current wallet. // Draw button to enable/disable Tor listener for current wallet.
@ -202,7 +214,9 @@ impl WalletTransport {
// Setup wallet API address text. // Setup wallet API address text.
let port = wallet.foreign_api_port().unwrap(); let port = wallet.foreign_api_port().unwrap();
let address_text = format!("{} http://127.0.0.1:{}", GLOBE_SIMPLE, port); let address_text = format!("{} http://127.0.0.1:{}",
COMPUTER_TOWER,
port);
ui.label(RichText::new(address_text).size(15.0).color(Colors::TEXT)); ui.label(RichText::new(address_text).size(15.0).color(Colors::TEXT));
ui.add_space(1.0); ui.add_space(1.0);
@ -227,6 +241,29 @@ impl WalletTransport {
}); });
} }
/// Draw tor transport settings [`Modal`] content.
fn tor_settings_modal_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet, modal: &Modal) {
ui.add_space(6.0);
ui.vertical_centered(|ui| {
ui.label(RichText::new(t!("transport.tor_autorun_desc"))
.size(17.0)
.color(Colors::INACTIVE_TEXT));
// Show Tor service autorun checkbox.
let autorun = wallet.auto_start_tor_listener();
View::checkbox(ui, autorun, t!("network.autorun"), || {
wallet.update_auto_start_tor_listener(!autorun);
});
});
ui.add_space(6.0);
ui.vertical_centered_justified(|ui| {
View::button(ui, t!("close"), Colors::WHITE, || {
modal.close();
});
ui.add_space(6.0);
});
}
/// Draw Tor send content. /// Draw Tor send content.
fn tor_receive_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) { fn tor_receive_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) {
let slatepack_addr = wallet.slatepack_address().unwrap(); let slatepack_addr = wallet.slatepack_address().unwrap();
@ -281,7 +318,7 @@ impl WalletTransport {
} }
/// Draw Tor receive content. /// Draw Tor receive content.
fn tor_send_ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) { fn tor_send_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
// Setup layout size. // Setup layout size.
let mut rect = ui.available_rect_before_wrap(); let mut rect = ui.available_rect_before_wrap();
rect.set_height(55.0); rect.set_height(55.0);
@ -494,9 +531,11 @@ impl WalletTransport {
ui.add_space(6.0); ui.add_space(6.0);
} else if has_send_err { } else if has_send_err {
ui.add_space(6.0); ui.add_space(6.0);
ui.label(RichText::new(t!("transport.tor_send_error")) ui.vertical_centered(|ui| {
.size(17.0) ui.label(RichText::new(t!("transport.tor_send_error"))
.color(Colors::RED)); .size(17.0)
.color(Colors::RED));
});
ui.add_space(12.0); ui.add_space(12.0);
// Setup spacing between buttons. // Setup spacing between buttons.
@ -549,6 +588,7 @@ impl WalletTransport {
}); });
}); });
}); });
ui.add_space(6.0);
} else { } else {
ui.add_space(16.0); ui.add_space(16.0);
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
@ -556,7 +596,7 @@ impl WalletTransport {
ui.add_space(12.0); ui.add_space(12.0);
ui.label(RichText::new(t!("transport.tor_sending")) ui.label(RichText::new(t!("transport.tor_sending"))
.size(17.0) .size(17.0)
.color(Colors::TEXT)); .color(Colors::GRAY));
}); });
ui.add_space(10.0); ui.add_space(10.0);

View file

@ -728,17 +728,21 @@ impl Wallet {
return None; return None;
} }
// Slatepack message json value.
let slate_value = res["result"]["Ok"].clone(); let slate_value = res["result"]["Ok"].clone();
println!("slate_value: {}", slate_value);
let mut ret_slate = None; let mut ret_slate = None;
match Slate::deserialize_upgrade(&serde_json::to_string(&slate_value).unwrap()) { match Slate::deserialize_upgrade(&serde_json::to_string(&slate_value).unwrap()) {
Ok(s) => { Ok(s) => {
let mut api = Owner::new(self.instance.clone().unwrap(), None); let mut api = Owner::new(self.instance.clone().unwrap(), None);
controller::owner_single_use(None, None, Some(&mut api), |api, m| { controller::owner_single_use(None, None, Some(&mut api), |api, m| {
// Finalize transaction.
return if let Ok(slate) = api.finalize_tx(m, &s) { return if let Ok(slate) = api.finalize_tx(m, &s) {
ret_slate = Some(slate.clone()); ret_slate = Some(slate.clone());
let result = api.post_tx(m, &slate, self.can_use_dandelion()); // Save Slatepack message to file.
let _ = self.create_slatepack_message(&slate).unwrap_or("".to_string());
// Post transaction to blockchain.
let result = self.post(&slate, self.can_use_dandelion());
match result { match result {
Ok(_) => { Ok(_) => {
println!("Tx sent successfully", ); println!("Tx sent successfully", );
@ -828,8 +832,9 @@ impl Wallet {
let mut slate = self.parse_slatepack(message)?; let mut slate = self.parse_slatepack(message)?;
let api = Owner::new(self.instance.clone().unwrap(), None); let api = Owner::new(self.instance.clone().unwrap(), None);
slate = api.finalize_tx(None, &slate)?; slate = api.finalize_tx(None, &slate)?;
// Post transaction to blockchain. // Save Slatepack message to file.
let _ = self.create_slatepack_message(&slate)?; let _ = self.create_slatepack_message(&slate)?;
// Post transaction to blockchain.
let _ = self.post(&slate, dandelion); let _ = self.post(&slate, dandelion);
// Sync wallet info. // Sync wallet info.
self.sync(); self.sync();