Cw 744 improve address book (#1771)

* add sort function to contact list

* fix UI

* prevent duplicate contact names

* dispose contact source subscription

* fix custom order issue

* update the address book UI

* fix saving custom order

* fix merge conflict issue

* fix the address book filter by the selected currency

* add dropdown for wallets with multiple address types

* minor fixes

* add dropdown for wallets with multiple address types

* Update lib/entities/contact.dart [skip ci]

* Update lib/src/screens/contact/contact_list_page.dart [skip ci]

* Update lib/src/screens/contact/contact_list_page.dart [skip ci]

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii
2024-11-12 05:29:32 +02:00
committed by GitHub
co-authored by Omar Hatem
parent 2c37e427e9
commit 96db38c0aa
2 changed files with 75 additions and 22 deletions
@@ -28,7 +28,8 @@ abstract class ContactListViewModelBase with Store {
isAutoGenerateEnabled =
settingsStore.autoGenerateSubaddressStatus == AutoGenerateSubaddressStatus.enabled {
walletInfoSource.values.forEach((info) {
if ([WalletType.monero, WalletType.wownero, WalletType.haven].contains(info.type) && info.addressInfos != null) {
if ([WalletType.monero, WalletType.wownero, WalletType.haven].contains(info.type) &&
info.addressInfos != null) {
for (var key in info.addressInfos!.keys) {
final value = info.addressInfos![key];
final address = value?.first;
@@ -60,15 +61,19 @@ abstract class ContactListViewModelBase with Store {
address,
name,
walletTypeToCryptoCurrency(info.type,
isTestnet:
info.network == null ? false : info.network!.toLowerCase().contains("testnet")),
isTestnet: info.network == null
? false
: info.network!.toLowerCase().contains("testnet")),
));
});
}
} else {
walletContacts.add(WalletContact(
info.address,
_createName(info.name, "", key: [WalletType.monero, WalletType.wownero, WalletType.haven].contains(info.type) ? 0 : null),
_createName(info.name, "",
key: [WalletType.monero, WalletType.wownero, WalletType.haven].contains(info.type)
? 0
: null),
walletTypeToCryptoCurrency(info.type),
));
}
@@ -82,8 +87,11 @@ abstract class ContactListViewModelBase with Store {
}
String _createName(String walletName, String label, {int? key = null}) {
final actualLabel = label.replaceAll(RegExp(r'active', caseSensitive: false), S.current.active).replaceAll(RegExp(r'silent payments', caseSensitive: false), S.current.silent_payments);
return '$walletName${key == null ? "" : " [#${key}]"} ${actualLabel.isNotEmpty ? "($actualLabel)" : ""}'.trim();
final actualLabel = label
.replaceAll(RegExp(r'active', caseSensitive: false), S.current.active)
.replaceAll(RegExp(r'silent payments', caseSensitive: false), S.current.silent_payments);
return '$walletName${key == null ? "" : " [#${key}]"} ${actualLabel.isNotEmpty ? "($actualLabel)" : ""}'
.trim();
}
final bool isAutoGenerateEnabled;
@@ -108,18 +116,19 @@ abstract class ContactListViewModelBase with Store {
Future<void> delete(ContactRecord contact) async => contact.original.delete();
ObservableList<ContactRecord> get contactsToShow =>
ObservableList.of(contacts.where((element) => _isValidForCurrency(element)));
ObservableList.of(contacts.where((element) => _isValidForCurrency(element, false)));
@computed
List<WalletContact> get walletContactsToShow =>
walletContacts.where((element) => _isValidForCurrency(element)).toList();
walletContacts.where((element) => _isValidForCurrency(element, true)).toList();
bool _isValidForCurrency(ContactBase element) {
if (element.name.contains('Silent Payments')) return false;
if (element.name.contains('MWEB')) return false;
bool _isValidForCurrency(ContactBase element, bool isWalletContact) {
if (_currency == null) return true;
if (!element.name.contains('Active') &&
isWalletContact &&
(element.type == CryptoCurrency.btc || element.type == CryptoCurrency.ltc)) return false;
return _currency == null ||
element.type == _currency ||
return element.type == _currency ||
(element.type.tag != null &&
_currency?.tag != null &&
element.type.tag == _currency?.tag) ||