mirror of
https://code.gri.mw/GUI/grim.git
synced 2026-07-04 05:57:29 +00:00
tx: show message input after copy/share if finalization is needed
This commit is contained in:
@@ -64,7 +64,7 @@ impl WalletContentContainer for WalletAccountContent {
|
||||
CREATE_MODAL_ID => self.create_account_content.ui(ui, wallet, modal, cb),
|
||||
SEND_MODAL_ID => {
|
||||
if let Some(c) = self.send_content.as_mut() {
|
||||
c.modal_ui(ui, wallet, modal, cb);
|
||||
c.ui(ui, wallet, modal, cb);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -58,36 +58,41 @@ pub struct WalletContent {
|
||||
const INVOICE_MODAL_ID: &'static str = "invoice_request_modal";
|
||||
/// Identifier for sending request creation [`Modal`].
|
||||
const SEND_MODAL_ID: &'static str = "send_request_modal";
|
||||
/// Identifier for Slatepack message input [`Modal`].
|
||||
pub const MESSAGE_MODAL_ID: &'static str = "input_message_modal";
|
||||
|
||||
impl WalletContentContainer for WalletContent {
|
||||
fn modal_ids(&self) -> Vec<&'static str> {
|
||||
vec![
|
||||
INVOICE_MODAL_ID,
|
||||
SEND_MODAL_ID,
|
||||
MESSAGE_MODAL_ID
|
||||
MessageInputContent::MODAL_ID
|
||||
]
|
||||
}
|
||||
|
||||
fn modal_ui(&mut self, ui: &mut egui::Ui, w: &Wallet, m: &Modal, cb: &dyn PlatformCallbacks) {
|
||||
match m.id {
|
||||
INVOICE_MODAL_ID => {
|
||||
if let Some(c) = self.invoice_content.as_mut() {
|
||||
c.modal_ui(ui, w, m, cb);
|
||||
if self.invoice_content.is_none() {
|
||||
self.invoice_content = Some(InvoiceRequestContent::default());
|
||||
}
|
||||
self.invoice_content.as_mut().unwrap().ui(ui, w, m, cb);
|
||||
}
|
||||
SEND_MODAL_ID => {
|
||||
if let Some(c) = self.send_content.as_mut() {
|
||||
c.modal_ui(ui, w, m, cb);
|
||||
if self.send_content.is_none() {
|
||||
self.send_content = Some(SendRequestContent::new(None));
|
||||
}
|
||||
self.send_content.as_mut().unwrap().ui(ui, w, m, cb);
|
||||
}
|
||||
MESSAGE_MODAL_ID => {
|
||||
if let Some(c) = self.message_content.as_mut() {
|
||||
c.ui(ui, w, m, cb);
|
||||
MessageInputContent::MODAL_ID => {
|
||||
if self.message_content.is_none() {
|
||||
self.message_content = Some(MessageInputContent::default());
|
||||
}
|
||||
self.message_content.as_mut().unwrap().ui(ui, w, m, cb);
|
||||
}
|
||||
_ => {
|
||||
self.invoice_content = None;
|
||||
self.send_content = None;
|
||||
self.message_content = None;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +399,10 @@ impl WalletContent {
|
||||
} else {
|
||||
let (icon, color) = (FILE_ARROW_DOWN, Some(Colors::green()));
|
||||
View::tab_button(ui, icon, color, active, |_| {
|
||||
self.invoice_content = Some(InvoiceRequestContent::default());
|
||||
if self.txs_content.is_none() {
|
||||
self.txs_content = Some(WalletTransactionsContent::new(None));
|
||||
self.settings_content = None;
|
||||
}
|
||||
Modal::new(INVOICE_MODAL_ID)
|
||||
.position(ModalPosition::CenterTop)
|
||||
.title(t!("wallets.receive"))
|
||||
@@ -409,8 +417,11 @@ impl WalletContent {
|
||||
} else {
|
||||
let (icon, color) = (FILE_TEXT, Some(Colors::gold_dark()));
|
||||
View::tab_button(ui, icon, color, active, |_| {
|
||||
self.message_content = Some(MessageInputContent::default());
|
||||
Modal::new(MESSAGE_MODAL_ID)
|
||||
if self.txs_content.is_none() {
|
||||
self.txs_content = Some(WalletTransactionsContent::new(None));
|
||||
self.settings_content = None;
|
||||
}
|
||||
Modal::new(MessageInputContent::MODAL_ID)
|
||||
.position(ModalPosition::Center)
|
||||
.title(t!("wallets.messages"))
|
||||
.show();
|
||||
@@ -425,7 +436,10 @@ impl WalletContent {
|
||||
} else {
|
||||
let (icon, color) = (FILE_ARROW_UP, Some(Colors::red()));
|
||||
View::tab_button(ui, icon, color, active, |_| {
|
||||
self.send_content = Some(SendRequestContent::new(None));
|
||||
if self.txs_content.is_none() {
|
||||
self.txs_content = Some(WalletTransactionsContent::new(None));
|
||||
self.settings_content = None;
|
||||
}
|
||||
Modal::new(SEND_MODAL_ID)
|
||||
.position(ModalPosition::CenterTop)
|
||||
.title(t!("wallets.send"))
|
||||
@@ -488,7 +502,7 @@ impl WalletContent {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
MESSAGE_MODAL_ID => {
|
||||
MessageInputContent::MODAL_ID => {
|
||||
match t {
|
||||
WalletTask::VerifyProof(proof, res) => {
|
||||
if let Some(res) = res {
|
||||
|
||||
@@ -56,6 +56,9 @@ impl Default for MessageInputContent {
|
||||
}
|
||||
|
||||
impl MessageInputContent {
|
||||
/// Identifier for [`Modal`].
|
||||
pub const MODAL_ID: &'static str = "input_message_modal";
|
||||
|
||||
/// Draw [`Modal`] content.
|
||||
pub fn ui(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
|
||||
@@ -37,7 +37,7 @@ impl Default for InvoiceRequestContent {
|
||||
|
||||
impl InvoiceRequestContent {
|
||||
/// Draw [`Modal`] content.
|
||||
pub fn modal_ui(&mut self,
|
||||
pub fn ui(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
wallet: &Wallet,
|
||||
modal: &Modal,
|
||||
|
||||
@@ -73,11 +73,11 @@ impl SendRequestContent {
|
||||
}
|
||||
|
||||
/// Draw [`Modal`] content.
|
||||
pub fn modal_ui(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
wallet: &Wallet,
|
||||
modal: &Modal,
|
||||
cb: &dyn PlatformCallbacks) {
|
||||
pub fn ui(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
wallet: &Wallet,
|
||||
modal: &Modal,
|
||||
cb: &dyn PlatformCallbacks) {
|
||||
ui.add_space(6.0);
|
||||
|
||||
// Draw QR code scanner content if requested.
|
||||
|
||||
@@ -45,6 +45,13 @@ pub struct WalletTransactionsContent {
|
||||
manual_sync: Option<u128>
|
||||
}
|
||||
|
||||
/// Identifier for transaction information [`Modal`].
|
||||
const TX_INFO_MODAL: &'static str = "tx_info_modal";
|
||||
/// Identifier for transaction cancellation confirmation [`Modal`].
|
||||
const CANCEL_TX_CONFIRMATION_MODAL: &'static str = "cancel_tx_conf_modal";
|
||||
/// Identifier for transaction deletion confirmation [`Modal`].
|
||||
const DELETE_TX_CONFIRMATION_MODAL: &'static str = "delete_tx_conf_modal";
|
||||
|
||||
impl WalletContentContainer for WalletTransactionsContent {
|
||||
fn modal_ids(&self) -> Vec<&'static str> {
|
||||
vec![TX_INFO_MODAL, CANCEL_TX_CONFIRMATION_MODAL, DELETE_TX_CONFIRMATION_MODAL]
|
||||
@@ -78,13 +85,6 @@ impl WalletContentContainer for WalletTransactionsContent {
|
||||
}
|
||||
}
|
||||
|
||||
/// Identifier for transaction information [`Modal`].
|
||||
const TX_INFO_MODAL: &'static str = "tx_info_modal";
|
||||
/// Identifier for transaction cancellation confirmation [`Modal`].
|
||||
const CANCEL_TX_CONFIRMATION_MODAL: &'static str = "cancel_tx_conf_modal";
|
||||
/// Identifier for transaction deletion confirmation [`Modal`].
|
||||
const DELETE_TX_CONFIRMATION_MODAL: &'static str = "delete_tx_conf_modal";
|
||||
|
||||
impl WalletTransactionsContent {
|
||||
/// Height of transaction list item.
|
||||
pub const TX_ITEM_HEIGHT: f32 = 75.0;
|
||||
|
||||
@@ -28,6 +28,8 @@ use crate::gui::Colors;
|
||||
use crate::wallet::types::{WalletTask, WalletTx};
|
||||
use crate::wallet::Wallet;
|
||||
use crate::AppConfig;
|
||||
use crate::gui::views::types::ModalPosition;
|
||||
use crate::gui::views::wallets::wallet::message::MessageInputContent;
|
||||
|
||||
/// Transaction information [`Modal`] content.
|
||||
pub struct WalletTransactionContent {
|
||||
@@ -219,6 +221,8 @@ impl WalletTransactionContent {
|
||||
// Setup spacing between buttons.
|
||||
ui.spacing_mut().item_spacing = egui::Vec2::new(8.0, 0.0);
|
||||
|
||||
let mut finalization_needed = false;
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
// Draw button to show Slatepack message as QR code.
|
||||
@@ -232,7 +236,12 @@ impl WalletTransactionContent {
|
||||
let copy_text = format!("{} {}", COPY, t!("copy"));
|
||||
View::button(ui, copy_text, Colors::white_or_black(false), || {
|
||||
cb.copy_string_to_buffer(m.clone());
|
||||
Modal::close();
|
||||
// Show message input or close modal.
|
||||
if tx.can_finalize() {
|
||||
finalization_needed = true;
|
||||
} else {
|
||||
Modal::close();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -249,10 +258,22 @@ impl WalletTransactionContent {
|
||||
let name = format!("{}.{}.slatepack", slate_id, tx.state);
|
||||
let data = m.as_bytes().to_vec();
|
||||
cb.share_data(name, data).unwrap_or_default();
|
||||
Modal::close();
|
||||
// Show message input or close modal.
|
||||
if tx.can_finalize() {
|
||||
finalization_needed = true;
|
||||
} else {
|
||||
Modal::close();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if finalization_needed {
|
||||
Modal::new(MessageInputContent::MODAL_ID)
|
||||
.position(ModalPosition::Center)
|
||||
.title(t!("wallets.messages"))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user