ui: do not show send button at 0 balance, empty txs message

This commit is contained in:
ardocrat 2024-05-01 04:49:48 +03:00
parent c0fd7cf0aa
commit 1c1e39045e
4 changed files with 75 additions and 44 deletions

View file

@ -22,7 +22,7 @@ wallets:
await_conf_amount: Awaiting confirmation
await_fin_amount: Awaiting finalization
locked_amount: Locked
txs_empty: 'To receive or send funds manually or through transport use %{message} or %{transport} buttons at the bottom of the screen, to change wallet settings press %{settings}.'
txs_empty: 'To receive funds manually or over transport use %{message} or %{transport} buttons at the bottom of the screen, to change wallet settings press %{settings} button.'
title: Wallets
create_desc: Create or import existing wallet from saved recovery phrase.
add: Add wallet

View file

@ -22,7 +22,7 @@ wallets:
await_conf_amount: Ожидает подтверждения
await_fin_amount: Ожидает завершения
locked_amount: Заблокировано
txs_empty: 'Для получения или отправки средств вручную или через транспорт используйте кнопки %{message} или %{transport} внизу экрана, для изменения настроек кошелька нажмите %{settings}.'
txs_empty: 'Для получения средств вручную или через транспорт используйте кнопки %{message} или %{transport} внизу экрана, для изменения настроек кошелька нажмите кнопку %{settings}.'
title: Кошельки
create_desc: Создайте или импортируйте существующий кошелёк из сохранённой фразы восстановления.
add: Добавить кошелёк
@ -113,7 +113,7 @@ wallets:
settings: Настройки кошелька
change_server_confirmation: Для применения изменения настроек соединения необходимо переоткрыть кошелёк. Переоткрыть его сейчас?
transport:
desc: 'Используйте транспорт для синхронного получения или отправки сообщений:'
desc: 'Используйте транспорт для синхронных получения или отправки сообщений:'
tor_network: Сеть Tor
connected: Подключено
connecting: Подключение

View file

@ -148,7 +148,7 @@ impl WalletMessages {
ui.add_space(3.0);
// Show creation of request to send or receive funds.
self.request_ui(ui, cb);
self.request_ui(ui, wallet, cb);
ui.add_space(12.0);
View::horizontal_line(ui, Colors::ITEM_STROKE);
@ -183,12 +183,16 @@ impl WalletMessages {
/// Draw creation of request to send or receive funds.
fn request_ui(&mut self,
ui: &mut egui::Ui,
wallet: &Wallet,
cb: &dyn PlatformCallbacks) {
ui.label(RichText::new(t!("wallets.create_request_desc"))
.size(16.0)
.color(Colors::INACTIVE_TEXT));
ui.add_space(7.0);
// Show send button only if balance is not empty.
let data = wallet.get_data().unwrap();
if data.info.amount_currently_spendable > 0 {
// Setup spacing between buttons.
ui.spacing_mut().item_spacing = egui::Vec2::new(6.0, 0.0);
@ -211,6 +215,17 @@ impl WalletMessages {
});
columns[1].vertical_centered_justified(|ui| {
// Draw invoice request creation button.
self.receive_button_ui(ui, cb);
});
});
} else {
// Draw invoice creation button.
self.receive_button_ui(ui, cb);
}
}
/// Draw invoice request creation button.
fn receive_button_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) {
let receive_text = format!("{} {}", DOWNLOAD_SIMPLE, t!("wallets.receive"));
View::button(ui, receive_text, Colors::BUTTON, || {
// Setup modal values.
@ -224,8 +239,6 @@ impl WalletMessages {
.show();
cb.show_keyboard();
});
});
});
}
/// Draw Slatepack message input content.

View file

@ -27,6 +27,7 @@ use crate::gui::views::types::{ModalPosition, TextEditOptions};
use crate::gui::views::wallets::wallet::types::{WalletTab, WalletTabType};
use crate::gui::views::wallets::wallet::WalletContent;
use crate::tor::Tor;
use crate::wallet::types::WalletData;
use crate::wallet::Wallet;
/// Wallet transport tab content.
@ -153,20 +154,24 @@ impl WalletTransport {
/// Draw Tor transport content.
fn tor_ui(&mut self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) {
let data = wallet.get_data().unwrap();
// Draw header content.
self.tor_header_ui(ui, wallet);
// Draw receive info content.
if wallet.slatepack_address().is_some() {
self.tor_receive_ui(ui, wallet, cb);
self.tor_receive_ui(ui, wallet, &data, cb);
}
// Draw send content.
if data.info.amount_currently_spendable > 0 {
self.tor_send_ui(ui, cb);
}
}
/// Draw Tor transport header content.
fn tor_header_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet) {
fn tor_header_ui(&self, ui: &mut egui::Ui, wallet: &Wallet) {
// Setup layout size.
let mut rect = ui.available_rect_before_wrap();
rect.set_height(78.0);
@ -245,7 +250,7 @@ impl WalletTransport {
}
/// Draw tor transport settings [`Modal`] content.
fn tor_settings_modal_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet, modal: &Modal) {
fn tor_settings_modal_ui(&self, ui: &mut egui::Ui, wallet: &Wallet, modal: &Modal) {
ui.add_space(6.0);
ui.vertical_centered(|ui| {
ui.label(RichText::new(t!("transport.tor_autorun_desc"))
@ -268,9 +273,14 @@ impl WalletTransport {
}
/// Draw Tor send content.
fn tor_receive_ui(&self, ui: &mut egui::Ui, wallet: &mut Wallet, cb: &dyn PlatformCallbacks) {
fn tor_receive_ui(&self,
ui: &mut egui::Ui,
wallet: &Wallet,
data: &WalletData,
cb: &dyn PlatformCallbacks) {
let slatepack_addr = wallet.slatepack_address().unwrap();
let service_id = &wallet.identifier();
let can_send = data.info.amount_currently_spendable > 0;
// Setup layout size.
let mut rect = ui.available_rect_before_wrap();
@ -278,13 +288,21 @@ impl WalletTransport {
// Draw round background.
let bg_rect = rect.clone();
let item_rounding = View::item_rounding(1, 3, false);
let item_rounding = if can_send {
View::item_rounding(1, 3, false)
} else {
View::item_rounding(1, 2, false)
};
ui.painter().rect(bg_rect, item_rounding, Colors::BUTTON, View::ITEM_STROKE);
ui.vertical(|ui| {
ui.allocate_ui_with_layout(rect.size(), Layout::right_to_left(Align::Center), |ui| {
// Draw button to setup Tor transport.
let button_rounding = View::item_rounding(1, 3, true);
let button_rounding = if can_send {
View::item_rounding(1, 3, true)
} else {
View::item_rounding(1, 2, true)
};
View::item_button(ui, button_rounding, QR_CODE, None, || {
//TODO: qr for address
});