tx: remove manual slatepack input, scan outputs after wallet db deletion

This commit is contained in:
ardocrat
2025-06-10 20:09:24 +03:00
parent 845c1dc0ea
commit 1222399926
10 changed files with 159 additions and 450 deletions
+1 -1
View File
@@ -619,7 +619,7 @@ impl WalletsContent {
fn select_wallet(&mut self, wallet: &Wallet, data: Option<String>, cb: &dyn PlatformCallbacks) {
self.wallet_content.account_content.close_qr_scan(cb);
if let Some(data) = data {
wallet.open_slatepack(data);
wallet.open_message(data);
}
self.wallets.select(Some(wallet.get_config().id));
}
@@ -288,7 +288,7 @@ impl AccountContent {
//TODO: send with address
}
QrScanResult::Slatepack(m) => {
wallet.open_slatepack(m.to_string());
wallet.open_message(m.to_string());
}
_ => {
self.qr_scan_result = Some(result);
+1 -1
View File
@@ -392,7 +392,7 @@ impl WalletContent {
message = m;
});
if !message.is_empty() {
wallet.open_slatepack(message);
wallet.open_message(message);
}
}
});
@@ -201,8 +201,7 @@ impl InvoiceRequestContent {
let result = r_request.as_ref().unwrap();
match result {
Ok(tx) => {
self.result_tx_content =
Some(WalletTransactionContent::new(tx, false));
self.result_tx_content = Some(WalletTransactionContent::new(tx));
}
Err(_) => {
self.request_error = Some(t!("wallets.invoice_slatepack_err"));
+1 -2
View File
@@ -342,8 +342,7 @@ impl SendRequestContent {
let result = r_request.as_ref().unwrap();
match result {
Ok(tx) => {
self.result_tx_content =
Some(WalletTransactionContent::new(tx, false));
self.result_tx_content = Some(WalletTransactionContent::new(tx));
}
Err(err) => {
let m = match err {
+7 -17
View File
@@ -21,7 +21,7 @@ use grin_wallet_libwallet::TxLogEntryType;
use std::ops::Range;
use std::time::{SystemTime, UNIX_EPOCH};
use crate::gui::icons::{ARCHIVE_BOX, ARROW_CIRCLE_DOWN, ARROW_CIRCLE_UP, CALENDAR_CHECK, CHECK, DOTS_THREE_CIRCLE, FILE_ARROW_DOWN, FILE_TEXT, GEAR_FINE, PROHIBIT, X_CIRCLE};
use crate::gui::icons::{ARCHIVE_BOX, ARROW_CIRCLE_DOWN, ARROW_CIRCLE_UP, CALENDAR_CHECK, DOTS_THREE_CIRCLE, FILE_ARROW_DOWN, FILE_TEXT, GEAR_FINE, PROHIBIT, X_CIRCLE};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::types::{LinePosition, ModalPosition};
use crate::gui::views::wallets::types::WalletTab;
@@ -72,7 +72,7 @@ impl WalletTransactions {
manual_sync: None,
};
if let Some(tx) = &tx {
content.show_tx_info_modal(tx, false);
content.show_tx_info_modal(tx);
}
content
}
@@ -161,22 +161,12 @@ impl WalletTransactions {
r.nw = 0.0 as u8;
r.sw = 0.0 as u8;
View::item_button(ui, r, FILE_TEXT, None, || {
self.show_tx_info_modal(tx, false);
});
}
let wallet_loaded = wallet.foreign_api_port().is_some();
// Draw button to show transaction finalization.
if wallet_loaded && tx.can_finalize {
let (icon, color) = (CHECK, Some(Colors::green()));
View::item_button(ui, CornerRadius::default(), icon, color, || {
self.show_tx_info_modal(tx, true);
self.show_tx_info_modal(tx);
});
}
// Draw button to cancel transaction.
if wallet_loaded && tx.can_cancel() {
if tx.can_cancel() {
let (icon, color) = (PROHIBIT, Some(Colors::red()));
View::item_button(ui, CornerRadius::default(), icon, color, || {
self.confirm_cancel_tx_id = Some(tx.data.id);
@@ -449,11 +439,11 @@ impl WalletTransactions {
}
/// Show transaction information [`Modal`].
fn show_tx_info_modal(&mut self, tx: &WalletTransaction, finalize: bool) {
let modal = WalletTransactionContent::new(tx, finalize);
fn show_tx_info_modal(&mut self, tx: &WalletTransaction) {
let modal = WalletTransactionContent::new(tx);
self.tx_info_content = Some(modal);
Modal::new(TX_INFO_MODAL)
.position(ModalPosition::CenterTop)
.position(ModalPosition::Center)
.title(t!("wallets.tx"))
.show();
}
+133 -406
View File
@@ -12,21 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::thread;
use std::sync::Arc;
use parking_lot::RwLock;
use egui::scroll_area::ScrollBarVisibility;
use egui::{Align, Id, Layout, RichText, CornerRadius, ScrollArea, StrokeKind};
use grin_util::ToHex;
use egui::{Align, CornerRadius, Layout, RichText, StrokeKind};
use grin_core::core::amount_to_hr_string;
use grin_wallet_libwallet::{Error, Slate, SlateState, TxLogEntryType};
use grin_util::ToHex;
use grin_wallet_libwallet::TxLogEntryType;
use crate::gui::Colors;
use crate::gui::icons::{BROOM, CHECK, CLIPBOARD_TEXT, COPY, CUBE, FILE_ARCHIVE, FILE_TEXT, HASH_STRAIGHT, PROHIBIT, QR_CODE, SCAN};
use crate::gui::icons::{COPY, CUBE, FILE_ARCHIVE, FILE_TEXT, HASH_STRAIGHT, PROHIBIT, QR_CODE, SCAN};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{CameraContent, FilePickContent, FilePickContentType, Modal, QrCodeContent, View};
use crate::gui::views::wallets::wallet::txs::WalletTransactions;
use crate::gui::views::wallets::wallet::types::SLATEPACK_MESSAGE_HINT;
use crate::gui::views::{CameraContent, FilePickContent, FilePickContentType, Modal, QrCodeContent, View};
use crate::gui::Colors;
use crate::wallet::types::WalletTransaction;
use crate::wallet::Wallet;
@@ -35,20 +30,6 @@ pub struct WalletTransactionContent {
/// Transaction identifier.
tx_id: u32,
/// Response Slatepack message input value.
response_edit: Option<String>,
/// Flag to show transaction finalization input.
show_finalization: bool,
/// Finalization Slatepack message input value.
finalize_edit: String,
/// Flag to check if error happened during transaction finalization.
finalize_error: bool,
/// Flag to check if transaction is finalizing.
finalizing: bool,
/// Transaction finalization result.
final_result: Arc<RwLock<Option<Result<WalletTransaction, Error>>>>,
/// QR code Slatepack message image content.
qr_code_content: Option<QrCodeContent>,
@@ -61,18 +42,14 @@ pub struct WalletTransactionContent {
impl WalletTransactionContent {
/// Create new content instance with [`Wallet`] from provided [`WalletTransaction`].
pub fn new(tx: &WalletTransaction, show_finalization: bool) -> Self {
pub fn new(tx: &WalletTransaction) -> Self {
Self {
tx_id: tx.data.id,
response_edit: None,
finalize_edit: "".to_string(),
finalize_error: false,
show_finalization,
finalizing: false,
final_result: Arc::new(RwLock::new(None)),
qr_code_content: None,
scan_qr_content: None,
file_pick_button: FilePickContent::new(FilePickContentType::Button),
file_pick_button: FilePickContent::new(
FilePickContentType::ItemButton(CornerRadius::default())
),
}
}
@@ -99,133 +76,131 @@ impl WalletTransactionContent {
}
let tx = txs.get(0).unwrap();
// Check if response was loaded.
if self.response_edit.is_none() {
self.response_edit = Some(
if !tx.cancelling && !tx.finalizing && !tx.data.confirmed &&
tx.data.tx_slate_id.is_some() &&
(tx.data.tx_type == TxLogEntryType::TxSent ||
tx.data.tx_type == TxLogEntryType::TxReceived) {
let mut slate = Slate::blank(1, false);
slate.state = if tx.can_finalize {
if tx.data.tx_type == TxLogEntryType::TxSent {
SlateState::Standard1
} else {
SlateState::Invoice1
}
} else {
if tx.data.tx_type == TxLogEntryType::TxReceived {
SlateState::Standard2
} else {
SlateState::Invoice2
}
};
slate.id = tx.data.tx_slate_id.unwrap();
wallet.read_slatepack(&slate).unwrap_or("".to_string())
} else {
"".to_string()
}
);
}
if let Some(content) = self.qr_code_content.as_mut() {
content.ui(ui, cb);
// Show transaction information.
if self.qr_code_content.is_none() && self.scan_qr_content.is_none() {
self.info_ui(ui, tx, wallet, cb);
}
// Show Slatepack message interaction.
if !self.response_edit.as_ref().unwrap().is_empty() {
self.message_ui(ui, tx, wallet, modal, cb);
}
if !self.finalizing {
// Setup spacing between buttons.
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
if self.qr_code_content.is_some() {
// Show buttons to close modal or come back to text request content.
ui.columns(2, |cols| {
cols[0].vertical_centered_justified(|ui| {
View::button(ui, t!("close"), Colors::white_or_black(false), || {
self.qr_code_content = None;
Modal::close();
});
});
cols[1].vertical_centered_justified(|ui| {
View::button(ui, t!("back"), Colors::white_or_black(false), || {
self.qr_code_content = None;
});
});
});
} else if self.scan_qr_content.is_some() {
ui.add_space(8.0);
// Show buttons to close modal or scanner.
ui.columns(2, |cols| {
cols[0].vertical_centered_justified(|ui| {
View::button(ui, t!("close"), Colors::white_or_black(false), || {
cb.stop_camera();
self.scan_qr_content = None;
Modal::close();
});
});
cols[1].vertical_centered_justified(|ui| {
View::button(ui, t!("back"), Colors::white_or_black(false), || {
cb.stop_camera();
self.scan_qr_content = None;
modal.enable_closing();
});
});
});
} else {
ui.add_space(8.0);
View::horizontal_line(ui, Colors::item_stroke());
ui.add_space(8.0);
// Show button to close modal.
ui.vertical_centered_justified(|ui| {
// Show buttons to close modal or come back to text request content.
ui.columns(2, |cols| {
cols[0].vertical_centered_justified(|ui| {
View::button(ui, t!("close"), Colors::white_or_black(false), || {
self.qr_code_content = None;
Modal::close();
});
});
}
ui.add_space(6.0);
} else {
// Show loader on finalizing.
ui.vertical_centered(|ui| {
View::small_loading_spinner(ui);
ui.add_space(16.0);
cols[1].vertical_centered_justified(|ui| {
View::button(ui, t!("back"), Colors::white_or_black(false), || {
self.qr_code_content = None;
});
});
});
// Check finalization result.
let has_res = {
let r_res = self.final_result.read();
r_res.is_some()
};
if has_res {
let res = {
let r_res = self.final_result.read();
r_res.as_ref().unwrap().clone()
};
if let Ok(_) = res {
self.show_finalization = false;
self.finalize_edit = "".to_string();
self.response_edit = Some("".to_string());
} else {
self.finalize_error = true;
}
// Clear status and result.
{
let mut w_res = self.final_result.write();
*w_res = None;
}
self.finalizing = false;
} else if let Some(scan_content) = self.scan_qr_content.as_mut() {
if let Some(result) = scan_content.qr_scan_result() {
cb.stop_camera();
modal.enable_closing();
self.scan_qr_content = None;
// Provide scan result as Slatepack message.
wallet.open_message(result.text());
} else {
scan_content.ui(ui, cb);
}
ui.add_space(8.0);
// Setup spacing between buttons.
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
// Show buttons to close modal or scanner.
ui.columns(2, |cols| {
cols[0].vertical_centered_justified(|ui| {
View::button(ui, t!("close"), Colors::white_or_black(false), || {
cb.stop_camera();
self.scan_qr_content = None;
Modal::close();
});
});
cols[1].vertical_centered_justified(|ui| {
View::button(ui, t!("back"), Colors::white_or_black(false), || {
cb.stop_camera();
self.scan_qr_content = None;
modal.enable_closing();
});
});
});
} else {
// Show transaction information.
self.info_ui(ui, modal, tx, wallet, cb);
// Show tx description.
let amount = amount_to_hr_string(tx.amount, true);
let desc_text = if tx.can_finalize {
if tx.data.tx_type == TxLogEntryType::TxSent {
t!("wallets.send_request_desc", "amount" => amount)
} else {
t!("wallets.invoice_desc", "amount" => amount)
}
} else {
if tx.data.tx_type == TxLogEntryType::TxSent {
t!("wallets.parse_i1_slatepack_desc", "amount" => amount)
} else {
t!("wallets.parse_s1_slatepack_desc", "amount" => amount)
}
};
ui.add_space(6.0);
ui.vertical_centered_justified(|ui| {
ui.label(RichText::new(desc_text).size(16.0).color(Colors::inactive_text()));
});
ui.add_space(6.0);
// Setup spacing between buttons.
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
ui.columns(2, |columns| {
columns[0].vertical_centered_justified(|ui| {
// Draw button to show Slatepack message as QR code.
let qr_text = format!("{} {}", QR_CODE, t!("qr_code"));
View::button(ui, qr_text.clone(), Colors::white_or_black(false), || {
if let Some((_, d)) = wallet.read_slate_by_tx(tx) {
self.qr_code_content = Some(QrCodeContent::new(d, true));
}
});
});
columns[1].vertical_centered_justified(|ui| {
// Show button to share response as file.
let share_text = format!("{} {}", FILE_TEXT, t!("file"));
View::colored_text_button(ui,
share_text,
Colors::blue(),
Colors::white_or_black(false), || {
if let Some((s, d)) = wallet.read_slate_by_tx(tx) {
let name = format!("{}.{}.slatepack", s.id, s.state);
let data = d.as_bytes().to_vec();
cb.share_data(name, data).unwrap_or_default();
}
});
});
});
ui.add_space(8.0);
View::horizontal_line(ui, Colors::item_stroke());
ui.add_space(8.0);
// Show button to close modal.
ui.vertical_centered_justified(|ui| {
View::button(ui, t!("close"), Colors::white_or_black(false), || {
Modal::close();
});
});
}
ui.add_space(6.0);
}
/// Draw transaction information content.
fn info_ui(&mut self,
ui: &mut egui::Ui,
modal: &Modal,
tx: &WalletTransaction,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
@@ -242,9 +217,6 @@ impl WalletTransactionContent {
// Show transaction amount status and time.
let data = wallet.get_data().unwrap();
WalletTransactions::tx_item_ui(ui, tx, rect, &data, |ui| {
if self.finalizing {
return;
}
// Show block height or buttons.
if let Some(h) = tx.height {
if h != 0 {
@@ -259,34 +231,28 @@ impl WalletTransactionContent {
}
return;
}
let wallet_loaded = wallet.foreign_api_port().is_some();
// Draw button to show transaction finalization or request info.
if wallet_loaded && tx.can_finalize {
let (icon, color) = if self.show_finalization {
(FILE_TEXT, None)
} else {
(CHECK, Some(Colors::green()))
};
// Draw button to cancel transaction.
if tx.can_cancel() {
let r = View::item_rounding(0, 2, true);
View::item_button(ui, r, icon, color, || {
if self.show_finalization {
self.show_finalization = false;
return;
}
self.show_finalization = true;
View::item_button(ui, r, PROHIBIT, Some(Colors::red()), || {
wallet.cancel(tx.data.id);
});
}
// Draw button to cancel transaction.
if wallet_loaded && tx.can_cancel() {
let r = if tx.can_finalize {
if tx.can_finalize {
// Draw button to scan QR code.
let r = if tx.can_cancel() {
CornerRadius::default()
} else {
View::item_rounding(0, 2, true)
};
View::item_button(ui, r, PROHIBIT, Some(Colors::red()), || {
wallet.cancel(tx.data.id);
View::item_button(ui, r, SCAN, Some(Colors::text_button()), || {
modal.disable_closing();
cb.start_camera();
self.scan_qr_content = Some(CameraContent::default());
});
// Draw button to pick file.
self.file_pick_button.ui(ui, cb, |data| {
wallet.open_message(data);
});
}
});
@@ -307,245 +273,6 @@ impl WalletTransactionContent {
info_item_ui(ui, rec.to_string(), label, true, cb);
}
}
/// Draw Slatepack message content.
fn message_ui(&mut self,
ui: &mut egui::Ui,
tx: &WalletTransaction,
wallet: &Wallet,
modal: &Modal,
cb: &dyn PlatformCallbacks) {
ui.add_space(6.0);
// Draw QR code scanner content if requested.
if let Some(scan_content) = self.scan_qr_content.as_mut() {
if let Some(result) = scan_content.qr_scan_result() {
cb.stop_camera();
// Setup value to finalization input field.
self.finalize_edit = result.text();
self.on_finalization_input_change(tx, wallet, modal);
modal.enable_closing();
self.scan_qr_content = None;
} else {
scan_content.ui(ui, cb);
}
return;
}
let amount = amount_to_hr_string(tx.amount, true);
// Draw Slatepack message description text.
ui.vertical_centered(|ui| {
if self.show_finalization {
let desc_text = if self.finalize_error {
t!("wallets.finalize_slatepack_err")
} else {
if tx.data.tx_type == TxLogEntryType::TxSent {
t!("wallets.parse_s2_slatepack_desc", "amount" => amount)
} else {
t!("wallets.parse_i2_slatepack_desc", "amount" => amount)
}
};
let desc_color = if self.finalize_error {
Colors::red()
} else {
Colors::gray()
};
ui.label(RichText::new(desc_text).size(16.0).color(desc_color));
} else {
let desc_text = if tx.can_finalize {
if tx.data.tx_type == TxLogEntryType::TxSent {
t!("wallets.send_request_desc", "amount" => amount)
} else {
t!("wallets.invoice_desc", "amount" => amount)
}
} else {
if tx.data.tx_type == TxLogEntryType::TxSent {
t!("wallets.parse_i1_slatepack_desc", "amount" => amount)
} else {
t!("wallets.parse_s1_slatepack_desc", "amount" => amount)
}
};
ui.label(RichText::new(desc_text).size(16.0).color(Colors::gray()));
}
});
ui.add_space(6.0);
// Setup message input value.
let message_edit = if self.show_finalization {
&mut self.finalize_edit
} else {
&mut self.response_edit.as_mut().unwrap()
};
let message_before = message_edit.clone();
// Draw QR code content if requested.
if let Some(qr_content) = self.qr_code_content.as_mut() {
qr_content.ui(ui, cb);
return;
}
// Draw Slatepack message finalization input or request text.
ui.vertical_centered(|ui| {
let scroll_id = if self.show_finalization {
Id::from("tx_info_message_finalize")
} else {
Id::from("tx_info_message_request")
}.with(tx.data.id);
View::horizontal_line(ui, Colors::item_stroke());
ui.add_space(3.0);
ScrollArea::vertical()
.id_salt(scroll_id)
.scroll_bar_visibility(ScrollBarVisibility::AlwaysHidden)
.max_height(128.0)
.auto_shrink([false; 2])
.show(ui, |ui| {
ui.add_space(7.0);
let input_id = scroll_id.with("_input");
let resp = egui::TextEdit::multiline(message_edit)
.id(input_id)
.font(egui::TextStyle::Small)
.desired_rows(5)
.interactive(self.show_finalization && !self.finalizing)
.hint_text(SLATEPACK_MESSAGE_HINT)
.desired_width(f32::INFINITY)
.show(ui).response;
if self.show_finalization && resp.clicked() {
resp.request_focus();
}
ui.add_space(6.0);
});
});
ui.add_space(2.0);
View::horizontal_line(ui, Colors::item_stroke());
ui.add_space(8.0);
// Do not show buttons on finalization.
if self.finalizing {
return;
}
// Setup spacing between buttons.
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
if self.show_finalization {
ui.columns(2, |columns| {
columns[0].vertical_centered_justified(|ui| {
// Draw button to scan Slatepack message QR code.
let qr_text = format!("{} {}", SCAN, t!("scan"));
View::button(ui, qr_text, Colors::fill_lite(), || {
modal.disable_closing();
cb.start_camera();
self.scan_qr_content = Some(CameraContent::default());
});
});
columns[1].vertical_centered_justified(|ui| {
// Draw button to paste data from clipboard.
let paste_text = format!("{} {}", CLIPBOARD_TEXT, t!("paste"));
View::button(ui, paste_text, Colors::fill_lite(), || {
self.finalize_edit = cb.get_string_from_buffer();
});
});
});
ui.add_space(8.0);
ui.vertical_centered(|ui| {
if self.finalize_error {
// Draw button to clear message input.
let clear_text = format!("{} {}", BROOM, t!("clear"));
View::button(ui, clear_text, Colors::fill_lite(), || {
self.finalize_edit.clear();
self.finalize_error = false;
});
} else {
// Draw button to choose file.
self.file_pick_button.ui(ui, cb, |text| {
self.finalize_edit = text;
});
}
});
// Callback on finalization message input change.
if message_before != self.finalize_edit {
self.on_finalization_input_change(tx, wallet, modal);
}
} else {
ui.columns(2, |columns| {
columns[0].vertical_centered_justified(|ui| {
// Draw button to show Slatepack message as QR code.
let qr_text = format!("{} {}", QR_CODE, t!("qr_code"));
View::button(ui, qr_text.clone(), Colors::white_or_black(false), || {
let text = self.response_edit.clone();
self.qr_code_content = Some(QrCodeContent::new(text.unwrap(), true));
});
});
columns[1].vertical_centered_justified(|ui| {
// Draw copy button.
let copy_text = format!("{} {}", COPY, t!("copy"));
View::button(ui, copy_text, Colors::white_or_black(false), || {
cb.copy_string_to_buffer(self.response_edit.clone().unwrap());
self.finalize_edit = "".to_string();
if tx.can_finalize {
self.show_finalization = true;
} else {
Modal::close();
}
});
});
});
// Show button to share response as file.
ui.add_space(8.0);
ui.vertical_centered(|ui| {
let share_text = format!("{} {}", FILE_TEXT, t!("share"));
View::colored_text_button(ui,
share_text,
Colors::blue(),
Colors::white_or_black(false), || {
if let Some((s, _)) = wallet.read_slate_by_tx(tx) {
let name = format!("{}.{}.slatepack", s.id, s.state);
let data = self.response_edit.as_ref().unwrap().as_bytes().to_vec();
cb.share_data(name, data).unwrap_or_default();
}
});
});
}
}
/// Parse Slatepack message on transaction finalization input change.
fn on_finalization_input_change(&mut self, tx: &WalletTransaction, w: &Wallet, modal: &Modal) {
let message = &self.finalize_edit;
if message.is_empty() {
self.finalize_error = false;
} else {
// Parse input message to finalize.
if let Ok(slate) = w.parse_slatepack(message) {
let send = slate.state == SlateState::Standard2 &&
tx.data.tx_type == TxLogEntryType::TxSent;
let receive = slate.state == SlateState::Invoice2 &&
tx.data.tx_type == TxLogEntryType::TxReceived;
if Some(slate.id) == tx.data.tx_slate_id && (send || receive) {
let message = message.clone();
let wallet = w.clone();
let final_res = self.final_result.clone();
// Finalize transaction at separate thread.
self.finalizing = true;
modal.disable_closing();
thread::spawn(move || {
let res = wallet.finalize(&message);
let mut w_res = final_res.write();
*w_res = Some(res);
});
} else {
self.finalize_error = true;
}
} else {
self.finalize_error = true;
}
}
}
}
/// Draw transaction information item content.
-2
View File
@@ -19,8 +19,6 @@ use crate::wallet::Wallet;
/// GRIN coin symbol.
pub const GRIN: &str = "";
/// Hint for Slatepack message input.
pub const SLATEPACK_MESSAGE_HINT: &'static str = "BEGINSLATEPACK.\n...\n...\n...\nENDSLATEPACK.";
/// Content container to simplify modals management and navigation.
pub trait WalletContentContainer {
+1 -3
View File
@@ -166,14 +166,12 @@ pub struct WalletTransaction {
pub finalizing: bool,
/// Block height where tx was included.
pub height: Option<u64>,
/// Flag to check if tx was received after sync from node.
pub from_node: bool,
}
impl WalletTransaction {
/// Check if transaction can be cancelled.
pub fn can_cancel(&self) -> bool {
self.from_node && !self.cancelling && !self.data.confirmed &&
!self.cancelling && !self.data.confirmed &&
self.data.tx_type != TxLogEntryType::TxReceivedCancelled
&& self.data.tx_type != TxLogEntryType::TxSentCancelled
}
+13 -15
View File
@@ -99,9 +99,9 @@ pub struct Wallet {
repair_progress: Arc<AtomicU8>,
/// Flag to check if Slatepack message file is opening.
slatepack_opening: Arc<AtomicBool>,
message_opening: Arc<AtomicBool>,
/// Result of Slatepack message file opening.
slatepack_result: Arc<RwLock<Option<Result<WalletTransaction, Error>>>>,
message_result: Arc<RwLock<Option<Result<WalletTransaction, Error>>>>,
}
impl Wallet {
@@ -127,8 +127,8 @@ impl Wallet {
syncing: Arc::new(AtomicBool::new(false)),
repair_needed: Arc::new(AtomicBool::new(false)),
repair_progress: Arc::new(AtomicU8::new(0)),
slatepack_opening: Arc::new(AtomicBool::from(false)),
slatepack_result: Arc::new(RwLock::new(None)),
message_opening: Arc::new(AtomicBool::from(false)),
message_result: Arc::new(RwLock::new(None)),
}
}
@@ -457,7 +457,7 @@ impl Wallet {
let wallet_close = self.clone();
let service_id = wallet_close.identifier();
let conn = wallet_close.connection.clone();
let message_opening = self.slatepack_opening.clone();
let message_opening = self.message_opening.clone();
thread::spawn(move || {
// Wait message opening to finish.
while message_opening.load(Ordering::Relaxed) {
@@ -657,17 +657,17 @@ impl Wallet {
}
/// Open Slatepack message with the wallet.
pub fn open_slatepack(&self, message: String) {
pub fn open_message(&self, message: String) {
if !self.is_open() {
return;
}
if message.is_empty() {
let mut res_w = self.slatepack_result.write();
let mut res_w = self.message_result.write();
*res_w = Some(Err(Error::InvalidSlatepackData("".to_string())));
}
let w = self.clone();
let load = self.slatepack_opening.clone();
let res = self.slatepack_result.clone();
let load = self.message_opening.clone();
let res = self.message_result.clone();
let msg = message.clone();
thread::spawn(move || {
load.store(true, Ordering::Relaxed);
@@ -719,18 +719,18 @@ impl Wallet {
/// Check if Slatepack message is opening.
pub fn message_opening(&self) -> bool {
self.slatepack_opening.load(Ordering::Relaxed)
self.message_opening.load(Ordering::Relaxed)
}
/// Consume Slatepack message result.
pub fn consume_message_result(&self) -> Option<Result<WalletTransaction, Error>> {
let res = {
let r_mes = self.slatepack_result.read();
let r_mes = self.message_result.read();
r_mes.clone()
};
// Clear message result.
if res.is_some() {
let mut w_mes = self.slatepack_result.write();
let mut w_mes = self.message_result.write();
*w_mes = None;
}
res
@@ -1160,6 +1160,7 @@ impl Wallet {
let _ = fs::remove_dir_all(wallet_delete.get_config().get_db_path());
// Start sync to close thread.
wallet_delete.sync();
wallet_delete.repair();
// Mark wallet to reopen.
wallet_delete.set_reopen(reopen);
});
@@ -1333,8 +1334,6 @@ fn start_sync(wallet: Wallet) -> Thread {
/// Retrieve [`WalletData`] from local base or node.
fn sync_wallet_data(wallet: &Wallet, from_node: bool) {
let fresh_sync = wallet.get_data().is_none();
// Update info sync progress at separate thread.
let wallet_info = wallet.clone();
let (info_tx, info_rx) = mpsc::channel::<StatusMessage>();
@@ -1496,7 +1495,6 @@ fn sync_wallet_data(wallet: &Wallet, from_node: bool) {
can_finalize,
finalizing,
height: conf_height,
from_node: !fresh_sync || from_node
});
}