1818#import < DMPasscode/DMPasscode.h>
1919#import " UIBAlertView.h"
2020#import " ContactList.h"
21+ #import " ContactListListener.h"
2122#import " ContactHelper.h"
2223#import " AccountActionButton.h"
2324#import < QuartzCore/QuartzCore.h>
3031#import " ChooseContactsViewController.h"
3132#import " ChooseContactDelegate.h"
3233
33- @interface SendViewController () <ScanDelegate, ExchangeListener, AddressListener, AmountViewDelegate, UITextFieldDelegate, HTAutocompleteDataSource, HTAutocompleteTextFieldDelegate, ChooseContactDelegate>
34+ @interface SendViewController () <ScanDelegate, ExchangeListener, AddressListener, AmountViewDelegate, UITextFieldDelegate, HTAutocompleteDataSource, HTAutocompleteTextFieldDelegate, ChooseContactDelegate, ContactListListener >
3435@end
3536
3637static double FEE = 10000 ;
3738
3839@implementation SendViewController {
3940 HTAutocompleteTextField* _addressField;
4041 AmountView* _amountView;
42+ UIButton* _contactButton;
4143 UILabel* _infoLabel;
4244 ChooseContactsViewController* _chooseContactsViewController;
4345 ScanNavigationController* _scanViewController;
@@ -57,12 +59,13 @@ - (id)init {
5759
5860- (id )initWithAddress : (NSString *)address amount : (NSString *)amount {
5961 if (self = [super initWithStyle: UITableViewStyleGrouped]) {
62+ _initAddress = address;
63+ _initAmount = amount;
6064 self.title = l10n (@" send" );
6165 Address* a = [AddressHelper instance ].defaultAddress ;
6266 [a addAddressListener: self ];
6367 [[ExchangeHelper instance ] addExchangeListener: self ];
64- _initAddress = address;
65- _initAmount = amount;
68+ [[ContactHelper instance ] addContactListListener: self ];
6669 }
6770 return self;
6871}
@@ -114,10 +117,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
114117 [scanButton addTarget: self action: @selector (scan: ) forControlEvents: UIControlEventTouchUpInside];
115118 [cell.contentView addSubview: scanButton];
116119
117- UIButton* contactButton = [[UIButton alloc ] initWithFrame: CGRectMake (self .view.frame.size.width - 82 , 14 , 32 , 32 )];
118- [contactButton setImage: [UIImage imageNamed: @" user" ] forState: UIControlStateNormal];
119- [contactButton addTarget: self action: @selector (chooseContact: ) forControlEvents: UIControlEventTouchUpInside];
120- [cell.contentView addSubview: contactButton ];
120+ _contactButton = [[UIButton alloc ] initWithFrame: CGRectMake (self .view.frame.size.width - 82 , 14 , 32 , 32 )];
121+ [_contactButton setImage: [UIImage imageNamed: @" user" ] forState: UIControlStateNormal];
122+ [_contactButton addTarget: self action: @selector (chooseContact: ) forControlEvents: UIControlEventTouchUpInside];
123+ [cell.contentView addSubview: _contactButton ];
121124
122125 _amountView = [[AmountView alloc ] initWithDelegate: self frame: CGRectMake (0 , 58 , self .view.frame.size.width, 60 )];
123126 _amountView.amountField .returnKeyType = UIReturnKeyNext;
@@ -196,6 +199,8 @@ - (void)updateFields {
196199 } else {
197200 [self setDefaultInfo ];
198201 }
202+
203+ _contactButton.enabled = [ContactHelper instance ].contacts .count > 0 ;
199204
200205 BTCAddress* addr = [BTCAddress addressWithBase58String: [self address ]];
201206 if (!error && addr != nil && [addr isPublicAddress ] && _satoshi > 0 ) {
@@ -317,6 +322,11 @@ - (void)choseContact:(Address *)contact {
317322 [_amountView becomeFirstResponder ];
318323}
319324
325+ #pragma mark - ContactListListener
326+ - (void )contactListChanged : (ContactList *)contactList {
327+ [self updateFields ];
328+ }
329+
320330
321331#pragma mark - Send TX
322332- (void )startSend {
0 commit comments