@@ -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}
0 commit comments