wallet + ui: sending and receiving rework, ability to use dandelion on broadcast, remove node restart modal, fix txs statuses

This commit is contained in:
ardocrat 2024-04-18 05:20:49 +03:00
parent fa71dc2ada
commit 7e2e08530b
15 changed files with 469 additions and 392 deletions

View file

@ -64,19 +64,27 @@ wallets:
tx_cancelling: Cancelling tx_cancelling: Cancelling
tx_canceled: Canceled tx_canceled: Canceled
tx_confirmed: Confirmed tx_confirmed: Confirmed
manually: Manually txs: Transactions
receive_slatepack_desc: 'Enter Slatepack message received from the sender to create response or finalize the transaction:' messages: Messages
receive_send_slatepack: 'Send Slatepack message to the sender to finalize the transaction:' transport: Transport
receive_slatepack_err: 'An error occurred during creation of the response, check input data:' input_slatepack_desc: 'Enter received message to create a response or finalize the transaction:'
create_response: Create response send_slatepack_desc: 'Send message to the receiver to finalize the transaction:'
invoice: Invoice parse_slatepack_err: 'An error occurred during handling of the message, check input data:'
issue_invoice: Issue invoice parse_i1_slatepack_desc: 'To pay %{amount} ツ send message to the receiver:'
issue_invoice_desc: 'Create a request to receive funds by entering the required amount:' parse_i2_slatepack_desc: 'Finalize transaction to receive %{amount} ツ'
invoice_desc: 'You have created a request to receive %{amount} ツ. Send Slatepack message to the sender:' parse_s1_slatepack_desc: 'To receive %{amount} ツ send message to the sender:'
parse_s2_slatepack_desc: 'Finalize transaction to send %{amount} ツ'
response_slatepack_err: 'An error occurred during creation of the response, check input data:'
create_request_desc: 'Create a request to send or receive the funds:'
send_request_desc: 'You have created a request to send %{amount} ツ. Send message to the receiver of the funds:'
send_slatepack_err: An error occurred during creation of request to send funds, check input data.
invoice_desc: 'You have created a request to receive %{amount} ツ. Send message to the sender of the funds:'
invoice_slatepack_err: An error occurred during issuing of the invoice, check input data. invoice_slatepack_err: An error occurred during issuing of the invoice, check input data.
finalize_slatepack_err: 'An error occurred during finalization of the transaction, check input data:' finalize_slatepack_err: 'An error occurred during finalization, check input data:'
finalize: Finalize finalize: Finalize
enter_amount: 'Enter amount:' use_dandelion: Use Dandelion
enter_amount_send: 'You have %{amount} ツ. Enter amount to send:'
enter_amount_receive: 'Enter amount to receive:'
recovery: Recovery recovery: Recovery
repair_wallet: Repair wallet repair_wallet: Repair wallet
repair_desc: Check a wallet, repairing and restoring missing outputs if required. This operation will take time. repair_desc: Check a wallet, repairing and restoring missing outputs if required. This operation will take time.

View file

@ -64,19 +64,27 @@ wallets:
tx_cancelling: Отмена tx_cancelling: Отмена
tx_canceled: Отменено tx_canceled: Отменено
tx_confirmed: Подтверждено tx_confirmed: Подтверждено
manually: Вручную txs: Транзакции
receive_slatepack_desc: 'Введите Slatepack сообщение, полученное от отправителя, для создания ответа или завершения транзакции:' messages: Сообщения
receive_send_slatepack: 'Отправьте Slatepack сообщение отправителю для завершения транзакции:' transport: Транспорт
receive_slatepack_err: 'Во время создания ответа произошла ошибка, проверьте входные данные:' input_slatepack_desc: 'Введите полученное сообщение для создания ответа или завершения транзакции:'
create_response: Создать ответ send_slatepack_desc: 'Отправьте сообщение получателю средств для завершения транзакции:'
invoice: Инвойс parse_slatepack_err: 'Во время обработки сообщения произошла ошибка, проверьте входные данные:'
issue_invoice: Выставить счёт parse_i1_slatepack_desc: 'Для оплаты %{amount} ツ отправьте сообщение получателю:'
issue_invoice_desc: 'Создайте запрос на получение средств, введя требуемое количество:' parse_i2_slatepack_desc: 'Завершите транзакцию для получения %{amount} ツ'
invoice_desc: 'Вы создали запрос на получение %{amount} ツ. Отправьте Slatepack сообщение отправителю:' parse_s1_slatepack_desc: 'Для получения %{amount} ツ отправьте сообщение отправителю:'
parse_s2_slatepack_desc: 'Завершите транзакцию для отправки %{amount} ツ'
response_slatepack_err: 'Во время создания ответа произошла ошибка, проверьте входные данные:'
create_request_desc: 'Cоздать запрос на получение или отправку средств:'
send_request_desc: 'Вы создали запрос на отправку %{amount} ツ. Отправьте сообщение получателю средств:'
send_slatepack_err: Во время создания запроса на отправку средств произошла ошибка, проверьте входные данные.
invoice_desc: 'Вы создали запрос на получение %{amount} ツ. Отправьте сообщение отправителю средств:'
invoice_slatepack_err: Во время выставления счёта произошла ошибка, проверьте входные данные. invoice_slatepack_err: Во время выставления счёта произошла ошибка, проверьте входные данные.
finalize_slatepack_err: 'Во время завершения транзакции произошла ошибка, проверьте входные данные:' finalize_slatepack_err: 'Во время завершения произошла ошибка, проверьте входные данные:'
finalize: Завершить finalize: Завершить
enter_amount: 'Введите количество:' use_dandelion: Использовать Dandelion
enter_amount_send: 'У вас есть %{amount} ツ. Введите количество для отправки:'
enter_amount_receive: 'Введите количество для получения:'
recovery: Восстановление recovery: Восстановление
repair_wallet: Починить кошелёк repair_wallet: Починить кошелёк
repair_desc: Проверить кошелёк, исправляя и восстанавливая недостающие выходы, если это необходимо. Эта операция займёт время. repair_desc: Проверить кошелёк, исправляя и восстанавливая недостающие выходы, если это необходимо. Эта операция займёт время.

View file

