Skip to content

Commit cb5b3ec

Browse files
committed
Add receive all and reply buttons + UI improvements
* Added receive all button in inbox UI that receives all non-messages. * Added a reply button when reading a message. * Made the accounts UI jump straight to highlighting the top account. * Automatically jump to message input when address is pre-filled. * Changed the location of the back button on the accounts UI to make navigation easier. * Added a gap between <Send> and <Back> in the send UI.
1 parent 3de083d commit cb5b3ec

File tree

8 files changed

+119
-81
lines changed

8 files changed

+119
-81
lines changed

src/app/components/accounts/ui/primary.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ pub fn show_accounts(s: &mut Cursive) {
1818
let prefix = data.coins[data.coin_idx].prefix.clone();
1919

2020
let mut buttons = LinearLayout::horizontal().child(DummyView);
21+
buttons.add_child(Button::new("Back", |s| {
22+
s.pop_layer();
23+
show_wallets(s);
24+
}));
25+
buttons.add_child(DummyView);
2126
if !wallet.mnemonic.is_empty() {
2227
buttons.add_child(Button::new("Show next", move |s| {
2328
add_account(s, None, &prefix);
@@ -35,12 +40,7 @@ pub fn show_accounts(s: &mut Cursive) {
3540
buttons.add_child(Button::new("Show index", add_index));
3641
buttons.add_child(DummyView);
3742
buttons.add_child(Button::new("Hide", hide_account));
38-
buttons.add_child(DummyView);
3943
}
40-
buttons.add_child(Button::new("Back", |s| {
41-
s.pop_layer();
42-
show_wallets(s);
43-
}));
4444

4545
let mut select = SelectView::<String>::new().on_submit(select_account);
4646

@@ -97,4 +97,5 @@ pub fn show_accounts(s: &mut Cursive) {
9797
)
9898
.title(wallet_name),
9999
);
100+
s.focus_name("accounts").unwrap();
100101
}

src/app/components/inbox/ui/primary.rs

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use crate::app::{
99
accounts::ui::primary::show_accounts,
1010
addressbook::ui::primary::show_addressbook,
1111
messages::{structs::Filter, ui::primary::show_messages},
12-
receive::{load::load_receivables, ui::primary::show_receivable},
12+
receive::{
13+
load::load_receivables, ui::primary::show_receivable, ui::process::process_receive,
14+
},
1315
send::ui::primary::show_send,
1416
},
1517
constants::EMPTY_MSG,
@@ -29,28 +31,6 @@ pub fn show_inbox(s: &mut Cursive) {
2931
let data: UserData = s.take_user_data().unwrap();
3032
let wallet = &data.wallets[data.wallet_idx];
3133
let address = wallet.accounts[wallet.acc_idx].address.clone();
32-
let buttons = LinearLayout::vertical()
33-
.child(Button::new("Refresh", load_receivables))
34-
.child(DummyView)
35-
.child(Button::new("Send", |s| show_send(s, false)))
36-
.child(DummyView)
37-
.child(Button::new("Messages log", |s| {
38-
let filter: Filter = Default::default();
39-
show_messages(s, filter);
40-
}))
41-
.child(Button::new("Address book", show_addressbook))
42-
.child(Button::new("Copy address", move |s| {
43-
copy_to_clip(s, address.clone())
44-
}))
45-
.child(Button::new("Change rep", show_change_rep))
46-
.child(DummyView)
47-
.child(Button::new("Back", show_accounts));
48-
49-
let select = SelectView::<String>::new()
50-
.on_submit(show_receivable)
51-
.with_name("select")
52-
.scrollable()
53-
.fixed_height(5);
5434

5535
let bal = display_to_dp(
5636
wallet.accounts[wallet.acc_idx].balance,
@@ -59,39 +39,18 @@ pub fn show_inbox(s: &mut Cursive) {
5939
&data.coins[data.coin_idx].ticker,
6040
);
6141
let bal_text = format!("Balance: {}", bal);
62-
let bal_content = TextView::new(StyledString::styled(
63-
bal_text,
64-
data.coins[data.coin_idx].colour,
65-
))
66-
.with_name("balance");
67-
s.add_layer(
68-
HideableView::new(
69-
Dialog::around(
70-
LinearLayout::horizontal()
71-
.child(
72-
LinearLayout::vertical()
73-
.child(DummyView)
74-
.child(bal_content)
75-
.child(DummyView)
76-
.child(
77-
Dialog::around(select)
78-
.padding_lrtb(1, 1, 1, 1)
79-
.title("Incoming"),
80-
),
81-
)
82-
.child(DummyView)
83-
.child(DummyView)
84-
.child(LinearLayout::vertical().child(DummyView).child(buttons)),
85-
)
86-
.title(format!("dagchat {}", VERSION)),
87-
)
88-
.with_name("hideable"),
42+
let top_content = LinearLayout::horizontal().child(
43+
TextView::new(StyledString::styled(
44+
bal_text,
45+
data.coins[data.coin_idx].colour,
46+
))
47+
.with_name("balance"),
8948
);
49+
let mut select = SelectView::<String>::new().on_submit(show_receivable);
9050

51+
let mut has_non_msg = false;
9152
if wallet.accounts[wallet.acc_idx].receivables.is_empty() {
92-
s.call_on_name("select", |view: &mut SelectView<String>| {
93-
view.add_item_str(EMPTY_MSG);
94-
});
53+
select.add_item_str(EMPTY_MSG);
9554
} else {
9655
for receivable in &wallet.accounts[wallet.acc_idx].receivables {
9756
let mut tag;
@@ -106,6 +65,8 @@ pub fn show_inbox(s: &mut Cursive) {
10665
);
10766
if receivable.message.is_some() {
10867
tag = format!("{} + Msg", tag);
68+
} else {
69+
has_non_msg = true;
10970
}
11071
}
11172
let mut source_parts: Vec<&str> = receivable.source.split('_').collect();
@@ -116,11 +77,57 @@ pub fn show_inbox(s: &mut Cursive) {
11677
receivable.source.get(0..11).unwrap()
11778
};
11879
tag = format!("{} > {}", addr, tag);
119-
s.call_on_name("select", |view: &mut SelectView<String>| {
120-
view.add_item_str(&tag)
121-
});
80+
select.add_item_str(&tag)
12281
}
12382
}
12483

84+
let mut receive_all =
85+
HideableView::new(Button::new("Receive all", |s| process_receive(s, 0, true)));
86+
if !has_non_msg {
87+
receive_all.set_visible(false);
88+
}
89+
let buttons = LinearLayout::vertical()
90+
.child(Button::new("Refresh", load_receivables))
91+
.child(DummyView)
92+
.child(Button::new("Send", |s| show_send(s, false)))
93+
.child(receive_all.with_name("receiveall"))
94+
.child(DummyView)
95+
.child(Button::new("Messages log", |s| {
96+
let filter: Filter = Default::default();
97+
show_messages(s, filter);
98+
}))
99+
.child(Button::new("Address book", show_addressbook))
100+
.child(Button::new("Copy address", move |s| {
101+
copy_to_clip(s, address.clone())
102+
}))
103+
.child(Button::new("Change rep", show_change_rep))
104+
.child(DummyView)
105+
.child(Button::new("Back", show_accounts));
106+
125107
s.set_user_data(data);
108+
s.add_layer(
109+
HideableView::new(
110+
Dialog::around(
111+
LinearLayout::horizontal()
112+
.child(
113+
LinearLayout::vertical()
114+
.child(DummyView)
115+
.child(top_content)
116+
.child(DummyView)
117+
.child(
118+
Dialog::around(
119+
select.with_name("select").scrollable().fixed_height(5),
120+
)
121+
.padding_lrtb(1, 1, 1, 1)
122+
.title("Incoming"),
123+
),
124+
)
125+
.child(DummyView)
126+
.child(DummyView)
127+
.child(LinearLayout::vertical().child(DummyView).child(buttons)),
128+
)
129+
.title(format!("dagchat {}", VERSION)),
130+
)
131+
.with_name("hideable"),
132+
);
126133
}

src/app/components/receive/ui/primary.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::process::process_receive;
22
use crate::app::components::messages::readmessage::read_message;
3+
use crate::app::components::send::ui::primary::show_send;
34
use crate::app::constants::colours::RED;
45
use crate::app::constants::EMPTY_MSG;
56
use crate::app::{
@@ -9,9 +10,9 @@ use crate::app::{
910
userdata::UserData,
1011
};
1112
use crate::crypto::conversions::display_to_dp;
12-
use cursive::views::{Dialog, DummyView, LinearLayout, SelectView, TextView};
13+
use cursive::views::{Dialog, DummyView, LinearLayout, SelectView, TextArea, TextView};
1314
use cursive::{
14-
traits::{Resizable, Scrollable},
15+
traits::{Nameable, Resizable, Scrollable},
1516
utils::markup::StyledString,
1617
Cursive,
1718
};
@@ -55,7 +56,8 @@ pub fn show_receivable(s: &mut Cursive, _name: &str) {
5556
plaintext = plaintext_res;
5657
message.plaintext = plaintext.clone();
5758
} else {
58-
plaintext = format!("Failed to read message. Error: {}", read_res.err().unwrap());
59+
plaintext =
60+
format!("Failed to read message. Error: {}", read_res.err().unwrap());
5961
receivable.message = None;
6062
}
6163
} else {
@@ -95,6 +97,7 @@ pub fn show_receivable(s: &mut Cursive, _name: &str) {
9597
let source_suffix = String::from('_') + source_parts.pop().unwrap();
9698

9799
let sender = receivable.source.clone();
100+
let sender2 = receivable.source.clone();
98101

99102
let from = if data.addressbook.contains_key(&source_suffix) {
100103
data.addressbook.get(&source_suffix).unwrap()
@@ -103,15 +106,21 @@ pub fn show_receivable(s: &mut Cursive, _name: &str) {
103106
};
104107
content.add_child(TextView::new(StyledString::styled("From", colour)));
105108
content.add_child(TextView::new(StyledString::styled(from, OFF_WHITE)).fixed_width(65));
106-
s.add_layer(
107-
Dialog::around(content)
108-
.button(receive_label, move |s| {
109-
process_receive(s, focus);
110-
})
111-
.button("Copy address", move |s| copy_to_clip(s, sender.clone()))
112-
.button("Back", go_back)
113-
.title(title),
114-
);
109+
let mut main_view = Dialog::around(content).button(receive_label, move |s| {
110+
process_receive(s, focus, false);
111+
});
112+
if receivable.message.is_some() {
113+
main_view.add_button("Reply", move |s| {
114+
s.pop_layer();
115+
s.pop_layer();
116+
s.add_layer(TextArea::new().content(&sender2).with_name("address"));
117+
show_send(s, true);
118+
});
119+
}
120+
main_view.add_button("Copy address", move |s| copy_to_clip(s, sender.clone()));
121+
main_view.add_button("Back", go_back);
122+
main_view.set_title(title);
123+
s.add_layer(main_view);
115124
}
116125
}
117126
}

src/app/components/receive/ui/process.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,30 @@ use crate::app::{
88
userdata::UserData,
99
};
1010
use crate::crypto::conversions::display_to_dp;
11-
use cursive::views::{Dialog, ProgressBar, SelectView, TextView};
11+
use cursive::views::{Button, Dialog, HideableView, ProgressBar, SelectView, TextView};
1212
use cursive::{traits::Resizable, utils::markup::StyledString, Cursive};
1313
use std::time::SystemTime;
1414

15-
pub fn process_receive(s: &mut Cursive, idx: usize) {
15+
pub fn process_receive(s: &mut Cursive, mut idx: usize, all: bool) {
1616
let data = &s.user_data::<UserData>().unwrap();
1717
let wallet = &data.wallets[data.wallet_idx];
1818
let account = &wallet.accounts[wallet.acc_idx];
1919
let private_key = account.private_key;
20+
if all {
21+
let non_msg_idx = account.receivables.iter().position(|r| r.message.is_none());
22+
if let Some(non_msg_idx) = non_msg_idx {
23+
idx = non_msg_idx;
24+
} else {
25+
s.set_autorefresh(false);
26+
s.call_on_name("receiveall", |view: &mut HideableView<Button>| {
27+
view.set_visible(false);
28+
})
29+
.unwrap();
30+
return;
31+
}
32+
}
2033
let receivable = &account.receivables[idx];
2134
let send_block_hash = receivable.hash.clone();
22-
2335
let amount = receivable.amount;
2436
let address = account.address.clone();
2537
let coin = data.coins[data.coin_idx].clone();
@@ -101,7 +113,12 @@ pub fn process_receive(s: &mut Cursive, idx: usize) {
101113
data.coins[data.coin_idx].colour,
102114
));
103115
s.pop_layer();
104-
s.pop_layer();
116+
if all {
117+
return process_receive(s, 0, all);
118+
} else {
119+
s.pop_layer();
120+
s.set_autorefresh(false);
121+
}
105122
if save_res.is_err() {
106123
s.add_layer(
107124
Dialog::info(StyledString::styled(save_res.err().unwrap(), RED))

src/app/components/send/ui/primary.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn show_send(s: &mut Cursive, with_message: bool) {
6262
let mut address_entry = TextArea::new();
6363
address_entry.set_cursor(address.len());
6464
let address_entry = address_entry
65-
.content(address)
65+
.content(&address)
6666
.with_name("address")
6767
.max_width(68);
6868

@@ -201,6 +201,7 @@ pub fn show_send(s: &mut Cursive, with_message: bool) {
201201
}
202202
process_send(s, raw, address, message);
203203
}))
204+
.child(DummyView)
204205
.child(Button::new("Back", show_inbox))
205206
.child(DummyView)
206207
.child(DummyView)
@@ -216,4 +217,7 @@ pub fn show_send(s: &mut Cursive, with_message: bool) {
216217
)
217218
.with_name("hideable"),
218219
);
220+
if !address.is_empty() && with_message {
221+
s.focus_name("message").unwrap();
222+
}
219223
}

src/app/components/settings/ui/primary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn show_settings(s: &mut Cursive) {
8181
})
8282
.unwrap();
8383
let test = test_work_server(&work_server_url);
84-
if let Ok(_) = test {
84+
if test.is_ok() {
8585
s.add_layer(Dialog::info(StyledString::styled(
8686
"Communicated successfully with work server.",
8787
colour,

src/app/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub const VERSION: &str = "v1.2.1";
1+
pub const VERSION: &str = "v1.3.0";
22
pub const SHOW_TO_DP: usize = 12;
33
pub const AUTHOR: &str = "derfarctor (Author)";
44
pub const AUTHOR_ADDR: &str = "_3kpznqbuzs3grswcqkzitd5fwky4s5cmyt76wru7kbenfwza7q9c1f1egzhm";

src/crypto/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn get_signed_block(
7777
&coin.network.send_thresh
7878
};
7979

80-
get_server_work(previous_hash, &threshold, &coin.network.work_server_url)?
80+
get_server_work(previous_hash, threshold, &coin.network.work_server_url)?
8181
}
8282
} else if work_type == WorkType::BOOMPOW {
8383
String::from("")

0 commit comments

Comments
 (0)