wallet: fix confirmations count, ability to repost and cancel transaction at posting state after timeout, repost height, fix posting state flag, cancel tx at send/receive modal

This commit is contained in:
ardocrat
2024-04-21 19:59:12 +03:00
parent f42fd94281
commit 1b7d96eff5
5 changed files with 132 additions and 38 deletions
+3 -2
View File
@@ -358,8 +358,9 @@ impl WalletContent {
columns[1].vertical_centered_justified(|ui| {
let is_messages = current_type == WalletTabType::Messages;
View::tab_button(ui, CHAT_CIRCLE_TEXT, is_messages, || {
let dandelion = wallet.get_config().use_dandelion.unwrap_or(true);
self.current_tab = Box::new(WalletMessages::new(dandelion));
self.current_tab = Box::new(
WalletMessages::new(wallet.can_use_dandelion())
);
});
});
columns[2].vertical_centered_justified(|ui| {
+31 -6
View File
@@ -671,7 +671,7 @@ impl WalletMessages {
} 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::GRAY));
ui.add_space(6.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(3.0);
@@ -699,12 +699,37 @@ impl WalletMessages {
});
ui.add_space(2.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
ui.add_space(10.0);
});
// Draw copy button.
let copy_text = format!("{} {}", COPY, t!("copy"));
View::button(ui, copy_text, Colors::BUTTON, || {
cb.copy_string_to_buffer(self.request_edit.clone());
// Show modal buttons.
ui.add_space(12.0);
// 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| {
// Button to cancel transaction.
let clear_text = format!("{} {}", PROHIBIT, t!("modal.cancel"));
View::button(ui, clear_text, Colors::BUTTON, || {
if let Ok(slate) = wallet.parse_slatepack(self.request_edit.clone()) {
if let Some(tx) = wallet.tx_by_slate(&slate) {
wallet.cancel(tx.data.id);
}
}
self.amount_edit = "".to_string();
self.request_edit = "".to_string();
modal.close();
});
});
columns[1].vertical_centered_justified(|ui| {
// Draw copy button.
let copy_text = format!("{} {}", COPY, t!("copy"));
View::button(ui, copy_text, Colors::BUTTON, || {
cb.copy_string_to_buffer(self.request_edit.clone());
self.amount_edit = "".to_string();
self.request_edit = "".to_string();
modal.close();
});
});
});
+35 -8
View File
@@ -15,10 +15,10 @@
use egui::{Align, Id, Layout, Margin, RichText, Rounding, ScrollArea};
use egui::scroll_area::ScrollBarVisibility;
use grin_core::core::amount_to_hr_string;
use grin_wallet_libwallet::{TxLogEntryType};
use grin_wallet_libwallet::{Slate, SlateState, TxLogEntryType};
use crate::gui::Colors;
use crate::gui::icons::{ARROW_CIRCLE_DOWN, BRIDGE, CALENDAR_CHECK, CHAT_CIRCLE_TEXT, CHECK_CIRCLE, DOTS_THREE_CIRCLE, FILE_TEXT, GEAR_FINE, PROHIBIT, X_CIRCLE};
use crate::gui::icons::{ARROW_CIRCLE_DOWN, ARROWS_CLOCKWISE, BRIDGE, CALENDAR_CHECK, CHAT_CIRCLE_TEXT, CHECK_CIRCLE, DOTS_THREE_CIRCLE, FILE_TEXT, GEAR_FINE, PROHIBIT, X_CIRCLE};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{Root, View};
use crate::gui::views::wallets::types::WalletTab;
@@ -183,14 +183,43 @@ fn tx_item_ui(ui: &mut egui::Ui,
//TODO: Show tx info
});
if !tx.posting && !tx.data.confirmed &&
// Setup flag to repost unconfirmed posting transaction after min confirmation time.
let last_height = data.info.last_confirmed_height;
let min_conf = data.info.minimum_confirmations;
let can_repost = tx.posting && tx.repost_height.is_some() &&
last_height - tx.repost_height.unwrap() > min_conf;
// Draw cancel button for txs to repost or also non-cancelled, non-posting.
if can_repost || (!tx.posting && !tx.data.confirmed &&
tx.data.tx_type != TxLogEntryType::TxReceivedCancelled
&& tx.data.tx_type != TxLogEntryType::TxSentCancelled {
&& tx.data.tx_type != TxLogEntryType::TxSentCancelled) {
View::item_button(ui, Rounding::default(), PROHIBIT, Some(Colors::RED), || {
wallet.cancel(tx.data.id);
});
}
// Draw button to repost transaction.
if can_repost {
View::item_button(ui,
Rounding::default(),
ARROWS_CLOCKWISE,
Some(Colors::GREEN), || {
// Create slate to check existing file.
let mut slate = Slate::blank(1, false);
slate.id = tx.data.tx_slate_id.unwrap();
slate.state = match tx.data.tx_type {
TxLogEntryType::TxReceived => SlateState::Invoice3,
_ => SlateState::Standard3
};
// Post tx after getting slate from slatepack file.
if let Some(sp) = wallet.read_slatepack(&slate) {
if let Ok(s) = wallet.parse_slatepack(sp) {
let _ = wallet.post(&s, wallet.can_use_dandelion());
}
}
});
}
let layout_size = ui.available_size();
ui.allocate_ui_with_layout(layout_size, Layout::left_to_right(Align::Center), |ui| {
ui.add_space(12.0);
@@ -230,9 +259,7 @@ fn tx_item_ui(ui: &mut egui::Ui,
|| tx.data.tx_type == TxLogEntryType::TxReceivedCancelled;
if is_canceled {
format!("{} {}", X_CIRCLE, t!("wallets.tx_canceled"))
} else if tx.posting || (tx.data.kernel_excess.is_some() &&
(tx.data.tx_type == TxLogEntryType::TxReceived ||
tx.data.tx_type == TxLogEntryType::TxSent)) {
} else if tx.posting {
format!("{} {}", DOTS_THREE_CIRCLE, t!("wallets.tx_finalizing"))
} else {
match tx.data.tx_type {
@@ -254,7 +281,7 @@ fn tx_item_ui(ui: &mut egui::Ui,
format!("{} {}", CHECK_CIRCLE, t!("wallets.tx_confirmed"))
},
TxLogEntryType::TxSent | TxLogEntryType::TxReceived => {
if data.info.last_confirmed_height - tx_height > min_conf + 1 {
if data.info.last_confirmed_height - tx_height > min_conf {
let text = if tx.data.tx_type == TxLogEntryType::TxSent {
t!("wallets.tx_sent")
} else {