@ -40,8 +40,6 @@ pub struct NetworkSettings {
modal_ids: Vec<&'static str> modal_ids: Vec<&'static str>
} }
/// Identifier for node restart confirmation [`Modal`].
pub const NODE_RESTART_REQUIRED_MODAL: &'static str = "node_restart_required";
/// Identifier for settings reset confirmation [`Modal`]. /// Identifier for settings reset confirmation [`Modal`].
pub const RESET_SETTINGS_MODAL: &'static str = "reset_settings"; pub const RESET_SETTINGS_MODAL: &'static str = "reset_settings";
@ -54,7 +52,6 @@ impl Default for NetworkSettings {
pool: PoolSetup::default(), pool: PoolSetup::default(),
dandelion: DandelionSetup::default(), dandelion: DandelionSetup::default(),
modal_ids: vec![ modal_ids: vec![
NODE_RESTART_REQUIRED_MODAL,
RESET_SETTINGS_MODAL RESET_SETTINGS_MODAL
] ]
} }
@ -72,7 +69,6 @@ impl ModalContainer for NetworkSettings {
modal: &Modal, modal: &Modal,
_: &dyn PlatformCallbacks) { _: &dyn PlatformCallbacks) {
match modal.id { match modal.id {
NODE_RESTART_REQUIRED_MODAL => node_restart_required_modal(ui, modal),
RESET_SETTINGS_MODAL => reset_settings_confirmation_modal(ui, modal), RESET_SETTINGS_MODAL => reset_settings_confirmation_modal(ui, modal),
_ => {} _ => {}
} }
@ -147,17 +143,6 @@ impl NetworkSettings {
} }
} }
/// Show [`Modal`] to ask node restart if setting is changed on enabled node.
pub fn show_node_restart_required_modal() {
if Node::is_running() {
// Show modal to apply changes by node restart.
Modal::new(NODE_RESTART_REQUIRED_MODAL)
.position(ModalPosition::Center)
.title(t!("network.settings"))
.show();
}
}
/// Draw IP addresses as radio buttons. /// Draw IP addresses as radio buttons.
pub fn ip_addrs_ui(ui: &mut egui::Ui, pub fn ip_addrs_ui(ui: &mut egui::Ui,
saved_ip: &String, saved_ip: &String,
@ -209,38 +194,6 @@ impl NetworkSettings {
} }
} }
/// Node restart reminder modal content.
fn node_restart_required_modal(ui: &mut egui::Ui, modal: &Modal) {
ui.add_space(6.0);
ui.vertical_centered(|ui| {
ui.label(RichText::new(t!("network_settings.restart_node_required"))
.size(17.0)
.color(Colors::GRAY));
ui.add_space(8.0);
});
// Show modal buttons.
ui.scope(|ui| {
// 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!("network_settings.restart"), Colors::WHITE, || {
Node::restart();
modal.close();
});
});
columns[1].vertical_centered_justified(|ui| {
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
modal.close();
});
});
});
ui.add_space(6.0);
});
}
/// Draw button to reset integrated node settings to default values. /// Draw button to reset integrated node settings to default values.
fn reset_settings_ui(ui: &mut egui::Ui) { fn reset_settings_ui(ui: &mut egui::Ui) {
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {

View file

@ -243,7 +243,9 @@ impl NodeSetup {
if saved_chain_type != selected_chain_type { if saved_chain_type != selected_chain_type {
AppConfig::change_chain_type(&selected_chain_type); AppConfig::change_chain_type(&selected_chain_type);
NetworkSettings::show_node_restart_required_modal(); if Node::is_running() {
Node::restart();
}
} }
} }
@ -520,7 +522,9 @@ impl NodeSetup {
let validate = NodeConfig::is_full_chain_validation(); let validate = NodeConfig::is_full_chain_validation();
View::checkbox(ui, validate, t!("network_settings.full_validation"), || { View::checkbox(ui, validate, t!("network_settings.full_validation"), || {
NodeConfig::toggle_full_chain_validation(); NodeConfig::toggle_full_chain_validation();
NetworkSettings::show_node_restart_required_modal(); if Node::is_running() {
Node::restart();
}
}); });
ui.add_space(4.0); ui.add_space(4.0);
ui.label(RichText::new(t!("network_settings.full_validation_description")) ui.label(RichText::new(t!("network_settings.full_validation_description"))
@ -534,7 +538,9 @@ impl NodeSetup {
let archive_mode = NodeConfig::is_archive_mode(); let archive_mode = NodeConfig::is_archive_mode();
View::checkbox(ui, archive_mode, t!("network_settings.archive_mode"), || { View::checkbox(ui, archive_mode, t!("network_settings.archive_mode"), || {
NodeConfig::toggle_archive_mode(); NodeConfig::toggle_archive_mode();
NetworkSettings::show_node_restart_required_modal(); if Node::is_running() {
Node::restart();
}
}); });
ui.add_space(4.0); ui.add_space(4.0);
ui.label(RichText::new(t!("network_settings.archive_mode_desc")) ui.label(RichText::new(t!("network_settings.archive_mode_desc"))

View file

@ -363,13 +363,10 @@ impl View {
let mut r = range.clone(); let mut r = range.clone();
let mut index = r.primary.index; let mut index = r.primary.index;
println!("insert_str {} {}", index, w_input.as_str());
value.insert_text(w_input.as_str(), index); value.insert_text(w_input.as_str(), index);
index = index + 1; index = index + 1;
println!("12345 {} {}", value, r.primary.index);
if index == 0 { if index == 0 {
r.primary.index = value.len(); r.primary.index = value.len();
r.secondary.index = r.primary.index; r.secondary.index = r.primary.index;

View file

@ -160,15 +160,15 @@ impl WalletsContent {
}); });
// Flag to check if wallet list is hidden on the screen. // Flag to check if wallet list is hidden on the screen.
let list_hidden = content_width == 0.0 let list_hidden = content_width == 0.0 || empty_list || create_wallet
|| (dual_panel && show_wallet && !self.show_wallets_at_dual_panel) || (dual_panel && show_wallet && !self.show_wallets_at_dual_panel)
|| (!dual_panel && show_wallet); || (!dual_panel && show_wallet);
// Setup flag to show wallets bottom panel if wallet is not showing // Setup flag to show wallets bottom panel if wallet is not showing
// at non-dual panel mode and network is no open or showing at dual panel mode. // at non-dual panel mode and network is no open or showing at dual panel mode.
let show_bottom_panel = let show_bottom_panel = !list_hidden &&
(!show_wallet && !dual_panel && !Root::is_network_panel_open()) || ((!show_wallet && !dual_panel && !Root::is_network_panel_open()) ||
(dual_panel && show_wallet); (dual_panel && show_wallet));
// Show wallets bottom panel. // Show wallets bottom panel.
egui::TopBottomPanel::bottom("wallets_bottom_panel") egui::TopBottomPanel::bottom("wallets_bottom_panel")
@ -183,7 +183,7 @@ impl WalletsContent {
}, },
..Default::default() ..Default::default()
}) })
.show_animated_inside(ui, !create_wallet && !list_hidden && show_bottom_panel, |ui| { .show_animated_inside(ui, show_bottom_panel, |ui| {
// Setup vertical padding inside buttons. // Setup vertical padding inside buttons.
ui.style_mut().spacing.button_padding = egui::vec2(10.0, 4.0); ui.style_mut().spacing.button_padding = egui::vec2(10.0, 4.0);
@ -195,8 +195,8 @@ impl WalletsContent {
}); });
}); });
// Show non-empty list if wallet is not creating. // Show non-empty list if wallet is not creating and list not hidden.
if !empty_list && !create_wallet { if !list_hidden {
// Show wallet list panel. // Show wallet list panel.
egui::CentralPanel::default() egui::CentralPanel::default()
.frame(egui::Frame { .frame(egui::Frame {
@ -219,10 +219,6 @@ impl WalletsContent {
..Default::default() ..Default::default()
}) })
.show_inside(ui, |ui| { .show_inside(ui, |ui| {
// Do not draw content when list is hidden.
if list_hidden {
return;
}
// Show list of wallets. // Show list of wallets.
self.wallet_list_ui(ui, dual_panel, cb); self.wallet_list_ui(ui, dual_panel, cb);
}); });
@ -336,7 +332,7 @@ impl WalletsContent {
ui.style_mut().visuals.widgets.hovered.bg_fill = Colors::STROKE; ui.style_mut().visuals.widgets.hovered.bg_fill = Colors::STROKE;
// Draw list of wallets. // Draw list of wallets.
let scroll = ScrollArea::vertical() ScrollArea::vertical()
.id_source("wallet_list") .id_source("wallet_list")
.auto_shrink([false; 2]) .auto_shrink([false; 2])
.show(ui, |ui| { .show(ui, |ui| {

View file

@ -20,11 +20,11 @@ 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::{CHECK, CHECK_FAT, DOWNLOAD, FILE_ARCHIVE, GEAR_FINE, LIST, PACKAGE, PLUS, POWER, REPEAT, UPLOAD, WALLET}; use crate::gui::icons::{BRIDGE, CHAT_CIRCLE_TEXT, CHECK, CHECK_FAT, FILE_ARCHIVE, GEAR_FINE, LIST, PACKAGE, PLUS, POWER, REPEAT, WALLET};
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};
use crate::gui::views::wallets::{WalletInfo, WalletReceive, WalletSend, WalletSettings}; use crate::gui::views::wallets::{WalletInfo, WalletMessages, WalletTransport, WalletSettings};
use crate::gui::views::wallets::types::{GRIN, WalletTab, WalletTabType}; use crate::gui::views::wallets::types::{GRIN, WalletTab, WalletTabType};
use crate::node::Node; use crate::node::Node;
use crate::wallet::{Wallet, WalletConfig}; use crate::wallet::{Wallet, WalletConfig};
@ -351,18 +351,18 @@ impl WalletContent {
let current_type = self.current_tab.get_type(); let current_type = self.current_tab.get_type();
ui.columns(4, |columns| { ui.columns(4, |columns| {
columns[0].vertical_centered_justified(|ui| { columns[0].vertical_centered_justified(|ui| {
View::tab_button(ui, WALLET, current_type == WalletTabType::Info, || { View::tab_button(ui, WALLET, current_type == WalletTabType::Txs, || {
self.current_tab = Box::new(WalletInfo::default()); self.current_tab = Box::new(WalletInfo::default());
}); });
}); });
columns[1].vertical_centered_justified(|ui| { columns[1].vertical_centered_justified(|ui| {
View::tab_button(ui, DOWNLOAD, current_type == WalletTabType::Receive, || { View::tab_button(ui, CHAT_CIRCLE_TEXT, current_type == WalletTabType::Messages, || {
self.current_tab = Box::new(WalletReceive::default()); self.current_tab = Box::new(WalletMessages::default());
}); });
}); });
columns[2].vertical_centered_justified(|ui| { columns[2].vertical_centered_justified(|ui| {
View::tab_button(ui, UPLOAD, current_type == WalletTabType::Send, || { View::tab_button(ui, BRIDGE, current_type == WalletTabType::Transport, || {
self.current_tab = Box::new(WalletSend::default()); self.current_tab = Box::new(WalletTransport::default());
}); });
}); });
columns[3].vertical_centered_justified(|ui| { columns[3].vertical_centered_justified(|ui| {

View file

@ -15,9 +15,10 @@
use egui::{Id, Margin, RichText, ScrollArea}; use egui::{Id, Margin, RichText, ScrollArea};
use egui::scroll_area::ScrollBarVisibility; use egui::scroll_area::ScrollBarVisibility;
use grin_core::core::{amount_from_hr_string, amount_to_hr_string}; use grin_core::core::{amount_from_hr_string, amount_to_hr_string};
use grin_wallet_libwallet::{Slate, SlateState, TxLogEntry};
use crate::gui::Colors; use crate::gui::Colors;
use crate::gui::icons::{BROOM, CLIPBOARD_TEXT, COPY, HAND_COINS, RECEIPT}; use crate::gui::icons::{BROOM, CLIPBOARD_TEXT, COPY, DOWNLOAD, UPLOAD};
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};
@ -25,52 +26,58 @@ use crate::gui::views::wallets::wallet::types::{SLATEPACK_MESSAGE_HINT, WalletTa
use crate::gui::views::wallets::wallet::WalletContent; use crate::gui::views::wallets::wallet::WalletContent;
use crate::wallet::Wallet; use crate::wallet::Wallet;
/// Receiving tab content. /// Slatepacks messages interaction tab content.
pub struct WalletReceive { pub struct WalletMessages {
/// Flag to check if there is invoice transaction type. /// Flag to check if send or receive request was opened.
is_invoice: bool, send_request: bool,
/// Slatepack message from sender to create response message. /// Slatepack message to create response message.
message_edit: String, message_edit: String,
/// Generated Slatepack response message for sender. /// Parsed Slatepack message.
message_slate: Option<Slate>,
/// Flag to check if there is an error happened on response creation.
parse_error: bool,
/// Generated Slatepack response message.
response_edit: String, response_edit: String,
/// Flag to check if there is an error happened on response creation. /// Flag to check if there is an error happened on response creation.
response_error: bool, response_error: bool,
/// Flag to check if there is an error happened on transaction finalization.
finalize_error: bool,
/// Flag to check if Dandelion is needed to finalize transaction.
use_dandelion: Option<bool>,
/// Amount to receive for invoice transaction type. /// Amount to send or receive.
amount_edit: String, amount_edit: String,
/// Generated Slatepack message for invoice transaction. /// Generated Slatepack message as request to send or receive funds.
request_edit: String, request_edit: String,
/// Flag to check if there is an error happened on invoice creation. /// Flag to check if there is an error happened on invoice creation.
request_error: bool, request_error: bool,
/// Slatepack message from sender to finalize transaction.
finalization_edit: String,
/// Flag to check if there is an error happened on transaction finalization.
finalization_error: bool,
} }
/// Identifier for invoice amount [`Modal`]. /// Identifier for invoice amount [`Modal`].
const INVOICE_AMOUNT_MODAL: &'static str = "invoice_amount_modal"; const AMOUNT_MODAL: &'static str = "amount_modal";
impl Default for WalletReceive { impl Default for WalletMessages {
fn default() -> Self { fn default() -> Self {
Self { Self {
is_invoice: false, send_request: false,
message_edit: "".to_string(), message_edit: "".to_string(),
message_slate: None,
parse_error: false,
response_edit: "".to_string(), response_edit: "".to_string(),
response_error: false, response_error: false,
finalize_error: false,
use_dandelion: None,
amount_edit: "".to_string(), amount_edit: "".to_string(),
request_edit: "".to_string(), request_edit: "".to_string(),
request_error: false, request_error: false,
finalization_edit: "".to_string(),
finalization_error: false,
} }
} }
} }
impl WalletTab for WalletReceive { impl WalletTab for WalletMessages {
fn get_type(&self) -> WalletTabType { fn get_type(&self) -> WalletTabType {
WalletTabType::Receive WalletTabType::Messages
} }
fn ui(&mut self, fn ui(&mut self,
@ -85,7 +92,7 @@ impl WalletTab for WalletReceive {
// Show modal content for this ui container. // Show modal content for this ui container.
self.modal_content_ui(ui, wallet, cb); self.modal_content_ui(ui, wallet, cb);
// Show receiving content panel. // Show manual wallet content panel.
egui::CentralPanel::default() egui::CentralPanel::default()
.frame(egui::Frame { .frame(egui::Frame {
stroke: View::ITEM_STROKE, stroke: View::ITEM_STROKE,
@ -101,12 +108,12 @@ impl WalletTab for WalletReceive {
.show_inside(ui, |ui| { .show_inside(ui, |ui| {
ScrollArea::vertical() ScrollArea::vertical()
.scroll_bar_visibility(ScrollBarVisibility::AlwaysVisible) .scroll_bar_visibility(ScrollBarVisibility::AlwaysVisible)
.id_source(Id::from("wallet_receive").with(wallet.get_config().id)) .id_source(Id::from("wallet_manual").with(wallet.get_config().id))
.auto_shrink([false; 2]) .auto_shrink([false; 2])
.show(ui, |ui| { .show(ui, |ui| {
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| { View::max_width_ui(ui, Root::SIDE_PANEL_WIDTH * 1.3, |ui| {
self.receive_ui(ui, wallet, cb); self.ui(ui, wallet, cb);
}); });
}); });
}); });
@ -114,18 +121,25 @@ impl WalletTab for WalletReceive {
} }
} }
impl WalletReceive { impl WalletMessages {
/// Draw receiving content. /// Draw manual wallet transaction interaction content.
pub fn receive_ui(&mut self, pub fn ui(&mut self,
ui: &mut egui::Ui, ui: &mut egui::Ui,
wallet: &mut Wallet, wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) { cb: &dyn PlatformCallbacks) {
ui.add_space(2.0); ui.add_space(4.0);
View::sub_title(ui, format!("{} {}", HAND_COINS, t!("wallets.manually")));
// Show creation of request to send or receive funds.
self.request_ui(ui, cb);
ui.add_space(12.0);
View::horizontal_line(ui, Colors::ITEM_STROKE); View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(3.0); ui.add_space(8.0);
// Show manual receiving content.
self.manual_ui(ui, wallet, cb); // Show Slatepack message input field.
self.input_slatepack_ui(ui, wallet, cb);
ui.add_space(6.0);
} }
/// Draw [`Modal`] content for this ui container. /// Draw [`Modal`] content for this ui container.
@ -137,9 +151,9 @@ impl WalletReceive {
None => {} None => {}
Some(id) => { Some(id) => {
match id { match id {
INVOICE_AMOUNT_MODAL => { AMOUNT_MODAL => {
Modal::ui(ui.ctx(), |ui, modal| { Modal::ui(ui.ctx(), |ui, modal| {
self.invoice_amount_modal(ui, wallet, modal, cb); self.amount_modal_ui(ui, wallet, modal, cb);
}); });
} }
_ => {} _ => {}
@ -148,73 +162,67 @@ impl WalletReceive {
} }
} }
/// Draw manual receiving content. /// Draw Slatepack message input content.
fn manual_ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) { fn input_slatepack_ui(&mut self,
ui.add_space(10.0); ui: &mut egui::Ui,
ui.columns(2, |columns| { wallet: &mut Wallet,
let mut is_invoice = self.is_invoice; cb: &dyn PlatformCallbacks) {
columns[0].vertical_centered(|ui| {
View::radio_value(ui, &mut is_invoice, false, t!("wallets.receive"));
});
columns[1].vertical_centered(|ui| {
View::radio_value(ui, &mut is_invoice, true, t!("wallets.invoice"));
});
if is_invoice != self.is_invoice {
self.is_invoice = is_invoice;
// Reset fields to default values on mode change.
if is_invoice {
self.amount_edit = "".to_string();
self.request_edit = "".to_string();
self.request_error = false;
self.finalization_edit = "".to_string();
self.finalization_error = false;
} else {
self.message_edit = "".to_string();
self.response_edit = "".to_string();
self.response_error = false;
}
}
});
ui.add_space(10.0);
if self.is_invoice {
// Show invoice creation content.
self.manual_invoice_ui(ui, wallet, cb);
} else {
// Show manual transaction receiving content.
self.manual_receive_ui(ui, wallet, cb);
}
}
/// Draw manual receiving content.
fn manual_receive_ui(&mut self,
ui: &mut egui::Ui,
wallet: &mut Wallet,
cb: &dyn PlatformCallbacks) {
// Setup description. // Setup description.
let response_empty = self.response_edit.is_empty(); let response_empty = self.response_edit.is_empty();
if self.parse_error {
if self.response_error { ui.label(RichText::new(t!("wallets.parse_slatepack_err"))
ui.label(RichText::new(t!("wallets.receive_slatepack_err")) .size(16.0)
.color(Colors::RED));
} else if self.response_error {
ui.label(RichText::new(t!("wallets.response_slatepack_err"))
.size(16.0)
.color(Colors::RED));
} else if self.finalize_error {
ui.label(RichText::new(t!("wallets.finalize_slatepack_err"))
.size(16.0) .size(16.0)
.color(Colors::RED)); .color(Colors::RED));
} else { } else {
let desc_text = if response_empty { let desc_text = if response_empty && self.message_slate.is_none() {
t!("wallets.receive_slatepack_desc") t!("wallets.input_slatepack_desc")
} else { } else {
t!("wallets.receive_send_slatepack") let slate = self.message_slate.as_ref().unwrap();
let amount = amount_to_hr_string(slate.amount, true);
match slate.state {
SlateState::Standard1 => {
t!("wallets.parse_s1_slatepack_desc","amount" => amount)
}
SlateState::Standard2 => {
t!("wallets.parse_s2_slatepack_desc","amount" => amount)
}
SlateState::Standard3 => {t!("wallets.input_slatepack_desc")}
SlateState::Invoice1 => {
let a_f = u64::from(slate.fee_fields) + slate.amount;
let a = amount_to_hr_string(a_f, true);
t!("wallets.parse_i1_slatepack_desc","amount" => a)
}
SlateState::Invoice2 => {
t!("wallets.parse_i2_slatepack_desc","amount" => amount)
}
SlateState::Invoice3 => {t!("wallets.input_slatepack_desc")}
_ => {
t!("wallets.input_slatepack_desc")
}
}
}; };
ui.label(RichText::new(desc_text).size(16.0).color(Colors::INACTIVE_TEXT)); ui.label(RichText::new(desc_text).size(16.0).color(Colors::INACTIVE_TEXT));
} }
ui.add_space(6.0); ui.add_space(7.0);
// Setup Slatepack message text input. // Setup Slatepack message text input.
let message = if response_empty { let mut message = if response_empty {
&mut self.message_edit &mut self.message_edit
} else { } else {
&mut self.response_edit &mut self.response_edit
}; };
// Save message to check for changes.
let message_before = message.clone();
View::horizontal_line(ui, Colors::ITEM_STROKE); View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(3.0); ui.add_space(3.0);
ScrollArea::vertical() ScrollArea::vertical()
@ -223,7 +231,6 @@ impl WalletReceive {
.auto_shrink([false; 2]) .auto_shrink([false; 2])
.show(ui, |ui| { .show(ui, |ui| {
ui.add_space(7.0); ui.add_space(7.0);
let message_before = message.clone();
egui::TextEdit::multiline(message) egui::TextEdit::multiline(message)
.font(egui::TextStyle::Small) .font(egui::TextStyle::Small)
.desired_rows(5) .desired_rows(5)
@ -231,10 +238,6 @@ impl WalletReceive {
.hint_text(SLATEPACK_MESSAGE_HINT) .hint_text(SLATEPACK_MESSAGE_HINT)
.desired_width(f32::INFINITY) .desired_width(f32::INFINITY)
.show(ui); .show(ui);
// Clear an error when message changed.
if &message_before != message {
self.response_error = false;
}
ui.add_space(6.0); ui.add_space(6.0);
}); });
ui.add_space(2.0); ui.add_space(2.0);
@ -242,26 +245,21 @@ impl WalletReceive {
ui.add_space(10.0); ui.add_space(10.0);
// Draw buttons to clear/copy/paste. // Draw buttons to clear/copy/paste.
let field_is_empty = self.message_edit.is_empty() && self.response_edit.is_empty(); let fields_empty = self.message_edit.is_empty() && self.response_edit.is_empty();
let columns_num = if !field_is_empty { 2 } else { 1 }; let columns_num = if fields_empty { 1 } else { 2 };
let mut show_dandelion = false;
ui.scope(|ui| { ui.scope(|ui| {
// Setup spacing between buttons. // Setup spacing between buttons.
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0); ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
ui.columns(columns_num, |columns| { ui.columns(columns_num, |columns| {
let first_column_content = |ui: &mut egui::Ui| { let first_column_content = |ui: &mut egui::Ui| {
if !self.response_edit.is_empty() && !self.response_error { if self.message_slate.is_some() && !self.response_error && !self.parse_error {
let clear_text = format!("{} {}", BROOM, t!("clear")); self.clear_message_button_ui(ui);
View::button(ui, clear_text, Colors::BUTTON, || {
self.response_error = false;
self.message_edit.clear();
self.response_edit.clear();
});
} else { } else {
let paste_text = format!("{} {}", CLIPBOARD_TEXT, t!("paste")); let paste_text = format!("{} {}", CLIPBOARD_TEXT, t!("paste"));
View::button(ui, paste_text, Colors::BUTTON, || { View::button(ui, paste_text, Colors::BUTTON, || {
self.message_edit = cb.get_string_from_buffer(); self.message_edit = cb.get_string_from_buffer();
self.response_error = false;
}); });
} }
}; };
@ -270,30 +268,25 @@ impl WalletReceive {
} else { } else {
columns[0].vertical_centered_justified(first_column_content); columns[0].vertical_centered_justified(first_column_content);
columns[1].vertical_centered_justified(|ui| { columns[1].vertical_centered_justified(|ui| {
if self.response_error { if self.finalize_error || self.response_error || self.parse_error {
let clear_text = format!("{} {}", BROOM, t!("clear")); self.clear_message_button_ui(ui);
View::button(ui, clear_text, Colors::BUTTON, || {
self.response_error = false;
self.message_edit.clear();
self.response_edit.clear();
});
} else if !self.response_edit.is_empty() { } else if !self.response_edit.is_empty() {
let copy_text = format!("{} {}", COPY, t!("copy")); let copy_text = format!("{} {}", COPY, t!("copy"));
View::button(ui, copy_text, Colors::BUTTON, || { View::button(ui, copy_text, Colors::BUTTON, || {
cb.copy_string_to_buffer(self.response_edit.clone()); cb.copy_string_to_buffer(self.response_edit.clone());
}); });
} else { } else {
View::button(ui, t!("wallets.create_response"), Colors::GOLD, || { show_dandelion = true;
match wallet.receive(self.message_edit.clone()) { View::button(ui, t!("wallets.finalize"), Colors::GOLD, || {
Ok(response) => { let message = self.message_edit.clone();
self.response_edit = response.trim().to_string(); match wallet.finalize(message, self.use_dandelion.unwrap()) {
Ok(_) => {
self.message_edit.clear(); self.message_edit.clear();
cb.copy_string_to_buffer(response); self.message_slate = None;
}, },
Err(e) => { Err(e) => {
wallet.sync();
println!("error {}", e); println!("error {}", e);
self.response_error = true self.finalize_error = true
} }
} }
}); });
@ -302,108 +295,171 @@ impl WalletReceive {
} }
}); });
}); });
// Draw setup of ability to post transaction with Dandelion.
if show_dandelion {
if self.use_dandelion.is_none() {
self.use_dandelion = if let Some(u) = wallet.get_config().use_dandelion {
Some(u)
} else {
Some(true)
};
}
let use_dandelion = self.use_dandelion.unwrap();
View::checkbox(ui, use_dandelion, t!("wallets.use_dandelion"), || {
self.use_dandelion = Some(!use_dandelion);
wallet.update_use_dandelion(use_dandelion);
});
}
// Parse Slatepack message if input field was changed to setup response input.
message = if response_empty {
&mut self.message_edit
} else {
&mut self.response_edit
};
if &message_before != message {
if message.is_empty() {
self.message_slate = None;
}
self.response_error = false;
self.parse_error = false;
if !self.message_edit.is_empty() {
match wallet.parse_slatepack(self.message_edit.clone()) {
Ok(mut slate) => {
// Try to get amount from transaction by id.
if slate.amount == 0 {
let _ = wallet.get_data().unwrap().txs.clone().iter().map(|tx| {
if tx.tx_slate_id == Some(slate.id) {
slate.amount = if tx.amount_debited > tx.amount_credited {
tx.amount_debited - tx.amount_credited
} else {
tx.amount_credited - tx.amount_debited
}
}
tx
}).collect::<Vec<&TxLogEntry>>();
}
println!("SLATE: {}", slate);
self.message_slate = Some(slate.clone());
match slate.state {
SlateState::Unknown => {}
SlateState::Standard1 => {
match wallet.receive(self.message_edit.clone()) {
Ok(resp) => {
self.response_edit = resp;
}
Err(_) => {
self.response_error = true;
}
}
}
SlateState::Standard2 => {}
SlateState::Standard3 => {}
SlateState::Invoice1 => {
match wallet.pay(self.message_edit.clone()) {
Ok(resp) => {
self.response_edit = resp;
}
Err(_) => {
self.response_error = true;
}
}
}
SlateState::Invoice2 => {
}
SlateState::Invoice3 => {}
}
}
Err(_) => {
self.message_slate = None;
self.parse_error = true;
}
}
}
}
} }
/// Draw invoice creation content. /// Draw button to clear entered message, slate and errors.
fn manual_invoice_ui(&mut self, fn clear_message_button_ui(&mut self, ui: &mut egui::Ui) {
ui: &mut egui::Ui, let clear_text = format!("{} {}", BROOM, t!("clear"));
wallet: &mut Wallet, View::button(ui, clear_text, Colors::BUTTON, || {
cb: &dyn PlatformCallbacks) { self.response_error = false;
ui.label(RichText::new(t!("wallets.issue_invoice_desc")) self.parse_error = false;
.size(16.0) self.finalize_error = false;
.color(Colors::INACTIVE_TEXT)); self.message_edit.clear();
ui.add_space(6.0); self.response_edit.clear();
self.message_slate = None;
// Draw invoice creation button.
let invoice_text = format!("{} {}", RECEIPT, t!("wallets.issue_invoice"));
View::button(ui, invoice_text, Colors::BUTTON, || {
// Reset modal values.
self.amount_edit = "".to_string();
self.request_error = false;
// Show invoice amount modal.
Modal::new(INVOICE_AMOUNT_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.issue_invoice"))
.show();
cb.show_keyboard();
}); });
}
ui.add_space(12.0); /// Draw creation of request to send or receive funds.
View::horizontal_line(ui, Colors::ITEM_STROKE); fn request_ui(&mut self,
ui.add_space(6.0); ui: &mut egui::Ui,
ui.label(RichText::new(t!("wallets.receive_slatepack_desc")) cb: &dyn PlatformCallbacks) {
ui.label(RichText::new(t!("wallets.create_request_desc"))
.size(16.0) .size(16.0)
.color(Colors::INACTIVE_TEXT)); .color(Colors::INACTIVE_TEXT));
ui.add_space(6.0); ui.add_space(7.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(3.0);
// Draw invoice finalization text input. // Setup spacing between buttons.
ScrollArea::vertical() ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
.max_height(128.0)
.id_source(Id::from("receive_input").with(wallet.get_config().id))
.auto_shrink([false; 2])
.show(ui, |ui| {
ui.add_space(7.0);
let finalization_before = self.finalization_edit.clone();
egui::TextEdit::multiline(&mut self.finalization_edit)
.font(egui::TextStyle::Small)
.desired_rows(5)
.interactive(true)
.hint_text(SLATEPACK_MESSAGE_HINT)
.desired_width(f32::INFINITY)
.show(ui);
// Clear an error when message changed.
if finalization_before != self.finalization_edit {
self.finalization_error = false;
}
ui.add_space(6.0);
});
ui.add_space(2.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(10.0);
// Draw buttons to clear/paste. ui.columns(2, |columns| {
ui.scope(|ui| { columns[0].vertical_centered_justified(|ui| {
// Setup spacing between buttons. // Draw send request creation button.
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0); let send_text = format!("{} {}", UPLOAD, t!("wallets.send"));
View::button(ui, send_text.clone(), Colors::BUTTON, || {
ui.columns(2, |columns| { // Setup modal values.
columns[0].vertical_centered_justified(|ui| { self.send_request = true;
let paste_text = format!("{} {}", CLIPBOARD_TEXT, t!("paste")); self.amount_edit = "".to_string();
View::button(ui, paste_text, Colors::BUTTON, || { self.request_error = false;
self.finalization_edit = cb.get_string_from_buffer(); // Show send amount modal.
self.response_error = false; Modal::new(AMOUNT_MODAL)
}); .position(ModalPosition::CenterTop)
.title(t!("wallets.send"))
.show();
cb.show_keyboard();
}); });
columns[1].vertical_centered_justified(|ui| { });
View::button(ui, t!("wallets.finalize"), Colors::GOLD, || { columns[1].vertical_centered_justified(|ui| {
wallet.finalize(); // Draw invoice request creation button.
//TODO: finalize let receive_text = format!("{} {}", DOWNLOAD, t!("wallets.receive"));
}); View::button(ui, receive_text.clone(), Colors::BUTTON, || {
// Setup modal values.
self.send_request = false;
self.amount_edit = "".to_string();
self.request_error = false;
// Show receive amount modal.
Modal::new(AMOUNT_MODAL)
.position(ModalPosition::CenterTop)
.title(t!("wallets.receive"))
.show();
cb.show_keyboard();
}); });
}); });
}); });
if self.finalization_error {
ui.add_space(8.0);
ui.label(RichText::new(t!("wallets.finalize_slatepack_err"))
.size(16.0)
.color(Colors::RED));
}
ui.add_space(8.0);
} }
/// Draw invoice amount [`Modal`] content. /// Draw invoice amount [`Modal`] content.
fn invoice_amount_modal(&mut self, fn amount_modal_ui(&mut self,
ui: &mut egui::Ui, ui: &mut egui::Ui,
wallet: &mut Wallet, wallet: &mut Wallet,
modal: &Modal, modal: &Modal,
cb: &dyn PlatformCallbacks) { cb: &dyn PlatformCallbacks) {
ui.add_space(6.0); ui.add_space(6.0);
if self.request_edit.is_empty() { if self.request_edit.is_empty() {
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
ui.label(RichText::new(t!("wallets.enter_amount")) let enter_text = if self.send_request {
let data = wallet.get_data().unwrap();
let amount = amount_to_hr_string(data.info.amount_currently_spendable, true);
t!("wallets.enter_amount_send","amount" => amount)
} else {
t!("wallets.enter_amount_receive")
};
ui.label(RichText::new(enter_text)
.size(17.0) .size(17.0)
.color(Colors::GRAY)); .color(Colors::GRAY));
}); });
@ -447,10 +503,16 @@ impl WalletReceive {
}); });
}); });
columns[1].vertical_centered_justified(|ui| { columns[1].vertical_centered_justified(|ui| {
// Button to create Slatepack message for request.
View::button(ui, t!("continue"), Colors::WHITE, || { View::button(ui, t!("continue"), Colors::WHITE, || {
match amount_from_hr_string(self.amount_edit.as_str()) { match amount_from_hr_string(self.amount_edit.as_str()) {
Ok(amount) => { Ok(amount) => {
match wallet.issue_invoice(amount) { let message = if self.send_request {
wallet.send(amount)
} else {
wallet.issue_invoice(amount)
};
match message {
Ok(message) => { Ok(message) => {
self.request_edit = message; self.request_edit = message;
cb.hide_keyboard(); cb.hide_keyboard();
@ -473,16 +535,25 @@ impl WalletReceive {
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
let amount = amount_from_hr_string(self.amount_edit.as_str()).unwrap(); let amount = amount_from_hr_string(self.amount_edit.as_str()).unwrap();
let amount_format = amount_to_hr_string(amount, true); let amount_format = amount_to_hr_string(amount, true);
let desc_text = t!("wallets.invoice_desc","amount" => amount_format); let desc_text = if self.send_request {
t!("wallets.send_request_desc","amount" => amount_format)
} else {
t!("wallets.invoice_desc","amount" => amount_format)
};
ui.label(RichText::new(desc_text).size(16.0).color(Colors::INACTIVE_TEXT)); ui.label(RichText::new(desc_text).size(16.0).color(Colors::INACTIVE_TEXT));
ui.add_space(6.0); ui.add_space(6.0);
View::horizontal_line(ui, Colors::ITEM_STROKE); View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(3.0); ui.add_space(3.0);
// Draw invoice request text. // Draw output Slatepack message text.
let input_id = if self.send_request {
Id::from("send_request_output").with(wallet.get_config().id)
} else {
Id::from("receive_request_output").with(wallet.get_config().id)
};
ScrollArea::vertical() ScrollArea::vertical()
.max_height(128.0) .max_height(128.0)
.id_source(Id::from("receive_input").with(wallet.get_config().id)) .id_source(input_id)
.auto_shrink([false; 2]) .auto_shrink([false; 2])
.show(ui, |ui| { .show(ui, |ui| {
ui.add_space(7.0); ui.add_space(7.0);

View file

@ -14,14 +14,14 @@
pub mod types; pub mod types;
mod info; mod txs;
pub use info::WalletInfo; pub use txs::WalletInfo;
mod receive; mod messages;
pub use receive::WalletReceive; pub use messages::WalletMessages;
mod send; mod transport;
pub use send::WalletSend; pub use transport::WalletTransport;
mod settings; mod settings;
pub use settings::WalletSettings; pub use settings::WalletSettings;

View file

@ -22,11 +22,11 @@ use crate::wallet::Wallet;
/// Sending tab content. /// Sending tab content.
#[derive(Default)] #[derive(Default)]
pub struct WalletSend; pub struct WalletTransport;
impl WalletTab for WalletSend { impl WalletTab for WalletTransport {
fn get_type(&self) -> WalletTabType { fn get_type(&self) -> WalletTabType {
WalletTabType::Send WalletTabType::Transport
} }
fn ui(&mut self, fn ui(&mut self,
@ -38,7 +38,7 @@ impl WalletTab for WalletSend {
return; return;
} }
// Show sending content panel. // Show transport content panel.
egui::CentralPanel::default() egui::CentralPanel::default()
.frame(egui::Frame { .frame(egui::Frame {
stroke: View::ITEM_STROKE, stroke: View::ITEM_STROKE,
@ -52,14 +52,14 @@ impl WalletTab for WalletSend {
..Default::default() ..Default::default()
}) })
.show_inside(ui, |ui| { .show_inside(ui, |ui| {
self.send_ui(ui, wallet); self.transport_ui(ui, wallet);
}); });
} }
} }
impl WalletSend { impl WalletTransport {
/// Draw sending content. /// Draw transport content.
pub fn send_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet) { pub fn transport_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet) {
} }
} }

View file

@ -32,7 +32,7 @@ pub struct WalletInfo;
impl WalletTab for WalletInfo { impl WalletTab for WalletInfo {
fn get_type(&self) -> WalletTabType { fn get_type(&self) -> WalletTabType {
WalletTabType::Info WalletTabType::Txs
} }
fn ui(&mut self, fn ui(&mut self,
@ -203,11 +203,12 @@ fn tx_item_ui(ui: &mut egui::Ui,
ui.vertical(|ui| { ui.vertical(|ui| {
// Setup transaction amount. // Setup transaction amount.
ui.add_space(3.0); ui.add_space(3.0);
let amount = amount_to_hr_string(tx.amount_credited - tx.amount_debited, true);
let amount_text = if tx.amount_credited > tx.amount_debited { let amount_text = if tx.amount_credited > tx.amount_debited {
format!("+{}", amount) format!("+{}",
amount_to_hr_string(tx.amount_credited - tx.amount_debited, true))
} else { } else {
amount format!("-{}",
amount_to_hr_string(tx.amount_debited - tx.amount_credited, true))
}; };
// Setup amount color. // Setup amount color.
@ -254,17 +255,17 @@ fn tx_item_ui(ui: &mut egui::Ui,
} else { } else {
format!("{} {}", format!("{} {}",
DOTS_THREE_CIRCLE, DOTS_THREE_CIRCLE,
t!("wallets.tx_awaiting_conf")) t!("wallets.tx_confirming"))
} }
}, },
TxLogEntryType::TxSent => { TxLogEntryType::TxSent => {
if last_height - tx_height > min_confirmations { if last_height - tx_height > min_confirmations {
format!("{} {}", ARROW_CIRCLE_DOWN, t!("wallets.tx_sent")) format!("{} {}", ARROW_CIRCLE_UP, t!("wallets.tx_sent"))
} else { } else {
format!("{} {}", DOTS_THREE_CIRCLE, t!("wallets.tx_confirming")) format!("{} {}", DOTS_THREE_CIRCLE, t!("wallets.tx_confirming"))
} }
}, },
_ => format!("{} {}", ARROW_CIRCLE_UP, t!("wallets.canceled")) _ => format!("{} {}", X_CIRCLE, t!("wallets.canceled"))
} }
}; };

View file

@ -33,9 +33,9 @@ pub trait WalletTab {
/// Type of [`WalletTab`] content. /// Type of [`WalletTab`] content.
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum WalletTabType { pub enum WalletTabType {
Info, Txs,
Receive, Messages,
Send, Transport,
Settings Settings
} }
@ -43,9 +43,9 @@ impl WalletTabType {
/// Name of wallet tab to show at ui. /// Name of wallet tab to show at ui.
pub fn name(&self) -> String { pub fn name(&self) -> String {
match *self { match *self {
WalletTabType::Info => t!("wallets.wallet"), WalletTabType::Txs => t!("wallets.txs"),
WalletTabType::Receive => t!("wallets.receive"), WalletTabType::Messages => t!("wallets.messages"),
WalletTabType::Send => t!("wallets.send"), WalletTabType::Transport => t!("wallets.transport"),
WalletTabType::Settings => t!("wallets.settings") WalletTabType::Settings => t!("wallets.settings")
} }
} }

View file

@ -214,6 +214,6 @@ fn setup_i18n() {
locale.as_str() locale.as_str()
}; };
if _rust_i18n_available_locales().contains(&locale_str) { if _rust_i18n_available_locales().contains(&locale_str) {
rust_i18n::set_locale(locale_str); rust_i18n::set_locale(DEFAULT_LOCALE);
} }
} }

View file

@ -36,7 +36,9 @@ pub struct WalletConfig {
/// External connection identifier. /// External connection identifier.
pub ext_conn_id: Option<i64>, pub ext_conn_id: Option<i64>,
/// Minimal amount of confirmations. /// Minimal amount of confirmations.
pub min_confirmations: u64 pub min_confirmations: u64,
/// Flag to use Dandelion to broadcast transactions.
pub use_dandelion: Option<bool>
} }
/// Base wallets directory name. /// Base wallets directory name.
@ -69,7 +71,8 @@ impl WalletConfig {
ConnectionMethod::Integrated => None, ConnectionMethod::Integrated => None,
ConnectionMethod::External(id) => Some(*id) ConnectionMethod::External(id) => Some(*id)
}, },
min_confirmations: MIN_CONFIRMATIONS_DEFAULT min_confirmations: MIN_CONFIRMATIONS_DEFAULT,
use_dandelion: Some(true),
}; };
Settings::write_to_file(&config, config_path); Settings::write_to_file(&config, config_path);
config config

View file

@ -22,8 +22,8 @@ use std::sync::{Arc, mpsc, RwLock};
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU8, Ordering}; use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU8, Ordering};
use std::thread::Thread; use std::thread::Thread;
use std::time::Duration; use std::time::Duration;
use futures::channel::oneshot; use futures::channel::oneshot;
use grin_api::{ApiServer, Router}; use grin_api::{ApiServer, Router};
use grin_chain::SyncStatus; use grin_chain::SyncStatus;
use grin_core::global; use grin_core::global;
@ -35,7 +35,7 @@ use grin_wallet_controller::command::parse_slatepack;
use grin_wallet_controller::controller; use grin_wallet_controller::controller;
use grin_wallet_controller::controller::ForeignAPIHandlerV2; use grin_wallet_controller::controller::ForeignAPIHandlerV2;
use grin_wallet_impls::{DefaultLCProvider, DefaultWalletImpl, HTTPNodeClient}; use grin_wallet_impls::{DefaultLCProvider, DefaultWalletImpl, HTTPNodeClient};
use grin_wallet_libwallet::{Error, InitTxArgs, IssueInvoiceTxArgs, NodeClient, RetrieveTxQueryArgs, Slate, StatusMessage, TxLogEntry, TxLogEntryType, WalletInst, WalletLCProvider}; use grin_wallet_libwallet::{Error, InitTxArgs, IssueInvoiceTxArgs, NodeClient, Slate, SlatepackAddress, StatusMessage, TxLogEntry, TxLogEntryType, WalletInst, WalletLCProvider};
use grin_wallet_libwallet::api_impl::owner::{cancel_tx, retrieve_summary_info, retrieve_txs}; use grin_wallet_libwallet::api_impl::owner::{cancel_tx, retrieve_summary_info, retrieve_txs};
use crate::node::{Node, NodeConfig}; use crate::node::{Node, NodeConfig};
@ -226,6 +226,13 @@ impl Wallet {
w_config.save(); w_config.save();
} }
/// Update usage of Dandelion to broadcast transactions.
pub fn update_use_dandelion(&self, use_dandelion: bool) {
let mut w_config = self.config.write().unwrap();
w_config.use_dandelion = Some(use_dandelion);
w_config.save();
}
/// Update minimal amount of confirmations. /// Update minimal amount of confirmations.
pub fn update_min_confirmations(&self, min_confirmations: u64) { pub fn update_min_confirmations(&self, min_confirmations: u64) {
let mut w_config = self.config.write().unwrap(); let mut w_config = self.config.write().unwrap();
@ -460,6 +467,19 @@ impl Wallet {
} }
} }
/// Parse Slatepack message into [`Slate`].
pub fn parse_slatepack(&self, message: String) -> Result<Slate, Error> {
let mut api = Owner::new(self.instance.clone().unwrap(), None);
return match parse_slatepack(&mut api, None, None, Some(message.clone())) {
Ok((slate, _)) => {
Ok(slate)
}
Err(_) => {
Err(Error::SlatepackDeser("Slatepack parse error".to_string()))
}
}
}
/// Create Slatepack message from provided slate. /// Create Slatepack message from provided slate.
fn create_slatepack_message(&self, slate: Slate) -> Result<String, Error> { fn create_slatepack_message(&self, slate: Slate) -> Result<String, Error> {
let mut message = "".to_string(); let mut message = "".to_string();
@ -481,60 +501,33 @@ impl Wallet {
Ok(message) Ok(message)
} }
/// Receive transaction via Slatepack message, return response to sender. /// Initialize a transaction to send amount, return request for funds receiver.
pub fn receive(&self, message: String) -> Result<String, Error> { pub fn send(&self, amount: u64) -> Result<String, Error> {
let config = self.get_config();
let args = InitTxArgs {
src_acct_name: Some(config.account),
amount,
minimum_confirmations: config.min_confirmations,
num_change_outputs: 1,
selection_strategy_is_use_all: false,
..Default::default()
};
let mut api = Owner::new(self.instance.clone().unwrap(), None); let mut api = Owner::new(self.instance.clone().unwrap(), None);
match parse_slatepack(&mut api, None, None, Some(message.clone())) { let slate = api.init_send_tx(None, args)?;
Ok((mut slate, _)) => {
let config = self.get_config();
controller::foreign_single_use(api.wallet_inst.clone(), None, |api| {
slate = api.receive_tx(&slate, Some(config.account.as_str()), None)?;
Ok(())
})?;
// Create Slatepack message response.
let response = self.create_slatepack_message(slate)?;
// Sync wallet info. // Lock outputs to for this transaction.
self.sync(); api.tx_lock_outputs(None, &slate)?;
Ok(response)
} // Create Slatepack message response.
Err(_) => { let response = self.create_slatepack_message(slate)?;
Err(Error::GenericError("Parsing error".to_string()))
} // Sync wallet info.
} self.sync();
Ok(response)
} }
/// S transaction via Slatepack message and return response to sender. /// Initialize an invoice transaction to receive amount, return request for funds sender.
pub fn pay(&self, message: String) -> Result<String, Error> {
let mut api = Owner::new(self.instance.clone().unwrap(), None);
match parse_slatepack(&mut api, None, None, Some(message.clone())) {
Ok((mut slate, _)) => {
let config = self.get_config();
let args = InitTxArgs {
src_acct_name: None,
amount: slate.amount,
minimum_confirmations: config.min_confirmations,
selection_strategy_is_use_all: false,
..Default::default()
};
let mut api = Owner::new(self.instance.clone().unwrap(), None);
let slate = api.process_invoice_tx(None, &slate, args)?;
// Create Slatepack message response.
let response = self.create_slatepack_message(slate)?;
// Sync wallet info.
self.sync();
Ok(response)
}
Err(_) => {
Err(Error::GenericError("Parsing error".to_string()))
}
}
}
/// Initialize an invoice transaction.
pub fn issue_invoice(&self, amount: u64) -> Result<String, Error> { pub fn issue_invoice(&self, amount: u64) -> Result<String, Error> {
let args = IssueInvoiceTxArgs { let args = IssueInvoiceTxArgs {
dest_acct_name: None, dest_acct_name: None,
@ -553,8 +546,57 @@ impl Wallet {
Ok(response) Ok(response)
} }
pub fn send(&self) { /// Handle message from the invoice issuer to send founds, return response for funds receiver.
pub fn pay(&self, message: String) -> Result<String, Error> {
let slate = self.parse_slatepack(message)?;
let config = self.get_config();
let args = InitTxArgs {
src_acct_name: None,
amount: slate.amount,
minimum_confirmations: config.min_confirmations,
selection_strategy_is_use_all: false,
..Default::default()
};
let mut api = Owner::new(self.instance.clone().unwrap(), None);
let slate = api.process_invoice_tx(None, &slate, args)?;
api.tx_lock_outputs(None, &slate)?;
// Create Slatepack message response.
let response = self.create_slatepack_message(slate)?;
// Sync wallet info.
self.sync();
Ok(response)
}
/// Handle message to receive funds, return response to sender.
pub fn receive(&self, message: String) -> Result<String, Error> {
let mut slate = self.parse_slatepack(message)?;
let mut api = Owner::new(self.instance.clone().unwrap(), None);
controller::foreign_single_use(api.wallet_inst.clone(), None, |api| {
slate = api.receive_tx(&slate, Some(self.get_config().account.as_str()), None)?;
Ok(())
})?;
// Create Slatepack message response.
let response = self.create_slatepack_message(slate)?;
// Sync wallet info.
self.sync();
Ok(response)
}
/// Finalize transaction from provided message as sender or invoice issuer with Dandelion.
pub fn finalize(&self, message: String, dandelion: bool) -> Result<Slate, Error> {
let mut slate = self.parse_slatepack(message)?;
let mut api = Owner::new(self.instance.clone().unwrap(), None);
slate = api.finalize_tx(None, &slate)?;
api.post_tx(None, &slate, dandelion)?;
// Sync wallet info.
self.sync();
Ok(slate)
} }
/// Cancel transaction. /// Cancel transaction.
@ -581,11 +623,6 @@ impl Wallet {
cancelling_r.contains(id) cancelling_r.contains(id)
} }
/// Finalize transaction from provided Slatepack message.
pub fn finalize(&self) {
}
/// Change wallet password. /// Change wallet password.
pub fn change_password(&self, old: String, new: String) -> Result<(), Error> { pub fn change_password(&self, old: String, new: String) -> Result<(), Error> {
let instance = self.instance.clone().unwrap(); let instance = self.instance.clone().unwrap();
@ -889,6 +926,7 @@ fn sync_wallet_data(wallet: &Wallet) {
}).collect::<Vec<TxLogEntry>>(); }).collect::<Vec<TxLogEntry>>();
// Update txs statuses. // Update txs statuses.
for tx in &txs { for tx in &txs {
println!("{}", serde_json::to_string(tx).unwrap());
if tx.tx_type == TxLogEntryType::TxSentCancelled if tx.tx_type == TxLogEntryType::TxSentCancelled
|| tx.tx_type == TxLogEntryType::TxReceivedCancelled { || tx.tx_type == TxLogEntryType::TxReceivedCancelled {
// Remove cancelling status. // Remove cancelling status.
@ -903,15 +941,11 @@ fn sync_wallet_data(wallet: &Wallet) {
return; return;
} }
} }
Err(e) => { Err(e) => println!("error on retrieve_txs {}", e),
println!("error on retrieve_txs {}", e);
}
} }
} }
} }
Err(e) => { Err(e) => println!("error on retrieve_summary_info {}", e),
println!("error on retrieve_summary_info {}", e);
}
} }
} }