ui: clear button at message response, color text button, fix translation
This commit is contained in:
parent
7558eebc18
commit
49aeabf9d3
3 changed files with 91 additions and 60 deletions
|
@ -79,7 +79,7 @@ wallets:
|
||||||
parse_s3_slatepack_desc: 'Опубликуйте транзакцию для завершения отправки %{amount} ツ'
|
parse_s3_slatepack_desc: 'Опубликуйте транзакцию для завершения отправки %{amount} ツ'
|
||||||
resp_slatepack_err: 'Во время создания ответа произошла ошибка, проверьте входные данные:'
|
resp_slatepack_err: 'Во время создания ответа произошла ошибка, проверьте входные данные:'
|
||||||
resp_exists_err: 'Такая транзакция уже существует.'
|
resp_exists_err: 'Такая транзакция уже существует.'
|
||||||
create_request_desc: 'Cоздать запрос на получение или отправку средств:'
|
create_request_desc: 'Cоздать запрос на отправку или получение средств:'
|
||||||
send_request_desc: 'Вы создали запрос на отправку %{amount} ツ. Отправьте это сообщение получателю:'
|
send_request_desc: 'Вы создали запрос на отправку %{amount} ツ. Отправьте это сообщение получателю:'
|
||||||
send_slatepack_err: Во время создания запроса на отправку средств произошла ошибка, проверьте входные данные.
|
send_slatepack_err: Во время создания запроса на отправку средств произошла ошибка, проверьте входные данные.
|
||||||
invoice_desc: 'Вы создали запрос на получение %{amount} ツ. Отправьте это сообщение отправителю:'
|
invoice_desc: 'Вы создали запрос на получение %{amount} ツ. Отправьте это сообщение отправителю:'
|
||||||
|
|
|
@ -205,21 +205,41 @@ impl View {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw [`Button`] with specified background fill color.
|
/// Draw [`Button`] with specified background fill and text color.
|
||||||
pub fn button(ui: &mut egui::Ui, text: String, fill: Color32, action: impl FnOnce()) {
|
fn button_resp(ui: &mut egui::Ui, text: String, text_color: Color32, bg: Color32) -> Response {
|
||||||
let button_text = Self::ellipsize(text.to_uppercase(), 17.0, Colors::TEXT_BUTTON);
|
let button_text = Self::ellipsize(text.to_uppercase(), 17.0, text_color);
|
||||||
let br = Button::new(button_text)
|
Button::new(button_text)
|
||||||
.stroke(Self::DEFAULT_STROKE)
|
.stroke(Self::DEFAULT_STROKE)
|
||||||
.fill(fill)
|
.fill(bg)
|
||||||
.ui(ui)
|
.ui(ui)
|
||||||
.on_hover_cursor(CursorIcon::PointingHand);
|
.on_hover_cursor(CursorIcon::PointingHand)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Draw [`Button`] with specified background fill color and default text color.
|
||||||
|
pub fn button(ui: &mut egui::Ui, text: String, fill: Color32, action: impl FnOnce()) {
|
||||||
|
let br = Self::button_resp(ui, text, Colors::TEXT_BUTTON, fill);
|
||||||
if Self::touched(ui, br) {
|
if Self::touched(ui, br) {
|
||||||
(action)();
|
(action)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw [`Button`] with specified background fill color.
|
/// Draw [`Button`] with specified background fill color and text color.
|
||||||
pub fn button_ui(ui: &mut egui::Ui, text: String, fill: Color32, action: impl FnOnce(&mut egui::Ui)) {
|
pub fn colored_text_button(ui: &mut egui::Ui,
|
||||||
|
text: String,
|
||||||
|
text_color: Color32,
|
||||||
|
fill: Color32,
|
||||||
|
action: impl FnOnce()) {
|
||||||
|
let br = Self::button_resp(ui, text, text_color, fill);
|
||||||
|
if Self::touched(ui, br) {
|
||||||
|
(action)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Draw [`Button`] with specified background fill color and ui at callback.
|
||||||
|
pub fn button_ui(ui: &mut egui::Ui,
|
||||||
|
text: String,
|
||||||
|
fill: Color32,
|
||||||
|
action: impl FnOnce(&mut egui::Ui)) {
|
||||||
let button_text = Self::ellipsize(text.to_uppercase(), 17.0, Colors::TEXT_BUTTON);
|
let button_text = Self::ellipsize(text.to_uppercase(), 17.0, Colors::TEXT_BUTTON);
|
||||||
let br = Button::new(button_text)
|
let br = Button::new(button_text)
|
||||||
.stroke(Self::DEFAULT_STROKE)
|
.stroke(Self::DEFAULT_STROKE)
|
||||||
|
|
|
@ -194,7 +194,7 @@ impl WalletMessages {
|
||||||
let desc_text = if self.message_slate.is_none() {
|
let desc_text = if self.message_slate.is_none() {
|
||||||
t!("wallets.input_slatepack_desc")
|
t!("wallets.input_slatepack_desc")
|
||||||
} else {
|
} else {
|
||||||
let mut slate = self.message_slate.clone().unwrap();
|
let slate = self.message_slate.clone().unwrap();
|
||||||
let amount = amount_to_hr_string(slate.amount, true);
|
let amount = amount_to_hr_string(slate.amount, true);
|
||||||
match slate.state {
|
match slate.state {
|
||||||
SlateState::Standard1 => {
|
SlateState::Standard1 => {
|
||||||
|
@ -285,8 +285,8 @@ impl WalletMessages {
|
||||||
self.message_slate = None;
|
self.message_slate = None;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let clear_text = format!("{} {}", PROHIBIT, t!("modal.cancel"));
|
let cancel = format!("{} {}", PROHIBIT, t!("modal.cancel"));
|
||||||
View::button(ui, clear_text, Colors::BUTTON, || {
|
View::colored_text_button(ui, cancel, Colors::RED, Colors::BUTTON, || {
|
||||||
let slate = self.message_slate.clone().unwrap();
|
let slate = self.message_slate.clone().unwrap();
|
||||||
if let Some(tx) = wallet.tx_by_slate(&slate) {
|
if let Some(tx) = wallet.tx_by_slate(&slate) {
|
||||||
wallet.cancel(tx.data.id);
|
wallet.cancel(tx.data.id);
|
||||||
|
@ -297,8 +297,8 @@ impl WalletMessages {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let paste_text = format!("{} {}", CLIPBOARD_TEXT, t!("paste"));
|
let paste = format!("{} {}", CLIPBOARD_TEXT, t!("paste"));
|
||||||
View::button(ui, paste_text, Colors::BUTTON, || {
|
View::button(ui, paste, Colors::BUTTON, || {
|
||||||
let buf = cb.get_string_from_buffer();
|
let buf = cb.get_string_from_buffer();
|
||||||
let previous = self.message_edit.clone();
|
let previous = self.message_edit.clone();
|
||||||
self.message_edit = buf.clone();
|
self.message_edit = buf.clone();
|
||||||
|
@ -366,6 +366,19 @@ impl WalletMessages {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ui.add_space(12.0);
|
||||||
|
|
||||||
|
// Draw clear button on response.
|
||||||
|
if !self.response_edit.is_empty() && self.message_slate.is_some() {
|
||||||
|
let clear_text = format!("{} {}", BROOM, t!("clear"));
|
||||||
|
View::button(ui, clear_text, Colors::BUTTON, || {
|
||||||
|
self.message_error = None;
|
||||||
|
self.message_edit.clear();
|
||||||
|
self.response_edit.clear();
|
||||||
|
self.message_slate = None;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Draw setup of ability to post transaction with Dandelion.
|
// Draw setup of ability to post transaction with Dandelion.
|
||||||
|
@ -502,7 +515,7 @@ impl WalletMessages {
|
||||||
columns[0].vertical_centered_justified(|ui| {
|
columns[0].vertical_centered_justified(|ui| {
|
||||||
// Draw send request creation button.
|
// Draw send request creation button.
|
||||||
let send_text = format!("{} {}", UPLOAD, t!("wallets.send"));
|
let send_text = format!("{} {}", UPLOAD, t!("wallets.send"));
|
||||||
View::button(ui, send_text.clone(), Colors::BUTTON, || {
|
View::button(ui, send_text, Colors::BUTTON, || {
|
||||||
// Setup modal values.
|
// Setup modal values.
|
||||||
self.send_request = true;
|
self.send_request = true;
|
||||||
self.amount_edit = "".to_string();
|
self.amount_edit = "".to_string();
|
||||||
|
@ -518,7 +531,7 @@ impl WalletMessages {
|
||||||
columns[1].vertical_centered_justified(|ui| {
|
columns[1].vertical_centered_justified(|ui| {
|
||||||
// Draw invoice request creation button.
|
// Draw invoice request creation button.
|
||||||
let receive_text = format!("{} {}", DOWNLOAD, t!("wallets.receive"));
|
let receive_text = format!("{} {}", DOWNLOAD, t!("wallets.receive"));
|
||||||
View::button(ui, receive_text.clone(), Colors::BUTTON, || {
|
View::button(ui, receive_text, Colors::BUTTON, || {
|
||||||
// Setup modal values.
|
// Setup modal values.
|
||||||
self.send_request = false;
|
self.send_request = false;
|
||||||
self.amount_edit = "".to_string();
|
self.amount_edit = "".to_string();
|
||||||
|
@ -608,57 +621,55 @@ impl WalletMessages {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show modal buttons.
|
|
||||||
ui.add_space(12.0);
|
ui.add_space(12.0);
|
||||||
ui.scope(|ui| {
|
|
||||||
// Setup spacing between buttons.
|
|
||||||
ui.spacing_mut().item_spacing = egui::Vec2::new(6.0, 0.0);
|
|
||||||
|
|
||||||
ui.columns(2, |columns| {
|
// Setup spacing between buttons.
|
||||||
columns[0].vertical_centered_justified(|ui| {
|
ui.spacing_mut().item_spacing = egui::Vec2::new(6.0, 0.0);
|
||||||
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
|
|
||||||
self.amount_edit = "".to_string();
|
ui.columns(2, |columns| {
|
||||||
self.request_error = None;
|
columns[0].vertical_centered_justified(|ui| {
|
||||||
cb.hide_keyboard();
|
View::button(ui, t!("modal.cancel"), Colors::WHITE, || {
|
||||||
modal.close();
|
self.amount_edit = "".to_string();
|
||||||
});
|
self.request_error = None;
|
||||||
|
cb.hide_keyboard();
|
||||||
|
modal.close();
|
||||||
});
|
});
|
||||||
columns[1].vertical_centered_justified(|ui| {
|
});
|
||||||
// Button to create Slatepack message for request.
|
columns[1].vertical_centered_justified(|ui| {
|
||||||
View::button(ui, t!("continue"), Colors::WHITE, || {
|
// Button to create Slatepack message for request.
|
||||||
if let Ok(a) = amount_from_hr_string(self.amount_edit.as_str()) {
|
View::button(ui, t!("continue"), Colors::WHITE, || {
|
||||||
let message = if self.send_request {
|
if let Ok(a) = amount_from_hr_string(self.amount_edit.as_str()) {
|
||||||
wallet.send(a)
|
let message = if self.send_request {
|
||||||
} else {
|
wallet.send(a)
|
||||||
wallet.issue_invoice(a)
|
} else {
|
||||||
};
|
wallet.issue_invoice(a)
|
||||||
match message {
|
};
|
||||||
Ok(message) => {
|
match message {
|
||||||
self.request_edit = message;
|
Ok(message) => {
|
||||||
cb.hide_keyboard();
|
self.request_edit = message;
|
||||||
}
|
cb.hide_keyboard();
|
||||||
Err(err) => {
|
}
|
||||||
match err {
|
Err(err) => {
|
||||||
grin_wallet_libwallet::Error::NotEnoughFunds { .. } => {
|
match err {
|
||||||
let m = t!(
|
grin_wallet_libwallet::Error::NotEnoughFunds { .. } => {
|
||||||
|
let m = t!(
|
||||||
"wallets.pay_balance_error",
|
"wallets.pay_balance_error",
|
||||||
"amount" => self.amount_edit
|
"amount" => self.amount_edit
|
||||||
);
|
);
|
||||||
self.request_error = Some(MessageError::Other(m));
|
self.request_error = Some(MessageError::Other(m));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let m = t!("wallets.invoice_slatepack_err");
|
let m = t!("wallets.invoice_slatepack_err");
|
||||||
self.request_error = Some(MessageError::Other(m));
|
self.request_error = Some(MessageError::Other(m));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
self.request_error = Some(
|
|
||||||
MessageError::Other(t!("wallets.invoice_slatepack_err"))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
self.request_error = Some(
|
||||||
|
MessageError::Other(t!("wallets.invoice_slatepack_err"))
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -702,16 +713,16 @@ impl WalletMessages {
|
||||||
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
View::horizontal_line(ui, Colors::ITEM_STROKE);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show modal buttons.
|
|
||||||
ui.add_space(12.0);
|
ui.add_space(12.0);
|
||||||
|
|
||||||
// Setup spacing between buttons.
|
// Setup spacing between buttons.
|
||||||
ui.spacing_mut().item_spacing = egui::Vec2::new(6.0, 0.0);
|
ui.spacing_mut().item_spacing = egui::Vec2::new(6.0, 0.0);
|
||||||
|
|
||||||
ui.columns(2, |columns| {
|
ui.columns(2, |columns| {
|
||||||
columns[0].vertical_centered_justified(|ui| {
|
columns[0].vertical_centered_justified(|ui| {
|
||||||
// Button to cancel transaction.
|
// Button to cancel transaction.
|
||||||
let clear_text = format!("{} {}", PROHIBIT, t!("modal.cancel"));
|
let cancel = format!("{} {}", PROHIBIT, t!("modal.cancel"));
|
||||||
View::button(ui, clear_text, Colors::BUTTON, || {
|
View::colored_text_button(ui, cancel, Colors::RED, Colors::BUTTON, || {
|
||||||
if let Ok(slate) = wallet.parse_slatepack(self.request_edit.clone()) {
|
if let Ok(slate) = wallet.parse_slatepack(self.request_edit.clone()) {
|
||||||
if let Some(tx) = wallet.tx_by_slate(&slate) {
|
if let Some(tx) = wallet.tx_by_slate(&slate) {
|
||||||
wallet.cancel(tx.data.id);
|
wallet.cancel(tx.data.id);
|
||||||
|
|
Loading…
Reference in a new issue