ui: better check for wallet data emptiness

This commit is contained in:
ardocrat
2026-05-23 18:21:04 +03:00
parent 4aeda9c9dc
commit 4c4b6cd5dc
6 changed files with 52 additions and 25 deletions
@@ -133,11 +133,11 @@ impl WalletAccountContent {
/// Draw wallet account content.
fn account_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
// Check wallet data.
if wallet.get_data().is_none() {
let data = wallet.get_data();
if data.is_none() {
return;
}
let data = wallet.get_data().unwrap();
let data = data.unwrap();
let mut rect = ui.available_rect_before_wrap();
rect.set_height(75.0);
+11 -11
View File
@@ -32,7 +32,7 @@ use crate::gui::views::wallets::wallet::types::WalletContentContainer;
use crate::gui::views::wallets::wallet::{WalletSettingsContent, WalletTransactionsContent};
use crate::gui::views::{Content, Modal, View};
use crate::node::Node;
use crate::wallet::types::{ConnectionMethod, WalletTask};
use crate::wallet::types::{ConnectionMethod, WalletData, WalletTask};
use crate::wallet::{ExternalConnection, Wallet};
/// Wallet content.
@@ -131,7 +131,7 @@ impl WalletContentContainer for WalletContent {
.show_animated_inside(ui, !block_nav, |ui| {
let r = ui.available_rect_before_wrap();
View::max_width_ui(ui, Content::SIDE_PANEL_WIDTH * 1.3, |ui| {
self.tabs_ui(wallet, ui);
self.tabs_ui(wallet, data, ui);
});
let rect = {
let mut r = r.clone();
@@ -360,14 +360,13 @@ impl WalletContent {
}
/// Draw tab buttons at the bottom of the screen.
fn tabs_ui(&mut self, wallet: &Wallet, ui: &mut egui::Ui) {
fn tabs_ui(&mut self, wallet: &Wallet, data: Option<WalletData>, ui: &mut egui::Ui) {
ui.scope(|ui| {
// Setup spacing between tabs.
ui.style_mut().spacing.item_spacing = egui::vec2(View::TAB_ITEMS_PADDING, 0.0);
let has_wallet_data = wallet.get_data().is_some();
let can_send = if has_wallet_data {
wallet.get_data().unwrap().info.amount_currently_spendable > 0
let can_send = if let Some(data) = &data {
data.info.amount_currently_spendable > 0
} else {
false
};
@@ -381,7 +380,7 @@ impl WalletContent {
self.settings_content = None;
});
});
let active = if has_wallet_data { Some(false) } else { None };
let active = if data.is_some() { Some(false) } else { None };
columns[1].vertical_centered_justified(|ui| {
if wallet.invoice_creating() {
ui.add_space(4.0);
@@ -458,15 +457,17 @@ impl WalletContent {
/// Handle wallet task result.
fn handle_task_result(&mut self, wallet: &Wallet) {
let res = wallet.consume_task_result();
if res.is_none() || wallet.get_data().is_none() {
let data = wallet.get_data();
if res.is_none() || data.is_none() {
return;
}
let data = data.unwrap();
let (id, t) = res.unwrap();
match Modal::opened() {
None => {
// Show transaction modal on wallet task result.
if let Some(id) = id {
let tx = wallet.get_data().unwrap().tx_by_id(id);
let tx = data.tx_by_id(id);
if tx.is_some() {
self.txs_content = Some(WalletTransactionsContent::new(tx));
self.settings_content = None;
@@ -481,7 +482,6 @@ impl WalletContent {
// Setup calculated tx fee at modal.
if let Some(m) = self.send_content.as_mut() {
if m.max_calculating {
let data = wallet.get_data().unwrap();
let a = data.info.amount_currently_spendable;
let max = if f > a { 0 } else { a - f };
m.on_max_amount_calculated(max, f);
@@ -510,7 +510,7 @@ impl WalletContent {
}
}
} else if let Ok((id, _, _)) = res {
let tx = wallet.get_data().unwrap().tx_by_id(id);
let tx = data.tx_by_id(id);
if let Some(tx) = tx {
let mut tx_c = WalletTransactionsContent::new(Some(tx));
if let Ok(p) = serde_json::to_string_pretty(&proof) {
+9 -3
View File
@@ -80,6 +80,13 @@ impl SendRequestContent {
modal: &Modal,
cb: &dyn PlatformCallbacks,
) {
let data = wallet.get_data();
if data.is_none() {
Modal::close();
return;
}
let data = data.unwrap();
ui.add_space(6.0);
// Draw QR code scanner content if requested.
@@ -122,7 +129,6 @@ impl SendRequestContent {
}
ui.vertical_centered(|ui| {
let data = wallet.get_data().unwrap();
let amount = amount_to_hr_string(data.info.amount_currently_spendable, true);
let enter_text = t!("wallets.enter_amount_send","amount" => amount);
ui.label(RichText::new(enter_text).size(17.0).color(Colors::gray()));
@@ -158,7 +164,7 @@ impl SendRequestContent {
});
if calculate_max {
self.max_calculating = true;
let max = wallet.get_data().unwrap().info.amount_currently_spendable;
let max = data.info.amount_currently_spendable;
self.amount_edit = amount_to_hr_string(max, true);
}
ui.add_space(8.0);
@@ -196,7 +202,7 @@ impl SendRequestContent {
// Do not input amount more than balance.
if amount != 0 && self.amount_edit != amount_edit_before {
let fee = amount_from_hr_string(self.fee_edit.as_str()).unwrap_or(0);
let max = wallet.get_data().unwrap().info.amount_currently_spendable;
let max = data.info.amount_currently_spendable;
if amount > max || amount + fee > max {
self.max_calculating = true;
wallet.task(WalletTask::CalculateFee(max, 0));
@@ -104,10 +104,11 @@ impl WalletTransportContent {
/// Draw Tor transport header content.
fn tor_header_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet) {
let wallet_data = wallet.get_data();
if wallet_data.is_none() {
let data = wallet.get_data();
if data.is_none() {
return;
}
let data = data.unwrap();
let addr = wallet.slatepack_address().unwrap();
// Setup layout size.
@@ -115,7 +116,7 @@ impl WalletTransportContent {
rect.set_height(78.0);
// Draw round background.
let info = wallet.get_data().unwrap().info;
let info = data.info;
let awaiting_balance = info.amount_awaiting_confirmation > 0
|| info.amount_awaiting_finalization > 0
|| info.amount_locked > 0;
+18 -4
View File
@@ -115,7 +115,11 @@ impl WalletTransactionsContent {
/// Draw transactions content.
fn txs_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet) {
let data = wallet.get_data().unwrap();
let data = wallet.get_data();
if data.is_none() {
return;
}
let data = data.unwrap();
let config = wallet.get_config();
if data.txs.is_none() {
ui.centered_and_justified(|ui| {
@@ -177,7 +181,7 @@ impl WalletTransactionsContent {
.show_rows(ui, Self::TX_ITEM_HEIGHT, rows_size, |ui, row_range| {
ui.add_space(1.0);
View::max_width_ui(ui, Content::SIDE_PANEL_WIDTH * 1.3, |ui| {
self.tx_list_ui(ui, row_range, &wallet, txs);
self.tx_list_ui(ui, row_range, &wallet, &data, txs);
});
})
});
@@ -197,9 +201,9 @@ impl WalletTransactionsContent {
ui: &mut egui::Ui,
row_range: Range<usize>,
wallet: &Wallet,
data: &WalletData,
txs: Vec<&WalletTx>,
) {
let data = wallet.get_data().unwrap();
for index in row_range {
if index == txs.len() && ui.is_visible() {
// Load more txs when needed.
@@ -652,6 +656,11 @@ impl WalletTransactionsContent {
/// Confirmation [`Modal`] to cancel transaction.
fn cancel_confirmation_modal(&mut self, ui: &mut egui::Ui, wallet: &Wallet) {
let data = wallet.get_data();
if data.is_none() {
Modal::close();
return;
}
let data = wallet.get_data().unwrap();
let data_txs = data.txs.unwrap();
let txs = data_txs
@@ -721,7 +730,12 @@ impl WalletTransactionsContent {
/// Confirmation [`Modal`] to delete transaction.
fn delete_confirmation_modal(&mut self, ui: &mut egui::Ui, wallet: &Wallet) {
let data = wallet.get_data().unwrap();
let data = wallet.get_data();
if data.is_none() {
Modal::close();
return;
}
let data = data.unwrap();
let data_txs = data.txs.unwrap();
let txs = data_txs
.into_iter()
+7 -1
View File
@@ -300,6 +300,13 @@ impl WalletTransactionContent {
cb: &dyn PlatformCallbacks,
on_delete: impl FnOnce(u32),
) {
let data = wallet.get_data();
if data.is_none() {
Modal::close();
return;
}
let data = wallet.get_data().unwrap();
ui.add_space(6.0);
// Transaction item background setup.
let mut rect = ui.available_rect_before_wrap();
@@ -307,7 +314,6 @@ impl WalletTransactionContent {
let rounding = View::item_rounding(0, 2, false);
let bg = Colors::TRANSPARENT;
// Show transaction amount status and time.
let data = wallet.get_data().unwrap();
let on_click = (false, || {});
WalletTransactionsContent::tx_item_ui(ui, tx, rect, bg, rounding, &data, on_click, |ui| {
// Show button to delete transaction from database.