fix contact bug

This commit is contained in:
fosse 2023-08-21 15:01:33 -04:00
parent c5af031354
commit ad3ff94bcc
2 changed files with 14 additions and 11 deletions

View file

@ -238,6 +238,7 @@ abstract class NanoWalletBase
_isTransactionUpdating = true; _isTransactionUpdating = true;
final transactions = await fetchTransactions(); final transactions = await fetchTransactions();
transactionHistory.clear();
transactionHistory.addMany(transactions); transactionHistory.addMany(transactions);
await transactionHistory.save(); await transactionHistory.save();
_isTransactionUpdating = false; _isTransactionUpdating = false;

View file

@ -13,25 +13,29 @@ import 'package:cw_core/crypto_currency.dart';
part 'contact_list_view_model.g.dart'; part 'contact_list_view_model.g.dart';
class ContactListViewModel = ContactListViewModelBase class ContactListViewModel = ContactListViewModelBase with _$ContactListViewModel;
with _$ContactListViewModel;
abstract class ContactListViewModelBase with Store { abstract class ContactListViewModelBase with Store {
ContactListViewModelBase(this.contactSource, this.walletInfoSource, ContactListViewModelBase(
this._currency, this.settingsStore) this.contactSource, this.walletInfoSource, this._currency, this.settingsStore)
: contacts = ObservableList<ContactRecord>(), : contacts = ObservableList<ContactRecord>(),
walletContacts = [] { walletContacts = [] {
walletInfoSource.values.forEach((info) { walletInfoSource.values.forEach((info) {
if (info.addresses?.isNotEmpty ?? false) { if (info.addresses?.isNotEmpty ?? false) {
info.addresses?.forEach((address, label) { info.addresses?.forEach((address, label) {
final name = label.isNotEmpty ? info.name + ' ($label)' : info.name; final name = label.isNotEmpty ? info.name + ' ($label)' : info.name;
walletContacts.add(WalletContact( walletContacts.add(WalletContact(
address, address,
name, name,
walletTypeToCryptoCurrency(info.type), walletTypeToCryptoCurrency(info.type),
)); ));
}); });
} else if (info.address != null) {
walletContacts.add(WalletContact(
info.address,
info.name,
walletTypeToCryptoCurrency(info.type),
));
} }
}); });
@ -57,14 +61,12 @@ abstract class ContactListViewModelBase with Store {
Future<void> delete(ContactRecord contact) async => contact.original.delete(); Future<void> delete(ContactRecord contact) async => contact.original.delete();
@computed @computed
List<ContactRecord> get contactsToShow => contacts List<ContactRecord> get contactsToShow =>
.where((element) => _isValidForCurrency(element)) contacts.where((element) => _isValidForCurrency(element)).toList();
.toList();
@computed @computed
List<WalletContact> get walletContactsToShow => walletContacts List<WalletContact> get walletContactsToShow =>
.where((element) => _isValidForCurrency(element)) walletContacts.where((element) => _isValidForCurrency(element)).toList();
.toList();
bool _isValidForCurrency(ContactBase element) { bool _isValidForCurrency(ContactBase element) {
return _currency == null || element.type == _currency || element.type.title == _currency!.tag; return _currency == null || element.type == _currency || element.type.title == _currency!.tag;